Feat: MemberAdd 컴포넌트 구현
This commit is contained in:
parent
1a656b463c
commit
141b39d33e
81
frontend/src/components/MemberAdd/MemberAddForm.tsx
Normal file
81
frontend/src/components/MemberAdd/MemberAddForm.tsx
Normal file
@ -0,0 +1,81 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { z } from 'zod';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../ui/form';
|
||||
import { Input } from '../ui/input';
|
||||
import { Button } from '../ui/button';
|
||||
import { Select } from '../ui/select';
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email({ message: '올바른 이메일 형식을 입력해주세요.' }),
|
||||
role: z.string().min(1, { message: '역할을 선택해주세요.' }),
|
||||
});
|
||||
|
||||
export type MemberAddFormValues = z.infer<typeof formSchema>;
|
||||
|
||||
const defaultValues: Partial<MemberAddFormValues> = {
|
||||
email: '',
|
||||
role: '',
|
||||
};
|
||||
|
||||
const roleOptions = [
|
||||
{ value: 'admin', label: '관리자' },
|
||||
{ value: 'viewer', label: '뷰어' },
|
||||
{ value: 'editor', label: '에디터' },
|
||||
];
|
||||
|
||||
export default function MemberAddForm({ onSubmit }: { onSubmit: (data: MemberAddFormValues) => void }) {
|
||||
const form = useForm<MemberAddFormValues>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues,
|
||||
});
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
className="flex flex-col gap-5"
|
||||
>
|
||||
<FormField
|
||||
name="email"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="body-strong">이메일</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder="이메일을 입력해주세요."
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
name="role"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel className="body-strong">역할</FormLabel>
|
||||
<FormControl>
|
||||
<Select
|
||||
{...field}
|
||||
options={roleOptions}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="outlinePrimary"
|
||||
disabled={!form.formState.isValid}
|
||||
>
|
||||
멤버 초대하기
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
);
|
||||
}
|
20
frontend/src/components/MemberAdd/index.stories.tsx
Normal file
20
frontend/src/components/MemberAdd/index.stories.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { Meta, StoryObj } from '@storybook/react';
|
||||
import MemberAddModal from '.';
|
||||
|
||||
const meta: Meta<typeof MemberAddModal> = {
|
||||
title: 'Modal/MemberAddModal',
|
||||
component: MemberAddModal,
|
||||
argTypes: {
|
||||
title: { control: 'text' },
|
||||
},
|
||||
};
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof MemberAddModal>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
title: '프로젝트 멤버 초대하기',
|
||||
},
|
||||
};
|
27
frontend/src/components/MemberAdd/index.tsx
Normal file
27
frontend/src/components/MemberAdd/index.tsx
Normal file
@ -0,0 +1,27 @@
|
||||
import MemberAddForm, { MemberAddFormValues } from './MemberAddForm';
|
||||
import XIcon from '@/assets/icons/x.svg?react';
|
||||
|
||||
export default function MemberAddModal({
|
||||
title = '새 멤버 초대',
|
||||
onClose,
|
||||
onSubmit,
|
||||
}: {
|
||||
title?: string;
|
||||
onClose: () => void;
|
||||
onSubmit: (data: MemberAddFormValues) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex w-[610px] flex-col gap-10 rounded-3xl border px-10 py-5 shadow-lg">
|
||||
<header className="flex gap-5">
|
||||
<h1 className="small-title w-full">{title}</h1>
|
||||
<button
|
||||
className="flex h-8 w-8 items-center justify-center"
|
||||
onClick={onClose}
|
||||
>
|
||||
<XIcon className="stroke-gray-900" />
|
||||
</button>
|
||||
</header>
|
||||
<MemberAddForm onSubmit={onSubmit} />
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user