-
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.
implement: Implement to disable days that do not have a created diary…
… and implement that clicking on a day will take you to the diary details page for that day
- Loading branch information
1 parent
b12df4d
commit 735567e
Showing
15 changed files
with
236 additions
and
168 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 |
---|---|---|
|
@@ -35,3 +35,6 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# sample | ||
/public/sample.* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,40 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const StDiaryHeader = styled.div` | ||
padding: 2.25rem 2.25rem 0.75rem 2.25rem; | ||
margin-bottom: 0.5rem; | ||
position: sticky; | ||
top: calc(80px + 1vh + 1vw); | ||
z-index: 10; | ||
background-color: ${({ theme }) => theme.bgclr.primary}; | ||
${({ theme }) => theme.mixins.flexBox('row', 'center', 'space-between')}; | ||
svg { | ||
width: 2rem; | ||
height: 2rem; | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
export const StDiaryIconContainer = styled.div` | ||
${({ theme }) => theme.mixins.flexBox('row', 'baseline')}; | ||
svg { | ||
margin-left: 1.25rem; | ||
} | ||
`; | ||
|
||
export const StCalendarBox = styled.div` | ||
position: relative; | ||
`; | ||
|
||
export const StCalendarLoadingBox = styled.div` | ||
position: absolute; | ||
z-index: 10; | ||
right: 0; | ||
margin-top: 0.25rem; | ||
box-shadow: ${({ theme }) => theme.boxShadow.normal}; | ||
background: ${({ theme }) => theme.bgclr.primary}; | ||
${({ theme }) => theme.mixins.flexBox('column')}; | ||
min-width: 275px; | ||
min-height: 266px; | ||
border-radius: 0.75rem; | ||
`; |
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,102 @@ | ||
import Link from 'next/link'; | ||
import { ArrowLeft, Calendar, Edit, Trash2 } from 'react-feather'; | ||
import DeleteModal from '../DeleteModal/DeleteModal'; | ||
import useDropdown from '@/hooks/useDropdown'; | ||
import useDeleteModal from '@/hooks/useDeleteModal'; | ||
import { Dispatch, SetStateAction, useRef } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { deleteDiaryFn, fetchDiaryDatesFn } from '@/apis/diaryApi'; | ||
import { useMutation, useQuery } from 'react-query'; | ||
import { AxiosError } from 'axios'; | ||
import IDiary from '@/types/IDiary'; | ||
import { | ||
StCalendarBox, | ||
StCalendarLoadingBox, | ||
StDiaryHeader, | ||
StDiaryIconContainer, | ||
} from './DiaryHeader.styled'; | ||
import { ClipLoader } from 'react-spinners'; | ||
import DatePicker from '@/components/atoms/DatePicker/DatePicker'; | ||
import useTodayDate from '@/hooks/useTodayDate'; | ||
|
||
interface IDiaryHeaderProps { | ||
diary: IDiary; | ||
date: string; | ||
setDate: Dispatch<SetStateAction<string>>; | ||
} | ||
|
||
export default function DiaryHeader({ | ||
diary, | ||
date, | ||
setDate, | ||
}: IDiaryHeaderProps) { | ||
const router = useRouter(); | ||
const { dateStr } = useTodayDate(); | ||
const dropdownRef = useRef<HTMLDivElement>(null); | ||
const [isCalendarOpen, setIsCalendarOpen, handleCalendarOpen] = | ||
useDropdown(dropdownRef); | ||
const { isLoading: datesLoading, data: diaryDates } = useQuery( | ||
'diaryDates', | ||
fetchDiaryDatesFn, | ||
{ retry: 0, enabled: isCalendarOpen } | ||
); | ||
const { mutate } = useMutation(deleteDiaryFn, { | ||
onSuccess: data => { | ||
alert(data.message); | ||
router.push('/diary'); | ||
}, | ||
onError: (error: AxiosError) => { | ||
alert(error.message); | ||
// message 결과에 따라 input 필드 초기화 구현해야함 | ||
}, | ||
}); | ||
const { isModalOpen, handleOpen, handleClose, handleDelete } = useDeleteModal( | ||
diary?.diary_id, | ||
mutate | ||
); | ||
|
||
return ( | ||
<StDiaryHeader> | ||
<Link href='/diary'> | ||
<ArrowLeft /> | ||
</Link> | ||
<StDiaryIconContainer> | ||
<Link | ||
href={{ | ||
pathname: `/diary/${router.query.id}/edit`, | ||
query: { data: JSON.stringify(diary) }, | ||
}} | ||
as={`/diary/${router.query.id}/edit`} | ||
> | ||
<Edit /> | ||
</Link> | ||
<Trash2 onClick={handleOpen} /> | ||
{isModalOpen && ( | ||
<DeleteModal | ||
titleMsg='Delete Diary' | ||
subMsg='Are you sure you want to delete this diary?' | ||
handleDelete={handleDelete} | ||
handleClose={handleClose} | ||
/> | ||
)} | ||
<StCalendarBox ref={dropdownRef}> | ||
<Calendar onClick={handleCalendarOpen} /> | ||
{datesLoading && ( | ||
<StCalendarLoadingBox> | ||
<ClipLoader /> | ||
</StCalendarLoadingBox> | ||
)} | ||
{!datesLoading && isCalendarOpen && ( | ||
<DatePicker | ||
enabled={diaryDates} | ||
current={dateStr} | ||
selected={date} | ||
setSelected={setDate} | ||
setIsCalendarOpen={setIsCalendarOpen} | ||
/> | ||
)} | ||
</StCalendarBox> | ||
</StDiaryIconContainer> | ||
</StDiaryHeader> | ||
); | ||
} |
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
Oops, something went wrong.