forked from rajun/ar-test
feat: add project form fields
This commit is contained in:
parent
b093803c2f
commit
69f9b9bc1e
55
app/components/projects/form/project-form-fields.tsx
Normal file
55
app/components/projects/form/project-form-fields.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import { useFormContext, useWatch } from 'react-hook-form';
|
||||
import { DialogBody } from '~/components/ui/dialog';
|
||||
import { Field } from '~/components/ui/field';
|
||||
import { Input } from '~/components/ui/input';
|
||||
import { SegmentedControl } from '~/components/ui/segmented-control';
|
||||
import { Textarea } from '~/components/ui/textarea';
|
||||
import { ArPageFields } from '~/components/projects/form/ar-page-fields';
|
||||
import { ButtonStyleFields } from '~/components/projects/form/button-style-fields';
|
||||
import { LogoBackgroundField } from '~/components/projects/form/logo-background-field';
|
||||
import { LogoField } from '~/components/projects/form/logo-field';
|
||||
import { PROJECT_STATUS_OPTIONS } from '~/data/projects/constants';
|
||||
import { useAdminData } from '~/hooks/admin/use-admin-data';
|
||||
import type { ProjectFormValues } from '~/schemas/projects/project-form';
|
||||
import type { BrandIdentity } from '~/types/project';
|
||||
|
||||
export function ProjectFormFields({ isEdit, brand }: { isEdit: boolean; brand: BrandIdentity }) {
|
||||
const { settings } = useAdminData();
|
||||
const { register, control, setValue, formState } = useFormContext<ProjectFormValues>();
|
||||
const status = useWatch({ control, name: 'status' });
|
||||
const { errors } = formState;
|
||||
|
||||
// relative: the switches' hidden inputs are positioned, and must stay inside this scroll area
|
||||
return (
|
||||
<DialogBody className='relative min-h-0 overflow-y-auto'>
|
||||
<Field label='Company name' htmlFor='project-name' error={errors.name?.message}>
|
||||
<Input id='project-name' placeholder='e.g. Oakline Interiors' aria-invalid={!!errors.name} {...register('name')} />
|
||||
</Field>
|
||||
|
||||
<LogoField brand={brand} />
|
||||
<LogoBackgroundField />
|
||||
<ArPageFields />
|
||||
{settings.brand_button && <ButtonStyleFields />}
|
||||
|
||||
<Field label='Description' htmlFor='project-description' requirement='optional'>
|
||||
<Textarea id='project-description' rows={2} placeholder='Internal note about this client' {...register('description')} />
|
||||
</Field>
|
||||
|
||||
{isEdit && (
|
||||
<Field
|
||||
label='Status'
|
||||
action={
|
||||
<SegmentedControl
|
||||
label='Status'
|
||||
size='sm'
|
||||
surface='sunken'
|
||||
value={status}
|
||||
options={PROJECT_STATUS_OPTIONS}
|
||||
onChange={(value) => setValue('status', value, { shouldDirty: true })}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</DialogBody>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user