-
Notifications
You must be signed in to change notification settings - Fork 6
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
[Feat] 그룹 생성 페이지 추가 #509
Merged
Merged
[Feat] 그룹 생성 페이지 추가 #509
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fb10b9e
✨ 그룹 생성 페이지 추가
ttaerrim 9438b36
🔨 그룹 생성 폼 필드 추가
ttaerrim 5093d81
💄 그룹 생성 페이지 css 수정
ttaerrim 4efd47b
🔨 react-hook-form `useForm` 사용
ttaerrim 7ccd2e5
♻️ map 메소드 사용하여 라디오 버튼 렌더링하도록 리팩토링
ttaerrim 0372466
🔨 그룹 생성 시 가입 방식 rhf Controller 사용
ttaerrim e59346d
🔨 그룹 유형 비공개로 설정했을 때만 가입 방식 필드를 노출
ttaerrim 07fcb71
♻️ 그룹 생성 폼 컴포넌트 분리
ttaerrim facb1d6
🔨 그룹 유형 비공개일 때 가입 방식을 한 개 이상 선택하도록 rules 추가
ttaerrim 70709fa
🔥 비공개 그룹의 체크박스 컴포넌트 삭제
ttaerrim 65a6c02
🔨 그룹명 useController 적용
ttaerrim 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
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
49 changes: 49 additions & 0 deletions
49
app/frontend/src/pages/Groups/Create/GroupJoinTypeCheckbox.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,49 @@ | ||
import { Control, useController } from 'react-hook-form'; | ||
|
||
import * as styles from './index.css'; | ||
import { GroupCreate } from './types'; | ||
|
||
type GroupJoin = 'approve' | 'code'; | ||
|
||
export function GroupJoinTypeCheckbox({ | ||
control, | ||
required, | ||
}: { | ||
control: Control<GroupCreate>; | ||
required: boolean; | ||
}) { | ||
const { | ||
field: { value, onChange }, | ||
} = useController({ | ||
name: 'joinType', | ||
control, | ||
rules: { | ||
validate: { | ||
moreThanOne: (v) => required && v.length > 0, | ||
}, | ||
}, | ||
}); | ||
|
||
const onChangeCheckbox = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const joinType = e.target.id as GroupJoin; | ||
if (value.includes(joinType)) { | ||
const newValue = value.filter((item) => item !== joinType); | ||
onChange(newValue); | ||
} else { | ||
onChange([...value, joinType]); | ||
} | ||
}; | ||
|
||
return ['approve', 'code'].map((type) => ( | ||
<label key={type} className={styles.inputField} htmlFor={type}> | ||
<input | ||
type="checkbox" | ||
id={type} | ||
name={type} | ||
checked={value.includes(type as GroupJoin)} | ||
onChange={onChangeCheckbox} | ||
/> | ||
{type === 'approve' ? '그룹장의 가입 승인 필요' : '참여 코드로 바로 가입'} | ||
</label> | ||
)); | ||
} |
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,30 @@ | ||
import { Control, useController } from 'react-hook-form'; | ||
|
||
import * as styles from './index.css'; | ||
import { GroupCreate } from './types'; | ||
|
||
export function GroupTypeRadio({ control }: { control: Control<GroupCreate> }) { | ||
const { | ||
field: { value, onChange }, | ||
} = useController({ | ||
name: 'type', | ||
control, | ||
}); | ||
|
||
return ( | ||
<div className={styles.groupWrapper}> | ||
{['public', 'private'].map((type) => ( | ||
<label key={type} className={styles.inputField} htmlFor={type}> | ||
<input | ||
type="radio" | ||
name="group" | ||
id={type} | ||
checked={value === type} | ||
onChange={(e) => onChange(e.target.id)} | ||
/> | ||
{type === 'public' ? '공개' : '비공개'} 그룹 | ||
</label> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
import { sansRegular14 } from '@/styles/font.css'; | ||
|
||
export const container = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '2.4rem', | ||
maxWidth: '80rem', | ||
margin: '0 auto', | ||
}); | ||
|
||
export const groupWrapper = style({ | ||
display: 'flex', | ||
gap: '1.2rem', | ||
}); | ||
export const inputField = style([ | ||
sansRegular14, | ||
{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '0.4rem', | ||
}, | ||
]); | ||
|
||
export const inputWrapper = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '0.8rem', | ||
}); |
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,60 @@ | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import { TextLabel, Button } from '@morak/ui'; | ||
|
||
import { FormInput } from '@/components'; | ||
|
||
import { GroupJoinTypeCheckbox } from './GroupJoinTypeCheckbox'; | ||
import { GroupTypeRadio } from './GroupTypeRadio'; | ||
import * as styles from './index.css'; | ||
import { GroupCreate } from './types'; | ||
|
||
export function GroupCreatePage() { | ||
const { | ||
control, | ||
handleSubmit, | ||
formState: { isValid }, | ||
watch, | ||
} = useForm<GroupCreate>({ | ||
defaultValues: { | ||
name: '', | ||
type: 'public', | ||
joinType: ['approve'], | ||
}, | ||
mode: 'all', | ||
}); | ||
|
||
const groupType = watch('type'); | ||
|
||
return ( | ||
<form | ||
className={styles.container} | ||
onSubmit={handleSubmit((data) => console.log(data))} | ||
> | ||
<FormInput label="그룹명" required /> | ||
<div className={styles.inputWrapper}> | ||
<TextLabel label="그룹 유형" required /> | ||
<GroupTypeRadio control={control} /> | ||
</div> | ||
{groupType === 'private' && ( | ||
<div className={styles.inputWrapper}> | ||
<TextLabel label="가입 방식" required /> | ||
<GroupJoinTypeCheckbox | ||
control={control} | ||
required={groupType === 'private'} | ||
/> | ||
</div> | ||
)} | ||
<Button | ||
type="submit" | ||
theme="primary" | ||
shape="fill" | ||
size="large" | ||
fullWidth | ||
disabled={!isValid} | ||
> | ||
확인 | ||
</Button> | ||
</form> | ||
); | ||
} |
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,6 @@ | ||
export type GroupCreate = { | ||
name: string; | ||
type: 'public' | 'private'; | ||
joinType: GroupJoin[]; | ||
}; | ||
export type GroupJoin = 'approve' | 'code'; |
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.
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.
p3: 저도 useController 훅을 사용하는 편이 html 쪽이 더 자연스럽고 보기 편해져서 좋은 것 같아요!
그리고 아까 그룹 방식 관련해서 잠깐 더 대화가 이어졌었는데, 참여 코드 방식이 아예 빠지고 비공개 그룹은 무조건 가입 신청->승인 방식으로만 진행하기로 다시 결론이 나왔던 것 같습니다.
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.
반영했습니다.