Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat]: Group the custom fields by required and optional on asset create/edit #1454

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 93 additions & 34 deletions app/components/assets/custom-fields-inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,40 +209,99 @@ export default function AssetCustomFields({
</Link>
</div>
{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 (
<FormRow
key={field.id + index}
rowLabel={field.name}
subHeading={field.helpText ? <p>{field.helpText}</p> : undefined}
className="border-b-0"
required={field.required}
>
{typeof fieldTypeToCompMap[field.type] === "function" ? (
fieldTypeToCompMap[field.type]!(field as unknown as CustomField)
) : (
<Input
hideLabel
placeholder={field.helpText || undefined}
type={field.type.toLowerCase()}
label={field.name}
name={`cf-${field.id}`}
error={zo.errors[`cf-${field.id}`]()?.message}
disabled={disabled}
defaultValue={displayVal}
className="w-full"
required={zodFieldIsRequired(schema.shape[`cf-${field.id}`])}
/>
)}
</FormRow>
);
})
<>
<div>
<h3 className="mb-4 text-lg font-medium">Required Fields</h3>
{customFields
.filter((field) => field.required)
.map((field, index) => {
const value = customFieldsValues?.find(
(cfv) => cfv.customFieldId === field.id
)?.value;
const displayVal = value
? (getCustomFieldDisplayValue(value) as string)
: "";
return (
<FormRow
key={field.id + index}
rowLabel={field.name}
subHeading={
field.helpText ? <p>{field.helpText}</p> : undefined
}
className="border-b-0"
required={field.required}
>
{typeof fieldTypeToCompMap[field.type] === "function" ? (
fieldTypeToCompMap[field.type]!(
field as unknown as CustomField
)
) : (
<Input
hideLabel
placeholder={field.helpText || undefined}
type={field.type.toLowerCase()}
label={field.name}
name={`cf-${field.id}`}
error={zo.errors[`cf-${field.id}`]()?.message}
disabled={disabled}
defaultValue={displayVal}
className="w-full"
required={zodFieldIsRequired(
schema.shape[`cf-${field.id}`]
)}
/>
)}
</FormRow>
);
})}
</div>
<hr className="my-6 border-gray-300" />
<div>
<h3 className="mb-4 text-lg font-medium">Optional Fields</h3>
{customFields
.filter((field) => !field.required)
.map((field, index) => {
const value = customFieldsValues?.find(
(cfv) => cfv.customFieldId === field.id
)?.value;
const displayVal = value
? (getCustomFieldDisplayValue(value) as string)
: "";
return (
<FormRow
key={field.id + index}
rowLabel={field.name}
subHeading={
field.helpText ? <p>{field.helpText}</p> : undefined
}
className="border-b-0"
required={field.required}
>
{typeof fieldTypeToCompMap[field.type] === "function" ? (
fieldTypeToCompMap[field.type]!(
field as unknown as CustomField
)
) : (
<Input
hideLabel
placeholder={field.helpText || undefined}
type={field.type.toLowerCase()}
label={field.name}
name={`cf-${field.id}`}
error={zo.errors[`cf-${field.id}`]()?.message}
disabled={disabled}
defaultValue={displayVal}
className="w-full"
required={zodFieldIsRequired(
schema.shape[`cf-${field.id}`]
)}
/>
)}
</FormRow>
);
})}
</div>
</>
) : (
<div>
<div className=" mx-auto max-w-screen-sm rounded-xl border border-gray-300 bg-white px-5 py-10 text-center">
Expand Down