diff --git a/bun.lockb b/bun.lockb index e412d77d..ebf79ef3 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 2c62c8a8..fa5799a1 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,6 @@ "@trpc/server": "next", "@vercel/postgres": "^0.7.2", "drizzle-orm": "^0.28.5", - "formik": "^2.4.5", "next": "^14.1.3", "postgres": "^3.4.4", "react": "18.2.0", diff --git a/src/views/board/components/List.tsx b/src/views/board/components/List.tsx index 9907f23f..6c6b8208 100644 --- a/src/views/board/components/List.tsx +++ b/src/views/board/components/List.tsx @@ -1,7 +1,7 @@ import { type ReactNode } from "react"; import { HiOutlinePlusSmall } from "react-icons/hi2"; import { Draggable } from "react-beautiful-dnd"; -import { useFormik } from "formik"; +import { useForm } from "react-hook-form"; import { api } from "~/utils/api"; import { useModal } from "~/providers/modal"; @@ -42,20 +42,20 @@ export default function List({ const updateList = api.list.update.useMutation(); - const formik = useFormik({ - initialValues: { + const { register, handleSubmit, setValue } = useForm({ + defaultValues: { listPublicId: list.publicId, name: list.name, }, - onSubmit: (values: FormValues) => { - updateList.mutate({ - listPublicId: values.listPublicId, - name: values.name, - }); - }, - enableReinitialize: true, }); + const onSubmit = (values: FormValues) => { + updateList.mutate({ + listPublicId: values.listPublicId, + name: values.name, + }); + }; + return ( {(provided) => ( @@ -68,17 +68,15 @@ export default function List({ >
diff --git a/src/views/board/index.tsx b/src/views/board/index.tsx index d1fcd4d4..9a36fe7f 100644 --- a/src/views/board/index.tsx +++ b/src/views/board/index.tsx @@ -8,7 +8,7 @@ import { type DropResult, Draggable, } from "react-beautiful-dnd"; -import { useFormik } from "formik"; +import { useForm } from "react-hook-form"; import { api } from "~/utils/api"; import { useBoard } from "~/providers/board"; @@ -40,20 +40,20 @@ export default function BoardPage() { const updateBoard = api.board.update.useMutation(); - const formik = useFormik({ - initialValues: { + const { register, handleSubmit, setValue } = useForm({ + values: { boardPublicId: boardId ?? "", - name: boardData?.name ? boardData.name : "", + name: "", }, - onSubmit: (values: UpdateBoardInput) => { - updateBoard.mutate({ - boardPublicId: values.boardPublicId, - name: values.name, - }); - }, - enableReinitialize: true, }); + const onSubmit = (values: UpdateBoardInput) => { + updateBoard.mutate({ + boardPublicId: values.boardPublicId, + name: values.name, + }); + }; + const { data, isSuccess, isLoading } = api.board.byId.useQuery( { boardPublicId: boardId ?? "" }, { @@ -64,8 +64,9 @@ export default function BoardPage() { useEffect(() => { if (isSuccess && data) { setBoardData(data); + setValue("name", data.name || ""); } - }, [isSuccess, data, setBoardData]); + }, [isSuccess, data, setBoardData, setValue]); if (!boardId || !boardData) return <>; @@ -136,16 +137,14 @@ export default function BoardPage() {
) : (
diff --git a/src/views/card/components/LabelSelector.tsx b/src/views/card/components/LabelSelector.tsx index 0264d76b..76ec0a86 100644 --- a/src/views/card/components/LabelSelector.tsx +++ b/src/views/card/components/LabelSelector.tsx @@ -2,7 +2,7 @@ import { Fragment } from "react"; import { api } from "~/utils/api"; import { Menu, Transition } from "@headlessui/react"; import { HiMiniPlus } from "react-icons/hi2"; -import { useFormik } from "formik"; +import { useForm } from "react-hook-form"; import { useModal } from "~/providers/modal"; @@ -33,18 +33,16 @@ export default function LabelSelector({ }, }); - const formik = useFormik({ - initialValues: { - ...Object.fromEntries( - labels?.map((label) => [label.publicId, label.selected]) ?? [], - ), - }, - onSubmit: (values) => { - console.log({ values }); - }, - enableReinitialize: true, + const { register, handleSubmit, setValue, watch } = useForm({ + values: Object.fromEntries( + labels?.map((label) => [label.publicId, label.selected]) ?? [], + ), }); + const onSubmit = (values: Record) => { + console.log({ values }); + }; + const selectedLabels = labels.filter((label) => label.selected); return ( @@ -99,36 +97,32 @@ export default function LabelSelector({ >
-
+ {labels?.map((label) => ( {() => (
{ - e.preventDefault(); - await formik.setFieldValue( - label.publicId, - !formik.values[label.publicId], - ); + onClick={async () => { + const newValue = !watch(label.publicId); + setValue(label.publicId, newValue); addOrRemoveLabel.mutate({ cardPublicId, labelPublicId: label.publicId, }); - await formik.submitForm(); + handleSubmit(onSubmit)(); }} > event.stopPropagation()} - onChange={formik.handleChange} - checked={formik.values[label.publicId]} + {...register(label.publicId)} + checked={watch(label.publicId)} />