diff --git a/client/components/post/PostForm/PostForm.tsx b/client/components/post/PostForm/PostForm.tsx index 49dfc8fc..7d517282 100644 --- a/client/components/post/PostForm/PostForm.tsx +++ b/client/components/post/PostForm/PostForm.tsx @@ -18,11 +18,11 @@ import { Selector, Editor, ImageUploader, + Button, } from "@components/shared/Form"; import SeriesCreateModalOpenButton from "./SeriesCreateModalOpenButton"; import { toast } from "react-toastify"; import { revalidatePost, revalidateSeries } from "@utils"; -import Button from "@components/shared/Form/Button"; interface Props { mode: "write" | "edit"; diff --git a/client/components/post/PostForm/SeriesCreateModalOpenButton.tsx b/client/components/post/PostForm/SeriesCreateModalOpenButton.tsx index f7090409..adf4d65d 100644 --- a/client/components/post/PostForm/SeriesCreateModalOpenButton.tsx +++ b/client/components/post/PostForm/SeriesCreateModalOpenButton.tsx @@ -2,7 +2,7 @@ import { useOverlay } from "@hooks"; import React from "react"; import styles from "./styles.module.scss"; import { OVERLAYS } from "@components/shared/Overlays/Overlays"; -import Button from "@components/shared/Form/Button"; +import { Button } from "@components/shared/Form"; const SeriesCreateModalOpenButton = () => { const { openOverlay } = useOverlay(); diff --git a/client/components/shared/Form/index.ts b/client/components/shared/Form/index.ts index 287edafa..870fdb6f 100644 --- a/client/components/shared/Form/index.ts +++ b/client/components/shared/Form/index.ts @@ -4,3 +4,4 @@ export { default as Input } from "./Input"; export { default as CheckBox } from "./CheckBox"; export { default as Editor } from "./Editor"; export { default as ImageUploader } from "./ImageUploader"; +export { default as Button } from "./Button"; diff --git a/client/components/shared/Overlays/AuthModal/LoginForm.tsx b/client/components/shared/Overlays/AuthModal/LoginForm.tsx index bf9ad4ed..be320723 100644 --- a/client/components/shared/Overlays/AuthModal/LoginForm.tsx +++ b/client/components/shared/Overlays/AuthModal/LoginForm.tsx @@ -5,8 +5,8 @@ import { toast } from "react-toastify"; import { MESSAGE } from "@constants"; import { UserFormDataType } from "@Types/user"; import { useForm, type SubmitHandler } from "react-hook-form"; -import { ErrorMsg, Input } from "@components/shared/Form"; -import Button from "@components/shared/Form/Button"; +import { ErrorMsg, Input, Button } from "@components/shared/Form"; + interface Props { onClose: () => void; openSignUpModal: () => void; diff --git a/client/components/shared/Overlays/AuthModal/SignUpForm.tsx b/client/components/shared/Overlays/AuthModal/SignUpForm.tsx index 97c4a557..aa6ab786 100644 --- a/client/components/shared/Overlays/AuthModal/SignUpForm.tsx +++ b/client/components/shared/Overlays/AuthModal/SignUpForm.tsx @@ -5,8 +5,7 @@ import { toast } from "react-toastify"; import { MESSAGE } from "@constants"; import { useForm, type SubmitHandler } from "react-hook-form"; import { UserFormDataType } from "@Types/user"; -import { ErrorMsg, Input } from "@components/shared/Form"; -import Button from "@components/shared/Form/Button"; +import { ErrorMsg, Input, Button } from "@components/shared/Form"; interface Props { onClose: () => void; @@ -19,7 +18,7 @@ const SignUpForm = ({ onClose }: Props) => { register, handleSubmit, watch, - formState: { errors, isValid }, + formState: { errors }, } = useForm(); const { mutate: signUpMutate } = useSignUp({ diff --git a/client/components/shared/Overlays/SeriesFormModal/SeriesFormModal.tsx b/client/components/shared/Overlays/SeriesFormModal/SeriesFormModal.tsx index bbd4dfa7..c11bac20 100644 --- a/client/components/shared/Overlays/SeriesFormModal/SeriesFormModal.tsx +++ b/client/components/shared/Overlays/SeriesFormModal/SeriesFormModal.tsx @@ -1,87 +1,56 @@ import { useAddSeries } from "@hooks/query"; -import ImageUploader from "@components/shared/ImageUploader"; import ModalView from "@components/shared/ModalView/ModalView"; import { MESSAGE } from "@constants"; -import React, { - useCallback, - useRef, - useState, - type ChangeEvent, - FormEventHandler, -} from "react"; +import React, { useCallback } from "react"; import { toast } from "react-toastify"; import styles from "./styles.module.scss"; import { revalidateSeries } from "@utils"; -import { Input } from "@components/shared/Form"; -import Button from "@components/shared/Form/Button"; +import { Input, ImageUploader, Button } from "@components/shared/Form"; +import { Controller, SubmitHandler, useForm } from "react-hook-form"; interface Props { onClose: () => void; } const SeriesFormModal = ({ onClose }: Props) => { - const titleRef = useRef(null); - const shortDescriptionRef = useRef(null); - const [thumbNailUrl, setThumbNailUrl] = useState(""); + const { register, handleSubmit, control } = + useForm[0]>(); const { mutate } = useAddSeries({ onSuccess: () => { - console.log("called"); toast.success(MESSAGE.ADD_SERIES_SUCCESS); }, }); - const onImageUploadeSuccess = useCallback((imageUrl: string) => { - setThumbNailUrl(imageUrl); - }, []); - - const onChangeThumbUrl = useCallback((e: ChangeEvent) => { - setThumbNailUrl(e.target.value); - }, []); - - const onSubmit: FormEventHandler = useCallback( - (e) => { - if (!titleRef.current || !shortDescriptionRef.current) { - return; - } - e.preventDefault(); - + const onSubmit: SubmitHandler[0]> = useCallback( + ({ title, shortDescription, thumbNailUrl }) => { mutate({ - title: titleRef.current.value, - shortDescription: shortDescriptionRef.current.value, + title, + shortDescription, thumbNailUrl, }); revalidateSeries(); onClose(); }, - [mutate, onClose, thumbNailUrl] + [mutate, onClose] ); return ( -
- - - -
- - + + + ( + field.onChange(imgUrl)} /> -
- -
+ )} + />