diff --git a/src/Pages/HomePage/AttendanceLog.jsx b/src/Pages/HomePage/AttendanceLog.jsx index f3e9d86..23763b4 100644 --- a/src/Pages/HomePage/AttendanceLog.jsx +++ b/src/Pages/HomePage/AttendanceLog.jsx @@ -1,4 +1,5 @@ -import React from "react"; +import React, { useEffect } from "react"; +import axios from "axios"; import TableCell from "@mui/material/TableCell"; import TableRow from "@mui/material/TableRow"; import Box from "@mui/material/Box"; @@ -6,8 +7,44 @@ import Collapse from "@mui/material/Collapse"; import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; import TableHead from "@mui/material/TableHead"; +import { format } from "date-fns"; +import { ko } from "date-fns/locale"; +import useStore from "../../store.js" const AttendanceLog = ({ open, attendanceLog }) => { + const { _intraId, _isAttended, _attendanceLog, setAttendanceLog } = useStore( + (state) => state + ); + useEffect(() => { + const getAttendanceLog = async () => { + try { + const config = { + headers: { + authorization: `Bearer ${localStorage.getItem("accessToken")}`, + }, + }; + const response = await axios.get( + `https://${process.env.REACT_APP_AWS_BACKEND_SERVER}/statistic/${_intraId}/userAttendanceList`, + config + ); + + const attendanceList = response.data.map(({ timelog }) => { + const attendanceDate = new Date(timelog); + const _date = format(attendanceDate, "PPP EEEE", { locale: ko }); + const _time = format(attendanceDate, "HH:mm:ss"); + return { date: _date, time: _time }; + }); + + console.log(attendanceList); + + setAttendanceLog(attendanceList); + } catch (error) { + console.log(error); + } + }; + getAttendanceLog(); + }, [_isAttended]); + if (!attendanceLog && attendanceLog.length === 0) { return; } else { @@ -24,7 +61,7 @@ const AttendanceLog = ({ open, attendanceLog }) => { - {attendanceLog.map((log) => ( + {_attendanceLog.map((log) => ( {log.date} diff --git a/src/Pages/HomePage/AttendanceSummary.jsx b/src/Pages/HomePage/AttendanceSummary.jsx index ea01b10..ebdb2d9 100644 --- a/src/Pages/HomePage/AttendanceSummary.jsx +++ b/src/Pages/HomePage/AttendanceSummary.jsx @@ -8,9 +8,10 @@ import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"; import useStore from "../../store.js"; -function AttendanceSummary(props) { - const { attendanceLog } = props; - const { _intraId, _summary, setSummary } = useStore((state) => state); +function AttendanceSummary() { + const { _intraId, _summary, setSummary } = useStore( + (state) => state + ); const [open, setOpen] = useState(false); const getSummary = async () => { @@ -54,7 +55,7 @@ function AttendanceSummary(props) { {_summary.isPerfect ? "✅" : "❌"} - + ); } diff --git a/src/Pages/HomePage/AttendanceTable.jsx b/src/Pages/HomePage/AttendanceTable.jsx index f3eb63d..8881c32 100644 --- a/src/Pages/HomePage/AttendanceTable.jsx +++ b/src/Pages/HomePage/AttendanceTable.jsx @@ -8,44 +8,8 @@ import TableContainer from "@mui/material/TableContainer"; import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; -import useStore from "../../store.js"; -import { format } from "date-fns"; -import { ko } from "date-fns/locale"; - -const AttendanceTable = ({ summary }) => { - const { _intraId, _attendanceLog, _isAttended, setAttendanceLog } = useStore( - (state) => state - ); - - useEffect(() => { - const getAttendanceLog = async () => { - try { - const config = { - headers: { - authorization: `Bearer ${localStorage.getItem("accessToken")}`, - }, - }; - const response = await axios.get( - `https://${process.env.REACT_APP_AWS_BACKEND_SERVER}/statistic/${_intraId}/userAttendanceList` - , config); - - const attendanceList = response.data.map(({ timelog }) => { - const attendanceDate = new Date(timelog); - const _date = format(attendanceDate, "PPP EEEE", { locale: ko }); - const _time = format(attendanceDate, "HH:mm:ss"); - return { date: _date, time: _time }; - }); - - console.log(attendanceList); - - setAttendanceLog(attendanceList); - } catch (error) { - console.log(error); - } - }; - getAttendanceLog(); - }, [_isAttended]); +const AttendanceTable = () => { return ( @@ -60,8 +24,9 @@ const AttendanceTable = ({ summary }) => { + - +
diff --git a/src/Pages/HomePage/index.jsx b/src/Pages/HomePage/index.jsx index 3c7d415..fc91408 100644 --- a/src/Pages/HomePage/index.jsx +++ b/src/Pages/HomePage/index.jsx @@ -43,7 +43,7 @@ function Home() { <> - + {/* */} {isOperator && }