diff --git a/src/components/input/DateInput.tsx b/src/components/input/DateInput.tsx index e6225d5e..77267090 100644 --- a/src/components/input/DateInput.tsx +++ b/src/components/input/DateInput.tsx @@ -215,7 +215,7 @@ const DateInput = ({
>(() => { return { - product_category_id: initialValues?.product_category?.id ?? 0, - product_id: initialValues?.product?.id ?? 0, - warehouse_id: initialValues?.warehouse?.id ?? 0, + product_id: initialValues?.product_warehouse?.product_id ?? 0, + warehouse_id: initialValues?.product_warehouse?.warehouse_id ?? 0, product_category: undefined, product: undefined, warehouse: undefined, diff --git a/src/components/pages/marketing/MarketingTable.tsx b/src/components/pages/marketing/MarketingTable.tsx index e253fe39..d1d5940a 100644 --- a/src/components/pages/marketing/MarketingTable.tsx +++ b/src/components/pages/marketing/MarketingTable.tsx @@ -2,7 +2,7 @@ import Button from '@/components/Button'; import CheckboxInput from '@/components/input/CheckboxInput'; -import { OptionType } from '@/components/input/SelectInput'; +import SelectInput, { OptionType } from '@/components/input/SelectInput'; import Modal, { useModal } from '@/components/Modal'; import ConfirmationModal from '@/components/modal/ConfirmationModal'; import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes'; @@ -183,14 +183,18 @@ const MarketingTable = () => { ); const hasApprovable = selectedRowsData.some( - (row) => row.latest_approval.step_number === 1 + (row) => + row.latest_approval.step_number === 1 && + row.latest_approval.action !== 'REJECTED' ); const hasRejectable = selectedRowsData.some( - (row) => row.latest_approval.step_number === 2 + (row) => + row.latest_approval.step_number === 1 && + row.latest_approval.action !== 'REJECTED' ); - const disableApprove = !hasApprovable || hasRejectable; - // const disableReject = !hasRejectable || hasApprovable; + const disableApprove = !hasApprovable; + const disableReject = !hasRejectable; const idsToProcess = approveAction === 'APPROVED' @@ -204,15 +208,9 @@ const MarketingTable = () => { const approveMarketingHandler = async (notes: string) => { let idsToProcess: number[] = []; - if (approveAction === 'APPROVED') { - idsToProcess = selectedRowsData - .filter((row) => row.latest_approval.step_number === 1) - .map((row) => row.id); - } else if (approveAction === 'REJECTED') { - idsToProcess = selectedRowsData - .filter((row) => row.latest_approval.step_number === 2) - .map((row) => row.id); - } + idsToProcess = selectedRowsData + .filter((row) => row.latest_approval.step_number === 1) + .map((row) => row.id); if (idsToProcess.length === 0) { toast.error(`Tidak ada data yang valid untuk di ${approveAction}.`); @@ -263,8 +261,8 @@ const MarketingTable = () => { }); const getRowCanSelect = (row: Row): boolean => { - const step = row.original.latest_approval?.step_number; - return step === 1; + const approval = row.original.latest_approval; + return approval?.step_number === 1 && approval?.action !== 'REJECTED'; }; return ( @@ -282,11 +280,6 @@ const MarketingTable = () => { placeholder: 'Cari Sales Order', }} /> -
- {/* */} +
+ + {/* select multiple product */} + + {/* select status */} + + {/* select customer */} + +
{ - // setApprovalAction('REJECTED'); - // confirmationModal.openModal(); - // }; + const rejectClickHandler = () => { + setApprovalAction('REJECTED'); + confirmationModal.openModal(); + }; const deliveryClickHandler = () => { deliveryModal.openModal(); @@ -87,10 +87,11 @@ const MarketingDetail = ({ const confirmationModalDeleteClickHandler = async () => { setIsLoading(true); const res = await MarketingApi.delete(initialValues?.id as number); - setIsLoading(false); deleteModal.closeModal(); + router.push('/marketing'); toast.success(res?.message as string); refresh?.(); + setIsLoading(false); }; const confirmationModalApproveClickHandler = async (notes: string) => { @@ -131,32 +132,45 @@ const MarketingDetail = ({ )}
- {initialValues?.latest_approval?.step_number != 3 && ( + {initialValues?.latest_approval?.step_number == 1 && ( <> - {/* */} + )} - {initialValues?.latest_approval?.step_number == 2 && ( + {initialValues?.latest_approval?.step_number != 1 && ( )} @@ -398,14 +412,16 @@ const MarketingDetail = ({ )}
- + {initialValues?.latest_approval?.step_number != 3 && ( + + )}
- {(formType == 'add' || formType == 'edit') && ( - - {/*
{JSON.stringify(initialValues)}
-
{JSON.stringify(formik.values)}
-
{JSON.stringify(formik.errors)}
*/} - -
- )} + + {/* Input Table Repeater Sales Order */} + + + + + {/* Input Table Repeater Delivery Order */} {(formType == 'add_deliver' || formType == 'edit_deliver') && initialValues?.sales_order && initialValues?.sales_order.length > 0 && ( @@ -611,29 +652,24 @@ const MarketingForm = ({ wrapper: 'bg-white w-full', }} > - {/* {JSON.stringify(memoSalesOrder)} */} - {/* {JSON.stringify(memoDeliveryOrder)} */} - {/* + {/*
+ {JSON.stringify(formik.values)} +
+
{JSON.stringify(formik.errors)} - */} +
*/} )} + {/* Input Notes */}
-