mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-22 06:15:47 +00:00
feat(FE): add drawer ui store
This commit is contained in:
@@ -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 (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user