Skip to content

Commit

Permalink
feat: 년도를 고를 수 있게 하는 유틸 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
khj0426 committed Jun 18, 2024
1 parent 6f2e0e9 commit bc17324
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/Component/Common/Calendar/DateGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { useState } from 'react';
import { getDate, isSaturday, isSunday, isToday } from 'date-fns';
import styled from 'styled-components';

import { buttonTheme } from '@/style/theme/button';

interface DateGridProps {
prevMonthDates: Date[];
currentMonthDates: Date[];
Expand Down Expand Up @@ -94,7 +92,7 @@ const DateCell = styled.div<DateCellProps>`
: 'none'};
color: ${(props) =>
props.isToday
? 'red'
? '#2D8CFF'
: props.isSaturDay
? 'blue'
: props.isSunday
Expand Down
10 changes: 3 additions & 7 deletions src/Component/Common/Calendar/MonthNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DropDown from '@/Component/Common/DropDown/DropDown';
import Flex from '@/Component/Common/Flex/Flex';
import IconButton from '@/Component/Common/IconButton/IconButton';
import useBoolean from '@/hooks/useBoolean';
import { generateYearOptionsFromDate } from '@/utils/generateYearOptions';
interface MonthNavigationProps {
readonly date: Date;
readonly setCurrentDate: (_newYear: string) => void;
Expand All @@ -18,12 +19,7 @@ const MonthNavigation = ({
prevMonth,
nextMonth,
}: MonthNavigationProps) => {
const years = Array.from({ length: 20 }).map((year, index) => {
return {
key: (getYear(date) - index).toString(),
label: (getYear(date) - index).toString(),
};
});
const selectableYearOptions = generateYearOptionsFromDate();

const { setFalse, state: clickedYear, toggle } = useBoolean();
return (
Expand All @@ -37,7 +33,7 @@ const MonthNavigation = ({
<span onClick={toggle}>{getYear(date)}</span>
{clickedYear && (
<DropDown
items={years}
items={selectableYearOptions}
onChangeSelectedItem={(item) => {
if (item) {
setCurrentDate(item.key);
Expand Down
29 changes: 20 additions & 9 deletions src/app/api/report/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import { formatDateToString } from '@/utils/formatDateToString';

export async function POST(req: NextRequest) {
const { type, startDate, endDate } = await req.json();
console.log(startDate, endDate);

switch (type) {
case '총 사용자 수':
return (
await get(
`/api/active-users?startDate=${formatDateToString(
new Date(startDate)
)}&endDate=${formatDateToString(new Date(endDate))}`
)
).data;
return {};
try {
const response = await get('/api/active-users', {
params: {
startDate: formatDateToString(new Date(startDate)),
endDate: formatDateToString(new Date(endDate)),
},
});
const responseData = await response.data;
return NextResponse.json(responseData, {
status: 200,
});
} catch (e) {
console.error(e);
return NextResponse.json(JSON.stringify(e), {
status: 500,
statusText: JSON.stringify(e),
});
}

case '참여 시간':
return {};
case '도시별 한 페이지 당 방문 세션 수':
Expand Down
7 changes: 3 additions & 4 deletions src/utils/axiosClient.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { setContext, withScope, captureException } from '@sentry/nextjs';
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';

import getCurrentBasePath from '@/utils/getCurrentBasePath';
const axiosClient = axios.create({
baseURL:
process.env.NODE_ENV === 'production'
? process.env.NEXT_PUBLIC_PRODUCT_URL
: process.env.NEXT_PUBLIC_LOCAL_URL,
baseURL: getCurrentBasePath(),
});

axiosClient.interceptors.response.use(
Expand Down
15 changes: 15 additions & 0 deletions src/utils/generateYearOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getYear } from 'date-fns';

export const generateYearOptionsFromDate = (
date: Date = new Date(),
length = 20
) => {
return Array.from({ length })
.map((year, index) => {
return {
key: (getYear(date) - index).toString(),
label: (getYear(date) - index).toString(),
};
})
.reverse();
};

0 comments on commit bc17324

Please sign in to comment.