Skip to content

Commit

Permalink
Merge pull request #84 from Team-INSERT/feat/calender
Browse files Browse the repository at this point in the history
캘린더 페이지 완성
  • Loading branch information
Ubinquitous authored Oct 3, 2023
2 parents 0d99f0a + ef8b32a commit cb5fa47
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 41 deletions.
1 change: 1 addition & 0 deletions src/apis/httpClient/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ export default {
like: new HttpClient("api/likes/update", axiosConfig),
image: new HttpClient("api/image/save", axiosConfig),
meal: new HttpClient("api/meal", axiosConfig),
calender: new HttpClient("api/calender", axiosConfig),
};
121 changes: 121 additions & 0 deletions src/components/common/Modal/PlanAddModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { XIcon } from "@/assets/icons";
import { Column } from "@/components/Flex";
import { Button, Input, Select } from "@/components/atoms";
import useModal from "@/hooks/useModal";
import useUser from "@/hooks/useUser";
import { useAddCalenderPlanMutation } from "@/page/calender/services/mutation.service";
import { color, flex, font } from "@/styles";
import React from "react";
import styled from "styled-components";

interface IPlanAddModalProps {
date: string;
}

const PlanAddModal = ({ date }: IPlanAddModalProps) => {
const { closeModal } = useModal();
const { mutate } = useAddCalenderPlanMutation();
const { user } = useUser();
const [planType, setPlanType] = React.useState("CLASS");
const [title, setTitle] = React.useState("");
const textareaRef = React.useRef<HTMLTextAreaElement>(null);

const handleAddButtonClick = () => {
mutate({
title,
priority: 0,
date,
color: "#000",
type: planType,
grade: user.grade,
classNumber: user.classNum,
});
};

React.useEffect(() => {
if (textareaRef.current) textareaRef.current.focus();
}, []);

return (
<Container>
<Header>
<BambooTitle />
<CloseButton>
<XIcon onClick={closeModal} />
</CloseButton>
</Header>
<Body>
<Input
label="일정 내용"
placeholder="간략한 일정 내용을 입력해주세요."
onChange={(e) => setTitle(e.target.value)}
value={title}
/>
<Column gap="6px">
<StyledTitle>일정 분류</StyledTitle>
<Select
label=""
width="100px"
options={["CLASS", "GRADE", "SCHOOL"]}
defaultOption={planType}
handler={setPlanType}
/>
</Column>
</Body>
<PlanButtonBox>
<Button onClick={handleAddButtonClick} color={color.primary_blue}>
추가하기
</Button>
</PlanButtonBox>
</Container>
);
};

const Container = styled.div`
width: 40vw;
height: fit-content;
overflow-y: scroll;
background-color: ${color.white};
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.2);
border-radius: 8px;
${flex.COLUMN};
`;

const Header = styled.header`
width: 100%;
padding: 10px 0 10px 18px;
display: flex;
align-items: center;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.15);
`;

const BambooTitle = styled.div`
${font.p2};
font-weight: 500;
&:after {
content: "📆 일정 추가하기";
}
`;

const Body = styled.div`
padding: 16px 28px;
${flex.COLUMN};
gap: 12px;
`;

const CloseButton = styled.button`
margin: 0 20px 0 auto;
`;

const PlanButtonBox = styled.div`
width: fit-content;
margin: 0 16px 16px auto;
`;

const StyledTitle = styled.span`
${font.p3};
font-weight: 500;
`;

export default PlanAddModal;
1 change: 1 addition & 0 deletions src/constants/key.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const KEY = {
BAMBOO: "useBamboo",
BAMBOO_ADMIN: "useBambooAdmin",
MEAL: "useMeal",
CALENDER: "useCalender",
} as const;

export default KEY;
14 changes: 14 additions & 0 deletions src/helpers/getClassName.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const getClassName = (classname: string) => {
switch (classname) {
case "GRADE":
return "학년";
case "CLASS":
return "학급";
case "SCHOOL":
return "학교";
default:
return classname;
}
};

