refactor(FE-114): improve validation messages and update layout for better responsiveness

This commit is contained in:
rstubryan
2025-10-20 13:10:41 +07:00
parent c64ff527dd
commit ba9ae07455
2 changed files with 105 additions and 94 deletions
@@ -52,7 +52,7 @@ export const RecordingFormSchema = Yup.object({
feed_qty: Yup.mixed<number | ''>().notRequired(), feed_qty: Yup.mixed<number | ''>().notRequired(),
feed_stock: Yup.number() feed_stock: Yup.number()
.required('Jumlah pakan yang digunakan wajib diisi!') .required('Jumlah pakan yang digunakan wajib diisi!')
.min(1, 'Jumlah pakan minimal 1 kg!') .min(1, 'Jumlah pakan minimal 1!')
.typeError('Jumlah pakan yang digunakan harus berupa angka!') .typeError('Jumlah pakan yang digunakan harus berupa angka!')
.test( .test(
'is-not-exceed-qty', 'is-not-exceed-qty',
@@ -60,7 +60,12 @@ export const RecordingFormSchema = Yup.object({
function (value) { function (value) {
const { feed_qty } = this.parent; const { feed_qty } = this.parent;
if (value === undefined) return true; if (value === undefined) return true;
if (feed_qty === undefined || feed_qty === '' || typeof feed_qty !== 'number') return true; if (
feed_qty === undefined ||
feed_qty === '' ||
typeof feed_qty !== 'number'
)
return true;
return value <= feed_qty; return value <= feed_qty;
} }
), ),
@@ -102,7 +107,12 @@ export const RecordingFormSchema = Yup.object({
function (value) { function (value) {
const { total_stock } = this.parent; const { total_stock } = this.parent;
if (value === undefined) return true; if (value === undefined) return true;
if (total_stock === undefined || total_stock === '' || typeof total_stock !== 'number') return true; if (
total_stock === undefined ||
total_stock === '' ||
typeof total_stock !== 'number'
)
return true;
return value <= total_stock; return value <= total_stock;
} }
), ),
@@ -477,7 +477,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
return ( return (
<> <>
<section className='w-full max-w-5xl'> <section className='w-full'>
<FormHeader type={type} title='Recording' backUrl='/flock/recording' /> <FormHeader type={type} title='Recording' backUrl='/flock/recording' />
<form <form
onSubmit={formik.handleSubmit} onSubmit={formik.handleSubmit}
@@ -488,8 +488,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
<div className='card-body flex flex-col gap-6'> <div className='card-body flex flex-col gap-6'>
<h2 className='card-title'>Recording Information</h2> <h2 className='card-title'>Recording Information</h2>
<div className='flex flex-col gap-6'> <div className='grid grid-cols-1 md:grid-cols-2 gap-6'>
<div className='flex gap-4'>
<SelectInput <SelectInput
required required
label='Lokasi' label='Lokasi'
@@ -534,9 +533,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
errorMessage={formik.errors.recording_date as string} errorMessage={formik.errors.recording_date as string}
readOnly={type === 'detail'} readOnly={type === 'detail'}
/> />
</div>
<div className='flex gap-4'>
<SelectInput <SelectInput
required required
label='Flock' label='Flock'
@@ -580,7 +577,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
</div> </div>
</div> </div>
</div> </div>
</div>
{/* Feed Data Table */} {/* Feed Data Table */}
<div className='card bg-base-100 shadow mb-4'> <div className='card bg-base-100 shadow mb-4'>
@@ -689,7 +685,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
isDisabled={type === 'detail'} isDisabled={type === 'detail'}
isClearable isClearable
className={{ className={{
wrapper: 'w-full min-w-24', wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}} }}
/> />
</td> </td>
@@ -1074,7 +1071,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
productWarehouseId as number productWarehouseId as number
) ?? '') ) ?? '')
: ''; : '';
formik.setFieldValue( formik.setFieldValue(
`vaccination.${idx}.vaccine`, `vaccination.${idx}.vaccine`,
val val
@@ -1111,7 +1107,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
isDisabled={type === 'detail'} isDisabled={type === 'detail'}
isClearable isClearable
className={{ className={{
wrapper: 'w-full min-w-24', wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}} }}
/> />
</td> </td>
@@ -1306,6 +1303,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
options={RECORDING_FLAG_OPTIONS} options={RECORDING_FLAG_OPTIONS}
isDisabled={type === 'detail'} isDisabled={type === 'detail'}
isClearable isClearable
className={{
wrapper:
'w-full min-w-52 md:min-w-72 lg:min-w-80',
}}
/> />
</td> </td>
<td> <td>