Skip to content

Commit bf65e09

Browse files
authored
Merge pull request #173 from imaginer-dev/27-add-schedule-success
๊ฐœ์ธ ์ผ์ • ์ถ”๊ฐ€&์ˆ˜์ • ์„ฑ๊ณต์‹œ ํ™”๋ฉด ์—…๋ฐ์ดํŠธ
2 parents 0c40489 + fe4e80d commit bf65e09

File tree

4 files changed

+69
-34
lines changed

4 files changed

+69
-34
lines changed

โ€Žsrc/components/MyCalendar/CreateEventButton.tsxโ€Ž

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import DialogButton from '@/components/common/DialogButton';
21
import { InputRef } from '../common/InputForm.tsx';
32
import { useState, useRef, useEffect } from 'react';
43
import { Events } from '@/utils/index.ts';
@@ -11,7 +10,7 @@ export interface eventProps {
1110
end_date?: string;
1211
}
1312

14-
const CreateEventButton = ({ id, title, start_date, end_date }: eventProps) => {
13+
const CreateEventDialog = ({ id, title, start_date, end_date }: eventProps) => {
1514
const [eventTitle, setTitle] = useState('');
1615
const [startDate, setStartDate] = useState('');
1716
const [endDate, setEndDate] = useState('');
@@ -54,13 +53,21 @@ const CreateEventButton = ({ id, title, start_date, end_date }: eventProps) => {
5453
end: endDate === '' ? startDate : endDate,
5554
};
5655
if (id) {
57-
updatePersonalSchedule(id, newEvent).catch((err) => {
58-
console.log(err);
59-
});
56+
updatePersonalSchedule(id, newEvent)
57+
.then(() => {
58+
location.href = '/';
59+
})
60+
.catch((err) => {
61+
console.log(err);
62+
});
6063
} else {
61-
addPersonalSchedule(newEvent).catch((err) => {
62-
console.log(err);
63-
});
64+
addPersonalSchedule(newEvent)
65+
.then(() => {
66+
location.href = '/';
67+
})
68+
.catch((err) => {
69+
console.log(err);
70+
});
6471
}
6572
}
6673

@@ -78,7 +85,7 @@ const CreateEventButton = ({ id, title, start_date, end_date }: eventProps) => {
7885
}
7986
};
8087

