From 3485435a3e3c1a068099cb663a931d14c55c0b8f Mon Sep 17 00:00:00 2001 From: Bhavya Jain Date: Tue, 26 Nov 2024 15:18:33 +0530 Subject: [PATCH] group required and optional --- .../assets/custom-fields-inputs.tsx | 69 +++++++++++++++---- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/app/components/assets/custom-fields-inputs.tsx b/app/components/assets/custom-fields-inputs.tsx index 3b5ad0175..3fe04106a 100644 --- a/app/components/assets/custom-fields-inputs.tsx +++ b/app/components/assets/custom-fields-inputs.tsx @@ -196,6 +196,25 @@ export default function AssetCustomFields({ ); }, }; + const requiredFields = customFields.filter((field) => field.required); + const optionalFields = customFields.filter((field) => !field.required); + type JsonifyObject = { + [K in keyof T]: T[K] extends Date + ? string // Dates are converted to strings in JSON + : T[K] extends object + ? JsonifyObject // Recursively apply to nested objects + : T[K]; + }; + + function convertJsonifiedCustomField( + field: JsonifyObject + ): CustomField { + return { + ...field, + createdAt: new Date(field.createdAt), + updatedAt: new Date(field.updatedAt), + }; + } return (
@@ -208,15 +227,9 @@ export default function AssetCustomFields({ Manage custom fields
- {customFields.length > 0 ? ( - customFields.map((field, index) => { - const value = customFieldsValues?.find( - (cfv) => cfv.customFieldId === field.id - )?.value; - const displayVal = value - ? (getCustomFieldDisplayValue(value) as string) - : ""; - return ( +
+

Required Fields

+ {requiredFields.map((field, index) => ( - {typeof fieldTypeToCompMap[field.type] === "function" ? ( - fieldTypeToCompMap[field.type]!(field as unknown as CustomField) - ) : ( + {fieldTypeToCompMap[field.type]?.(convertJsonifiedCustomField(field)) ?? ( )} - ); - }) + ))} +
+ {customFields.length > 0 ? ( +
+

Optional Fields

+ {optionalFields.map((field, index) => ( + {field.helpText}

: undefined} + className="border-b-0" + required={field.required} + > + {fieldTypeToCompMap[field.type]?.(convertJsonifiedCustomField(field)) ?? ( + + )} +
+ ))} +
) : (