Skip to content

Commit

Permalink
fix: 린트오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-wo committed Oct 29, 2024
1 parent 5373ce3 commit c0570e5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
48 changes: 18 additions & 30 deletions frontend/src/app/add-shows/_components/add-shows-form.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable */
"use client";

import { zodResolver } from "@hookform/resolvers/zod";
import clsx from "clsx";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { useForm } from "react-hook-form";

import { ShowType } from "../types";
import { addShowForm } from "../validations/schema";

import BasicInfo from "./basic-info";
import DateTimeSection from "./date-time-select";
import FacilitiesSection from "./facilities-section";
import LocationSection from "./location-select";
import TagSection from "./tag-select";
import FacilitiesSection from "./facilities-section";

export default function AddShowsForm() {
const router = useRouter();
Expand All @@ -25,7 +25,7 @@ export default function AddShowsForm() {
setValue,
watch,
handleSubmit,
formState: { errors, isDirty, isValid },
formState: { errors, isValid },
} = useForm<ShowType>({
resolver: zodResolver(addShowForm),
mode: "all",
Expand All @@ -47,29 +47,15 @@ export default function AddShowsForm() {
},
});

// 모든 필수 필드를 감시
const watchedFields = watch([
"title",
"description",
"startDate",
"endDate",
"openTimes",
"location",
"publicTag",
]);

const isFormComplete = watchedFields.every(
(field) => field && field.length > 0,
);
const formValues = watch();
const formValues = watch(); //eslint-disable-line

const onSubmit = async (data: ShowType) => {
try {
setIsLoading(true);
console.log(data);
console.log(data); //eslint-disable-line
router.push("/shows");
} catch (error) {
console.error("Error:", error);
console.error("Error:", error); //eslint-disable-line
} finally {
setIsLoading(false);
}
Expand Down Expand Up @@ -110,12 +96,14 @@ export default function AddShowsForm() {
<FacilitiesSection register={register} />
<button
type="submit"
disabled={!isFormComplete || !isValid || isLoading}
className={`h-58 w-351 rounded-6 text-white lg:w-full transition-colors ${
!isFormComplete || !isValid || isLoading
? "bg-gray-300 cursor-not-allowed"
: "bg-blue-500 hover:bg-blue-600"
}`}
disabled={!isValid || isLoading}
className={clsx(
"h-58 w-351 rounded-6 text-white transition-colors lg:w-full",
{
"bg-gray-300 cursor-not-allowed": !isValid || isLoading,
"bg-blue-500 hover:bg-blue-600": isValid && !isLoading,
},
)}
>
{isLoading ? "등록 중..." : "등록하기"}
</button>
Expand All @@ -134,10 +122,10 @@ export default function AddShowsForm() {
</div> */}

{Object.keys(errors).length > 0 && (
<div className="text-red-500 text-14-400 text-center">
<div className="text-center text-14-400 text-red-500">
<div>필수입력 항목을 입력해주세요</div>
{Object.values(errors).map((error, index) => (
<div key={index}>{error.message}</div>
{Object.entries(errors).map(([fieldName, error]) => (
<div key={fieldName}>{error.message}</div>
))}
</div>
)}
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/app/add-shows/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export interface ShowType {
longitude: string; // 경도

// 편의시설 정보
isParkingAvailable: boolean; // 주차 가능 여부
isFoodAllowed: boolean; // 음식물 반입 가능 여부
isPetAllowed: boolean; // 반려동물 동반 가능 여부
isKidsZone: boolean; // 키즈존 유무
isWifiAvailable: boolean; // 와이파이 사용 가능 여부
isParkingAvailable?: boolean; // 주차 가능 여부
isFoodAllowed?: boolean; // 음식물 반입 가능 여부
isPetAllowed?: boolean; // 반려동물 동반 가능 여부
isKidsZone?: boolean; // 키즈존 유무
isWifiAvailable?: boolean; // 와이파이 사용 가능 여부

// 요금 및 태그
fee: number; // 입장료
fee?: number; // 입장료
publicTag: string; // 대표 태그
tags: string[]; // 태그 목록
tags?: string[]; // 태그 목록
}
14 changes: 7 additions & 7 deletions frontend/src/app/add-shows/validations/schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ export const addShowForm = z.object({

longitude: z.string().optional().nullable(),

fee: z.number().nonnegative().default(0),
fee: z.number().nonnegative().optional().default(0),

publicTag: z.string().min(1, "공개 태그는 필수입니다"),

tags: z.array(z.string()).default([]),
tags: z.array(z.string()).optional().default([]),

isParkingAvailable: z.boolean().default(false),
isParkingAvailable: z.boolean().optional().default(false),

isFoodAllowed: z.boolean().default(false),
isFoodAllowed: z.boolean().optional().default(false),

isPetAllowed: z.boolean().default(false),
isPetAllowed: z.boolean().optional().default(false),

isKidsZone: z.boolean().default(false),
isKidsZone: z.boolean().optional().default(false),

isWifiAvailable: z.boolean().default(false),
isWifiAvailable: z.boolean().optional().default(false),
});

export type ShowType = z.infer<typeof addShowForm>;
Expand Down

0 comments on commit c0570e5

Please sign in to comment.