setFormErrorList([])}
+ />
+ )}
+
{/* Form Actions */}
+
+
+ {formErrorList.length > 0 && (
+ setFormErrorList([])}
+ />
+ )}
+
+
+
+
+ {/* Error List Alert */}
+ {formErrorList.length > 0 && (
+ setFormErrorList([])}
+ />
+ )}
+
Reset
@@ -321,7 +371,7 @@ const SalesOrderProductForm = ({
Submit
diff --git a/src/components/pages/production/chickin/form/ChickinForm.tsx b/src/components/pages/production/chickin/form/ChickinForm.tsx
index 7d8a4c7c..b5b1dc4d 100644
--- a/src/components/pages/production/chickin/form/ChickinForm.tsx
+++ b/src/components/pages/production/chickin/form/ChickinForm.tsx
@@ -18,6 +18,7 @@ import { Icon } from '@iconify/react';
import Badge from '@/components/Badge';
import { CHICKINS_APPROVAL_LINE } from '@/config/approval-line';
import RequirePermission from '@/components/helper/RequirePermission';
+import { BaseApproval } from '@/types/api/api-general';
const ChickinFormKandang = ({
formType = 'add',
initialValues,
@@ -33,11 +34,16 @@ const ChickinFormKandang = ({
approvals,
isLoading: approvalsLoading,
refresh: refreshApprovals,
+ rawDataApprovals,
} = useApprovalSteps({
- latestApproval: initialValues?.approval,
+ latestApproval: initialValues?.chickin_approval,
approvalLines: CHICKINS_APPROVAL_LINE,
moduleName: 'CHICKINS',
moduleId: initialValues?.id.toString() ?? '',
+ params: {
+ limit: 'limit',
+ group_step_number: false,
+ },
});
const afterSubmitFormChickin = () => {
@@ -180,6 +186,7 @@ const ChickinFormKandang = ({
{openChickin && (
diff --git a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
index 17c76822..e800ee68 100644
--- a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
+++ b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
@@ -8,6 +8,7 @@ import PillBadge from '@/components/PillBadge';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
import { formatDate, formatNumber } from '@/lib/helper';
import { ChickinApi } from '@/services/api/production/chickin';
+import { BaseApproval } from '@/types/api/api-general';
import { ProjectFlockKandang } from '@/types/api/production/project-flock-kandang';
import { Icon } from '@iconify/react';
import { useState } from 'react';
@@ -16,9 +17,11 @@ import toast from 'react-hot-toast';
const ChickinLogsView = ({
initialValues,
afterSubmit,
+ rawDataApprovals,
}: {
initialValues: ProjectFlockKandang;
afterSubmit?: () => void;
+ rawDataApprovals: BaseApproval[];
}) => {
const confirmModal = useModal();
const [isApproveLoading, setIsApproveLoading] = useState(false);
@@ -60,8 +63,15 @@ const ChickinLogsView = ({
) : (
(initialValues?.chickins || []).map((chickin, index) => {
- const isApproved = chickin.usage_qty !== 0;
- const isPending = chickin.pending_usage_qty !== 0;
+ const latestApproval = rawDataApprovals[0];
+ const isApproved =
+ index == (initialValues?.chickins || []).length - 1
+ ? latestApproval?.step_number === 2
+ : true;
+ const isPending =
+ index == (initialValues?.chickins || []).length - 1
+ ? latestApproval?.step_number === 1
+ : false;
const quantity = isApproved
? chickin.usage_qty
: isPending
@@ -81,7 +91,7 @@ const ChickinLogsView = ({
{/* Header with Status Badge */}
- Chick In #{index + 1}
+ Chick In #{index + 1} - {latestApproval?.step_number}
-
-
- Approve Semua Chick In
-
-
- )}
+ {initialValues.chickin_approval &&
+ initialValues?.chickin_approval?.step_number < 2 && (
+
+
+
+ Approve Semua Chick In
+
+
+ )}
{chickinErrorMessage && (
setChickinErrorMessage('')}>
diff --git a/src/components/pages/production/project-flock/ProjectFlockTable.tsx b/src/components/pages/production/project-flock/ProjectFlockTable.tsx
index 7d9ce7da..f6888c3d 100644
--- a/src/components/pages/production/project-flock/ProjectFlockTable.tsx
+++ b/src/components/pages/production/project-flock/ProjectFlockTable.tsx
@@ -308,7 +308,10 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
{
+ setRowSelection({});
+ router.push('/production/project-flock/add');
+ }}
>
Tambah
diff --git a/src/components/pages/production/project-flock/form/ProjectFlockForm.schema.ts b/src/components/pages/production/project-flock/form/ProjectFlockForm.schema.ts
index 5ed74b5a..dc972b14 100644
--- a/src/components/pages/production/project-flock/form/ProjectFlockForm.schema.ts
+++ b/src/components/pages/production/project-flock/form/ProjectFlockForm.schema.ts
@@ -64,9 +64,9 @@ export const ProjectFlockBudgetsSchema: Yup.ObjectSchema =
diff --git a/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx b/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx
index 348f96a4..7e90c94b 100644
--- a/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx
+++ b/src/components/pages/production/project-flock/form/ProjectFlockForm.tsx
@@ -6,6 +6,8 @@ import SelectInput, {
useSelect,
} from '@/components/input/SelectInput';
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
+import { getUniqueFormikErrors } from '@/lib/formik-helper';
+import AlertErrorList from '@/components/helper/form/FormErrors';
import {
AreaApi,
FcrApi,
@@ -38,11 +40,6 @@ import { BaseApiResponse } from '@/types/api/api-general';
import { FLOCK_CATEGORY_OPTIONS } from '@/config/constant';
import { useModal } from '@/components/Modal';
import ConfirmationModal from '@/components/modal/ConfirmationModal';
-import ApprovalSteps, {
- useApprovalSteps,
-} from '@/components/pages/ApprovalSteps';
-import { PROJECT_FLOCK_APPROVAL_LINE } from '@/config/approval-line';
-import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
import NumberInput from '@/components/input/NumberInput';
import Card from '@/components/Card';
import ProjectFlockKandangTable from '@/components/pages/production/project-flock/form/ProjectFlockKandangTable';
@@ -69,8 +66,10 @@ const ProjectFlockForm = ({
const [projectFlockFormErrorMessage, setProjectFlockFormErrorMessage] =
useState('');
+ const [formErrorList, setFormErrorList] = useState([]);
const [selectedArea, setSelectedArea] = useState('');
const [selectedLocation, setSelectedLocation] = useState('');
+ const [selectedCategory, setSelectedCategory] = useState('');
const [disabledLocation, setDisabledLocation] = useState(
initialValues?.location?.id ? false : true
);
@@ -90,18 +89,8 @@ const ProjectFlockForm = ({
const setIsValid = useUiStore((s) => s.setIsValid);
const deleteModal = useModal();
- const confirmModal = useModal();
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
- const [isApproveLoading, setIsApproveLoading] = useState(false);
- const [isApprovedDisabled, setIsApprovedDisabled] = useState(
- initialValues?.approval?.step_name == 'Pengajuan' ? false : true
- );
- const [isRejectedDisabled, setIsRejectedDisabled] =
- useState(!isApprovedDisabled);
- const [approvalAction, setApprovalAction] = useState<'APPROVED' | 'REJECTED'>(
- !isApprovedDisabled ? 'APPROVED' : 'REJECTED'
- );
const [rowSelection, setRowSelection] = useState>(
() =>
@@ -140,11 +129,15 @@ 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: '',
location_id: selectedLocation == '' ? '0' : selectedLocation,
+ limit: 'limit',
}).toString()}`;
const {
data: kandang,
@@ -163,17 +156,6 @@ const ProjectFlockForm = ({
isLoadingOptions: isLoadingNonstocks,
} = useSelect(NonstockApi.basePath, 'id', 'name');
- const {
- approvals,
- isLoading: approvalsLoading,
- refresh: refreshApprovals,
- } = useApprovalSteps({
- latestApproval: initialValues?.approval,
- approvalLines: PROJECT_FLOCK_APPROVAL_LINE,
- moduleName: 'PROJECT_FLOCKS',
- moduleId: initialValues?.id.toString() ?? '',
- });
-
useEffect(() => {
if (isResponseSuccess(kandang)) {
if (selectedLocation) {
@@ -263,9 +245,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);
}
};
@@ -404,8 +396,6 @@ const ProjectFlockForm = ({
validationSchema:
formType == 'add' ? ProjectFlockFormSchema : UpdateProjectFlockFormSchema,
validateOnBlur: true,
- // validateOnChange: true,
- // validateOnMount: true,
onSubmit: async (values) => {
setProjectFlockFormErrorMessage('');
const payload: CreateProjectFlockPayload = {
@@ -522,19 +512,6 @@ const ProjectFlockForm = ({
return unsub;
}, []);
- useEffect(() => {
- if (initialValues?.approval?.step_name) {
- const pengajuanRejected =
- initialValues.approval.step_number == 1 &&
- initialValues.approval.action == 'REJECTED';
- const approvedDisabled =
- initialValues.approval.step_number !== 1 || pengajuanRejected;
- setIsApprovedDisabled(approvedDisabled);
- setIsRejectedDisabled(!approvedDisabled || pengajuanRejected);
- setApprovalAction(!approvedDisabled ? 'APPROVED' : 'REJECTED');
- }
- }, [initialValues]);
-
// Actions handler
const confirmationModalDeleteClickHandler = async () => {
setIsDeleteLoading(true);
@@ -588,29 +565,6 @@ const ProjectFlockForm = ({
}
};
- const confirmApprovalHandler = async (
- notes: string,
- approvalAction: 'REJECTED' | 'APPROVED'
- ) => {
- if (initialValues?.id === undefined) return;
- setIsApproveLoading(true);
-
- const approvalRes =
- approvalAction == 'APPROVED'
- ? await ProjectFlockApi.approve(initialValues?.id, notes)
- : await ProjectFlockApi.reject(initialValues?.id, notes);
- if (isResponseSuccess(approvalRes)) {
- refreshProjectFlocks?.();
- toast.success(approvalRes.message as string);
- }
- if (isResponseError(approvalRes)) {
- toast.error(approvalRes?.message as string);
- }
- refreshApprovals();
- confirmModal.closeModal();
- setIsApproveLoading(false);
- };
-
const handleBudgetChange = (
index: number,
fieldName: 'qty' | 'price' | 'total_price',
@@ -688,6 +642,17 @@ const ProjectFlockForm = ({
return !isNonstockAlreadyInBudgets;
});
+ const handleValidateForm = async () => {
+ const errors = await formik.validateForm();
+
+ if (Object.keys(errors).length > 0) {
+ // Parse and display errors
+ const errorMessages = getUniqueFormikErrors(errors);
+ setFormErrorList(errorMessages);
+ return; // Stop submission
+ }
+ };
+
return (
<>
@@ -744,50 +709,14 @@ const ProjectFlockForm = ({
)}
- {approvals && !approvalsLoading && formType == 'detail' && (
-
- )}
- {formType == 'detail' && (
-
-
- {
- if (initialValues?.id) {
- setApprovalAction('APPROVED');
- confirmModal.openModal();
- }
- }}
- disabled={!initialValues?.id || isApprovedDisabled}
- className='w-full sm:w-fit'
- >
-
- Approve
-
-
-
- {
- if (initialValues?.id) {
- setApprovalAction('REJECTED');
- confirmModal.openModal();
- }
- }}
- disabled={!initialValues?.id || isRejectedDisabled}
- className='w-full sm:w-fit'
- >
-
- Reject
-
-
-
- )}
+