Skip to content
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 11 commits into from
Feb 4, 2024
5 changes: 5 additions & 0 deletions app/frontend/src/hooks/useRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Groups,
ProfilePage,
NotFound,
GroupCreatePage,
} from '@/pages';

export const useRouter = () =>
Expand Down Expand Up @@ -50,6 +51,10 @@ export const useRouter = () =>
path: 'groups',
element: <Groups />,
},
{
path: 'group/new',
element: <GroupCreatePage />,
},
],
},
{
Expand Down
49 changes: 49 additions & 0 deletions app/frontend/src/pages/Groups/Create/GroupJoinTypeCheckbox.tsx
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}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p3: 저도 useController 훅을 사용하는 편이 html 쪽이 더 자연스럽고 보기 편해져서 좋은 것 같아요!

그리고 아까 그룹 방식 관련해서 잠깐 더 대화가 이어졌었는데, 참여 코드 방식이 아예 빠지고 비공개 그룹은 무조건 가입 신청->승인 방식으로만 진행하기로 다시 결론이 나왔던 것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다.

<input
type="checkbox"
id={type}
name={type}
checked={value.includes(type as GroupJoin)}
onChange={onChangeCheckbox}
/>
{type === 'approve' ? '그룹장의 가입 승인 필요' : '참여 코드로 바로 가입'}
</label>
));
}
30 changes: 30 additions & 0 deletions app/frontend/src/pages/Groups/Create/GroupTypeRadio.tsx
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>
);
}
30 changes: 30 additions & 0 deletions app/frontend/src/pages/Groups/Create/index.css.ts
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',
});
60 changes: 60 additions & 0 deletions app/frontend/src/pages/Groups/Create/index.tsx
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>
);
}
6 changes: 6 additions & 0 deletions app/frontend/src/pages/Groups/Create/types.ts
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';
1 change: 1 addition & 0 deletions app/frontend/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './Calendar';
export * from './Groups';
export * from './Groups/Create';
export * from './Main';
export * from './Map';
export * from './Mogaco';
Expand Down
Loading