From 70bb40d4f2ff073cfbd8e8cdccc8cf3d8f997375 Mon Sep 17 00:00:00 2001 From: randy-ar Date: Sat, 31 Jan 2026 13:15:47 +0700 Subject: [PATCH] fix(FE): refactor sales order form create --- src/app/marketing/page.tsx | 3 + src/components/helper/form/FormErrors.tsx | 51 +- src/components/input/DebouncedTextArea.tsx | 7 + src/components/input/TextArea.tsx | 3 + .../pages/marketing/MarketingTable.tsx | 10 +- .../pages/marketing/SalesOrderFormModal.tsx | 744 ++++++++++++++++++ .../pages/marketing/form/MarketingForm.tsx | 4 +- .../sales-order/SalesOrderProductForm.tsx | 321 ++++---- .../table-view/SalesOrderProductTable.tsx | 149 ++-- src/services/hooks/useFormikErrorList.ts | 6 + 10 files changed, 1060 insertions(+), 238 deletions(-) create mode 100644 src/components/pages/marketing/SalesOrderFormModal.tsx diff --git a/src/app/marketing/page.tsx b/src/app/marketing/page.tsx index 5bdcd48f..70eb4549 100644 --- a/src/app/marketing/page.tsx +++ b/src/app/marketing/page.tsx @@ -1,9 +1,12 @@ import MarketingTable from '@/components/pages/marketing/MarketingTable'; +import SalesOrderFormModal from '@/components/pages/marketing/SalesOrderFormModal'; const Marketing = () => { return (
+ +
); }; diff --git a/src/components/helper/form/FormErrors.tsx b/src/components/helper/form/FormErrors.tsx index 1fd7b58f..d4959e8b 100644 --- a/src/components/helper/form/FormErrors.tsx +++ b/src/components/helper/form/FormErrors.tsx @@ -1,5 +1,6 @@ import Alert from '@/components/Alert'; import Button from '@/components/Button'; +import { cn } from '@/lib/helper'; import { Icon } from '@iconify/react'; import { useState } from 'react'; @@ -10,34 +11,66 @@ import { useState } from 'react'; */ const AlertErrorList = ({ formErrorList, + className, onClose, }: { formErrorList: string[]; + className?: { + alert?: string; + button?: string; + headerWrapper?: string; + headerIcon?: string; + headerText?: string; + titleWrapper?: string; + ul?: string; + li?: string; + }; onClose: () => void; }) => { if (formErrorList.length === 0) return null; return ( - -
-
- - + +
+
+ + Terdapat {formErrorList.length} error pada form:
-
    +
      {formErrorList.map((error, index) => ( -
    • +
    • {error}
    • ))} diff --git a/src/components/input/DebouncedTextArea.tsx b/src/components/input/DebouncedTextArea.tsx index 3df2c032..24d4b4e7 100644 --- a/src/components/input/DebouncedTextArea.tsx +++ b/src/components/input/DebouncedTextArea.tsx @@ -7,6 +7,7 @@ import TextArea, { TextAreaProps } from '@/components/input/TextArea'; interface DebouncedTextAreaProps extends TextAreaProps { delay?: number; + ref?: React.RefObject; } const DebouncedTextArea = (props: DebouncedTextAreaProps) => { @@ -19,6 +20,11 @@ const DebouncedTextArea = (props: DebouncedTextAreaProps) => { const [debouncedChangeEvent] = useDebounce(internalChangeEvent, delay ?? 300); const [debouncedValue] = useDebounce(internalValue, delay ?? 300); + // Sync internal value with external props.value when it changes (e.g., form reset) + useEffect(() => { + setInternalValue(props.value); + }, [props.value]); + const internalChangeHandler: ChangeEventHandler = ( e ) => { @@ -35,6 +41,7 @@ const DebouncedTextArea = (props: DebouncedTextAreaProps) => { return (