81-
const eventForm = (
88+
return (
8289
<div>
8390
<hr className="mt-1" />
8491
<InputRef title="์ผ์ • ์ œ๋ชฉ" placeholder="์ƒˆ ์ผ์ • ์ œ๋ชฉ" onChange={onTitleChanged} ref={titleRef} />
@@ -90,16 +97,6 @@ const CreateEventButton = ({ id, title, start_date, end_date }: eventProps) => {
9097
</button>
9198
</div>
9299
);
93-
return (
94-
<div className="p-8 pl-0 pr-0">
95-
<DialogButton
96-
classname="btn bg-primary text-base-100 w-full"
97-
name={id ? '์ˆ˜์ •' : '์ƒˆ ์ผ์ • ์ถ”๊ฐ€ํ•˜๊ธฐ'}
98-
title={id ? '์ผ์ • ์ˆ˜์ •' : '์ผ์ • ์ถ”๊ฐ€'}
99-
desc={''}
100-
children={eventForm}
101-
/>
102-
</div>
103-
);
104100
};
105-
export default CreateEventButton;
101+
102+
export default CreateEventDialog;

โ€Žsrc/components/common/Calendar.tsxโ€Ž

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { useRef, useState, useEffect, useCallback } from 'react';
55
// import { formatDateRange, formatTime } from '../../utils/dateUtils';
66
import { Events, DB_Events } from '../../utils/index.ts';
77
import { formatDateRange } from '../../utils/dateUtils';
8-
import CreateEventButton from '@/components/MyCalendar/CreateEventButton.tsx';
8+
import CreateEventDialog from '@/components/MyCalendar/CreateEventButton.tsx';
9+
import Dialog from './Dialog.tsx';
10+
11+
interface DialogElement {
12+
openModal: () => void;
13+
closeModal: () => void;
14+
}
915

1016
interface EventInfo {
1117
timeText: string;
@@ -191,6 +197,13 @@ function EventCards({ events, date, onDelete }: EventCardsProps) {
191197
console.log(events, date);
192198
const [menuOpen, setMenuOpen] = useState(-1);
193199

200+
const dialogRef = useRef<DialogElement | null>(null);
201+
const openModal = (dialogRef: React.RefObject<DialogElement>) => {
202+
if (dialogRef.current) {
203+
dialogRef.current?.openModal();
204+
}
205+
};
206+
194207
if (!events.length) {
195208
return (
196209
<div className="min-h-[150px] min-w-[240px] bg-white p-4 text-black">
@@ -225,14 +238,22 @@ function EventCards({ events, date, onDelete }: EventCardsProps) {
225238
{menuOpen === index && (
226239
<div className="absolute right-0 top-10 z-10 rounded-lg bg-white shadow-md">
227240
<ul>
228-
<li className="cursor-pointer p-2 hover:bg-gray-100">
229-
<CreateEventButton
230-
id={event.id}
231-
title={event.title}
232-
start_date={event.start_date}
233-
end_date={event.end_date}
234-
/>
241+
<li className="cursor-pointer p-2 hover:bg-gray-100" onClick={() => openModal(dialogRef)}>
242+
์ˆ˜์ •
235243
</li>
244+
<Dialog
245+
ref={dialogRef}
246+
title="์ผ์ • ์ˆ˜์ •"
247+
desc={''}
248+
children={
249+
<CreateEventDialog
250+
id={event.id}
251+
title={event.title}
252+
start_date={event.start_date}
253+
end_date={event.end_date}
254+
/>
255+
}
256+
/>
236257
<li className="cursor-pointer p-2 hover:bg-gray-100" onClick={() => onDelete(event.id)}>
237258
์‚ญ์ œ
238259
</li>

โ€Žsrc/pages/GroupSchedulePage.tsxโ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AppBar from '@/components/common/AppBar';
22
import HamburgerButton from '@/components/common/SideBar/HamburgerButton';
33
import Calendar from '@/components/common/Calendar';
4-
import CreateEventButton from '@/components/MyCalendar/CreateEventButton';
4+
import CreateEventDialog from '@/components/MyCalendar/CreateEventButton';
55
import { useParams } from 'react-router-dom';
66
import { useGetOneGroupSchedule } from '@/react-queries/useGetOneGroupSchedule';
77
import { Loading } from '.';
@@ -42,7 +42,7 @@ const GroupSchedulePage = () => {
4242
</div>
4343
</div>
4444
</main>
45-
<CreateEventButton />
45+
<CreateEventDialog />
4646
</div>
4747
);
4848
};

โ€Žsrc/pages/MyCalendarPage.tsxโ€Ž

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import AppBar from '@/components/common/AppBar.tsx';
22
import Calendar from '../components/common/Calendar.tsx';
3-
import CreateEventButton from '@/components/MyCalendar/CreateEventButton.tsx';
3+
import CreateEventDialog from '@/components/MyCalendar/CreateEventButton.tsx';
44
import HamburgerButton from '@/components/common/SideBar/HamburgerButton.tsx';
55
import { getPersonalSchedule, deletePersonalSchedule } from '@/apis/personalScheduleApi';
66
import { useEventState } from '@/stores/myEventsStore';
7-
import { useEffect } from 'react';
7+
import { useEffect, useRef } from 'react';
8+
import Dialog from '@/components/common/Dialog.tsx';
9+
10+
interface DialogElement {
11+
openModal: () => void;
12+
closeModal: () => void;
13+
}
814

915
const MyCalendarPage: React.FC = () => {
1016
const { db_events, addDBEvents } = useEventState();
@@ -28,14 +34,25 @@ const MyCalendarPage: React.FC = () => {
2834
});
2935
};
3036

37+
const dialogRef = useRef<DialogElement | null>(null);
38+
39+
const openModal = (dialogRef: React.RefObject<DialogElement>) => {
40+
if (dialogRef.current) {
41+
dialogRef.current?.openModal();
42+
}
43+
};
44+
3145
return (
3246
<div className="lg:ml-80">
3347
<AppBar backButton={false} IconButton={<HamburgerButton />} calendarName="๋‚ด ์บ˜๋ฆฐ๋”" />
3448
<main className="z-1 relative flex-grow">
3549
<div className="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
3650
<div>
3751
<Calendar db_events={db_events} onDeleteClicked={onDeleteClicked} />
38-
<CreateEventButton />
52+
<button type="button" className="btn w-full bg-primary text-base-100" onClick={() => openModal(dialogRef)}>
53+
์ƒˆ ์ผ์ • ์ถ”๊ฐ€ํ•˜๊ธฐ
54+
</button>
55+
<Dialog ref={dialogRef} title="์ผ์ • ์ถ”๊ฐ€" desc={''} children={<CreateEventDialog />} />
3956
</div>
4057
</div>
4158
</main>

0 commit comments

Comments
ย (0)