diff --git a/src/components/common/input/calendar-filter/index.tsx b/src/components/common/input/calendar-filter/index.tsx index 3be9bdf6..26ad4047 100644 --- a/src/components/common/input/calendar-filter/index.tsx +++ b/src/components/common/input/calendar-filter/index.tsx @@ -12,7 +12,12 @@ export interface CalendarFilterProps { onChange: (date: Date) => void; } -export default function CalendarFilter({ value, toDoDates, onChange }: CalendarFilterProps) { +export default function CalendarFilter({ + value, + toDoDates, + onChange, + ...rest +}: CalendarFilterProps) { const [selected, setSelected] = useState(value); const handleSelect = (date: Date) => { @@ -69,6 +74,7 @@ export default function CalendarFilter({ value, toDoDates, onChange }: CalendarF ); }} + {...rest} /> ); diff --git a/src/components/common/input/date-time-picker/date-time-picker.stories.tsx b/src/components/common/input/date-time-picker/date-time-picker.stories.tsx index abc103c7..8b6805a7 100644 --- a/src/components/common/input/date-time-picker/date-time-picker.stories.tsx +++ b/src/components/common/input/date-time-picker/date-time-picker.stories.tsx @@ -29,7 +29,7 @@ export default meta; const Template: StoryFn = function DateTimePickerStory() { const [date, setDate] = useState(new Date()); - return ; + return setDate(new Date(newValue))} />; }; export const DateTimePicker01 = Template.bind({}); diff --git a/src/components/common/input/date-time-picker/index.tsx b/src/components/common/input/date-time-picker/index.tsx index 8e96f992..a20ecec7 100644 --- a/src/components/common/input/date-time-picker/index.tsx +++ b/src/components/common/input/date-time-picker/index.tsx @@ -9,7 +9,7 @@ import IconArrow from '@/public/assets/icons/ic-arrow'; export interface DateTimePickerProps { fullDate: Date; - onChange: (date: Date) => void; + onChange: (date: string) => void; } export default function DateTimePicker({ fullDate, onChange }: DateTimePickerProps) { @@ -26,9 +26,17 @@ export default function DateTimePicker({ fullDate, onChange }: DateTimePickerPro }; const handleTime = () => { - const newDate = dayjs(selected).hour(Number(hour)).minute(Number(minute)).toDate(); + const newDate = new Date(selected); + + newDate.setHours(Number(hour)); + newDate.setMinutes(Number(minute)); + + const kstDate = new Date(newDate.getTime() - newDate.getTimezoneOffset() * 60000).toISOString(); + setSelected(newDate); - onChange(newDate); + + // KST 기준 ISO 문자열 전달 + onChange(kstDate); }; return ( diff --git a/src/components/common/input/pop-over-calendar/index.tsx b/src/components/common/input/pop-over-calendar/index.tsx index 648314cf..395810d3 100644 --- a/src/components/common/input/pop-over-calendar/index.tsx +++ b/src/components/common/input/pop-over-calendar/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { Button, Popover } from '@mantine/core'; import { useDisclosure, useMediaQuery } from '@mantine/hooks'; import CalendarFilter from '@/src/components/common/input/calendar-filter'; @@ -11,46 +11,62 @@ export interface PopOverProps { } export default function PopOverCalendar({ value, onChange }: PopOverProps) { - const [opened, { close, open }] = useDisclosure(false); - const [inputTheme, setInputTheme] = useState('white'); + const [opened, { open, close }] = useDisclosure(); + const [inputTheme, setInputTheme] = useState(opened ? 'dark' : 'light'); const [date, setDate] = useState(value); const isMobile = useMediaQuery(`(max-width: ${theme.breakpoints.md})`); + const popOver = useRef(null); - const handleClear = () => { + const handleClear = (e: React.MouseEvent) => { + e.stopPropagation(); setDate(new Date()); onChange(new Date()); close(); }; - const handleSubmit = () => { + const handleSubmit = (e: React.MouseEvent) => { + e.stopPropagation(); onChange(date); close(); }; - + const handleOutsideClick = (e: MouseEvent) => { + if (popOver.current && !popOver.current.contains(e.target as Node)) { + close(); + } + }; + useEffect(() => { + document.addEventListener('click', handleOutsideClick); + return () => document.removeEventListener('click', handleOutsideClick); + }, []); return ( - +