diff --git a/src/pages/record/RecordPage.tsx b/src/pages/record/RecordPage.tsx index d28a6d5..677c9ee 100644 --- a/src/pages/record/RecordPage.tsx +++ b/src/pages/record/RecordPage.tsx @@ -181,7 +181,7 @@ const RecordPage = () => { ); }} // dayCellContent={renderDayCellContent} - titleFormat={renderTitle} + titleFormat={renderTitle} datesSet={(info) => { getAllRecords(info); }} diff --git a/src/pages/statistics/Period.tsx b/src/pages/statistics/Period.tsx index b5daf6a..a1fc8ff 100644 --- a/src/pages/statistics/Period.tsx +++ b/src/pages/statistics/Period.tsx @@ -4,7 +4,7 @@ import { StatisticsRequest, } from '@/api/statistics.api'; import { statisticsResultState } from '@/store/statistics'; -import { AppBar, Tabs, Tab, Box, Grid, TextField } from '@mui/material'; +import { AppBar, Tabs, Tab, Box, Grid, TextField, InputAdornment, IconButton, styled } from '@mui/material'; import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; @@ -14,9 +14,7 @@ import localizedFormat from 'dayjs/plugin/localizedFormat'; import 'dayjs/locale/ko'; import { useState, SyntheticEvent, useEffect } from 'react'; import { useRecoilState, useSetRecoilState } from 'recoil'; - import WeekPicker from './WeekPicker'; - import { selectedStartDate } from '@/store/statistics'; dayjs.extend(utc); @@ -45,6 +43,93 @@ const periodTypeList: IPeriodType[] = [ { title: '일 년', id: 'BY_YEAR' }, ]; + +interface StyledTabProps { + key: string; + label: string; + value: string; +} + + +/** + * render date input + */ +export const renderDateInput = ({params, width}: any) => { + return ( + + + + + + + + }} + sx={{ + display: 'flex', + color: '#4B4B4B', + fontWeight: '600', + fontSize: '14px', + ' .MuiInputBase-root': { justifyContent: 'center', p: 0 }, + ' .MuiInputBase-input': { p: '16px 0', flex: '1 1 auto', overflow: 'auto', width: width + 'px' }, + ' .MuiInputAdornment-root' : {flex: '0 0 auto'}, + '& input': { pl: 0 }, + '& fieldset': { border: 'none' } + }} + /> +)}; + +const StyledTabs = styled((props: StyledTabsProps) => ( + + }} + /> +))({ + height: '55px', + '& .MuiTabs-indicator': { + display: 'flex', + justifyContent: 'center', + backgroundColor: 'transparent', + bottom: '13px', + zIndex: 10 + }, + '& .MuiTabs-indicatorSpan': { + overflow: 'auto', + backgroundColor: '#FF7184', + borderRadius: '2px', + height: '4px', + width: '31px' + }, +}); + +const StyledTab = styled((props: StyledTabProps) => ( + +))(({ theme }) => ({ + textTransform: 'none', + fontSize: 14, + marginRight: theme.spacing(1), + color: '#949494', + fontWeight: 600, + '&.Mui-selected': { + color: '#FF7184' + }, + '&.Mui-focusVisible': { + backgroundColor: 'rgba(100, 95, 228, 0.32)', + }, +})); + + const Period = () => { const [periodType, setPeriodType] = useState( periodTypeList[0].id, @@ -82,80 +167,85 @@ const Period = () => { }; /** - * returns rendered input - * @param params - * @returns rendered input + * get period string + * @returns period string */ - const setRenderedInput = (params: any) => { - return ( - - )}; - - useEffect(() => { - let date = selectedDate[periodType]; - let type: ManipulateType = 'day'; + const getPeriodString = (): ManipulateType | undefined => { switch (periodType) { - case 'BY_MONTH': - type = 'month'; - break; + case 'BY_DAY': + return 'day'; case 'BY_WEEK': - type = 'week'; - break; + return 'week'; + case 'BY_MONTH': + return 'month'; case 'BY_YEAR': - type = 'year'; - break; + return 'year'; default: break; } + }; + useEffect(() => { + let date = selectedDate[periodType]; getStatistics({ fromStartedAt: `${date.format('YYYY-MM-DD')}T00:00:00`, - toFinishedAt: `${date.add(1, type).format('YYYY-MM-DD')}T00:00:00`, + toFinishedAt: `${date.add(1, getPeriodString()).format('YYYY-MM-DD')}T00:00:00`, }); }, [selectedDate, periodType]); + return ( {/* 날짜 선택 타입 시작 */} - + - {periodTypeList.map((period, idx) => ( - ))} - + + {/* 날짜 선택 타입 끝 */} @@ -165,15 +255,27 @@ const Period = () => { sx={{ direction: 'column', alignItems: 'center', - justifyContent: 'center', - padding: 1, + justifyContent: 'space-between', + p: '8px 17px', }} > + + {periodType === 'BY_DAY' && ( renderDateInput({params, width: 120})} + disableMaskedInput onChange={setNewDateRange} /> )} @@ -188,7 +290,7 @@ const Period = () => { renderDateInput({params, width: 95})} onChange={setNewDateRange} views={['year', 'month']} openTo='month' @@ -198,13 +300,24 @@ const Period = () => { renderDateInput({params, width: 55})} onChange={setNewDateRange} views={['year']} minDate={dayjs('2023-01-01')} maxDate={dayjs(currDate)} /> )} + + {/* 날짜 선택 끝 */} @@ -212,3 +325,4 @@ const Period = () => { }; export default Period; + \ No newline at end of file diff --git a/src/pages/statistics/WeekPicker.tsx b/src/pages/statistics/WeekPicker.tsx index e16b260..ccb5d7c 100644 --- a/src/pages/statistics/WeekPicker.tsx +++ b/src/pages/statistics/WeekPicker.tsx @@ -1,11 +1,11 @@ import { isPropsEqual } from '@fullcalendar/core/internal'; -import { TextField } from '@mui/material'; import { styled } from '@mui/material/styles'; import { DatePicker } from '@mui/x-date-pickers/DatePicker'; import { PickersDay, PickersDayProps } from '@mui/x-date-pickers/PickersDay'; import dayjs, { Dayjs } from 'dayjs'; import isBetweenPlugin from 'dayjs/plugin/isBetween'; import weekdayPlugin from 'dayjs/plugin/weekday'; +import { renderDateInput } from './Period'; dayjs.extend(isBetweenPlugin); dayjs.extend(weekdayPlugin); @@ -40,7 +40,7 @@ const CustomPickersDay = styled(PickersDay, { const WeekPicker = ({ value, setValue, onChange }: any): JSX.Element => { - + /** * render the weekpicker date * @param date @@ -83,7 +83,6 @@ const WeekPicker = ({ value, setValue, onChange }: any): JSX.Element => { const renderDayInputFormat = (value: any) => `${value.startOf('week').format('MM월 DD일 dddd')} ~ ${value.endOf('week').format('MM월 DD일 dddd')}`; - return ( { }} renderDay={renderWeekPickerDay} inputFormat={renderDayInputFormat(value)} - renderInput={(params) => ( - - )} + renderInput={(params: any) => renderDateInput({params, width: 250})} /> ); };