export default getClassName;
5 changes: 5 additions & 0 deletions src/helpers/getDay.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const getDay = (date: string) => {
return date.split("-")[2];
};

export default getDay;
2 changes: 2 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export { default as checkTextOverflow } from "./checkTextOverflow.helper";
export { default as getTextDepth } from "./getTextDepth.helper";
export { default as getMealName } from "./getMealName.helper";
export { default as getTimetableType } from "./getTimetableType.helper";
export { default as getDay } from "./getDay.helper";
export { default as getClassName } from "./getClassName.helper";
9 changes: 9 additions & 0 deletions src/interfaces/calender.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default interface ICalender {
title: string;
priority: number;
date: string;
color: string;
type: string;
grade: number;
classNumber: number;
}
6 changes: 6 additions & 0 deletions src/interfaces/calenderItem.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import IPlan from "./plan.interface";

export default interface ICalenderItem {
date: string;
plans: Array<IPlan>;
}
2 changes: 2 additions & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type { default as IPostInfiniteList } from "./postInfiniteList.interface"
export type { default as IInfiniteResult } from "./infiniteResult.interface";
export type { default as IInputPost } from "./inputPost.interface";
export type { default as IRecomment } from "./recomment.interface";
export type { default as ICalender } from "./calender.interface";
export type { default as IPlan } from "./plan.interface";
11 changes: 11 additions & 0 deletions src/interfaces/plan.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ICalender from "./calender.interface";

export default interface IPlan extends ICalender {
id: number;
type: string;
user: {
id: number;
nickName: string;
profileImage: string;
};
}
29 changes: 24 additions & 5 deletions src/page/calender/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import styled from "styled-components";
import { Aside } from "@/components/common";
import { color, flex, font } from "@/styles";
import { Column } from "@/components/Flex";
import ScheduleBox from "./layouts/ScheduleBox";

const CalenderPage = () => {
return (
<Layout>
<Container>
<Column gap="8px" alignItems="center">
<Title />
<SubTitle />
</Column>
<ScheduleBox />
<Aside />
</Container>
</Layout>
);
Expand All @@ -21,9 +25,24 @@ const Layout = styled.div`

const Container = styled.div`
width: 76%;
display: flex;
justify-content: center;
gap: 8px;
${flex.COLUMN};
align-items: center;
gap: 24px;
`;

const Title = styled.span`
${font.H2};
&:after {
content: "🗓️ 캘린더";
}
`;

const SubTitle = styled.span`
color: ${color.gray};
&:after {
content: "좌우 화살표 방향키를 탭해 날짜를 조정해보세요.";
}
`;

export default CalenderPage;
24 changes: 20 additions & 4 deletions src/page/calender/layouts/CalenderList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import styled from "styled-components";
import dayjs from "dayjs";
import ICalenderItem from "@/interfaces/calenderItem.interface";
import CalenderListItem from "./CalenderListItem";

const CalenderList = () => {
interface ICalenderListProps {
currentMonth: number;
calenderList: Array<ICalenderItem>;
}

const CalenderList = ({ currentMonth, calenderList }: ICalenderListProps) => {
const firstDayOfMonth = dayjs()
.year(new Date().getFullYear())
.month(currentMonth - 1)
.date(1);
const dayOfWeek = firstDayOfMonth.day();

return (
<Container>
{Array.from({ length: 10 }).map((_, index) => (
<CalenderListItem key={index} />
{Array.from({ length: dayOfWeek }).map((_, i) => (
<CalenderListItem key={i} calender={calenderList[0]} isEmpty />
))}
{calenderList?.map((calender) => (
<CalenderListItem key={calender.date} calender={calender} />
))}
</Container>
);
Expand All @@ -14,8 +30,8 @@ const CalenderList = () => {
const Container = styled.ul`
width: 100%;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
gap: 1.5%;
`;

export default CalenderList;
Loading

0 comments on commit cb5fa47

Please sign in to comment.