Uecko_ERP/modules/customers/src/web/components/editor/customer-basic-info-fields.tsx

135 lines
4.6 KiB
TypeScript
Raw Normal View History

2025-09-22 17:43:55 +00:00
import { TaxesMultiSelectField } from "@erp/core/components";
import { TextAreaField, TextField } from "@repo/rdx-ui/components";
import {
Card,
CardContent,
CardHeader,
CardTitle,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
RadioGroup,
RadioGroupItem,
} from "@repo/shadcn-ui/components";
import { useFormContext, useWatch } from "react-hook-form";
import { useTranslation } from "../../i18n";
2025-09-23 16:38:20 +00:00
import { CreateCustomerFormData } from "../../schemas";
2025-09-22 17:43:55 +00:00
export const CustomerBasicInfoFields = () => {
const { t } = useTranslation();
2025-09-23 16:38:20 +00:00
const { control } = useFormContext<CreateCustomerFormData>();
2025-09-22 17:43:55 +00:00
const isCompany = useWatch({
2025-09-23 11:48:19 +00:00
control,
2025-09-22 17:43:55 +00:00
name: "is_company",
defaultValue: "true",
});
return (
<Card className='border-0 shadow-none'>
<CardHeader>
<CardTitle>Identificación</CardTitle>
</CardHeader>
<CardContent>
<div className='grid grid-cols-1 gap-6 lg:grid-cols-4 mb-12 '>
<div className='lg:col-span-2'>
<TextField
control={control}
name='name'
required
label={t("form_fields.name.label")}
placeholder={t("form_fields.name.placeholder")}
description={t("form_fields.name.description")}
/>
</div>
<div className='lg:col-span-2'>
<FormField
control={control}
name='is_company'
render={({ field }) => (
<FormItem className='space-y-3'>
<FormLabel>{t("form_fields.customer_type.label")}</FormLabel>
<FormControl>
<RadioGroup
2025-09-23 11:48:19 +00:00
onValueChange={(value: string) => {
field.onChange(value === "false" ? "false" : "true");
}}
2025-09-22 17:43:55 +00:00
defaultValue={field.value ? "true" : "false"}
className='flex items-center gap-6'
>
<FormItem className='flex items-center space-x-2'>
<FormControl>
<RadioGroupItem id='rgi-company' value='true' />
</FormControl>
<FormLabel className='cursor-pointer' htmlFor='rgi-company'>
{t("form_fields.customer_type.company")}
</FormLabel>
</FormItem>
<FormItem className='flex items-center space-x-2'>
<FormControl>
<RadioGroupItem id='rgi-individual' value='false' />
</FormControl>
<FormLabel className='cursor-pointer' htmlFor='rgi-individual'>
{t("form_fields.customer_type.individual")}
</FormLabel>
</FormItem>
</RadioGroup>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{isCompany === "false" ? (
<div className='lg:col-span-full'>
<TextField
control={control}
name='trade_name'
label={t("form_fields.trade_name.label")}
placeholder={t("form_fields.trade_name.placeholder")}
description={t("form_fields.trade_name.description")}
/>
</div>
) : (
<></>
)}
<div className='lg:col-span-2 lg:col-start-1'>
<TextField
control={control}
name='reference'
label={t("form_fields.reference.label")}
placeholder={t("form_fields.reference.placeholder")}
description={t("form_fields.reference.description")}
/>
</div>
<div className='lg:col-span-2'>
<TaxesMultiSelectField
control={control}
name='default_taxes'
required
label={t("form_fields.default_taxes.label")}
placeholder={t("form_fields.default_taxes.placeholder")}
description={t("form_fields.default_taxes.description")}
/>
</div>
<TextAreaField
className='lg:col-span-full'
control={control}
name='legal_record'
label={t("form_fields.legal_record.label")}
placeholder={t("form_fields.legal_record.placeholder")}
description={t("form_fields.legal_record.description")}
/>
</div>
</CardContent>
</Card>
);
};