From 34052d41abaa4ee45c93c0d1bacb84e807529d97 Mon Sep 17 00:00:00 2001 From: Ainun Nadhifah Syamsiyah <58164571+ainunns@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:35:22 +0700 Subject: [PATCH] feat: add new ticket modal (#29) * feat: slicing form add new ticket * feat: integrate add ticket modal --- src/app/board/components/StatusBoard.tsx | 35 ++- .../board/container/modal/AddTicketModal.tsx | 135 +++++++++ src/app/board/hooks/mutation.ts | 35 +++ src/components/forms/Input.tsx | 2 +- src/components/forms/SelectInput.tsx | 268 ++++++++++++++---- src/components/forms/TextArea.tsx | 89 ++++++ src/constant/select-options.ts | 9 + 7 files changed, 501 insertions(+), 72 deletions(-) create mode 100644 src/app/board/container/modal/AddTicketModal.tsx create mode 100644 src/components/forms/TextArea.tsx create mode 100644 src/constant/select-options.ts diff --git a/src/app/board/components/StatusBoard.tsx b/src/app/board/components/StatusBoard.tsx index 3d19d7a..374640c 100644 --- a/src/app/board/components/StatusBoard.tsx +++ b/src/app/board/components/StatusBoard.tsx @@ -7,6 +7,8 @@ import Typography from '@/components/Typography'; import clsxm from '@/lib/clsxm'; import { taskType } from '@/types/entities/task'; +import AddTicketModal from '../container/modal/AddTicketModal'; + type StatusBoardProps = { title: string; data: taskType[] | null; @@ -52,21 +54,26 @@ export default function StatusBoard({ {ticketCount} - + {({ openModal }) => ( + )} - /> +
{data?.map((task) => ( diff --git a/src/app/board/container/modal/AddTicketModal.tsx b/src/app/board/container/modal/AddTicketModal.tsx new file mode 100644 index 0000000..a04b230 --- /dev/null +++ b/src/app/board/container/modal/AddTicketModal.tsx @@ -0,0 +1,135 @@ +import * as React from 'react'; +import { FormProvider, useForm } from 'react-hook-form'; + +import { + AddTicketFormType, + useAddTicketMutation, +} from '@/app/board/hooks/mutation'; +import Button from '@/components/buttons/Button'; +import DatePicker from '@/components/forms/DatePicker'; +import Input from '@/components/forms/Input'; +import SelectInput from '@/components/forms/SelectInput'; +import TextArea from '@/components/forms/TextArea'; +import Modal from '@/components/Modal'; +import { SELECT_OPTIONS } from '@/constant/select-options'; + +type ModalReturnType = { + openModal: () => void; +}; + +export default function AddTicketModal({ + refetch, + status, + children, +}: { + refetch: () => void; + status: string; + children: (props: ModalReturnType) => JSX.Element; +}) { + const [open, setOpen] = React.useState(false); + const modalReturn: ModalReturnType = { + openModal: () => setOpen(true), + }; + + const methods = useForm({ + mode: 'onTouched', + defaultValues: { + title: '', + description: '', + dueDate: new Date(), + tags: [], + status, + }, + }); + + const { handleSubmit } = methods; + + const { handleAdd, isPending } = useAddTicketMutation({ + refetch, + setOpen, + }); + + const onSubmit = (data: AddTicketFormType) => { + handleAdd({ + ...data, + status: status.toLowerCase(), + }); + }; + + return ( + <> + {children(modalReturn)} + + + +
+ +