feat(FE): add drawer ui store

This commit is contained in:
randy-ar
2025-12-01 10:13:28 +07:00
parent 892bb19dfd
commit 2ace95a0db
6 changed files with 89 additions and 9 deletions
+2 -2
View File
@@ -7,11 +7,11 @@ import {
useState,
} from 'react';
import { cn, formatDate } from '@/lib/helper';
import Modal, { useModal } from '../Modal';
import { DateRange, DayPicker, Matcher } from 'react-day-picker';
import 'react-day-picker/dist/style.css';
import Button from '../Button';
import { Icon } from '@iconify/react';
import Modal, { useModal } from '@/components/Modal';
import Button from '@/components/Button';
export interface DateInputProps {
label?: string;
@@ -43,6 +43,7 @@ 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 { useUiStore } from '@/stores/ui/ui.store';
interface ProjectFlockFormProps {
formType?: 'add' | 'edit' | 'detail';
@@ -79,6 +80,8 @@ const ProjectFlockForm = ({
initialValues?.flock_name?.lastIndexOf(' ')
) ?? ''
);
const subscribeValidate = useUiStore((s) => s.subscribeValidate);
const setIsValid = useUiStore((s) => s.setIsValid);
const deleteModal = useModal();
const confirmModal = useModal();
@@ -577,6 +580,29 @@ const ProjectFlockForm = ({
// return isValid;
// },
// }));
useEffect(() => {
const unsub = subscribeValidate(() => {
formik.validateForm().then((errors) => {
if (Object.keys(errors).length > 0) {
// Membentuk touched object yang strongly-typed
const touched = Object.keys(formik.values).reduce<
Record<keyof typeof formik.values, boolean>
>(
(acc, key) => {
acc[key as keyof typeof formik.values] = true;
return acc;
},
{} as Record<keyof typeof formik.values, boolean>
);
formik.setTouched(touched, true);
}
setIsValid(Object.keys(errors).length === 0);
});
});
return unsub;
}, []);
return (
<>