diff --git a/src/auth/jwtCookie.js b/src/auth/jwtCookie.js new file mode 100644 index 0000000..94a171b --- /dev/null +++ b/src/auth/jwtCookie.js @@ -0,0 +1,51 @@ +import { accessToken } from 'mapbox-gl'; +import axiosInstance from 'src/utils/axios'; + +export function setCookie(name, value, days) { + let expires = ''; + if (days) { + const date = new Date(); + date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); + expires = `; expires=${date.toUTCString()}`; + } + document.cookie = `${name}=${value || ''}${expires}; path=/`; +} + +export function setServerSideCookie(context) { + let { cookie } = context.req.headers; + + cookie = getKeyFromPairString(cookie, 'accessToken'); + + if (cookie !== '') { + axiosInstance.defaults.headers.common.Authorization = `Bearer ${cookie}`; + } +} + +export function getKeyFromPairString(pairString, key) { + const pairArr = pairString ? pairString?.split(';').map((pair) => pair.trim()) : []; + + // eslint-disable-next-line no-restricted-syntax + for (const pair of pairArr) { + const [pairKey, pairValue] = pair.split('=').map((c) => c.trim()); + + if (pairKey === key) { + return pairValue; + } + } + + return ''; +} + +export function getCookie(key) { + const cookies = document.cookie.split(';').map((cookie) => cookie.trim()); + console.log(cookies); + // eslint-disable-next-line no-restricted-syntax + for (const cookie of cookies) { + const [cookieKey, cookieValue] = cookie.split('=').map((c) => c.trim()); + if (cookieKey === key) { + console.log(cookieValue); + return cookieValue; + } + } + return null; +} diff --git a/src/components/common/Drawer/Drawer.tsx b/src/components/common/Drawer/Drawer.tsx index 6c1d780..2370a6a 100644 --- a/src/components/common/Drawer/Drawer.tsx +++ b/src/components/common/Drawer/Drawer.tsx @@ -140,8 +140,11 @@ export default function MiniDrawer() { return '/manage/student'; case 7: return '/manage/user'; + case 9: return '/mileage/result'; + case 10: + return '/manage/setting'; case 11: return '/report'; default: diff --git a/src/components/common/Table/SemesterTable.tsx b/src/components/common/Table/SemesterTable.tsx new file mode 100644 index 0000000..0434640 --- /dev/null +++ b/src/components/common/Table/SemesterTable.tsx @@ -0,0 +1,200 @@ +import * as React from 'react'; +import { useState } from 'react'; +import { styled } from '@mui/material/styles'; +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableCell, { tableCellClasses } from '@mui/material/TableCell'; +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 { Box, Button, TextField } from '@mui/material'; +import axiosInstance from 'src/utils/axios'; +import { + // formatDateToISOString, + // formatDateToISOStringExceptT, + getCurrentKST, +} from 'src/utils/formatTime'; +import { rowSelectionStateInitializer } from '@mui/x-data-grid/internals'; + +const StyledTableCell = styled(TableCell)(({ theme }) => ({ + [`&.${tableCellClasses.head}`]: { + backgroundColor: 'darkGray', + color: theme.palette.common.white, + }, + [`&.${tableCellClasses.body}`]: { + fontSize: 14, + }, +})); + +const StyledTableRow = styled(TableRow)(({ theme }) => ({ + '&:nth-of-type(odd)': { + backgroundColor: theme.palette.action.hover, + }, + // hide last border + '&:last-child td, &:last-child th': { + border: 0, + }, +})); + +interface IGetAllSemesterWithStatus { + count: number; + list: ISemesterWithStatus[]; +} + +interface IISemesterWithStatus { + id: number; + name: string; + status: string; + applyStart: string; + applyEnd: string; +} + +const FlexBox = styled(Box)({ + display: 'flex', + gap: '10px', + alignItems: 'center', +}); + +const headRow = ['번호', '학기 이름', '시작일', '마감일', '신청 상태', '설정']; + +export default function SemesterTable({ data }: IGetAllSemesterWithStatus) { + const [isModifying, setIsModifying] = React.useState( + new Array(data.list.length).fill(false) + ); + const [startDate, setStartDate] = React.useState(); + const [endDate, setEndDate] = React.useState(); + + const handleModify = (semesterId: number, rowIdx: number) => { + if (isModifying[rowIdx]) { + modifyApply(semesterId); + } + + setStartDate(data.list[rowIdx].applyStart); + setEndDate(data.list[rowIdx].applyEnd); + + let newIsModifying = new Array(data.list.length).fill(false); + newIsModifying[rowIdx] = true; + + setIsModifying(newIsModifying); + }; + + const handleCancel = (rowIdx: number) => { + console.log(data.list.length); + setIsModifying(new Array(data.list.length).fill(false)); + }; + + const modifyApply = async (semesterId: number) => { + const modifyData = { + semesterId: semesterId, + applyStart: startDate, + applyEnd: endDate, + }; + if (window.confirm('정말 수정하시겠습니까??')) { + axiosInstance.patch('/api/mileage/semesters/period', modifyData).then((res) => { + setIsModifying(new Array(data.list.length).fill(false)); + + window.location.reload(); + }); + } + }; + + const handleEnd = (row) => { + // console.log(formatDateToISOStringExceptT(getCurrentKST())); + + if (window.confirm('정말 마감하시겠습니까??')) { + const endData = { + semesterId: row.id, + applyStart: row.applyStart, + applyEnd: getCurrentKST(), + }; + console.log(endData); + + axiosInstance.patch('/api/mileage/semesters/period', endData).then((res) => { + window.location.reload(); + }); + } + }; + return ( + + + + + {headRow.map((elem, index) => ( + + {elem} + + ))} + + + + {data.list.map((row, idx) => ( + + + {idx + 1} + + {row.name} + {isModifying[idx] ? ( + + setStartDate(e.target.value)} + /> + + ) : ( + {row?.applyStart} + )} + {isModifying[idx] ? ( + + setEndDate(e.target.value)} + /> + + ) : ( + {row?.applyEnd} + )} + + {row.status} + + {isModifying[idx] ? ( + + + + + ) : ( + + {row.status !== '선정 완료' && ( + + )} + {row.status === '신청 가능' && ( + + )} + + )} + + + ))} + +
+
+ ); +} diff --git a/src/components/excel/ExcelExport.tsx b/src/components/excel/ExcelExport.tsx index 950e4ee..56c6e26 100644 --- a/src/components/excel/ExcelExport.tsx +++ b/src/components/excel/ExcelExport.tsx @@ -35,11 +35,11 @@ export default function ExcelExport() { const handleExcelExport = (e, endPoint) => { console.log(e.target.id, endPoint); - setMenuButton(0); - // axiosInstance.get(endPoint).then((res) => { - // console.log(res); - // alert(`${e.target.id} 다운로드가 완료되었습니다.`); - // }); + // setMenuButton(0); + axiosInstance.get(endPoint).then((res) => { + console.log(res); + alert(`${e.target.id} 다운로드가 완료되었습니다.`); + }); }; return ( @@ -49,8 +49,9 @@ export default function ExcelExport() { * @brief 엑셀 다운로드 버튼 * @description Link Masking (서버의 링크를 숨긴다.) */ - +