-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#562] [모임 생성] 모임 이름 퍼널 #565
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/stories/bookGroup/create/funnel/EnterTitleStep.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { appLayoutMeta } from '@/stories/meta'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
|
||
import { | ||
EnterTitleStep, | ||
type EnterTitleStepValues, | ||
} from '@/v1/bookGroup/create/steps/EnterTitleStep'; | ||
|
||
const meta: Meta<typeof EnterTitleStep> = { | ||
title: 'bookGroup/create/steps/EnterTitleStep', | ||
component: EnterTitleStep, | ||
...appLayoutMeta, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof EnterTitleStep>; | ||
|
||
const EnterTitleForm = () => { | ||
const methods = useForm<EnterTitleStepValues>({ | ||
mode: 'all', | ||
defaultValues: { | ||
title: '', | ||
}, | ||
}); | ||
|
||
return ( | ||
<FormProvider {...methods}> | ||
<form> | ||
<EnterTitleStep /> | ||
</form> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
export const Default: Story = { | ||
render: () => <EnterTitleForm />, | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/v1/bookGroup/create/steps/EnterTitleStep/EnterTitleStep.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useFormContext } from 'react-hook-form'; | ||
|
||
import BottomActionButton from '@/v1/base/BottomActionButton'; | ||
import { TitleField } from './fields'; | ||
|
||
interface MoveFunnelStepProps { | ||
onNextStep?: () => void; | ||
} | ||
|
||
export interface EnterTitleStepValues { | ||
title: string; | ||
} | ||
|
||
const EnterTitleStep = ({ onNextStep }: MoveFunnelStepProps) => { | ||
const { handleSubmit } = useFormContext<EnterTitleStepValues>(); | ||
|
||
return ( | ||
<article> | ||
<section className="flex flex-col gap-[1.5rem]"> | ||
<h2 className="text-lg font-bold text-black-700"> | ||
독서모임 이름을 적어주세요 | ||
</h2> | ||
<TitleField name="title" /> | ||
</section> | ||
|
||
<BottomActionButton | ||
type="submit" | ||
onClick={handleSubmit(() => onNextStep?.())} | ||
> | ||
다음 | ||
</BottomActionButton> | ||
</article> | ||
); | ||
}; | ||
|
||
export default EnterTitleStep; |
47 changes: 47 additions & 0 deletions
47
src/v1/bookGroup/create/steps/EnterTitleStep/fields/TitleField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useFormContext, useWatch } from 'react-hook-form'; | ||
|
||
import type { EnterTitleStepValues } from '../EnterTitleStep'; | ||
|
||
import ErrorMessage from '@/v1/base/ErrorMessage'; | ||
import Input from '@/v1/base/Input'; | ||
import InputLength from '@/v1/base/InputLength'; | ||
|
||
type DefaultFieldNameProps = { | ||
name: keyof EnterTitleStepValues; | ||
}; | ||
|
||
const TitleField = ({ name }: DefaultFieldNameProps) => { | ||
const { | ||
register, | ||
control, | ||
formState: { errors }, | ||
} = useFormContext<EnterTitleStepValues>(); | ||
|
||
const titleValue = useWatch({ control, name: name }); | ||
const titleErrors = errors[name]; | ||
|
||
return ( | ||
<label htmlFor={name} className="flex flex-col gap-[0.5rem]"> | ||
<Input | ||
id={name} | ||
placeholder="독서모임을 잘 표현할 수 있는 이름이면 좋아요." | ||
error={!!titleErrors} | ||
{...register(name, { | ||
required: '독서모임 이름을 작성해 주세요', | ||
minLength: { value: 2, message: '2글자 이상 입력해주세요' }, | ||
maxLength: { value: 20, message: '20글자 이하로 입력해주세요' }, | ||
})} | ||
/> | ||
<div className="flex flex-row-reverse justify-between"> | ||
<InputLength | ||
currentLength={titleValue.length} | ||
isError={!!titleErrors} | ||
maxLength={20} | ||
/> | ||
<ErrorMessage>{titleErrors?.message}</ErrorMessage> | ||
</div> | ||
</label> | ||
); | ||
}; | ||
|
||
export default TitleField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as TitleField } from './TitleField'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { EnterTitleStepValues } from './EnterTitleStep'; | ||
export { default as EnterTitleStep } from './EnterTitleStep'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment;
useWatch()
와formState: { errors }
가 사용되는 부분을TitleField.tsx
로 분리하여 리렌더링되는 컴포넌트 수를 줄였습니다.