-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from LEEJW1953/fe-post-form
[Feat] 모각코 게시글 작성 폼 유효성 검사
- Loading branch information
Showing
8 changed files
with
311 additions
and
83 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/frontend/src/components/MogacoPost/MogacoPostTitle.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,43 @@ | ||
import { Controller, Control } from 'react-hook-form'; | ||
|
||
import { MOGACO_POST } from '@/constants'; | ||
import { MogacoPostForm } from '@/types'; | ||
|
||
import * as styles from './index.css'; | ||
|
||
type MogacoPostTitleProps = { | ||
control: Control<MogacoPostForm>; | ||
}; | ||
|
||
export function MogacoPostTitle({ control }: MogacoPostTitleProps) { | ||
return ( | ||
<Controller | ||
control={control} | ||
name="title" | ||
rules={{ | ||
required: MOGACO_POST.TITLE.REQUIRED, | ||
maxLength: { | ||
value: MOGACO_POST.TITLE.MAX_LENGTH, | ||
message: MOGACO_POST.TITLE.MAX, | ||
}, | ||
}} | ||
render={({ field: { onChange, value }, fieldState: { error } }) => ( | ||
<div className={`${styles.titleContainer} ${error && styles.error}`}> | ||
<div className={styles.titleContent}> | ||
<input | ||
type="text" | ||
className={styles.title} | ||
placeholder={MOGACO_POST.TITLE.REQUIRED} | ||
maxLength={MOGACO_POST.TITLE.MAX_LENGTH} | ||
onChange={onChange} | ||
/> | ||
<div className={styles.count}> | ||
{value?.length || 0}/{MOGACO_POST.TITLE.MAX_LENGTH} | ||
</div> | ||
</div> | ||
{error && <div className={styles.errorMessage}>{error.message}</div>} | ||
</div> | ||
)} | ||
/> | ||
); | ||
} |
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
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
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
Oops, something went wrong.