|
1 | 1 | import GroupForm from '@/components/Group/GroupForm';
|
2 | 2 | import AppBar from '@/components/common/AppBar';
|
3 |
| -import { useGetOneGroupSchedule } from '@/react-queries/useGetOneGroupSchedule'; |
4 | 3 | import { useParams } from 'react-router-dom';
|
5 | 4 | import { Loading } from '.';
|
6 | 5 | import { Member } from '@/types/Member';
|
| 6 | +import { useUpdateGroupSchedule } from '@/react-queries/useUpdateGroupSchedule'; |
| 7 | +import { useGetGroupScheduleDefaultData } from '@/hooks/useGetGroupScheduleDefaultData'; |
7 | 8 |
|
8 | 9 | const EditGroupSchedulePage = () => {
|
9 | 10 | const params = useParams<{ groupId: string; scheduleId: string }>();
|
10 |
| - const { scheduleId } = params; |
11 |
| - const { data, isError, error, isLoading } = useGetOneGroupSchedule(scheduleId!); |
| 11 | + const scheduleId = params.scheduleId!; |
| 12 | + const groupId = params.groupId!; |
| 13 | + |
| 14 | + const { groupMemberData, groupScheduleData, error, isLoading, isError } = useGetGroupScheduleDefaultData( |
| 15 | + scheduleId, |
| 16 | + groupId, |
| 17 | + ); |
| 18 | + const { mutate, isError: updateHasError, isPending: updateIsPending } = useUpdateGroupSchedule(); |
12 | 19 |
|
13 | 20 | if (isError) {
|
14 |
| - // TODO: 에러 처리 |
15 |
| - return <div>{error.message}</div>; |
| 21 | + return <div>{error!.message}</div>; |
16 | 22 | }
|
17 | 23 |
|
18 |
| - if (!data) { |
19 |
| - // TODO: 에러 처리 |
| 24 | + if ((!groupMemberData || !groupScheduleData) && !isLoading) { |
20 | 25 | return <div>데이터를 찾을 수 없습니다.</div>;
|
21 | 26 | }
|
22 | 27 |
|
23 | 28 | const handleSubmit = (e: React.FormEvent<HTMLFormElement>, userList: Member[]) => {
|
24 | 29 | e.preventDefault();
|
25 | 30 | const formData = new FormData(e.currentTarget);
|
26 |
| - console.log(formData.get('name')); |
27 |
| - console.log(formData.get('description')); |
28 |
| - console.log(formData.get('startDate')); |
29 |
| - console.log(formData.get('endDate')); |
30 |
| - console.log(formData.get('memo')); |
31 |
| - console.log('userList', userList); |
| 31 | + const updatePayload = { |
| 32 | + name: formData.get('name') as string, |
| 33 | + description: formData.get('description') as string, |
| 34 | + startDate: formData.get('startDate') as string, |
| 35 | + endDate: formData.get('endDate') as string, |
| 36 | + memo: formData.get('memo') as string, |
| 37 | + scheduleId, |
| 38 | + newMemberList: userList, |
| 39 | + }; |
| 40 | + mutate(updatePayload); |
32 | 41 | };
|
33 | 42 |
|
| 43 | + if (updateHasError) { |
| 44 | + // TODO: 에러 다이얼로그 표시 |
| 45 | + } |
| 46 | + |
| 47 | + if (updateIsPending) { |
| 48 | + // TODO: 로딩 스피너 표시 |
| 49 | + } |
| 50 | + |
34 | 51 | return (
|
35 | 52 | <>
|
36 |
| - {isLoading && <Loading display="spinner" size="lg" color="primary" />} |
37 |
| - <div className="flex min-h-dvh w-screen flex-col overflow-x-hidden px-4"> |
38 |
| - <AppBar backButton title={'모임 일정 등록하기'} /> |
39 |
| - <GroupForm |
40 |
| - onSubmit={handleSubmit} |
41 |
| - name={data.title} |
42 |
| - description={data.description} |
43 |
| - startDate={data.start_date} |
44 |
| - endDate={data.end_date} |
45 |
| - memo={data.memo} |
46 |
| - /> |
47 |
| - </div> |
| 53 | + {isLoading ? ( |
| 54 | + <Loading display="spinner" size="lg" color="primary" /> |
| 55 | + ) : ( |
| 56 | + <div className="flex min-h-dvh w-screen flex-col overflow-x-hidden px-4"> |
| 57 | + <AppBar backButton title={'모임 일정 수정하기'} /> |
| 58 | + <GroupForm |
| 59 | + onSubmit={handleSubmit} |
| 60 | + name={groupScheduleData!.title} |
| 61 | + description={groupScheduleData!.description} |
| 62 | + startDate={groupScheduleData!.start_date} |
| 63 | + endDate={groupScheduleData!.end_date} |
| 64 | + memo={groupScheduleData!.memo} |
| 65 | + memberList={groupMemberData} |
| 66 | + /> |
| 67 | + </div> |
| 68 | + )} |
48 | 69 | </>
|
49 | 70 | );
|
50 | 71 | };
|
|
0 commit comments