From 8302d0735349b2c4897e8e14b9481226ca7c9c69 Mon Sep 17 00:00:00 2001 From: Chinedu Olebu Date: Tue, 12 Nov 2024 11:15:30 -0800 Subject: [PATCH] chore(3314): enforce distinct PO and TL idir --- app/package-lock.json | 6 +++--- app/validation-schemas/private-cloud.ts | 21 ++++++++++++++++++--- app/validation-schemas/public-cloud.ts | 22 +++++++++++++++++++--- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 79f1f7ce6..d116e6819 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -12609,9 +12609,9 @@ } }, "node_modules/react-hook-form": { - "version": "7.53.1", - "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.53.1.tgz", - "integrity": "sha512-6aiQeBda4zjcuaugWvim9WsGqisoUk+etmFEsSUMm451/Ic8L/UAb7sRtMj3V+Hdzm6mMjU1VhiSzYUZeBm0Vg==", + "version": "7.53.2", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.53.2.tgz", + "integrity": "sha512-YVel6fW5sOeedd1524pltpHX+jgU2u3DSDtXEaBORNdqiNrsX/nUI/iGXONegttg0mJVnfrIkiV0cmTU6Oo2xw==", "license": "MIT", "engines": { "node": ">=18.0.0" diff --git a/app/validation-schemas/private-cloud.ts b/app/validation-schemas/private-cloud.ts index 0423efa1d..058d832e7 100644 --- a/app/validation-schemas/private-cloud.ts +++ b/app/validation-schemas/private-cloud.ts @@ -146,9 +146,24 @@ const _privateCloudEditRequestBodySchema = _privateCloudCreateRequestBodySchema. }), ); -export const privateCloudEditRequestBodySchema = _privateCloudEditRequestBodySchema.refine(isEmailUnique, { - message: 'Project Owner and Primary Technical Lead must not have the same email.', -}); +export const privateCloudEditRequestBodySchema = _privateCloudEditRequestBodySchema + .merge( + z.object({ + isAgMinistryChecked: z.boolean().optional(), + }), + ) + .refine( + (formData) => { + return AGMinistries.includes(formData.ministry) ? formData.isAgMinistryChecked : true; + }, + { + message: 'AG Ministry Checkbox should be checked.', + path: ['isAgMinistryChecked'], + }, + ) + .refine(isEmailUnique, { + message: 'Project Owner and Primary Technical Lead must not have the same email.', + }); export const privateCloudRequestDecisionBodySchema = _privateCloudEditRequestBodySchema.merge( z.object({ diff --git a/app/validation-schemas/public-cloud.ts b/app/validation-schemas/public-cloud.ts index 39f140ef8..4afd12c4c 100644 --- a/app/validation-schemas/public-cloud.ts +++ b/app/validation-schemas/public-cloud.ts @@ -102,9 +102,25 @@ const _publicCloudEditRequestBodySchema = _publicCloudCreateRequestBodySchema.me }), ); -export const publicCloudEditRequestBodySchema = _publicCloudEditRequestBodySchema.refine(isEmailUnique, { - message: 'Project Owner and Primary Technical Lead must not have the same email.', -}); +export const publicCloudEditRequestBodySchema = _publicCloudEditRequestBodySchema + .merge( + z.object({ + isAgMinistryChecked: z.boolean().optional(), + isEaApproval: z.boolean().optional(), + }), + ) + .refine( + (formData) => { + return AGMinistries.includes(formData.ministry) ? formData.isAgMinistryChecked : true; + }, + { + message: 'AG Ministry Checkbox should be checked.', + path: ['isAgMinistryChecked'], + }, + ) + .refine(isEmailUnique, { + message: 'Project Owner and Primary Technical Lead must not have the same email.', + }); export const publicCloudRequestDecisionBodySchema = _publicCloudEditRequestBodySchema.merge( z.object({