Skip to content

Commit

Permalink
Merge pull request #13 from GDSC-snowflowerthon/feat/#8
Browse files Browse the repository at this point in the history
[#8] home api 연결
  • Loading branch information
SujinKim1127 authored Jan 12, 2024
2 parents 42bf9bc + d45eb68 commit 06e6b67
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 179 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.5",
"date-fns": "^3.2.0",
"iconify": "^1.4.0",
"jotai": "^2.6.1",
Expand Down
7 changes: 7 additions & 0 deletions src/api/axios.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import axios from "axios";

const instance = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});

export default instance;
28 changes: 19 additions & 9 deletions src/components/Calendar/Cells.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import { useEffect, useRef, useState } from "react";
import COLORS from "../../styles/colors";
import { useAtom } from "jotai";
import { modalState } from "../../atoms/modalState";

import axios from "../../api/axios";
import { DateConverter } from "../utils/DateConverter";
const Cells = ({ currentMonth, selectedDate, onDateClick, schedule }) => {
const monthStart = startOfMonth(currentMonth);
const monthEnd = endOfMonth(monthStart);
const startDate = startOfWeek(monthStart);
const endDate = endOfWeek(monthEnd);
const [data, setData] = useState([]);
const [selectday, setSelectday] = useState(new Date());
const [state, setState] = useState(false);
const statedayRef = useRef("");
const [isOpen, setIsOpen] = useAtom(modalState);

Expand All @@ -30,17 +29,26 @@ const Cells = ({ currentMonth, selectedDate, onDateClick, schedule }) => {
let formatDate = "";

useEffect(() => {
schedule.map((el) => {
setData((prev) => [el.day, ...prev]);
});
}, [schedule]);
axios
.get(`users/home/1/2024/${currentMonth.getMonth() + 1}`)
.then((res) => {
console.log(res.data.result.monthlyTumbles);
setData(res.data.result.monthlyTumbles);
});
}, []);

const SetColorDate = (targetDate) => {
const isDateInData = data.some((item) => item.createdDate === targetDate);
return isDateInData;
};

while (day <= endDate) {
for (let i = 0; i < 7; i++) {
formatDate = format(day, "d");
const cloneDay = day;
statedayRef.current = day.toDateString();
const string = cloneDay.toDateString();
const calDate = DateConverter(string);
days.push(
<Container>
<CellBox
Expand All @@ -56,7 +64,9 @@ const Cells = ({ currentMonth, selectedDate, onDateClick, schedule }) => {
}`}
onClick={() => {
onDateClick(cloneDay);
setIsOpen(!isOpen);
if (!SetColorDate(calDate)) {
setIsOpen(!isOpen);
}
}}
>
<Square>
Expand All @@ -66,7 +76,7 @@ const Cells = ({ currentMonth, selectedDate, onDateClick, schedule }) => {
? "text not-valid"
: ""
}`}
use={true}
use={SetColorDate(calDate)}
/>
</Square>
<span
Expand Down
10 changes: 4 additions & 6 deletions src/components/Diary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ import styled from "styled-components";
import COLORS from "../styles/colors";
import { useState } from "react";

const Diary = ({ date }) => {
const [sizeState, setSizeState] = useState([true, false, false]);

const Diary = ({ menu, Tsize, discountPrice }) => {
const size = ["S", "M", "L"];

return (
<DiaryWrapper>
<Box>
<InfoTitleBox>메뉴</InfoTitleBox>
<InfoDetailBox>자바칩 프라푸치노</InfoDetailBox>
<InfoDetailBox>{menu}</InfoDetailBox>
</Box>
<Box>
<InfoTitleBox>사이즈</InfoTitleBox>
<SizeBox>
{size.map((el, idx) => {
return <SizeBtn state={sizeState[idx]}>{el}</SizeBtn>;
return <SizeBtn state={size[idx] === Tsize}>{el}</SizeBtn>;
})}
</SizeBox>
</Box>
<Box>
<InfoTitleBox>할인 금액</InfoTitleBox>
<InfoMoneyBox></InfoMoneyBox>
<InfoMoneyBox>{discountPrice}</InfoMoneyBox>
</Box>
</DiaryWrapper>
);
Expand Down
59 changes: 0 additions & 59 deletions src/components/Modal/Modal.jsx

This file was deleted.

10 changes: 10 additions & 0 deletions src/components/utils/DateConverter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const DateConverter = (dateString) => {
const originalDate = new Date(dateString);
const formattedDate = `${originalDate.getFullYear()}-${(
originalDate.getMonth() + 1
)
.toString()
.padStart(2, "0")}-${originalDate.getDate().toString().padStart(2, "0")}`;

return formattedDate;
};
60 changes: 60 additions & 0 deletions src/images/spinner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 06e6b67

Please sign in to comment.