Skip to content

Commit

Permalink
refactor: 등록 및 수정 페이지 스키마 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
ccwnc committed Apr 12, 2024
1 parent 78d6d6c commit 2fd7561
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
39 changes: 39 additions & 0 deletions src/apis/activities/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { z } from 'zod';

const POST_SCHEMA_DEFAULT = z.object({
price: z.string(),
title: z.string().min(1),
description: z.string().min(5),
});

export const PostSchema = [
POST_SCHEMA_DEFAULT.extend({
headcount: z.string().min(1),
address: z.string().min(1),
discord: z.string().min(1),
date: z.string().min(1),
startTime: z.string().min(1),
endTime: z.string().min(1),
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),

POST_SCHEMA_DEFAULT.extend({
headcount: z.string().min(1),
discord: z.string().min(1),
date: z.string().min(1),
startTime: z.string().min(1),
endTime: z.string().min(1),
}),

POST_SCHEMA_DEFAULT.extend({
discord: z.string().min(1),
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),

POST_SCHEMA_DEFAULT.extend({
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),
];
2 changes: 1 addition & 1 deletion src/components/createPage/PostForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useDaumPostcodePopup } from 'react-daum-postcode';
import { FormProvider, useForm } from 'react-hook-form';

import Activities from '@/apis/activities';
import { PostSchema } from '@/apis/activities/schema';
import {
ADDRESS_CUSTOM_THEME,
ADDRESS_POPUP_SIZE,
Expand All @@ -20,7 +21,6 @@ import {
PAGE_PATHS,
PAGE_PATHS_MAINLIST_BY_CATEGORY,
PRICE_RADIO_LIST,
PostSchema,
SCRIPT_URL,
recruitmentTypes,
} from '@/constants';
Expand Down
2 changes: 1 addition & 1 deletion src/components/editPage/EditForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useDaumPostcodePopup } from 'react-daum-postcode';
import { FormProvider, useForm } from 'react-hook-form';

import Activities from '@/apis/activities';
import { PostSchema } from '@/apis/activities/schema';
import { MyActivities } from '@/apis/myActivities';
import {
ADDRESS_CUSTOM_THEME,
Expand All @@ -17,7 +18,6 @@ import {
DEFAULT_API_DATA_BANNER_IMAGE,
PAGE_PATHS,
PRICE_RADIO_LIST,
PostSchema,
SCRIPT_URL,
recruitmentTypes,
} from '@/constants';
Expand Down
40 changes: 0 additions & 40 deletions src/constants/postForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { z } from 'zod';

import { POST_TYPES } from './postTypes';

export const PRICE_RADIO_LIST = [
Expand All @@ -9,44 +7,6 @@ export const PRICE_RADIO_LIST = [
{ id: POST_TYPES['game-strategy'], label: POST_TYPES['game-strategy'], value: 3 },
];

const POST_SCHEMA_DEFAULT = z.object({
price: z.string(),
title: z.string().min(1),
description: z.string().min(5),
});

export const PostSchema = [
POST_SCHEMA_DEFAULT.extend({
headcount: z.string().min(1),
address: z.string().min(1),
discord: z.string().min(1),
date: z.string().min(1),
startTime: z.string().min(1),
endTime: z.string().min(1),
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),

POST_SCHEMA_DEFAULT.extend({
headcount: z.string().min(1),
discord: z.string().min(1),
date: z.string().min(1),
startTime: z.string().min(1),
endTime: z.string().min(1),
}),

POST_SCHEMA_DEFAULT.extend({
discord: z.string().min(1),
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),

POST_SCHEMA_DEFAULT.extend({
bannerImageUrl: z.string().optional(),
subImageUrls: z.string().optional(),
}),
];

export const SCRIPT_URL = '//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js';

export const ADDRESS_POPUP_SIZE = {
Expand Down

0 comments on commit 2fd7561

Please sign in to comment.