From 956f5b131eb184dbb961adf4c1393d53f32a4845 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 6 Dec 2023 21:28:38 +0000 Subject: [PATCH] feat: create new lists --- .../[...id]/{create.tsx => NewCardForm.tsx} | 0 src/app/boards/[...id]/NewListForm.tsx | 86 +++++++++++++++++++ src/app/boards/[...id]/page.tsx | 21 ++++- src/app/boards/page.tsx | 2 +- src/app/providers/modal.tsx | 12 ++- src/server/api/routers/card.ts | 2 - src/server/api/routers/list.ts | 44 +++++++++- 7 files changed, 155 insertions(+), 12 deletions(-) rename src/app/boards/[...id]/{create.tsx => NewCardForm.tsx} (100%) create mode 100644 src/app/boards/[...id]/NewListForm.tsx diff --git a/src/app/boards/[...id]/create.tsx b/src/app/boards/[...id]/NewCardForm.tsx similarity index 100% rename from src/app/boards/[...id]/create.tsx rename to src/app/boards/[...id]/NewCardForm.tsx diff --git a/src/app/boards/[...id]/NewListForm.tsx b/src/app/boards/[...id]/NewListForm.tsx new file mode 100644 index 00000000..ddaccb2b --- /dev/null +++ b/src/app/boards/[...id]/NewListForm.tsx @@ -0,0 +1,86 @@ +"use client"; + +import { api } from "~/trpc/react"; + +import { HiXMark } from "react-icons/hi2"; + +import { useBoard } from "~/app/providers/board"; +import { useModal } from "~/app/providers/modal"; + +import { Formik, Form, Field } from "formik"; + +interface FormValues { + name: string; +} + +interface boardPublicId { + boardPublicId: string; +} + +export function NewListForm({ boardPublicId }: boardPublicId) { + const utils = api.useUtils(); + const { boardData } = useBoard(); + const { closeModal } = useModal(); + + const refetchBoard = () => + utils.board.byId.refetch({ id: boardData.publicId }); + + const createList = api.list.create.useMutation({ + onSuccess: async () => { + try { + await refetchBoard(); + closeModal(); + } catch (e) { + console.log(e); + } + }, + }); + + return ( + <> +
+

New list

+ +
+ + { + createList.mutate({ + name: values.name, + boardPublicId, + }); + }} + > +
+ + +
+ +
+ +
+ + ); +} diff --git a/src/app/boards/[...id]/page.tsx b/src/app/boards/[...id]/page.tsx index 466ca4d0..7e962e9f 100644 --- a/src/app/boards/[...id]/page.tsx +++ b/src/app/boards/[...id]/page.tsx @@ -17,7 +17,9 @@ import { useBoard } from "~/app/providers/board"; import { useModal } from "~/app/providers/modal"; import Modal from "~/app/_components/modal"; -import { NewCardForm } from "~/app/boards/[...id]/create"; + +import { NewCardForm } from "./NewCardForm"; +import { NewListForm } from "./NewListForm"; interface List { publicId: string; @@ -40,7 +42,7 @@ type PublicListId = string; export default function BoardPage() { const params = useParams(); const { boardData, setBoardData, updateCard, updateList } = useBoard(); - const { openModal } = useModal(); + const { openModal, modalContentType } = useModal(); const [selectedPublicListId, setSelectedPublicListId] = useState(""); @@ -73,8 +75,13 @@ export default function BoardPage() { }, ); + const openNewListForm = (publicBoardId: string) => { + openModal("NEW_LIST"); + setSelectedPublicListId(publicBoardId); + }; + const openNewCardForm = (publicListId: PublicListId) => { - openModal(); + openModal("NEW_CARD"); setSelectedPublicListId(publicListId); }; @@ -153,6 +160,7 @@ export default function BoardPage() {