Skip to content
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
18 changes: 17 additions & 1 deletion src/app/workspaces/[workspaceId]/calendar/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@ interface WorkspaceCalendarPageProps {
}>;
}

function getSeoulTodayIsoDate() {
const formatter = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Asia/Seoul',
year: 'numeric',
month: '2-digit',
day: '2-digit',
});
const parts = formatter.formatToParts(new Date());
const year = parts.find((part) => part.type === 'year')?.value;
const month = parts.find((part) => part.type === 'month')?.value;
const day = parts.find((part) => part.type === 'day')?.value;

return `${year}-${month}-${day}`;
}
Comment thread
JiWoongE marked this conversation as resolved.

export default async function WorkspaceCalendarPage({ params }: WorkspaceCalendarPageProps) {
const { workspaceId } = await params;
const initialSelectedDate = getSeoulTodayIsoDate();

return <CalendarPage workspaceId={workspaceId} />;
return <CalendarPage workspaceId={workspaceId} initialSelectedDate={initialSelectedDate} />;
}
11 changes: 6 additions & 5 deletions src/features/manage-calendar/model/calendar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface CalendarDayCell {
isCurrentMonth: boolean;
}

function formatIsoDate(date: Date) {
export function formatIsoDate(date: Date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
Expand All @@ -16,6 +16,11 @@ export function createCalendarMonthLabel(currentMonth: Date) {
return `${currentMonth.getFullYear()}년 ${currentMonth.getMonth() + 1}월`;
}

export function createCalendarMonthStart(isoDate: string) {
const [year, month] = isoDate.split('-').map(Number);
return new Date(year, month - 1, 1);
}

export function createCalendarMonthGrid(currentMonth: Date): CalendarDayCell[] {
const year = currentMonth.getFullYear();
const monthIndex = currentMonth.getMonth();
Expand All @@ -34,7 +39,3 @@ export function createCalendarMonthGrid(currentMonth: Date): CalendarDayCell[] {
};
});
}

export function getInitialCalendarDate() {
return new Date(2025, 6, 1);
}
13 changes: 8 additions & 5 deletions src/features/manage-calendar/ui/CalendarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import {
} from '@/entities/calendar-event';
import { plusJakartaSans } from '@/shared/lib/fonts';
import {
createCalendarMonthStart,
createCalendarMonthGrid,
createCalendarMonthLabel,
getInitialCalendarDate,
} from '../model/calendar-utils';

interface CalendarViewProps {
workspaceId: string;
initialSelectedDate: string;
}

const weekdayLabels = ['일', '월', '화', '수', '목', '금', '토'] as const;
Expand Down Expand Up @@ -66,14 +67,16 @@ function formatSelectedDateLabel(isoDate: string) {
return `${year}년 ${Number(month)}월 ${Number(day)}일`;
}

export function CalendarView({ workspaceId }: CalendarViewProps) {
export function CalendarView({ workspaceId, initialSelectedDate }: CalendarViewProps) {
const calendarEventsQuery = useCalendarEventsByWorkspaceId(workspaceId);
const createCalendarEventMutation = useCreateCalendarEvent(workspaceId);
const deleteCalendarEventMutation = useDeleteCalendarEvent(workspaceId);
const updateCalendarEventMutation = useUpdateCalendarEvent(workspaceId);
const calendarEvents = calendarEventsQuery.data ?? [];
const [currentMonth, setCurrentMonth] = useState(getInitialCalendarDate);
const [selectedDate, setSelectedDate] = useState('2025-07-30');
const [currentMonth, setCurrentMonth] = useState(() =>
createCalendarMonthStart(initialSelectedDate),
);
const [selectedDate, setSelectedDate] = useState(initialSelectedDate);
const [isAddEventOpen, setIsAddEventOpen] = useState(false);
const [formValues, setFormValues] = useState(defaultFormValues);
const [hasSubmitted, setHasSubmitted] = useState(false);
Expand Down Expand Up @@ -227,7 +230,7 @@ export function CalendarView({ workspaceId }: CalendarViewProps) {
onClick={() => setSelectedDate(cell.isoDate)}
className={`hover:bg-brand-soft/30 relative min-h-[98px] border-r border-b border-[rgba(91,78,232,0.1)] px-[8px] pt-[5px] pb-[8px] text-left align-top transition sm:min-h-[108px] ${
(index + 1) % 7 === 0 ? 'border-r-0' : ''
} ${isSelected ? 'bg-[rgba(238,240,251,0.6)]' : ''}`}
} ${isSelected ? 'bg-brand/12' : ''}`}
>
<div className="absolute top-[5px] left-[8px]">
<span
Expand Down
5 changes: 3 additions & 2 deletions src/views/calendar/ui/CalendarPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { CalendarView } from '@/features/manage-calendar';

interface CalendarPageProps {
workspaceId: string;
initialSelectedDate: string;
}

export default function CalendarPage({ workspaceId }: CalendarPageProps) {
return <CalendarView workspaceId={workspaceId} />;
export default function CalendarPage({ workspaceId, initialSelectedDate }: CalendarPageProps) {
return <CalendarView workspaceId={workspaceId} initialSelectedDate={initialSelectedDate} />;
}