Skip to content

Commit

Permalink
Merge pull request #168 from IT-Cotato/feat/PR-3_sessoin_page
Browse files Browse the repository at this point in the history
Feat/pr 3 sessoin page
  • Loading branch information
WONYOUNG-HC authored Nov 21, 2024
2 parents 2dfd5b8 + 95b3057 commit 560d464
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 130 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"browserslist": "^4.18.1",
"camelcase": "^6.2.1",
"case-sensitive-paths-webpack-plugin": "^2.4.0",
"cotato-openapi-clients": "2.241116.0",
"cotato-openapi-clients": "2.241122.0",
"craco-alias": "^3.0.1",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^3.2.0",
Expand Down
37 changes: 8 additions & 29 deletions src/pages/Session/SessionHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import fetcherWithParams from '@utils/fetcherWithParams';
import { SessionListImageInfo, SessionUploadInfo } from '@/typing/session';
import api from '@/api/api';
import SessionUploadModal from '@pages/Session/SessionUploadModal';
import {
CotatoGenerationInfoResponse,
CotatoLocalTime,
CotatoSessionListResponse,
} from 'cotato-openapi-clients';
import { CotatoGenerationInfoResponse, CotatoSessionListResponse } from 'cotato-openapi-clients';
import CotatoDropBox from '@components/CotatoDropBox';
import { useMediaQuery } from '@mui/material';
import { device } from '@theme/media';
Expand Down Expand Up @@ -54,28 +50,11 @@ const SessionHome = () => {
/**
*
*/
const getDeadLineString = (deadLine?: CotatoLocalTime) => {
if (!deadLine) {
return '00:00:00';
const getDateString = (date?: Date) => {
if (!date) {
return '';
}

const numToString = (num?: number) => {
if (!num) {
return '00';
}

return num.toString().padStart(2, '0');
};

return `${numToString(deadLine.hour)}:${numToString(deadLine.minute)}:${numToString(
deadLine.second,
)}`;
};

/**
*
*/
const getDateString = (date: Date) => {
const dateISO = new Date(date);
dateISO.setHours(dateISO.getHours() + 9);
return dateISO.toISOString().substring(0, 19);
Expand Down Expand Up @@ -185,8 +164,8 @@ const SessionHome = () => {
formData.append('networking', session.networking);
formData.append('devTalk', session.devTalk);

formData.append('attendanceDeadLine', getDeadLineString(session.attendTime.attendanceDeadLine));
formData.append('lateDeadLine', getDeadLineString(session.attendTime.lateDeadLine));
formData.append('attendanceDeadLine', getDateString(session.attendTime.attendanceDeadLine));
formData.append('lateDeadLine', getDateString(session.attendTime.lateDeadLine));

session.imageInfos.forEach((imageInfo) => {
if (imageInfo.imageFile) {
Expand Down Expand Up @@ -219,8 +198,8 @@ const SessionHome = () => {
placeName: session.placeName,
location: session.location,
attendTime: {
attendanceDeadLine: getDeadLineString(session?.attendTime?.attendanceDeadLine),
lateDeadLine: getDeadLineString(session?.attendTime?.lateDeadLine),
attendanceDeadLine: getDateString(session?.attendTime?.attendanceDeadLine),
lateDeadLine: getDateString(session?.attendTime?.lateDeadLine),
},
itIssue: session.itIssue,
csEducation: session.csEducation,
Expand Down
85 changes: 17 additions & 68 deletions src/pages/Session/SessionUploadModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import dayjs from 'dayjs';
import { ToastContainer } from 'react-toastify';
import SearchLocationModal from '@components/SearchLocation/SearchLocationModal';
import {
CotatoLocalTime,
CotatoSessionContentsCsEducationEnum,
CotatoSessionContentsDevTalkEnum,
CotatoSessionContentsItIssueEnum,
Expand Down Expand Up @@ -63,16 +62,8 @@ const INITIAL_SESSION_STATE: SessionUploadInfo = {
description: '',
sessionDateTime: new Date(),
attendTime: {
attendanceDeadLine: {
hour: 19,
minute: 10,
second: 0,
},
lateDeadLine: {
hour: 19,
minute: 20,
second: 0,
},
attendanceDeadLine: new Date(),
lateDeadLine: new Date(),
},
itIssue: CotatoSessionContentsItIssueEnum.Off,
csEducation: CotatoSessionContentsCsEducationEnum.On,
Expand Down Expand Up @@ -106,7 +97,7 @@ const SessionUploadModal = ({
*/
const fetchUpdateSession = async () => {
try {
const response = await api.get('/v2/api/attendances/info', {
const { data: attendancesInfo } = await api.get('/v2/api/attendances/info', {
params: {
sessionId: sessionInfo?.sessionId,
},
Expand All @@ -118,21 +109,10 @@ const SessionUploadModal = ({
description: sessionInfo?.description || '',
sessionDateTime: new Date(sessionInfo?.sessionDateTime || ''),
placeName: sessionInfo?.placeName || '',
location: {
latitude: response.data.location?.latitude,
longitude: response.data.location?.longitude,
},
location: attendancesInfo.location,
attendTime: {
attendanceDeadLine: {
hour: response.data.attendanceDeadLine?.hour || 19,
minute: response.data.attendanceDeadLine?.minute || 10,
second: response.data.attendanceDeadLine?.second || 0,
},
lateDeadLine: {
hour: response.data.lateDeadLine?.hour || 19,
minute: response.data.lateDeadLine?.minute || 20,
second: response.data.lateDeadLine?.second || 0,
},
attendanceDeadLine: attendancesInfo.attendanceDeadLine,
lateDeadLine: attendancesInfo.lateDeadLine,
},
itIssue: sessionInfo?.sessionContents?.itIssue || CotatoSessionContentsItIssueEnum.Off,
csEducation:
Expand All @@ -149,17 +129,6 @@ const SessionUploadModal = ({
}
};

/**
*
*/
const convertCotatoLocalTimeToDate = (localTime?: CotatoLocalTime): Date => {
const date = new Date();
date.setHours(localTime?.hour || 0);
date.setMinutes(localTime?.minute || 0);
date.setSeconds(localTime?.second || 0);
return date;
};

/**
*
*/
Expand Down Expand Up @@ -300,19 +269,7 @@ const SessionUploadModal = ({
const handleAttendanceDeadlineChange = (date: Date) => {
setSession(
produce(session, (draft) => {
if (draft.attendTime?.attendanceDeadLine) {
draft.attendTime.attendanceDeadLine.hour = date.getHours();
draft.attendTime.attendanceDeadLine.minute = date.getMinutes();
draft.attendTime.attendanceDeadLine.second = date.getSeconds();
} else {
draft.attendTime = {
attendanceDeadLine: {
hour: date.getHours(),
minute: date.getMinutes(),
second: date.getSeconds(),
},
};
}
draft.attendTime!.attendanceDeadLine = date;
}),
);
};
Expand All @@ -323,19 +280,7 @@ const SessionUploadModal = ({
const handleLateDeadLineChange = (date: Date) => {
setSession(
produce(session, (draft) => {
if (draft.attendTime?.lateDeadLine) {
draft.attendTime.lateDeadLine.hour = date.getHours();
draft.attendTime.lateDeadLine.minute = date.getMinutes();
draft.attendTime.lateDeadLine.second = date.getSeconds();
} else {
draft.attendTime = {
lateDeadLine: {
hour: date.getHours(),
minute: date.getMinutes(),
second: date.getSeconds(),
},
};
}
draft.attendTime!.lateDeadLine = date;
}),
);
};
Expand Down Expand Up @@ -454,14 +399,14 @@ const SessionUploadModal = ({
<div>
출석 인정
<CotatoTimePicker
date={convertCotatoLocalTimeToDate(session.attendTime?.attendanceDeadLine)}
date={session.attendTime?.attendanceDeadLine ?? new Date()}
onDateChange={handleAttendanceDeadlineChange}
/>
</div>
<div>
지각 인정
<CotatoTimePicker
date={convertCotatoLocalTimeToDate(session?.attendTime?.lateDeadLine)}
date={session.attendTime?.lateDeadLine ?? new Date()}
onDateChange={handleLateDeadLineChange}
/>
</div>
Expand Down Expand Up @@ -508,18 +453,22 @@ const SessionUploadModal = ({
if (sessionInfo) {
fetchUpdateSession();
} else {
const getNextFiday = () => {
const getNextFidayDate = (hour: number, minute: number) => {
const today = new Date();
const day = today.getDay();
const diff = 5 - day;
const nextFriday = new Date(today);
nextFriday.setDate(today.getDate() + diff);
nextFriday.setHours(19, 0, 0, 0);
nextFriday.setHours(hour, minute, 0, 0);
return nextFriday;
};

const initialSession = produce(INITIAL_SESSION_STATE, (draft) => {
draft.sessionDateTime = getNextFiday();
draft.sessionDateTime = getNextFidayDate(19, 0);
draft.attendTime = {
attendanceDeadLine: getNextFidayDate(19, 10),
lateDeadLine: getNextFidayDate(19, 20),
};
});

setSession(initialSession);
Expand Down
39 changes: 7 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4754,10 +4754,10 @@ cosmiconfig@^7, cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
path-type "^4.0.0"
yaml "^1.10.0"

cotato-openapi-clients@2.241116.0:
version "2.241116.0"
resolved "https://registry.yarnpkg.com/cotato-openapi-clients/-/cotato-openapi-clients-2.241116.0.tgz#c4fd64a3b7e88bdf3140c7b08ee60612bbaabb4f"
integrity sha512-MwwxMtk9vVwTSGHcF9vyg68B5iUHCxU+6JiISoLnlOhkdjwHzdaEBAviNTp4JouRZ1JgIW7C6SXwoZFWssbLHw==
cotato-openapi-clients@2.241122.0:
version "2.241122.0"
resolved "https://registry.yarnpkg.com/cotato-openapi-clients/-/cotato-openapi-clients-2.241122.0.tgz#c6b8432bc547d8bed4ceda88c009818f3ff42fb7"
integrity sha512-utYFmmFjBOIZbVHURrBF/jc9eJ/VzVALwcCC9wXiuZKiXEyUM/Cdu5AIKIBJP4653OdA0lCMDVElTo9xG9rTgw==
dependencies:
"@openapitools/openapi-generator-cli" "^2.13.4"
"@testing-library/jest-dom" "^5.17.0"
Expand Down Expand Up @@ -10665,16 +10665,7 @@ string-natural-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4"
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^4.1.0, string-width@^4.2.0:
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -10777,14 +10768,7 @@ stringify-object@^3.3.0:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -12018,7 +12002,7 @@ [email protected]:
"@types/trusted-types" "^2.0.2"
workbox-core "6.6.1"

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -12036,15 +12020,6 @@ wrap-ansi@^6.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down

0 comments on commit 560d464

Please sign in to comment.