Skip to content

Commit fdbeddd

Browse files
authored
Merge pull request #154 from imaginer-dev/51-그룹일정-추가-시-DB-저장
51 그룹일정 추가 시 db 저장
2 parents de3664b + f28567b commit fdbeddd

File tree

6 files changed

+57
-37
lines changed

6 files changed

+57
-37
lines changed

src/components/GroupForm/GroupForm.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react';
1+
import { FC, useState } from 'react';
22
import GroupFormNameInput from './GroupFormNameInput';
33
import GroupFormDescriptionInput from './GroupFormDescriptionInput';
44
import GroupFormDateInput from './GroupFormDateInput';
@@ -22,13 +22,15 @@ const GroupForm: FC<Props> = ({
2222
memo = '',
2323
onSubmit,
2424
}) => {
25+
const [member, setMember] = useState<any[]>([]);
26+
2527
return (
2628
<form onSubmit={onSubmit} className="container mx-auto flex max-w-sm flex-1 flex-col gap-4 pb-[50px] pt-4">
2729
<div className="flex h-full w-full flex-1 flex-col gap-4">
2830
<GroupFormNameInput name={name} />
2931
<GroupFormDescriptionInput description={description} />
3032
<GroupFormDateInput startDate={startDate} endDate={endDate} />
31-
<UserInvite />
33+
<UserInvite member={member} setMember={setMember} />
3234
<GroupFormMemoInput memo={memo} />
3335
</div>
3436
<button type="submit" className="btn btn-outline btn-primary w-full">

src/components/common/UserInvite.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,58 @@
1-
import { FC } from 'react';
1+
import { FC, useState } from 'react';
2+
import { searchUser } from '../../apis/authApis.ts';
23
import DialogButton from '@/components/common/DialogButton';
34
import { IconUserPlus } from '@/assets/icons';
45
import UserInviteDialog from '@/components/common/UserInviteDialog';
6+
import UserInvited from './UserInvited';
7+
import UserInviteList from './UserInviteList.tsx';
8+
9+
interface Props {
10+
member: any;
11+
setMember: any;
12+
}
13+
14+
const UserInvite: FC<Props> = ({ member, setMember }) => {
15+
const [email, setEamil] = useState('');
16+
const [list, setList] = useState<any[]>([]);
17+
18+
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
19+
setEamil(event.target.value);
20+
};
21+
22+
const onSearchClick = () => {
23+
searchUser(email).then((nickNames) => {
24+
if (!nickNames.length) {
25+
alert('해당 닉네임을 찾을 수 없습니다.');
26+
return;
27+
}
28+
nickNames.map(({ user_nickname, id }) => {
29+
setList([
30+
<UserInviteList
31+
user_nickname={user_nickname}
32+
id={id}
33+
key={id + '-UserInviteList'}
34+
onClick={() => {
35+
if (!user_nickname.length) return;
36+
setMember([...member, <UserInvited user_nickname={user_nickname} id={id} key={id + '-Member'} />]);
37+
}}
38+
/>,
39+
]);
40+
});
41+
});
42+
};
543

6-
export const UserInvite: FC = () => {
744
return (
845
<div>
946
멤버 초대하기 *
1047
<ul className="flex gap-2">
48+
{member}
1149
<li>
1250
<DialogButton
1351
classname={'userInvite bg-base-200 hover:bg-base-300'}
1452
name={<IconUserPlus />}
1553
title={'멤버 찾기'}
1654
desc={''}
17-
children={<UserInviteDialog />}
55+
children={<UserInviteDialog list={list} onChange={onChange} onSearchClick={onSearchClick} />}
1856
/>
1957
</li>
2058
</ul>

src/components/common/UserInviteDialog.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
import InputForm from './InputForm.tsx';
2-
import { searchUser } from '../../apis/authApis.ts';
3-
import { FC, useState } from 'react';
2+
import { FC } from 'react';
43
import { IconSearch } from '@/assets/icons';
5-
import UserInviteList from './UserInviteList.tsx';
6-
7-
const UserInvite: FC = () => {
8-
const [email, setEamil] = useState('');
9-
const [list, setList] = useState<any[]>([]);
10-
11-
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
12-
setEamil(event.target.value);
13-
};
14-
15-
const onSearchClick = () => {
16-
searchUser(email).then((nickNames) => {
17-
if (!nickNames.length) {
18-
alert('해당 닉네임을 찾을 수 없습니다.');
19-
return;
20-
}
21-
setList(
22-
nickNames.map(({ user_nickname, id }) => {
23-
return <UserInviteList user_nickname={user_nickname} id={id} key={id + '-UserInviteList'} />;
24-
}),
25-
);
26-
return list;
27-
});
28-
};
4+
interface Props {
5+
list: any[];
6+
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
7+
onSearchClick: () => void;
8+
}
299

10+
const UserInvite: FC<Props> = ({ list, onChange, onSearchClick }) => {
3011
return (
3112
<div>
3213
<div className="flex items-end">

src/components/common/UserInviteList.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { IconPlus } from '@/assets/icons';
44
interface Props {
55
user_nickname: any;
66
id: string;
7+
onClick: () => void;
78
}
89

9-
const UserInviteList: FC<Props> = ({ user_nickname, id }) => {
10+
const UserInviteList: FC<Props> = ({ user_nickname, id, onClick }) => {
1011
return (
1112
<li key={id} className="border-b">
1213
<button type="button" className="ju btn flex w-full justify-between border-none bg-transparent" onClick={onClick}>
@@ -17,6 +18,4 @@ const UserInviteList: FC<Props> = ({ user_nickname, id }) => {
1718
);
1819
};
1920

20-
const onClick = () => {};
21-
2221
export default UserInviteList;

src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ProtectedRoute from './providers/ProtectedRoute.tsx';
1111

1212
import UserInvite from './components/common/UserInvite.tsx';
1313
import EditGroupPage from './pages/EditGroupPage.tsx';
14-
import AddGroupPage from './pages/AddGroupPage.tsx';
14+
import AddGroupSchedulePage from './pages/AddGroupSchedulePage.tsx';
1515

1616
const router = createBrowserRouter([
1717
{
@@ -35,7 +35,7 @@ const router = createBrowserRouter([
3535
},
3636
{
3737
path: '/add-group',
38-
element: <AddGroupPage />,
38+
element: <AddGroupSchedulePage />,
3939
},
4040
{
4141
path: '/login',

src/pages/AddGroupPage.tsx renamed to src/pages/AddGroupSchedulePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const AddGroupPage = () => {
55
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
66
e.preventDefault();
77
const formData = new FormData(e.currentTarget);
8-
console.log(formData);
8+
console.log(formData.get('name'));
99
};
1010

1111
return (

0 commit comments

Comments
 (0)