From ba09ecb91ef1b205308ea51025ead6c4d1f7a3f6 Mon Sep 17 00:00:00 2001 From: Asharon Baltazar Date: Wed, 22 Jan 2025 20:01:16 -0500 Subject: [PATCH] fix: hide errors pertaining to individual files when upload subsequent docs --- react-app/src/components/ActionForm/index.tsx | 2 +- .../upload-subsequent-documents/index.tsx | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/react-app/src/components/ActionForm/index.tsx b/react-app/src/components/ActionForm/index.tsx index 77dee40f78..b1dfe0198d 100644 --- a/react-app/src/components/ActionForm/index.tsx +++ b/react-app/src/components/ActionForm/index.tsx @@ -39,7 +39,7 @@ type EnforceSchemaProps = z.ZodObject< attachments?: z.ZodObject<{ [Key in keyof Shape]: z.ZodObject<{ label: z.ZodDefault; - files: z.ZodTypeAny; + files: z.ZodArray | z.ZodOptional>; }>; }>; }, diff --git a/react-app/src/features/forms/post-submission/upload-subsequent-documents/index.tsx b/react-app/src/features/forms/post-submission/upload-subsequent-documents/index.tsx index 184ea0fa99..cf7360d428 100644 --- a/react-app/src/features/forms/post-submission/upload-subsequent-documents/index.tsx +++ b/react-app/src/features/forms/post-submission/upload-subsequent-documents/index.tsx @@ -26,13 +26,18 @@ const pickAttachmentsAndAdditionalInfo = ( const shape = schema._def.shape(); const optionalAttachmentsShape = Object.fromEntries( - Object.entries(shape.attachments.shape).map(([key, value]) => [ - key, - z.object({ - files: value._def.shape().files.optional(), - label: value._def.shape().label, - }), - ]), + Object.entries(shape.attachments.shape).map(([key, value]) => { + const files = value._def.shape().files; + const filesArray = files instanceof z.ZodArray ? files : files.unwrap(); + + return [ + key, + z.object({ + files: z.array(filesArray.element).optional(), + label: value._def.shape().label, + }), + ]; + }), ); return z