-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
255 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Button, IconLeft, IconRight } from '@/components' | ||
import Modal from '@/components/common/Modal' | ||
import MonthSelect from '@/components/ui/MonthSelect' | ||
import { format } from 'date-fns' | ||
import { useEffect, useState } from 'react' | ||
import { useMonthTotalCount } from '@/store/monthCount' | ||
|
||
interface OverviewHeaderProps { | ||
currentDate: Date | ||
setCurrentDate: (date: Date) => void | ||
goToPreviousMonth: () => void | ||
goToNextMonth: () => void | ||
} | ||
|
||
export default function OverviewHeaderForDetail({ | ||
currentDate, | ||
setCurrentDate, | ||
goToPreviousMonth, | ||
goToNextMonth, | ||
}: OverviewHeaderProps) { | ||
const [isModalOpen, setIsModalOpen] = useState(false) | ||
const { monthCount } = useMonthTotalCount() | ||
const today = new Date() | ||
|
||
const canMoveToNextMonth = | ||
currentDate.getFullYear() < today.getFullYear() || | ||
(currentDate.getFullYear() === today.getFullYear() && | ||
currentDate.getMonth() < today.getMonth()) | ||
|
||
useEffect(() => { | ||
setIsModalOpen(false) | ||
}, [currentDate]) | ||
|
||
return ( | ||
<> | ||
<header className="flex flex-row justify-between px-35"> | ||
<div className="flex gap-15 items-center"> | ||
<Button | ||
onClick={goToPreviousMonth} | ||
className="bg-primary_foundation-5 w-24 h-24 rounded-8" | ||
> | ||
<IconLeft height={13} /> | ||
</Button> | ||
<button | ||
type="button" | ||
onClick={() => setIsModalOpen(true)} | ||
className="text-18 font-[500] underline underline-offset-4" | ||
> | ||
{format(currentDate, 'yyyy년 MM월')} | ||
</button> | ||
<Button | ||
onClick={goToNextMonth} | ||
className="bg-primary_foundation-5 w-24 h-24 rounded-8" | ||
disabled={!canMoveToNextMonth} | ||
> | ||
<IconRight | ||
height={13} | ||
color={!canMoveToNextMonth ? '#D1D1D3' : ''} | ||
/> | ||
</Button> | ||
</div> | ||
|
||
<span className="text-primary_foundation-60"> | ||
총 {monthCount}개의 조각 | ||
</span> | ||
</header> | ||
|
||
<Modal | ||
isOpen={isModalOpen} | ||
onClose={() => setIsModalOpen(false)} | ||
title="월 선택하기" | ||
className="max-h-350 overflow-auto" | ||
> | ||
<MonthSelect | ||
currentDate={currentDate} | ||
setCurrentDate={setCurrentDate} | ||
/> | ||
</Modal> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { create } from 'zustand' | ||
|
||
interface MonthCountState { | ||
monthCount: number | ||
setMonthCount: (newCount: number) => void | ||
} | ||
|
||
export const useMonthTotalCount = create<MonthCountState>((set) => ({ | ||
monthCount: 0, | ||
setMonthCount: (newCount) => | ||
set({ | ||
monthCount: newCount, | ||
}), | ||
})) |