Skip to content

Commit

Permalink
Calendar Panel (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 authored May 13, 2024
1 parent 619e2c3 commit 8340591
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
36 changes: 36 additions & 0 deletions components/calendar/calendar.panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ICalendar } from '@/types/calendar.interface';
import moment from 'moment';
import styled from 'styled-components';

const CalendarPanel = ({ nextEvent }: { nextEvent: ICalendar }) => {
const dDay = moment(nextEvent.event_date).diff(moment(), 'days');
return (
<div style={{ marginBottom: 12 }}>
<NoticeCard>
<div
style={{
fontWeight: 700,
fontSize: 36,
textDecoration: 'none',
marginBottom: 12,
}}
>
{dDay ? `D-${dDay}` : 'D-Day'}
</div>
<div>
{nextEvent.title}
<br />({`${moment(nextEvent.event_date).format('M월 D일')}`})
</div>
</NoticeCard>
</div>
);
};

export default CalendarPanel;

const NoticeCard = styled.div`
background: #eeeeee;
border-radius: 0.4em;
padding: 18px;
text-align: center;
`;
15 changes: 12 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import Layout from '@/components/layout';
import { INotice } from '@/types/notice.interface';
import { PoPoAxios } from '@/lib/axios.instance';
import NoticePanel from '@/components/notice/notice.panel';
import { ICalendar } from '@/types/calendar.interface';
import CalendarPanel from '@/components/calendar/calendar.panel';

const HomePage: React.FunctionComponent<{
noticeList: INotice[];
}> = ({ noticeList }) => {
nextEvent: ICalendar;
}> = ({ noticeList, nextEvent }) => {
const isDayTime = 9 <= new Date().getHours() && new Date().getHours() <= 18;

return (
Expand Down Expand Up @@ -59,7 +62,10 @@ const HomePage: React.FunctionComponent<{
/>
</div>
</HomeCard>
<NoticePanel noticeList={noticeList} />
<div>
<CalendarPanel nextEvent={nextEvent} />
<NoticePanel noticeList={noticeList} />
</div>
</HomeLayout>
</Layout>
);
Expand All @@ -71,8 +77,11 @@ export const getServerSideProps: GetServerSideProps = async () => {
const res = await PoPoAxios.get<INotice>('notice/active');
const noticeList = res.data;

const res2 = await PoPoAxios.get<ICalendar>('calendar/get-next-event');
const nextEvent = res2.data;

return {
props: { noticeList },
props: { noticeList, nextEvent },
};
};

Expand Down
5 changes: 5 additions & 0 deletions types/calendar.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface ICalendar {
id: number;
title: string;
event_date: string;
}

0 comments on commit 8340591

Please sign in to comment.