diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index bcf3a0cf..8c166700 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -31,6 +31,7 @@ import { ProjectFlock } from '@/types/api/production/project-flock'; import { Warehouse } from '@/types/api/master-data/warehouse'; import { LocationApi } from '@/services/api/master-data'; import FieldMessage from '@/components/helper/FieldMessage'; +import Card from '@/components/Card'; interface RecordingFormProps { type?: 'add' | 'edit' | 'detail'; @@ -634,463 +635,521 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { className='w-full mt-8 flex flex-col gap-6' > {/* Basic Info Card */} -
-
-

Informasi Recording

+ +
+ { + locationChangeHandler(val); + setTimeout(() => { + formik.setFieldTouched('location', true); + formik.setFieldTouched('location_id', true); + }, 0); + }} + options={locationOptions} + onInputChange={setLocationSelectInputValue} + isLoading={isLoadingLocations} + isError={ + formik.touched.location_id && + Boolean(formik.errors.location_id) + } + errorMessage={formik.errors.location_id as string} + isDisabled={type === 'detail'} + isClearable + placeholder='Pilih lokasi terlebih dahulu' + /> -
- { - locationChangeHandler(val); - setTimeout(() => { - formik.setFieldTouched('location', true); - formik.setFieldTouched('location_id', true); - }, 0); - }} - options={locationOptions} - onInputChange={setLocationSelectInputValue} - isLoading={isLoadingLocations} - isError={ - formik.touched.location_id && - Boolean(formik.errors.location_id) - } - errorMessage={formik.errors.location_id as string} - isDisabled={type === 'detail'} - isClearable - placeholder='Pilih lokasi terlebih dahulu' - /> + { + const date = e.target.value ? new Date(e.target.value) : null; + formik.setFieldValue('recording_date', date); + }} + onBlur={formik.handleBlur} + isError={ + formik.touched.recording_date && + Boolean(formik.errors.recording_date) + } + errorMessage={formik.errors.recording_date as string} + readOnly={type === 'detail'} + /> - { - const date = e.target.value - ? new Date(e.target.value) - : null; - formik.setFieldValue('recording_date', date); - }} - onBlur={formik.handleBlur} - isError={ - formik.touched.recording_date && - Boolean(formik.errors.recording_date) - } - errorMessage={formik.errors.recording_date as string} - readOnly={type === 'detail'} - /> + { + flockChangeHandler(val); + setTimeout(() => { + formik.setFieldTouched('flock', true); + formik.setFieldTouched('flock_id', true); + }, 0); + }} + options={flockOptions} + onInputChange={setFlockSelectInputValue} + isLoading={isLoadingFlocks} + isError={ + formik.touched.flock_id && Boolean(formik.errors.flock_id) + } + errorMessage={formik.errors.flock_id as string} + isDisabled={type === 'detail' || !formik.values.location_id} + isClearable + placeholder={ + !formik.values.location_id + ? 'Pilih lokasi terlebih dahulu' + : 'Pilih Flock' + } + /> - { - flockChangeHandler(val); - setTimeout(() => { - formik.setFieldTouched('flock', true); - formik.setFieldTouched('flock_id', true); - }, 0); - }} - options={flockOptions} - onInputChange={setFlockSelectInputValue} - isLoading={isLoadingFlocks} - isError={ - formik.touched.flock_id && Boolean(formik.errors.flock_id) - } - errorMessage={formik.errors.flock_id as string} - isDisabled={type === 'detail' || !formik.values.location_id} - isClearable - placeholder={ - !formik.values.location_id - ? 'Pilih lokasi terlebih dahulu' - : 'Pilih Flock' - } - /> - - { - coopChangeHandler(val); - setTimeout(() => { - formik.setFieldTouched('coop', true); - formik.setFieldTouched('coop_id', true); - }, 0); - }} - options={coopOptions} - isError={ - formik.touched.coop_id && Boolean(formik.errors.coop_id) - } - errorMessage={formik.errors.coop_id as string} - isDisabled={type === 'detail' || !selectedProjectFlock} - isClearable - placeholder={ - !selectedProjectFlock - ? 'Pilih flock terlebih dahulu' - : 'Pilih Kandang' - } - /> -
+ { + coopChangeHandler(val); + setTimeout(() => { + formik.setFieldTouched('coop', true); + formik.setFieldTouched('coop_id', true); + }, 0); + }} + options={coopOptions} + isError={ + formik.touched.coop_id && Boolean(formik.errors.coop_id) + } + errorMessage={formik.errors.coop_id as string} + isDisabled={type === 'detail' || !selectedProjectFlock} + isClearable + placeholder={ + !selectedProjectFlock + ? 'Pilih flock terlebih dahulu' + : 'Pilih Kandang' + } + />
-
+ {/* Feed Data Table */} -
-
-

