Skip to content

Commit

Permalink
Merge pull request #271 from TripInfoWeb/dev_informations
Browse files Browse the repository at this point in the history
Refactor: 정보 등록 시 useForm 사용
  • Loading branch information
HyunJinNo authored Sep 6, 2024
2 parents 1e8ab50 + 131233f commit 1de881e
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 175 deletions.
51 changes: 48 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 2 additions & 21 deletions src/components/diary/write/DiaryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useDiaryEditorStoreType } from "@/store/diaryEditorStore";
import dynamic from "next/dynamic";
import QuillEditorSkeleton from "@/components/skeleton/common/QuillEditorSkeleton";
import { useFormContext } from "react-hook-form";
import { parse } from "node-html-parser";

const QuillEditorContainer = dynamic(
() => import("@/containers/diary/write/QuillEditorContainer"),
Expand Down Expand Up @@ -62,7 +61,7 @@ const DiaryEditor = ({
제목<span className="text-main">*</span>
</h2>
<input
className={`${formContext.formState.errors.title ? "border-red-500" : "border-gray3 hover:border-main"} h-full flex-grow rounded-full border-[0.0625rem] bg-transparent pl-5 text-sm outline-none`}
className={`${formContext.formState.errors.title ? "border-red-500" : "border-gray3 hover:border-main focus:border-main"} h-full flex-grow rounded-full border-[0.0625rem] bg-transparent pl-5 text-sm outline-none`}
type="text"
placeholder="제목을 입력하세요."
{...formContext.register("title")}
Expand Down Expand Up @@ -208,25 +207,7 @@ const DiaryEditor = ({
<button
className={`${diaryEditorStore.days > 0 ? "bg-main hover:scale-105" : "cursor-not-allowed bg-gray1"} mb-[5.3125rem] mt-10 flex h-[2.625rem] w-[9.625rem] items-center justify-center self-end rounded-full text-[0.9375rem] text-white`}
type="submit"
onClick={() => {
const imageUrl =
parse(formContext.getValues("contents")[0])
.querySelector("img")
?.getAttribute("src") ?? "";

if (imageUrl === "") {
alert("Day1에 최소 1장의 이미지를 등록해 주세요.");
return;
}

formContext.setValue("image", imageUrl);

if (!formContext.formState.isValid) {
formContext.trigger();
} else {
onSubmit();
}
}}
onClick={() => onSubmit()}
disabled={diaryEditorStore.days === 0 || loading}
>
{loading ? (
Expand Down
Loading

0 comments on commit 1de881e

Please sign in to comment.