From 31128119ac1e8657a9899273e11ea018c56238e2 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 15 Aug 2024 21:38:10 +0100 Subject: [PATCH] chore: update modal design --- src/components/Button.tsx | 43 +++ src/components/Input.tsx | 18 ++ src/components/NewWorkspaceForm.tsx | 6 +- src/components/modal.tsx | 2 +- src/views/board/components/NewCardForm.tsx | 8 +- src/views/board/components/NewListForm.tsx | 59 ++-- src/views/boards/components/BoardsList.tsx | 2 +- .../boards/components/ImportBoardsForm.tsx | 271 ++++++++---------- src/views/boards/components/NewBoardForm.tsx | 90 +++--- 9 files changed, 260 insertions(+), 239 deletions(-) create mode 100644 src/components/Button.tsx create mode 100644 src/components/Input.tsx diff --git a/src/components/Button.tsx b/src/components/Button.tsx new file mode 100644 index 00000000..280816ae --- /dev/null +++ b/src/components/Button.tsx @@ -0,0 +1,43 @@ +interface ButtonProps extends React.ButtonHTMLAttributes { + isLoading?: boolean; +} + +const Button = ({ children, isLoading, ...props }: ButtonProps) => { + return ( + + ); +}; + +export default Button; diff --git a/src/components/Input.tsx b/src/components/Input.tsx new file mode 100644 index 00000000..38c03ca6 --- /dev/null +++ b/src/components/Input.tsx @@ -0,0 +1,18 @@ +import React, { forwardRef } from "react"; + +const Input = forwardRef< + HTMLInputElement, + React.InputHTMLAttributes +>(({ ...props }, ref) => { + return ( + + ); +}); + +Input.displayName = "Input"; + +export default Input; diff --git a/src/components/NewWorkspaceForm.tsx b/src/components/NewWorkspaceForm.tsx index 9b0ff2c7..ef3d9d99 100644 --- a/src/components/NewWorkspaceForm.tsx +++ b/src/components/NewWorkspaceForm.tsx @@ -12,11 +12,7 @@ interface FormValues { export function NewWorkspaceForm() { const { closeModal } = useModal(); const { switchWorkspace } = useWorkspace(); - const { - register, - handleSubmit, - formState: { errors }, - } = useForm(); + const { register, handleSubmit } = useForm(); const createWorkspace = api.workspace.create.useMutation({ onSuccess: (values) => { diff --git a/src/components/modal.tsx b/src/components/modal.tsx index 81ef9065..1f1f70fc 100644 --- a/src/components/modal.tsx +++ b/src/components/modal.tsx @@ -46,7 +46,7 @@ const Modal: React.FC = ({ children, modalSize = "sm" }) => { leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" > {children} diff --git a/src/views/board/components/NewCardForm.tsx b/src/views/board/components/NewCardForm.tsx index 0ff9deea..cae4dc25 100644 --- a/src/views/board/components/NewCardForm.tsx +++ b/src/views/board/components/NewCardForm.tsx @@ -55,12 +55,12 @@ export function NewCardForm({ listPublicId }: NewCardFormProps) { const position = watch("position"); const createCard = api.card.create.useMutation({ - onSuccess: () => { - refetchBoard(); + onSuccess: async () => { + await refetchBoard(); }, - onError: () => { + onError: async () => { closeModal(); - refetchBoard(); + await refetchBoard(); showPopup({ header: "Unable to create card", message: "Please try again later, or contact customer support.", diff --git a/src/views/board/components/NewListForm.tsx b/src/views/board/components/NewListForm.tsx index a5b02613..9792a2e9 100644 --- a/src/views/board/components/NewListForm.tsx +++ b/src/views/board/components/NewListForm.tsx @@ -36,10 +36,12 @@ export function NewListForm({ boardPublicId }: { boardPublicId: string }) { const isCreateAnotherEnabled = watch("isCreateAnotherEnabled"); const createList = api.list.create.useMutation({ - onSuccess: () => refetchBoard(), - onError: () => { + onSuccess: async () => { + await refetchBoard(); + }, + onError: async () => { closeModal(); - refetchBoard(); + await refetchBoard(); showPopup({ header: "Unable to create list", message: "Please try again later, or contact customer support.", @@ -69,32 +71,32 @@ export function NewListForm({ boardPublicId }: { boardPublicId: string }) { }; return ( -
-
-

- New list -

- -
+
+
+
+

+ New list +

+ +
- - -
+
+
+
Create more @@ -110,7 +112,7 @@ export function NewListForm({ boardPublicId }: { boardPublicId: string }) { "relative inline-flex h-4 w-6 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none", )} > - Create more + Create another
-
+ +
- -
+
+ ); } diff --git a/src/views/boards/components/BoardsList.tsx b/src/views/boards/components/BoardsList.tsx index 10d43ede..a914f997 100644 --- a/src/views/boards/components/BoardsList.tsx +++ b/src/views/boards/components/BoardsList.tsx @@ -27,7 +27,7 @@ export function BoardsList() {
{data?.map((board) => ( -
+

{board.name} diff --git a/src/views/boards/components/ImportBoardsForm.tsx b/src/views/boards/components/ImportBoardsForm.tsx index 7c2acfdb..35427f1d 100644 --- a/src/views/boards/components/ImportBoardsForm.tsx +++ b/src/views/boards/components/ImportBoardsForm.tsx @@ -1,6 +1,7 @@ import { Fragment, useState } from "react"; import { api } from "~/utils/api"; import { Listbox, Transition } from "@headlessui/react"; +import { useForm, Controller } from "react-hook-form"; import { FaTrello } from "react-icons/fa"; import { HiChevronUpDown, HiXMark } from "react-icons/hi2"; @@ -8,7 +9,8 @@ import { HiChevronUpDown, HiXMark } from "react-icons/hi2"; import { useModal } from "~/providers/modal"; import { useWorkspace } from "~/providers/workspace"; -import { useFormik } from "formik"; +import Button from "~/components/Button"; +import Input from "~/components/Input"; interface TrelloFormValues { apiKey: string; @@ -18,77 +20,78 @@ interface TrelloFormValues { const sources = [{ source: "Trello" }]; const SelectSource = ({ handleNextStep }: { handleNextStep: () => void }) => { - const formik = useFormik({ - initialValues: { + const { control, handleSubmit } = useForm({ + defaultValues: { source: "Trello", }, - onSubmit: () => { - handleNextStep(); - }, }); - return ( -

- - - {({ open }) => ( - <> -
- - - - - {formik.values.source} - - - - - + const onSubmit = () => { + handleNextStep(); + }; - - - {sources.map(({ source }, index) => ( - -
- - - {source} + return ( + +
+ ( + + {({ open }) => ( + <> +
+ + + + + {field.value} -
- - ))} - - -
- - )} - -
- + + + + + + + + {sources.map(({ source }, index) => ( + +
+ + + {source} + +
+
+ ))} +
+
+
+ + )} + + )} + /> +
+ +
+
+ +
); @@ -126,121 +129,85 @@ const ImportTrello: React.FC = () => { }, }); - const formik = useFormik({ - initialValues: { + const { register, handleSubmit } = useForm({ + defaultValues: { apiKey: "", token: "", }, - onSubmit: (values: TrelloFormValues) => { - handleSetAuthDetails(values.apiKey, values.token); - }, }); - const boardsFormik = useFormik({ - initialValues: { - ...Object.fromEntries( + const onSubmit = (values: TrelloFormValues) => { + handleSetAuthDetails(values.apiKey, values.token); + }; + + const { register: registerBoards, handleSubmit: handleSubmitBoards } = + useForm({ + defaultValues: Object.fromEntries( boards?.data?.map((board) => [board.id, true]) ?? [], ), - }, - onSubmit: () => { - const boardIds = Object.keys(boardsFormik.values).filter( - (key) => boardsFormik.values[key] === true, - ); + }); - importBoards.mutate({ - boardIds, - apiKey: formik.values.apiKey, - token: formik.values.token, - workspacePublicId: workspace?.publicId, - }); - }, - enableReinitialize: true, - }); + const onSubmitBoards = (values: Record) => { + const boardIds = Object.keys(values).filter((key) => values[key] === true); + + importBoards.mutate({ + boardIds, + apiKey, + token, + workspacePublicId: workspace?.publicId, + }); + }; if (boards?.data?.length) return ( -
-
+ +
{boards.data.map((board) => (
-
{ - e.preventDefault(); - await boardsFormik.setFieldValue( - board.id, - !boardsFormik.values[board.id], - ); - }} +
+ +
))}
-
- +
+
+ +
); return (
- - - - -
- +
+ + +
+ +
+
+ +
); @@ -251,8 +218,8 @@ export function ImportBoardsForm() { const [step, setStep] = useState(1); return ( -
-
+
+

New import

diff --git a/src/views/boards/components/NewBoardForm.tsx b/src/views/boards/components/NewBoardForm.tsx index 026fbc32..c24ec113 100644 --- a/src/views/boards/components/NewBoardForm.tsx +++ b/src/views/boards/components/NewBoardForm.tsx @@ -1,12 +1,8 @@ import { api } from "~/utils/api"; - import { HiXMark } from "react-icons/hi2"; - import { useModal } from "~/providers/modal"; import { useWorkspace } from "~/providers/workspace"; - -import { Formik, Form, Field } from "formik"; - +import { useForm } from "react-hook-form"; import { type NewBoardInput } from "~/types/router.types"; export function NewBoardForm() { @@ -14,6 +10,13 @@ export function NewBoardForm() { const { closeModal } = useModal(); const { workspace } = useWorkspace(); + const { register, handleSubmit } = useForm({ + defaultValues: { + name: "", + workspacePublicId: workspace?.publicId || "", + }, + }); + const refetchBoards = () => utils.board.all.refetch(); const createBoard = api.board.create.useMutation({ @@ -23,52 +26,43 @@ export function NewBoardForm() { }, }); + const onSubmit = (data: NewBoardInput) => { + createBoard.mutate(data); + }; + return ( - <> -
-

New board

- +
+
+
+

New board

+ +
+
- { - createBoard.mutate({ - name: values.name, - workspacePublicId: workspace?.publicId, - }); - }} - > - -
- + Create board + +
+
+ ); }