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

캘린더 일정 타입 관련 에러 수정 #196

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ const CalendarSchedule = ({
day,
title,
detail,
startDate,
endDate,
startDateTime,
endDateTime,
}: CalendarScheduleProps) => {
const { openModal } = useModal();
const isDateDiff = dayjs(startDate).diff(endDate, 'd');
const isDateDiff = dayjs(startDateTime).diff(endDateTime, 'd');
const isBeforeToday = day.isBefore(today, 'day');

const handleScheduleClick = useCallback(
(detail: string, startDate: string, endDate: string) => {
(detail: string, startDateTime: string, endDateTime: string) => {
openModal({
title: '📆 일정',
content: `일시: ${formattedDatePeriod(startDate, endDate)}\n내용: ${detail}`,
content: `일시: ${formattedDatePeriod(startDateTime, endDateTime)}\n내용: ${detail}`,
});
},
[openModal],
Expand All @@ -42,21 +42,21 @@ const CalendarSchedule = ({
isDateDiff === 0 ? 'rounded bg-blue-100' : 'bg-red-100',
{
'rounded-l bg-red-100':
isDateDiff !== 0 && day.isSame(startDate, 'date'),
isDateDiff !== 0 && day.isSame(startDateTime, 'date'),
},
{
'bg-red-100':
isDateDiff !== 0 &&
day.isAfter(startDate, 'date') &&
day.isBefore(endDate, 'date'),
day.isAfter(startDateTime, 'date') &&
day.isBefore(endDateTime, 'date'),
},
{
'rounded-r bg-red-100':
isDateDiff !== 0 && day.isSame(endDate, 'date'),
isDateDiff !== 0 && day.isSame(endDateTime, 'date'),
},
{ 'opacity-50': isBeforeToday },
)}
onClick={() => handleScheduleClick(detail, startDate, endDate)}
onClick={() => handleScheduleClick(detail, startDateTime, endDateTime)}
>
{title}
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const CalendarStatusSection = () => {
const { data: yearData } = useScheduleCollect();

const closestEvent = findClosestEvent(transformEvents(monthData.items));
const closestDDay = closestEvent?.startDate
? `D-${calculateDDay(closestEvent.startDate)}`
const closestDDay = closestEvent?.startDateTime
? `D-${calculateDDay(closestEvent.startDateTime)}`
: '이번 달에 남은 일정이 없어요';

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const CalendarTableSection = () => {
const { data } = useSchedule();

const handleScheduleClick = useCallback(
(detail: string, startDate: string, endDate: string) => {
(detail: string, startDateTime: string, endDateTime: string) => {
openModal({
title: '📆 일정',
content: `일시: ${formattedDatePeriod(startDate, endDate)}\n내용: ${detail}`,
content: `일시: ${formattedDatePeriod(startDateTime, endDateTime)}\n내용: ${detail}`,
});
},
[openModal],
Expand All @@ -26,12 +26,14 @@ const CalendarTableSection = () => {
return (
<Section>
<Table head={TABLE_HEAD.CALENDAR_TABLE} className="table-fixed">
{data.items.map(({ id, title, detail, startDate, endDate }) => (
{data.items.map(({ id, title, detail, startDateTime, endDateTime }) => (
<Table.Row
key={id}
onClick={() => handleScheduleClick(detail, startDate, endDate)}
onClick={() =>
handleScheduleClick(detail, startDateTime, endDateTime)
}
>
<Table.Cell>{`${formattedDate(startDate)} ~ ${formattedDate(endDate)}`}</Table.Cell>
<Table.Cell>{`${formattedDate(startDateTime)} ~ ${formattedDate(endDateTime)}`}</Table.Cell>
<Table.Cell>{title}</Table.Cell>
</Table.Row>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const MainNoticeSection = () => {
<Notice
title={closestNotice.title}
content={closestNotice.detail}
date={closestNotice.startDate}
date={closestNotice.startDateTime}
showDDay
/>
{data.items.length > 1 && (
Expand All @@ -50,12 +50,12 @@ const MainNoticeSection = () => {
>
<hr className="my-4" />
<div className="flex flex-col gap-4">
{data.items.slice(1).map(({ id, title, detail, startDate }) => (
{data.items.slice(1).map(({ id, title, detail, startDateTime }) => (
<Notice
key={id}
title={title}
content={detail}
date={startDate}
date={startDateTime}
showDDay
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,31 @@ const ManageCalendarSection = () => {
const renderView = {
view: (
<Table head={TABLE_HEAD.CALENDAR_SCHEDULE}>
{data.items.map(({ id, title, startDate, endDate, priority }) => (
<Table.Row
key={id}
className="text-nowrap text-center"
onClick={handleTableRowClick}
>
<Table.Cell>{id}</Table.Cell>
<Table.Cell className="w-full truncate text-left">
{toDecodeHTMLEntities(title)}
</Table.Cell>
<Table.Cell>{formattedDate(startDate)}</Table.Cell>
<Table.Cell>{formattedDate(endDate)}</Table.Cell>
<Table.Cell>{toPriorityText(priority)}</Table.Cell>
<Table.Cell className="space-x-2">
<ActionButton
color="red"
onClick={(e) => handleDeleteButtonClick(e, id)}
>
삭제
</ActionButton>
</Table.Cell>
</Table.Row>
))}
{data.items.map(
({ id, title, startDateTime, endDateTime, priority }) => (
<Table.Row
key={id}
className="text-nowrap text-center"
onClick={handleTableRowClick}
>
<Table.Cell>{id}</Table.Cell>
<Table.Cell className="w-full truncate text-left">
{toDecodeHTMLEntities(title)}
</Table.Cell>
<Table.Cell>{formattedDate(startDateTime)}</Table.Cell>
<Table.Cell>{formattedDate(endDateTime)}</Table.Cell>
<Table.Cell>{toPriorityText(priority)}</Table.Cell>
<Table.Cell className="space-x-2">
<ActionButton
color="red"
onClick={(e) => handleDeleteButtonClick(e, id)}
>
삭제
</ActionButton>
</Table.Cell>
</Table.Row>
),
)}
</Table>
),
add: <AddScheduleForm onSubmit={() => handleMenubarItemClick('view')} />,
Expand Down
4 changes: 2 additions & 2 deletions apps/member/src/types/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface ScheduleItem {
title: string;
detail: string;
activityName: string | null;
startDate: string;
endDate: string;
startDateTime: string;
endDateTime: string;
priority: SchedulePriority;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/member/src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export const transformEvents = (
): Record<string, ScheduleItem[]> => {
return events.reduce(
(acc, current) => {
const startDate = new Date(current.startDate.split('T')[0]); // 시작 날짜 객체 생성
const endDate = new Date(current.endDate.split('T')[0]); // 종료 날짜 객체 생성
const startDate = new Date(current.startDateTime.split('T')[0]); // 시작 날짜 객체 생성
const endDate = new Date(current.endDateTime.split('T')[0]); // 종료 날짜 객체 생성

for (
let date = new Date(startDate);
Expand Down
Loading