Data Pakan

-
- - - - {type !== 'detail' && ( - + ))} + +
-
- 0 + +
+ + + + {type !== 'detail' && ( + + )} + + + + {type !== 'detail' && } + + + + {formik.values.feed_data?.map((feed, idx) => ( + + {type !== 'detail' && ( + )} - - - - {type !== 'detail' && } - - - - {formik.values.feed_data?.map((feed, idx) => ( - - {type !== 'detail' && ( - - )} - + }, 0); + }} + options={pakanOptions} + isLoading={isLoadingPakan} + isError={ + isRepeaterInputError('feed_data', 'feed_id', idx) + .isError + } + errorMessage={ + isRepeaterInputError('feed_data', 'feed_id', idx) + .errorMessage + } + isDisabled={type === 'detail'} + isClearable + className={{ + wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80', + }} + /> + + + + {type !== 'detail' && ( - - {type !== 'detail' && ( - - )} - - ))} - -
+
+ 0 + } + onChange={(e) => { + if (e.target.checked) { + setSelectedFeed( + formik.values.feed_data?.map( + (_, idx) => idx + ) ?? [] + ); + } else { + setSelectedFeed([]); } + }} + naked={true} + size='sm' + /> +
+
+ Nama Pakan + + * + + Total Stock pada saat ini + Jumlah Stock yang digunakan + + * + + Action
+
+ { if (e.target.checked) { - setSelectedFeed( - formik.values.feed_data?.map( - (_, idx) => idx - ) ?? [] - ); + setSelectedFeed([...selectedFeed, idx]); } else { - setSelectedFeed([]); + setSelectedFeed( + selectedFeed.filter((i) => i !== idx) + ); } }} naked={true} size='sm' /> +
- +
- Nama Pakan - - * - - Total Stock pada saat ini - Jumlah Stock yang digunakan - - * - - Action
-
- { - if (e.target.checked) { - setSelectedFeed([...selectedFeed, idx]); - } else { - setSelectedFeed( - selectedFeed.filter((i) => i !== idx) - ); - } - }} - naked={true} - size='sm' - /> - -
-
- - Number(opt.value) === Number(feed.feed_id) - ) ?? null - } - onChange={(val) => { - const productWarehouseId = - (val as OptionType)?.value ?? 0; - const stock = productWarehouseId - ? (pakanStockMap.get( - productWarehouseId as number - ) ?? '') - : ''; + + + Number(opt.value) === Number(feed.feed_id) + ) ?? null + } + onChange={(val) => { + const productWarehouseId = + (val as OptionType)?.value ?? 0; + const stock = productWarehouseId + ? (pakanStockMap.get( + productWarehouseId as number + ) ?? '') + : ''; - formik.setFieldValue( + formik.setFieldValue(`feed_data.${idx}.feed`, val); + formik.setFieldValue( + `feed_data.${idx}.feed_id`, + productWarehouseId || '' + ); + formik.setFieldValue( + `feed_data.${idx}.feed_qty`, + stock + ); + formik.setFieldValue( + `feed_data.${idx}.feed_stock`, + 0 + ); + setTimeout(() => { + formik.setFieldTouched( `feed_data.${idx}.feed`, - val + true ); - formik.setFieldValue( + formik.setFieldTouched( `feed_data.${idx}.feed_id`, - productWarehouseId || '' + true ); - formik.setFieldValue( - `feed_data.${idx}.feed_qty`, - stock - ); - formik.setFieldValue( - `feed_data.${idx}.feed_stock`, - 0 - ); - setTimeout(() => { - formik.setFieldTouched( - `feed_data.${idx}.feed`, - true - ); - formik.setFieldTouched( - `feed_data.${idx}.feed_id`, - true - ); - }, 0); - }} - options={pakanOptions} - isLoading={isLoadingPakan} - isError={ - isRepeaterInputError('feed_data', 'feed_id', idx) - .isError - } - errorMessage={ - isRepeaterInputError('feed_data', 'feed_id', idx) - .errorMessage - } - isDisabled={type === 'detail'} - isClearable - className={{ - wrapper: - 'w-full min-w-52 md:min-w-72 lg:min-w-80', - }} - /> - + + + + - +
+ + +
- - -
- - -
-
-
- {type !== 'detail' && ( -
- {selectedFeed.length > 0 && ( - - )} + )} +
+
+ {type !== 'detail' && ( +
+ {selectedFeed.length > 0 && ( -
- )} -
-
+ )} + +
+ )} + {/* Body Weight Table */} -
-
-

Berat Ayam

-
- - - - {type !== 'detail' && ( - + ))} + +
-
- 0 + +
+ + + + {type !== 'detail' && ( + + )} + + + + {type !== 'detail' && } + + + + {formik.values.body_weight?.map((weight, idx) => ( + + {type !== 'detail' && ( + )} - - - - {type !== 'detail' && } - - - - {formik.values.body_weight?.map((weight, idx) => ( - - {type !== 'detail' && ( - - )} - + + + + + {type !== 'detail' && ( - - {type !== 'detail' && ( - - )} - - ))} - -
+
+ 0 + } + onChange={(e) => { + if (e.target.checked) { + setSelectedWeight( + formik.values.body_weight?.map( + (_, idx) => idx + ) ?? [] + ); + } else { + setSelectedWeight([]); } + }} + naked={true} + size='sm' + /> +
+
+ Berat (Gram) + + * + + + Jumlah Ayam + + * + + + Rata-rata berat Ayam + + * + + Action
+
+ { if (e.target.checked) { - setSelectedWeight( - formik.values.body_weight?.map( - (_, idx) => idx - ) ?? [] - ); + setSelectedWeight([...selectedWeight, idx]); } else { - setSelectedWeight([]); + setSelectedWeight( + selectedWeight.filter((i) => i !== idx) + ); } }} naked={true} size='sm' /> +
- +
- Berat (Gram) - - * - - - Jumlah Ayam - - * - - - Rata-rata berat Ayam - - * - - Action
-
- { - if (e.target.checked) { - setSelectedWeight([...selectedWeight, idx]); - } else { - setSelectedWeight( - selectedWeight.filter((i) => i !== idx) - ); - } - }} - naked={true} - size='sm' - /> - -
-
+ + + + + +
{ isError={ isRepeaterInputError( 'body_weight', - 'chicken_weight', + 'average_chicken_weight', idx ).isError } errorMessage={ isRepeaterInputError( 'body_weight', - 'chicken_weight', + 'average_chicken_weight', idx ).errorMessage } @@ -1114,587 +1173,518 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { className={{ wrapper: 'w-full min-w-24', }} + placeholder='' /> -
- - -
- +
+ +
-
- - -
-
-
- {type !== 'detail' && ( -
- {selectedWeight.length > 0 && ( - - )} + )} +
+
+ {type !== 'detail' && ( +
+ {selectedWeight.length > 0 && ( -
- )} -
-
+ )} + + + )} + {/* Vaccination Table */} -
-
-

Vaccination

-
- - - - {type !== 'detail' && ( - + ))} + +
-
- 0 + +
+ + + + {type !== 'detail' && ( + + )} + + + + {type !== 'detail' && } + + + + {formik.values.vaccination?.map((vaccine, idx) => ( + + {type !== 'detail' && ( + )} - - - - {type !== 'detail' && } - - - - {formik.values.vaccination?.map((vaccine, idx) => ( - - {type !== 'detail' && ( - - )} - - - - {type !== 'detail' && ( - - )} - - ))} - -
+
+ 0 + } + onChange={(e) => { + if (e.target.checked) { + setSelectedVaccine( + formik.values.vaccination?.map( + (_, idx) => idx + ) ?? [] + ); + } else { + setSelectedVaccine([]); } + }} + naked={true} + size='sm' + /> +
+
+ Name Vaksin + + * + + Total Stock pada saat ini + Jumlah Stock yang digunakan + + * + + Action
+
+ { if (e.target.checked) { + setSelectedVaccine([...selectedVaccine, idx]); + } else { setSelectedVaccine( - formik.values.vaccination?.map( - (_, idx) => idx - ) ?? [] + selectedVaccine.filter((i) => i !== idx) ); - } else { - setSelectedVaccine([]); } }} naked={true} size='sm' /> +
- +
- Name Vaksin - - * - - Total Stock pada saat ini - Jumlah Stock yang digunakan - - * - - Action
-
- { - if (e.target.checked) { - setSelectedVaccine([ - ...selectedVaccine, - idx, - ]); - } else { - setSelectedVaccine( - selectedVaccine.filter((i) => i !== idx) - ); - } - }} - naked={true} - size='sm' - /> - -
-
- - Number(opt.value) === - Number(vaccine.vaccine_id) - ) ?? null - } - onChange={(val) => { - const productWarehouseId = - (val as OptionType)?.value ?? 0; - const stock = productWarehouseId - ? (ovkStockMap.get( - productWarehouseId as number - ) ?? '') - : ''; - formik.setFieldValue( - `vaccination.${idx}.vaccine`, - val - ); - formik.setFieldValue( - `vaccination.${idx}.vaccine_id`, - productWarehouseId || '' - ); - formik.setFieldValue( - `vaccination.${idx}.total_stock`, - stock - ); - formik.setFieldValue( - `vaccination.${idx}.used_stock`, - 0 - ); - // Set touched after setting values to trigger validation - setTimeout(() => { - formik.setFieldTouched( - `vaccination.${idx}.vaccine`, - true - ); - formik.setFieldTouched( - `vaccination.${idx}.vaccine_id`, - true - ); - }, 0); - }} - options={ovkOptions} - isLoading={isLoadingOvk} - isError={ - isRepeaterInputError( - 'vaccination', - 'vaccine_id', - idx - ).isError - } - errorMessage={ - isRepeaterInputError( - 'vaccination', - 'vaccine_id', - idx - ).errorMessage - } - isDisabled={type === 'detail'} - isClearable - className={{ - wrapper: - 'w-full min-w-52 md:min-w-72 lg:min-w-80', - }} - /> - - - - - -
- - -
-
-
- {type !== 'detail' && ( -
- {selectedVaccine.length > 0 && ( - - )} - -
- )} -
- - - {/* Mortality Table */} -
-
-

Mortalitas

-
- - - - {type !== 'detail' && ( - - )} - - - {type !== 'detail' && } - - - - {formik.values.mortality?.map((mortality, idx) => ( - - {type !== 'detail' && ( - - )} - + }, 0); + }} + options={ovkOptions} + isLoading={isLoadingOvk} + isError={ + isRepeaterInputError( + 'vaccination', + 'vaccine_id', + idx + ).isError + } + errorMessage={ + isRepeaterInputError( + 'vaccination', + 'vaccine_id', + idx + ).errorMessage + } + isDisabled={type === 'detail'} + isClearable + className={{ + wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80', + }} + /> + + + + {type !== 'detail' && ( - {type !== 'detail' && ( - - )} - - ))} - -
-
- 0 - } - onChange={(e) => { - if (e.target.checked) { - setSelectedMortality( - formik.values.mortality?.map( - (_, idx) => idx - ) ?? [] - ); - } else { - setSelectedMortality([]); - } - }} - naked={true} - size='sm' - /> -
-
- Kondisi/Alasan Mortalitas - - * - - - Jumlah - - * - - Action
-
- { - if (e.target.checked) { - setSelectedMortality([ - ...selectedMortality, - idx, - ]); - } else { - setSelectedMortality( - selectedMortality.filter((i) => i !== idx) - ); - } - }} - naked={true} - size='sm' - /> - -
-
- opt.value === mortality.condition - )} - onChange={(val) => { + + + Number(opt.value) === Number(vaccine.vaccine_id) + ) ?? null + } + onChange={(val) => { + const productWarehouseId = + (val as OptionType)?.value ?? 0; + const stock = productWarehouseId + ? (ovkStockMap.get( + productWarehouseId as number + ) ?? '') + : ''; + formik.setFieldValue( + `vaccination.${idx}.vaccine`, + val + ); + formik.setFieldValue( + `vaccination.${idx}.vaccine_id`, + productWarehouseId || '' + ); + formik.setFieldValue( + `vaccination.${idx}.total_stock`, + stock + ); + formik.setFieldValue( + `vaccination.${idx}.used_stock`, + 0 + ); + // Set touched after setting values to trigger validation + setTimeout(() => { formik.setFieldTouched( - `mortality.${idx}.condition`, + `vaccination.${idx}.vaccine`, true ); - formik.setFieldValue( - `mortality.${idx}.condition`, - (val as OptionType)?.value + formik.setFieldTouched( + `vaccination.${idx}.vaccine_id`, + true ); - }} - isError={ - isRepeaterInputError( - 'mortality', - 'condition', - idx - ).isError - } - errorMessage={ - isRepeaterInputError( - 'mortality', - 'condition', - idx - ).errorMessage - } - options={RECORDING_FLAG_OPTIONS} - isDisabled={type === 'detail'} - isClearable - className={{ - wrapper: - 'w-full min-w-52 md:min-w-72 lg:min-w-80', - }} - /> - + + + + - +
+ + +
-
- - -
-
-
- {type !== 'detail' && ( -
- {selectedMortality.length > 0 && ( - - )} + )} +
+
+ {type !== 'detail' && ( +
+ {selectedVaccine.length > 0 && ( -
- )} + )} + +
+ )} + + + {/* Mortality Table */} + +
+ + + + {type !== 'detail' && ( + + )} + + + {type !== 'detail' && } + + + + {formik.values.mortality?.map((mortality, idx) => ( + + {type !== 'detail' && ( + + )} + + + {type !== 'detail' && ( + + )} + + ))} + +
+
+ 0 + } + onChange={(e) => { + if (e.target.checked) { + setSelectedMortality( + formik.values.mortality?.map( + (_, idx) => idx + ) ?? [] + ); + } else { + setSelectedMortality([]); + } + }} + naked={true} + size='sm' + /> +
+
+ Kondisi/Alasan Mortalitas + + * + + + Jumlah + + * + + Action
+
+ { + if (e.target.checked) { + setSelectedMortality([ + ...selectedMortality, + idx, + ]); + } else { + setSelectedMortality( + selectedMortality.filter((i) => i !== idx) + ); + } + }} + naked={true} + size='sm' + /> + +
+
+ opt.value === mortality.condition + )} + onChange={(val) => { + formik.setFieldTouched( + `mortality.${idx}.condition`, + true + ); + formik.setFieldValue( + `mortality.${idx}.condition`, + (val as OptionType)?.value + ); + }} + isError={ + isRepeaterInputError('mortality', 'condition', idx) + .isError + } + errorMessage={ + isRepeaterInputError('mortality', 'condition', idx) + .errorMessage + } + options={RECORDING_FLAG_OPTIONS} + isDisabled={type === 'detail'} + isClearable + className={{ + wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80', + }} + /> + + + +
+ + +
+
-
+ {type !== 'detail' && ( +
+ {selectedMortality.length > 0 && ( + + )} + +
+ )} + {/* Action buttons */}