) => {
if (e.target.checked) {
- setSelectedVaccine([...selectedVaccine, idx]);
+ setSelectedStocks([...selectedStocks, idx]);
} else {
- setSelectedVaccine(
- selectedVaccine.filter((i) => i !== idx)
+ setSelectedStocks(
+ selectedStocks.filter((i) => i !== idx)
);
}
}}
@@ -1353,131 +2191,94 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
- Number(opt.value) === Number(vaccine.vaccine_id)
- ) ?? null
+ unifiedStockProducts.find(
+ (product) =>
+ product.value === stock.product_warehouse_id
+ ) || null
}
- onChange={(val) => {
- const productWarehouseId =
- (val as OptionType)?.value ?? 0;
- const stock = productWarehouseId
- ? (ovkStockMap.get(
- productWarehouseId as number
- ) ?? '')
- : '';
+ onChange={(selectedOption) => {
+ const option = selectedOption as OptionType | null;
formik.setFieldValue(
- `vaccination.${idx}.vaccine`,
- val
+ `stocks.${idx}.product_warehouse_id`,
+ option?.value || 0
);
- 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}
+ options={unifiedStockProducts}
+ placeholder='Pilih Produk'
+ isLoading={isLoadingStockProducts}
isError={
isRepeaterInputError(
- 'vaccination',
- 'vaccine_id',
+ 'stocks',
+ 'product_warehouse_id',
idx
).isError
}
errorMessage={
isRepeaterInputError(
- 'vaccination',
- 'vaccine_id',
+ 'stocks',
+ 'product_warehouse_id',
idx
).errorMessage
}
+ className={{
+ wrapper: 'w-full min-w-48',
+ }}
+ isSearchable
isDisabled={type === 'detail'}
- isClearable
- className={{
- wrapper: 'w-full min-w-52 md:min-w-72 lg:min-w-80',
- }}
- />
- |
-
-
|
-
+
+
+ {(type as 'add' | 'edit' | 'detail') !== 'detail' &&
+ getStockUsageAdornment(idx)}
+
|
- {type !== 'detail' && (
+ {(type as 'add' | 'edit' | 'detail') !== 'detail' && (
-
+
|