From e1e0ea1615b45a0432229e769d605c498ab67690 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 28 Nov 2023 23:15:39 +0000 Subject: [PATCH] feat: update board name --- src/app/boards/[...id]/page.tsx | 41 +++++++++++++++++++++++++++++---- src/server/api/routers/board.ts | 13 +++++++++++ src/server/api/routers/card.ts | 34 +++++++++++++-------------- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/app/boards/[...id]/page.tsx b/src/app/boards/[...id]/page.tsx index 85e29816..466ca4d0 100644 --- a/src/app/boards/[...id]/page.tsx +++ b/src/app/boards/[...id]/page.tsx @@ -10,6 +10,7 @@ import { type DropResult, Draggable, } from "react-beautiful-dnd"; +import { useFormik } from "formik"; import { api } from "~/trpc/react"; import { useBoard } from "~/app/providers/board"; @@ -29,6 +30,11 @@ interface Card { title: string; } +interface FormValues { + boardId: string; + name: string; +} + type PublicListId = string; export default function BoardPage() { @@ -38,7 +44,23 @@ export default function BoardPage() { const [selectedPublicListId, setSelectedPublicListId] = useState(""); - const boardId = params?.id?.length && params.id[0]; + const boardId = params?.id?.length ? params.id[0] : null; + + const updateBoard = api.board.update.useMutation(); + + const formik = useFormik({ + initialValues: { + boardId: boardId ?? "", + name: boardData?.name ? boardData.name : "", + }, + onSubmit: (values: FormValues) => { + updateBoard.mutate({ + boardId: values.boardId, + name: values.name, + }); + }, + enableReinitialize: true, + }); if (!boardId) return <>; @@ -113,9 +135,20 @@ export default function BoardPage() { return (
-

- {boardData?.name} -

+
+ +