diff --git a/src/apis/index.ts b/src/apis/index.ts index 78d2b5b8..551e436a 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -2,7 +2,7 @@ import axios from 'axios'; import qs from 'qs'; const getToken = () => - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjIsInRlYW1JZCI6IjUtOSIsInNjb3BlIjoiYWNjZXNzIiwiaWF0IjoxNzIxNzI1NTI4LCJleHAiOjE3MjE3MjczMjgsImlzcyI6InNwLWVwaWdyYW0ifQ.9mNv7cYvpAelu8Z9Db6yvmyn4jj8UcaESnXDyefSRWc'; + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjIsInRlYW1JZCI6IjUtOSIsInNjb3BlIjoiYWNjZXNzIiwiaWF0IjoxNzIxNzQ0MDk3LCJleHAiOjE3MjE3NDU4OTcsImlzcyI6InNwLWVwaWdyYW0ifQ.vLG7eh4hG3Ka5r5xfmP9So2zt9-PcighDrTCmQ8wkAk'; const httpClient = axios.create({ baseURL: process.env.NEXT_PUBLIC_BASE_URL, diff --git a/src/pageLayout/Epigram/AddEpigram.tsx b/src/pageLayout/Epigram/AddEpigram.tsx index ee150f22..fcbb4ad3 100644 --- a/src/pageLayout/Epigram/AddEpigram.tsx +++ b/src/pageLayout/Epigram/AddEpigram.tsx @@ -114,6 +114,11 @@ function AddEpigram() { addEpigramMutation.mutate(submitData); }; + const isRequiredFieldsValid = () => { + const { content, author, tags } = form.getValues(); + return content.trim() !== '' && author.trim() !== '' && tags.length > 0; + }; + return ( <>
{}} /> @@ -254,7 +259,7 @@ function AddEpigram() { {field.value.map((tag) => (
{tag} -
@@ -267,7 +272,7 @@ function AddEpigram() { diff --git a/src/schema/addEpigram.ts b/src/schema/addEpigram.ts index f0e2490c..1d5d6818 100644 --- a/src/schema/addEpigram.ts +++ b/src/schema/addEpigram.ts @@ -4,7 +4,7 @@ const urlRegex = /^https?:\/\/.+/; export const AddEpigramRequestSchema = z.object({ tags: z.array(z.string().min(1).max(10)).max(3), - referenceUrl: z.string().url().regex(urlRegex, { message: '올바른 URL 형식이 아닙니다.' }).optional().nullable(), + referenceUrl: z.string().url().regex(urlRegex).optional().nullable(), referenceTitle: z.string().max(100).optional().nullable(), author: z.string().min(1).max(30), content: z.string().min(1).max(500), @@ -27,13 +27,18 @@ export const AddEpigramResponseSchema = z.object({ }); // 폼 입력값을 위한 스키마 -export const AddEpigramFormSchema = z.object({ - tags: z.array(z.string().min(1).max(10)).min(1, { message: '최소 1개의 태그를 추가해주세요.' }).max(3), - referenceUrl: z.union([z.string().url().regex(urlRegex), z.string().max(0)]).optional(), - referenceTitle: z.string().max(100).optional(), - author: z.string().min(1, { message: '저자의 이름을 입력해주세요' }).max(30), - content: z.string().min(1, { message: '내용을 입력해주세요.' }).max(500, { message: '500자 이내로 입력해주세요.' }), -}); +export const AddEpigramFormSchema = z + .object({ + tags: z.array(z.string().min(1).max(10)).min(1, { message: '최소 1개의 태그를 추가해주세요.' }).max(3), + author: z.string().min(1, { message: '저자의 이름을 입력해주세요' }).max(30), + content: z.string().min(1, { message: '내용을 입력해주세요.' }).max(500, { message: '500자 이내로 입력해주세요.' }), + referenceUrl: z.union([z.string().url().regex(urlRegex, { message: '올바른 URL 형식이 아닙니다.' }), z.literal('')]).optional(), + referenceTitle: z.union([z.string().max(100, { message: '100자 이내로 입력해주세요.' }), z.literal('')]).optional(), + }) + .refine((data) => (data.referenceUrl === '' && data.referenceTitle === '') || (data.referenceUrl !== '' && data.referenceTitle !== ''), { + message: 'URL과 제목을 모두 입력하거나 모두 비워두세요.', + path: ['referenceUrl', 'referenceTitle'], + }); export type AddEpigramRequestType = z.infer; export type AddEpigramResponseType = z.infer;