diff --git a/src/components/pages/production/chickin/form/ChickinForm.tsx b/src/components/pages/production/chickin/form/ChickinForm.tsx index 7d8a4c7c..8c613737 100644 --- a/src/components/pages/production/chickin/form/ChickinForm.tsx +++ b/src/components/pages/production/chickin/form/ChickinForm.tsx @@ -34,7 +34,7 @@ const ChickinFormKandang = ({ isLoading: approvalsLoading, refresh: refreshApprovals, } = useApprovalSteps({ - latestApproval: initialValues?.approval, + latestApproval: initialValues?.chickin_approval, approvalLines: CHICKINS_APPROVAL_LINE, moduleName: 'CHICKINS', moduleId: initialValues?.id.toString() ?? '', diff --git a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx index 17c76822..80846565 100644 --- a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx +++ b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx @@ -60,8 +60,9 @@ const ChickinLogsView = ({ ) : ( (initialValues?.chickins || []).map((chickin, index) => { - const isApproved = chickin.usage_qty !== 0; - const isPending = chickin.pending_usage_qty !== 0; + const isApproved = + initialValues.chickin_approval?.step_number === 2; + const isPending = initialValues.chickin_approval?.step_number === 1; const quantity = isApproved ? chickin.usage_qty : isPending @@ -146,18 +147,19 @@ const ChickinLogsView = ({ }) )} - {initialValues?.approval?.step_number <= 2 && ( - - - - )} + {initialValues.chickin_approval && + initialValues?.chickin_approval?.step_number < 2 && ( + + + + )} {chickinErrorMessage && (
setChickinErrorMessage('')}> diff --git a/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx b/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx index 36ea90ca..20a8aff4 100644 --- a/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx +++ b/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx @@ -66,6 +66,7 @@ const ProjectFlockForm = ({ useState(''); const [selectedArea, setSelectedArea] = useState(''); const [selectedLocation, setSelectedLocation] = useState(''); + const [selectedCategory, setSelectedCategory] = useState(''); const [disabledLocation, setDisabledLocation] = useState( initialValues?.location?.id ? false : true ); @@ -125,7 +126,10 @@ const ProjectFlockForm = ({ const { options: optionsProductionStandards, isLoadingOptions: isLoadingProductionStandards, - } = useSelect(ProductionStandardApi.basePath, 'id', 'name'); + } = useSelect(ProductionStandardApi.basePath, 'id', 'name', '', { + search: '', + project_category: selectedCategory, + }); const kandangUrl = `${KandangApi.basePath}?${new URLSearchParams({ search: '', @@ -237,9 +241,19 @@ const ProjectFlockForm = ({ }; const categoryChangeHandler = (val: OptionType | OptionType[] | null) => { - formik.setFieldValue('category', (val as OptionType)?.value); + // Reset production standard when category is changed + formik.setFieldValue('production_standard_id', ''); + formik.setFieldValue('production_standard', ''); + formik.setFieldValue('category_option', val); - if (val == null) { + formik.setFieldValue('category', val ? (val as OptionType)?.value : ''); + + setSelectedCategory((val as OptionType)?.value as string); + + if (Boolean(val)) { + formik.setFieldTouched('category', false); + formik.setFieldError('category', ''); + } else { formik.setFieldTouched('category', true); } }; @@ -378,8 +392,6 @@ const ProjectFlockForm = ({ validationSchema: formType == 'add' ? ProjectFlockFormSchema : UpdateProjectFlockFormSchema, validateOnBlur: true, - // validateOnChange: true, - // validateOnMount: true, onSubmit: async (values) => { setProjectFlockFormErrorMessage(''); const payload: CreateProjectFlockPayload = { @@ -770,23 +782,6 @@ const ProjectFlockForm = ({ isClearable isDisabled={formType != 'add'} /> - { - optionChangeHandler(val, 'production_standard'); - }} - options={optionsProductionStandards} - isLoading={isLoadingProductionStandards} - isError={ - formik.touched.production_standard && - Boolean(formik.errors.production_standard) - } - errorMessage={formik.errors.production_standard as string} - isClearable - isDisabled={formType != 'add'} - /> + { + optionChangeHandler(val, 'production_standard'); + }} + options={optionsProductionStandards} + isLoading={isLoadingProductionStandards} + isError={ + formik.touched.production_standard_id && + Boolean(formik.errors.production_standard_id) + } + errorMessage={formik.errors.production_standard_id as string} + isClearable + isDisabled={formType != 'add'} + /> diff --git a/src/types/api/production/project-flock-kandang.d.ts b/src/types/api/production/project-flock-kandang.d.ts index 3a98a6e8..8c8d6273 100644 --- a/src/types/api/production/project-flock-kandang.d.ts +++ b/src/types/api/production/project-flock-kandang.d.ts @@ -10,9 +10,10 @@ export type BaseProjectFlockKandang = { kandang_id: number; kandang: Kandang; project_flock: ProjectFlock; - available_qtys?: AvailableQty[]; - chickins?: Chickin[]; approval: BaseApproval; + chickins?: Chickin[]; + available_qtys?: AvailableQty[]; + chickin_approval?: BaseApproval; }; export type AvailableQty = { @@ -56,14 +57,6 @@ export type ClosingExpense = { reference_number: string; }; -// "flag_name": "PAKAN", -// "product_warehouse_id": 14, -// "product_id": 8, -// "product_name": "281 SPECIAL STARTER", -// "product_category": "Bahan Baku", -// "uom": "Kilogram", -// "quantity": 1100 - export type StockItem = { flag_name: string; product_warehouse_id: number;