diff --git a/src/v1/bookGroup/create/steps/EnterTitleStep/fields/TitleField.tsx b/src/v1/bookGroup/create/steps/EnterTitleStep/fields/TitleField.tsx index 7f74cdf48..9bdada48a 100644 --- a/src/v1/bookGroup/create/steps/EnterTitleStep/fields/TitleField.tsx +++ b/src/v1/bookGroup/create/steps/EnterTitleStep/fields/TitleField.tsx @@ -1,13 +1,13 @@ import { useFormContext, useWatch } from 'react-hook-form'; -import type { EnterTitleStepValues } from '../EnterTitleStep'; +import type { EnterTitleStepFormValues } from '../../../types'; import ErrorMessage from '@/v1/base/ErrorMessage'; import Input from '@/v1/base/Input'; import InputLength from '@/v1/base/InputLength'; type DefaultFieldNameProps = { - name: keyof EnterTitleStepValues; + name: keyof EnterTitleStepFormValues; }; const TitleField = ({ name }: DefaultFieldNameProps) => { @@ -15,7 +15,7 @@ const TitleField = ({ name }: DefaultFieldNameProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const titleValue = useWatch({ control, name: name }); const titleErrors = errors[name]; diff --git a/src/v1/bookGroup/create/steps/EnterTitleStep/index.ts b/src/v1/bookGroup/create/steps/EnterTitleStep/index.ts deleted file mode 100644 index 90646c32e..000000000 --- a/src/v1/bookGroup/create/steps/EnterTitleStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { EnterTitleStepValues } from './EnterTitleStep'; -export { default as EnterTitleStep } from './EnterTitleStep'; diff --git a/src/v1/bookGroup/create/funnel/SelectBookStep.tsx b/src/v1/bookGroup/create/steps/SelectBookStep/SelectBookStep.tsx similarity index 91% rename from src/v1/bookGroup/create/funnel/SelectBookStep.tsx rename to src/v1/bookGroup/create/steps/SelectBookStep/SelectBookStep.tsx index f7492292c..9fd306c8f 100644 --- a/src/v1/bookGroup/create/funnel/SelectBookStep.tsx +++ b/src/v1/bookGroup/create/steps/SelectBookStep/SelectBookStep.tsx @@ -2,7 +2,8 @@ import { ComponentPropsWithoutRef, Suspense, useEffect, useState } from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import { useInView } from 'react-intersection-observer'; -import { SearchedBookWithId } from '@/types/book'; +import type { MoveFunnelStepProps } from '@/v1/base/Funnel'; +import type { SelectBookStepFormValues } from '../../types'; import useBookSearchQuery from '@/queries/book/useBookSearchQuery'; import debounce from '@/utils/debounce'; @@ -11,20 +12,9 @@ import Input from '@/v1/base/Input'; import Loading from '@/v1/base/Loading'; import BookSearchList from '@/v1/bookSearch/BookSearchList'; -// TODO: Funnel 파일 내부로 이동 -interface MoveFunnelStepProps { - onPrevStep?: () => void; - onNextStep?: () => void; -} - -export type SelectBookFormValue = { - book: SearchedBookWithId; - queryKeyword: string; -}; - const SelectBookStep = ({ onNextStep }: MoveFunnelStepProps) => { const { control, getValues, setValue } = - useFormContext(); + useFormContext(); const keywordValue = getValues('queryKeyword'); const [keyword, setKeyword] = useState(keywordValue || ''); diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/SelectJoinTypeStep.tsx b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/SelectJoinTypeStep.tsx index 94037a13c..689e28858 100644 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/SelectJoinTypeStep.tsx +++ b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/SelectJoinTypeStep.tsx @@ -1,26 +1,16 @@ import { useFormContext } from 'react-hook-form'; -import BottomActionButton from '@/v1/base/BottomActionButton'; +import type { MoveFunnelStepProps } from '@/v1/base/Funnel'; +import type { SelectJoinTypeStepFormValues } from '../../types'; +import BottomActionButton from '@/v1/base/BottomActionButton'; import { JoinPasswordFieldset, JoinTypeFieldset } from './fields'; -interface MoveFunnelStepProps { - onPrevStep?: () => void; - onNextStep?: () => void; - onSubmit?: () => void; -} - -export type JoinTypeStepFormValues = { - hasJoinPasswd: 'true' | 'false'; - joinQuestion?: string; - joinPasswd?: string; -}; - -export type JoinTypeStepFieldName = keyof JoinTypeStepFormValues; +export type JoinTypeStepFieldName = keyof SelectJoinTypeStepFormValues; export type JoinTypeStepFieldProp = { name: JoinTypeStepFieldName }; const SelectJoinTypeStep = ({ onSubmit }: MoveFunnelStepProps) => { - const { handleSubmit } = useFormContext(); + const { handleSubmit } = useFormContext(); return ( @@ -28,12 +18,12 @@ const SelectJoinTypeStep = ({ onSubmit }: MoveFunnelStepProps) => { - + - + - + diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx index ee52151b7..3cefe1a36 100644 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx +++ b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx @@ -1,16 +1,16 @@ import { PropsWithChildren } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; -import ErrorMessage from '@/v1/base/ErrorMessage'; -import Input from '@/v1/base/Input'; -import InputLength from '@/v1/base/InputLength'; - -import { +import type { SelectJoinTypeStepFormValues } from '../../../types'; +import type { JoinTypeStepFieldName, - JoinTypeStepFormValues, JoinTypeStepFieldProp, } from '../SelectJoinTypeStep'; +import ErrorMessage from '@/v1/base/ErrorMessage'; +import Input from '@/v1/base/Input'; +import InputLength from '@/v1/base/InputLength'; + type JoinPasswordFieldsetProps = { joinTypeFieldName: JoinTypeStepFieldName; }; @@ -19,7 +19,7 @@ const JoinPasswordFieldset = ({ joinTypeFieldName, children, }: PropsWithChildren) => { - const { control } = useFormContext(); + const { control } = useFormContext(); const hasJoinPassword = useWatch({ control, name: joinTypeFieldName }); const shouldRender = hasJoinPassword === 'true'; @@ -38,7 +38,7 @@ const JoinQuestionField = ({ name }: JoinTypeStepFieldProp) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const joinQuestion = useWatch({ control, name }); @@ -76,7 +76,7 @@ const JoinAnswerField = ({ name }: JoinTypeStepFieldProp) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const joinPasswd = useWatch({ control, name }); diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx index 5489567d5..2270e6927 100644 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx +++ b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx @@ -1,9 +1,7 @@ import { useFormContext } from 'react-hook-form'; -import { - JoinTypeStepFormValues, - JoinTypeStepFieldProp, -} from '../SelectJoinTypeStep'; +import type { SelectJoinTypeStepFormValues } from '../../../types'; +import type { JoinTypeStepFieldProp } from '../SelectJoinTypeStep'; import JoinTypeRadioCard from './JoinTypeRadioCard'; @@ -12,7 +10,7 @@ const JoinTypeFieldset = ({ children }: { children?: React.ReactNode }) => { }; const RadioCardField = ({ name }: JoinTypeStepFieldProp) => { - const { register } = useFormContext(); + const { register } = useFormContext(); return ( <> diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts deleted file mode 100644 index d722f97c3..000000000 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { JoinTypeStepFormValues as SelectJoinTypeStepFormValues } from './SelectJoinTypeStep'; -export { default as SelectJoinTypeStep } from './SelectJoinTypeStep'; diff --git a/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx b/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx index cd4589671..55182f6e4 100644 --- a/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx +++ b/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx @@ -1,7 +1,7 @@ import { useFormContext, useWatch } from 'react-hook-form'; -import type { SearchedBookWithId } from '@/types/book'; -import type { APICreateGroup } from '@/types/group'; +import type { MoveFunnelStepProps } from '@/v1/base/Funnel'; +import type { SetUpDetailStepFormValues } from '../../types'; import { MAX_MEMBER_COUNT_OPTIONS } from '@/constants'; import { getTodayDate } from '@/utils/date'; @@ -16,12 +16,6 @@ import Switch from '@/v1/base/Switch'; import TextArea from '@/v1/base/TextArea'; import BookInfoCard from '@/v1/bookGroup/BookInfoCard'; -interface MoveFunnelStepProps { - onPrevStep?: () => void; - onNextStep?: () => void; - onSubmit?: () => void; -} - interface SetUpDetailStepProps extends MoveFunnelStepProps { goToSelectBookStep?: () => void; } @@ -31,21 +25,12 @@ interface SetUpDetailStepProps extends MoveFunnelStepProps { * Field 컴포넌트 분리 */ -export interface SetUpDetailStepValues - extends Pick< - APICreateGroup, - 'bookId' | 'title' | 'introduce' | 'startDate' | 'endDate' | 'isPublic' - > { - book: SearchedBookWithId; - maxMemberCount: string; - customMemberCount: string; -} - const SetUpDetailStep = ({ goToSelectBookStep, onNextStep, }: SetUpDetailStepProps) => { - const { handleSubmit, getValues } = useFormContext(); + const { handleSubmit, getValues } = + useFormContext(); return ( @@ -79,7 +64,7 @@ const SetUpDetailStep = ({ export default SetUpDetailStep; type SetUpDetailFieldProps = { - name: keyof SetUpDetailStepValues; + name: keyof SetUpDetailStepFormValues; }; const TitleField = ({ name }: SetUpDetailFieldProps) => { @@ -87,7 +72,7 @@ const TitleField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const titleValue = useWatch({ control, name: name }); const titleValueLength = @@ -125,7 +110,7 @@ const SelectedBookInfoField = ({ bookId?: number; onRemoveButtonClick?: () => void; }) => { - const { reset } = useFormContext(); + const { reset } = useFormContext(); const handleBookRemove = () => { onRemoveButtonClick?.(); @@ -149,7 +134,7 @@ const IntroduceField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const introduceErrors = errors[name]; @@ -176,7 +161,7 @@ const MaxMemberCountField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCountErrors = errors[name]; @@ -205,7 +190,7 @@ const CustomMemberCountField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCount = useWatch({ control, name: 'maxMemberCount' }); const isCustomInputCount = maxMemberCount === 'custom'; @@ -241,7 +226,7 @@ const PickStartDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDateErrors = errors[name]; const endDate = useWatch({ control, name: 'endDate' }); @@ -275,7 +260,7 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDate = useWatch({ control, name: 'startDate' }); const todayDate = getTodayDate(); @@ -302,14 +287,18 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { }; const SwitchIsPublicField = ({ name }: SetUpDetailFieldProps) => { - const { register } = useFormContext(); + const { register, control } = useFormContext(); + + const isCommentPublic = useWatch({ control, name }); return ( 댓글 공개 여부 - 모임에 가입하지 않은 사람도 댓글을 볼 수 있어요. + {isCommentPublic + ? '모임에 가입하지 않아도 댓글을 볼 수 있어요' + : '모임에 가입해야 댓글을 볼 수 있어요'} diff --git a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts b/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts deleted file mode 100644 index 381280758..000000000 --- a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { SetUpDetailStepValues } from './SetUpDetailStep'; -export { default as SetUpDetailStep } from './SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/steps/index.ts b/src/v1/bookGroup/create/steps/index.ts new file mode 100644 index 000000000..2b06facc9 --- /dev/null +++ b/src/v1/bookGroup/create/steps/index.ts @@ -0,0 +1,4 @@ +export { default as EnterTitleStep } from './EnterTitleStep/EnterTitleStep'; +export { default as SelectBookStep } from './SelectBookStep/SelectBookStep'; +export { default as SelectJoinTypeStep } from './SelectJoinTypeStep/SelectJoinTypeStep'; +export { default as SetUpDetailStep } from './SetUpDetailStep/SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/types.ts b/src/v1/bookGroup/create/types.ts new file mode 100644 index 000000000..a42f16fd8 --- /dev/null +++ b/src/v1/bookGroup/create/types.ts @@ -0,0 +1,40 @@ +import { SearchedBookWithId } from '@/types/book'; + +export type CreateBookGroupFormValues = { + book: SearchedBookWithId; + queryKeyword: string; + title: string; + introduce: string; + maxMemberCount: 9999 | 50 | 100 | 200 | 500 | 'custom'; + customMemberCount: number; + startDate: string; + endDate: string; + isPublic: boolean; + hasJoinPassword: 'true' | 'false'; + joinQuestion: string; + joinPassword: string; +}; + +export type SelectBookStepFormValues = Pick< + CreateBookGroupFormValues, + 'book' | 'queryKeyword' +>; + +export type EnterTitleStepFormValues = Pick; + +export type SetUpDetailStepFormValues = Pick< + CreateBookGroupFormValues, + | 'book' + | 'title' + | 'introduce' + | 'maxMemberCount' + | 'customMemberCount' + | 'startDate' + | 'endDate' + | 'isPublic' +>; + +export type SelectJoinTypeStepFormValues = Pick< + CreateBookGroupFormValues, + 'hasJoinPassword' | 'joinQuestion' | 'joinPassword' +>;
@@ -28,12 +18,12 @@ const SelectJoinTypeStep = ({ onSubmit }: MoveFunnelStepProps) => { - + - + - + diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx index ee52151b7..3cefe1a36 100644 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx +++ b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinPasswordFieldset.tsx @@ -1,16 +1,16 @@ import { PropsWithChildren } from 'react'; import { useFormContext, useWatch } from 'react-hook-form'; -import ErrorMessage from '@/v1/base/ErrorMessage'; -import Input from '@/v1/base/Input'; -import InputLength from '@/v1/base/InputLength'; - -import { +import type { SelectJoinTypeStepFormValues } from '../../../types'; +import type { JoinTypeStepFieldName, - JoinTypeStepFormValues, JoinTypeStepFieldProp, } from '../SelectJoinTypeStep'; +import ErrorMessage from '@/v1/base/ErrorMessage'; +import Input from '@/v1/base/Input'; +import InputLength from '@/v1/base/InputLength'; + type JoinPasswordFieldsetProps = { joinTypeFieldName: JoinTypeStepFieldName; }; @@ -19,7 +19,7 @@ const JoinPasswordFieldset = ({ joinTypeFieldName, children, }: PropsWithChildren) => { - const { control } = useFormContext(); + const { control } = useFormContext(); const hasJoinPassword = useWatch({ control, name: joinTypeFieldName }); const shouldRender = hasJoinPassword === 'true'; @@ -38,7 +38,7 @@ const JoinQuestionField = ({ name }: JoinTypeStepFieldProp) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const joinQuestion = useWatch({ control, name }); @@ -76,7 +76,7 @@ const JoinAnswerField = ({ name }: JoinTypeStepFieldProp) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const joinPasswd = useWatch({ control, name }); diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx index 5489567d5..2270e6927 100644 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx +++ b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/fields/JoinTypeFieldset.tsx @@ -1,9 +1,7 @@ import { useFormContext } from 'react-hook-form'; -import { - JoinTypeStepFormValues, - JoinTypeStepFieldProp, -} from '../SelectJoinTypeStep'; +import type { SelectJoinTypeStepFormValues } from '../../../types'; +import type { JoinTypeStepFieldProp } from '../SelectJoinTypeStep'; import JoinTypeRadioCard from './JoinTypeRadioCard'; @@ -12,7 +10,7 @@ const JoinTypeFieldset = ({ children }: { children?: React.ReactNode }) => { }; const RadioCardField = ({ name }: JoinTypeStepFieldProp) => { - const { register } = useFormContext(); + const { register } = useFormContext(); return ( <> diff --git a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts b/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts deleted file mode 100644 index d722f97c3..000000000 --- a/src/v1/bookGroup/create/steps/SelectJoinTypeStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { JoinTypeStepFormValues as SelectJoinTypeStepFormValues } from './SelectJoinTypeStep'; -export { default as SelectJoinTypeStep } from './SelectJoinTypeStep'; diff --git a/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx b/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx index cd4589671..55182f6e4 100644 --- a/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx +++ b/src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx @@ -1,7 +1,7 @@ import { useFormContext, useWatch } from 'react-hook-form'; -import type { SearchedBookWithId } from '@/types/book'; -import type { APICreateGroup } from '@/types/group'; +import type { MoveFunnelStepProps } from '@/v1/base/Funnel'; +import type { SetUpDetailStepFormValues } from '../../types'; import { MAX_MEMBER_COUNT_OPTIONS } from '@/constants'; import { getTodayDate } from '@/utils/date'; @@ -16,12 +16,6 @@ import Switch from '@/v1/base/Switch'; import TextArea from '@/v1/base/TextArea'; import BookInfoCard from '@/v1/bookGroup/BookInfoCard'; -interface MoveFunnelStepProps { - onPrevStep?: () => void; - onNextStep?: () => void; - onSubmit?: () => void; -} - interface SetUpDetailStepProps extends MoveFunnelStepProps { goToSelectBookStep?: () => void; } @@ -31,21 +25,12 @@ interface SetUpDetailStepProps extends MoveFunnelStepProps { * Field 컴포넌트 분리 */ -export interface SetUpDetailStepValues - extends Pick< - APICreateGroup, - 'bookId' | 'title' | 'introduce' | 'startDate' | 'endDate' | 'isPublic' - > { - book: SearchedBookWithId; - maxMemberCount: string; - customMemberCount: string; -} - const SetUpDetailStep = ({ goToSelectBookStep, onNextStep, }: SetUpDetailStepProps) => { - const { handleSubmit, getValues } = useFormContext(); + const { handleSubmit, getValues } = + useFormContext(); return ( @@ -79,7 +64,7 @@ const SetUpDetailStep = ({ export default SetUpDetailStep; type SetUpDetailFieldProps = { - name: keyof SetUpDetailStepValues; + name: keyof SetUpDetailStepFormValues; }; const TitleField = ({ name }: SetUpDetailFieldProps) => { @@ -87,7 +72,7 @@ const TitleField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const titleValue = useWatch({ control, name: name }); const titleValueLength = @@ -125,7 +110,7 @@ const SelectedBookInfoField = ({ bookId?: number; onRemoveButtonClick?: () => void; }) => { - const { reset } = useFormContext(); + const { reset } = useFormContext(); const handleBookRemove = () => { onRemoveButtonClick?.(); @@ -149,7 +134,7 @@ const IntroduceField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const introduceErrors = errors[name]; @@ -176,7 +161,7 @@ const MaxMemberCountField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCountErrors = errors[name]; @@ -205,7 +190,7 @@ const CustomMemberCountField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCount = useWatch({ control, name: 'maxMemberCount' }); const isCustomInputCount = maxMemberCount === 'custom'; @@ -241,7 +226,7 @@ const PickStartDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDateErrors = errors[name]; const endDate = useWatch({ control, name: 'endDate' }); @@ -275,7 +260,7 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDate = useWatch({ control, name: 'startDate' }); const todayDate = getTodayDate(); @@ -302,14 +287,18 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { }; const SwitchIsPublicField = ({ name }: SetUpDetailFieldProps) => { - const { register } = useFormContext(); + const { register, control } = useFormContext(); + + const isCommentPublic = useWatch({ control, name }); return ( 댓글 공개 여부 - 모임에 가입하지 않은 사람도 댓글을 볼 수 있어요. + {isCommentPublic + ? '모임에 가입하지 않아도 댓글을 볼 수 있어요' + : '모임에 가입해야 댓글을 볼 수 있어요'} diff --git a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts b/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts deleted file mode 100644 index 381280758..000000000 --- a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { SetUpDetailStepValues } from './SetUpDetailStep'; -export { default as SetUpDetailStep } from './SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/steps/index.ts b/src/v1/bookGroup/create/steps/index.ts new file mode 100644 index 000000000..2b06facc9 --- /dev/null +++ b/src/v1/bookGroup/create/steps/index.ts @@ -0,0 +1,4 @@ +export { default as EnterTitleStep } from './EnterTitleStep/EnterTitleStep'; +export { default as SelectBookStep } from './SelectBookStep/SelectBookStep'; +export { default as SelectJoinTypeStep } from './SelectJoinTypeStep/SelectJoinTypeStep'; +export { default as SetUpDetailStep } from './SetUpDetailStep/SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/types.ts b/src/v1/bookGroup/create/types.ts new file mode 100644 index 000000000..a42f16fd8 --- /dev/null +++ b/src/v1/bookGroup/create/types.ts @@ -0,0 +1,40 @@ +import { SearchedBookWithId } from '@/types/book'; + +export type CreateBookGroupFormValues = { + book: SearchedBookWithId; + queryKeyword: string; + title: string; + introduce: string; + maxMemberCount: 9999 | 50 | 100 | 200 | 500 | 'custom'; + customMemberCount: number; + startDate: string; + endDate: string; + isPublic: boolean; + hasJoinPassword: 'true' | 'false'; + joinQuestion: string; + joinPassword: string; +}; + +export type SelectBookStepFormValues = Pick< + CreateBookGroupFormValues, + 'book' | 'queryKeyword' +>; + +export type EnterTitleStepFormValues = Pick; + +export type SetUpDetailStepFormValues = Pick< + CreateBookGroupFormValues, + | 'book' + | 'title' + | 'introduce' + | 'maxMemberCount' + | 'customMemberCount' + | 'startDate' + | 'endDate' + | 'isPublic' +>; + +export type SelectJoinTypeStepFormValues = Pick< + CreateBookGroupFormValues, + 'hasJoinPassword' | 'joinQuestion' | 'joinPassword' +>;
@@ -79,7 +64,7 @@ const SetUpDetailStep = ({ export default SetUpDetailStep; type SetUpDetailFieldProps = { - name: keyof SetUpDetailStepValues; + name: keyof SetUpDetailStepFormValues; }; const TitleField = ({ name }: SetUpDetailFieldProps) => { @@ -87,7 +72,7 @@ const TitleField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const titleValue = useWatch({ control, name: name }); const titleValueLength = @@ -125,7 +110,7 @@ const SelectedBookInfoField = ({ bookId?: number; onRemoveButtonClick?: () => void; }) => { - const { reset } = useFormContext(); + const { reset } = useFormContext(); const handleBookRemove = () => { onRemoveButtonClick?.(); @@ -149,7 +134,7 @@ const IntroduceField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const introduceErrors = errors[name]; @@ -176,7 +161,7 @@ const MaxMemberCountField = ({ name }: SetUpDetailFieldProps) => { const { register, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCountErrors = errors[name]; @@ -205,7 +190,7 @@ const CustomMemberCountField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const maxMemberCount = useWatch({ control, name: 'maxMemberCount' }); const isCustomInputCount = maxMemberCount === 'custom'; @@ -241,7 +226,7 @@ const PickStartDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDateErrors = errors[name]; const endDate = useWatch({ control, name: 'endDate' }); @@ -275,7 +260,7 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { register, control, formState: { errors }, - } = useFormContext(); + } = useFormContext(); const startDate = useWatch({ control, name: 'startDate' }); const todayDate = getTodayDate(); @@ -302,14 +287,18 @@ const PickEndDateField = ({ name }: SetUpDetailFieldProps) => { }; const SwitchIsPublicField = ({ name }: SetUpDetailFieldProps) => { - const { register } = useFormContext(); + const { register, control } = useFormContext(); + + const isCommentPublic = useWatch({ control, name }); return ( 댓글 공개 여부 - 모임에 가입하지 않은 사람도 댓글을 볼 수 있어요. + {isCommentPublic + ? '모임에 가입하지 않아도 댓글을 볼 수 있어요' + : '모임에 가입해야 댓글을 볼 수 있어요'} diff --git a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts b/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts deleted file mode 100644 index 381280758..000000000 --- a/src/v1/bookGroup/create/steps/SetUpDetailStep/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export type { SetUpDetailStepValues } from './SetUpDetailStep'; -export { default as SetUpDetailStep } from './SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/steps/index.ts b/src/v1/bookGroup/create/steps/index.ts new file mode 100644 index 000000000..2b06facc9 --- /dev/null +++ b/src/v1/bookGroup/create/steps/index.ts @@ -0,0 +1,4 @@ +export { default as EnterTitleStep } from './EnterTitleStep/EnterTitleStep'; +export { default as SelectBookStep } from './SelectBookStep/SelectBookStep'; +export { default as SelectJoinTypeStep } from './SelectJoinTypeStep/SelectJoinTypeStep'; +export { default as SetUpDetailStep } from './SetUpDetailStep/SetUpDetailStep'; diff --git a/src/v1/bookGroup/create/types.ts b/src/v1/bookGroup/create/types.ts new file mode 100644 index 000000000..a42f16fd8 --- /dev/null +++ b/src/v1/bookGroup/create/types.ts @@ -0,0 +1,40 @@ +import { SearchedBookWithId } from '@/types/book'; + +export type CreateBookGroupFormValues = { + book: SearchedBookWithId; + queryKeyword: string; + title: string; + introduce: string; + maxMemberCount: 9999 | 50 | 100 | 200 | 500 | 'custom'; + customMemberCount: number; + startDate: string; + endDate: string; + isPublic: boolean; + hasJoinPassword: 'true' | 'false'; + joinQuestion: string; + joinPassword: string; +}; + +export type SelectBookStepFormValues = Pick< + CreateBookGroupFormValues, + 'book' | 'queryKeyword' +>; + +export type EnterTitleStepFormValues = Pick; + +export type SetUpDetailStepFormValues = Pick< + CreateBookGroupFormValues, + | 'book' + | 'title' + | 'introduce' + | 'maxMemberCount' + | 'customMemberCount' + | 'startDate' + | 'endDate' + | 'isPublic' +>; + +export type SelectJoinTypeStepFormValues = Pick< + CreateBookGroupFormValues, + 'hasJoinPassword' | 'joinQuestion' | 'joinPassword' +>;