Skip to content

Commit

Permalink
[FE] FEAT: config 에 연장권 사용기간 update
Browse files Browse the repository at this point in the history
  • Loading branch information
junyoung2015 committed Oct 27, 2023
1 parent df882cb commit d44f1c3
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 47 deletions.
2 changes: 1 addition & 1 deletion config
2 changes: 0 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import MainPage from "@/pages/MainPage";
import AdminMainPage from "@/pages/admin/AdminMainPage";
import LoadingAnimation from "@/components/Common/LoadingAnimation";
import ProfilePage from "./pages/ProfilePage";
import "./firebase-messaging-sw"


const NotFoundPage = lazy(() => import("@/pages/NotFoundPage"));
const LoginFailurePage = lazy(() => import("@/pages/LoginFailurePage"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export type TModalState =

export type TAdminModalState = "returnModal" | "statusModal" | "clubLentModal";

const calExpiredTime = (expireTime: Date) =>
export const calExpiredTime = (expireTime: Date) =>
Math.floor(
(expireTime.getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)
);
Expand Down Expand Up @@ -102,7 +102,9 @@ const getCabinetUserList = (selectedCabinetInfo: CabinetInfo): string => {
return userNameList;
};

const getDetailMessage = (selectedCabinetInfo: CabinetInfo): string | null => {
export const getDetailMessage = (
selectedCabinetInfo: CabinetInfo
): string | null => {
const { status, lentType, lents } = selectedCabinetInfo;
// 밴, 고장 사물함
if (status === CabinetStatus.BANNED || status === CabinetStatus.BROKEN)
Expand All @@ -120,7 +122,9 @@ const getDetailMessage = (selectedCabinetInfo: CabinetInfo): string | null => {
else return null;
};

const getDetailMessageColor = (selectedCabinetInfo: CabinetInfo): string => {
export const getDetailMessageColor = (
selectedCabinetInfo: CabinetInfo
): string => {
const { status, lentType, lents } = selectedCabinetInfo;
// 밴, 고장 사물함
if (status === CabinetStatus.BANNED || status === CabinetStatus.BROKEN)
Expand Down
47 changes: 26 additions & 21 deletions frontend/src/components/LeftNav/LeftMainNav/LeftMainNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,58 @@ const LeftMainNav = ({
? "active cabiButton"
: " cabiButton"
}
src={"/src/assets/images/search.svg"}
onClick={onClickSearchButton}
>
<SearchImg stroke="var(--gray-color)" />
<div></div>
Search
</BottomBtnStyled>
<BottomBtnStyled className="cabiButton">
<BottomBtnStyled
src={"/src/assets/images/slack.svg"}
className="cabiButton"
>
<a
href="https://42born2code.slack.com/archives/C02V6GE8LD7"
target="_blank"
title="슬랙 캐비닛 채널 새창으로 열기"
>
<SlackImg stroke="var(--gray-color)" />
<div></div>
Contact
</a>
</BottomBtnStyled>
<BottomBtnStyled
className={
pathname.includes("club")
? "active cabiButton"
: " cabiButton"
}
src={"/src/assets/images/clubIconGray.svg"}
className="cabiButton"
onClick={onClickClubButton}
>
<CulbImg stroke="var(--gray-color)" />
<div></div>
Club
</BottomBtnStyled>
<BottomBtnStyled
className="cabiButton"
onClick={onClickLogoutButton}
src={"/src/assets/images/close-square.svg"}
>
<LogoutImg stroke="var(--gray-color)" />
<div></div>
Logout
</BottomBtnStyled>
</>
)}
{!isAdmin && (
<BottomBtnStyled
className={
pathname.includes("profile")
? "active cabiButton"
: " cabiButton"
}
onClick={onClickProfileButton}
>
<ProfileImg stroke="var(--gray-color)" />
Profile
</BottomBtnStyled>
<>
<BottomBtnStyled
className={
pathname.includes("profile")
? "active cabiButton"
: " cabiButton"
}
src={"/src/assets/images/profile-circle.svg"}
onClick={onClickProfileButton}
>
<div></div>
Profile
</BottomBtnStyled>
</>
)}
</BottomBtnsStyled>
</BottomSectionStyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ const LeftSectionNav = ({
title="슬랙 캐비닛 채널 새창으로 열기"
>
문의하기
<LinkImg stroke="var(--gray-color)" />
<img src="/src/assets/images/link.svg" alt="" />
</SectionLinkStyled>
<SectionLinkStyled
onClick={() => onClickClubForm()}
title="동아리 사물함 사용 신청서 새창으로 열기"
>
동아리 신청서
<LinkImg stroke="var(--gray-color)" />
<img src="/src/assets/images/link.svg" alt="" />
</SectionLinkStyled>
</ProfileLeftNavOptionStyled>
</>
Expand Down Expand Up @@ -147,17 +147,18 @@ const SectionLinkStyled = styled.div`
display: flex;
align-items: center;
color: var(--gray-color);
& svg {
& img {
width: 15px;
height: 15px;
margin-left: auto;
}
@media (hover: hover) and (pointer: fine) {
&:hover {
color: var(--main-color);
svg {
stroke: var(--main-color);
}
}
&:hover img {
filter: invert(33%) sepia(55%) saturate(3554%) hue-rotate(230deg)
brightness(99%) contrast(107%);
}
}
`;
Expand Down
140 changes: 140 additions & 0 deletions frontend/src/components/Modals/ExtendModal/ExtendModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import React, { useState } from "react";
import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil";
import {
currentCabinetIdState,
isCurrentSectionRenderState,
myCabinetInfoState,
targetCabinetInfoState,
userState,
} from "@/recoil/atoms";
import Modal, { IModalContents } from "@/components/Modals/Modal";
import ModalPortal from "@/components/Modals/ModalPortal";
import {
FailResponseModal,
SuccessResponseModal,
} from "@/components/Modals/ResponseModal/ResponseModal";
import { additionalModalType, modalPropsMap } from "@/assets/data/maps";
import checkIcon from "@/assets/images/checkIcon.svg";
import { MyCabinetInfoResponseDto } from "@/types/dto/cabinet.dto";
import {
axiosCabinetById,
axiosExtendLentPeriod,
axiosMyLentInfo, // axiosExtend, // TODO: 연장권 api 생성 후 연결해야 함
} from "@/api/axios/axios.custom";
import {
getExtendedDateString,
getLastDayofMonthString,
} from "@/utils/dateUtils";

const ExtendModal: React.FC<{
onClose: () => void;
cabinetId: Number;
}> = (props) => {
const [showResponseModal, setShowResponseModal] = useState<boolean>(false);
const [hasErrorOnResponse, setHasErrorOnResponse] = useState<boolean>(false);
const [modalTitle, setModalTitle] = useState<string>("");
const currentCabinetId = useRecoilValue(currentCabinetIdState);
const [myInfo, setMyInfo] = useRecoilState(userState);
const [myLentInfo, setMyLentInfo] =
useRecoilState<MyCabinetInfoResponseDto>(myCabinetInfoState);
const setTargetCabinetInfo = useSetRecoilState(targetCabinetInfoState);
const setIsCurrentSectionRender = useSetRecoilState(
isCurrentSectionRenderState
);
const formattedExtendedDate = getExtendedDateString(
myLentInfo.lents ? myLentInfo.lents[0].expiredAt : undefined
);
const extendDetail = `사물함 연장권 사용 시,
대여 기간이 <strong>${formattedExtendedDate} 23:59</strong>으로
연장됩니다.
연장권 사용은 취소할 수 없습니다.
연장권을 사용하시겠습니까?`;
const extendInfoDetail = `사물함을 대여하시면 연장권 사용이 가능합니다.
연장권은 <strong>${getLastDayofMonthString(
null,
"/"
)} 23:59</strong> 이후 만료됩니다.`;
const getModalTitle = (cabinetId: number | null) => {
return cabinetId === null
? modalPropsMap[additionalModalType.MODAL_OWN_EXTENSION].title
: modalPropsMap[additionalModalType.MODAL_USE_EXTENSION].title;
};
const getModalDetail = (cabinetId: number | null) => {
return cabinetId === null ? extendInfoDetail : extendDetail;
};
const getModalProceedBtnText = (cabinetId: number | null) => {
return cabinetId === null
? modalPropsMap[additionalModalType.MODAL_OWN_EXTENSION].confirmMessage
: modalPropsMap[additionalModalType.MODAL_USE_EXTENSION].confirmMessage;
};
const tryExtendRequest = async (e: React.MouseEvent) => {
if (currentCabinetId === 0 || myInfo.cabinetId === null) {
setHasErrorOnResponse(true);
setModalTitle("현재 대여중인 사물함이 없습니다.");
setShowResponseModal(true);
return;
}
try {
await axiosExtendLentPeriod();
setMyInfo({
...myInfo,
cabinetId: currentCabinetId,
extensible: false,
});
setIsCurrentSectionRender(true);
setModalTitle("연장되었습니다");
try {
const { data } = await axiosCabinetById(currentCabinetId);
setTargetCabinetInfo(data);
} catch (error) {
throw error;
}
try {
const { data: myLentInfo } = await axiosMyLentInfo();
setMyLentInfo(myLentInfo);
} catch (error) {
throw error;
}
} catch (error: any) {
setHasErrorOnResponse(true);
setModalTitle(error.response.data.message);
} finally {
setShowResponseModal(true);
}
};

const extendModalContents: IModalContents = {
type: myInfo.cabinetId === null ? "penaltyBtn" : "hasProceedBtn",
icon: checkIcon,
title: getModalTitle(myInfo.cabinetId),
detail: getModalDetail(myInfo.cabinetId),
proceedBtnText: getModalProceedBtnText(myInfo.cabinetId),
onClickProceed:
myInfo.cabinetId === null
? async (e: React.MouseEvent) => {
props.onClose();
}
: tryExtendRequest,
closeModal: props.onClose,
};

return (
<ModalPortal>
{!showResponseModal && <Modal modalContents={extendModalContents} />}
{showResponseModal &&
(hasErrorOnResponse ? (
<FailResponseModal
modalTitle={modalTitle}
closeModal={props.onClose}
/>
) : (
<SuccessResponseModal
modalTitle={modalTitle}
closeModal={props.onClose}
/>
))}
</ModalPortal>
);
};

export default ExtendModal;
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,37 @@ import {
} from "@/recoil/atoms";
import TopNavButton from "@/components/TopNav/TopNavButtonGroup/TopNavButton/TopNavButton";
import { CabinetInfo } from "@/types/dto/cabinet.dto";
import { LentDto } from "@/types/dto/lent.dto";
import { UserDto } from "@/types/dto/user.dto";
import CabinetStatus from "@/types/enum/cabinet.status.enum";
import CabinetType from "@/types/enum/cabinet.type.enum";
import {
axiosCabinetById,
axiosDeleteCurrentBanLog,
} from "@/api/axios/axios.custom";
import useMenu from "@/hooks/useMenu";

export const getDefaultCabinetInfo = (myInfo: UserDto): CabinetInfo => ({
building: "",
floor: 0,
cabinetId: 0,
visibleNum: 0,
lentType: CabinetType.PRIVATE,
title: null,
maxUser: 0,
status: CabinetStatus.AVAILABLE,
section: "",
lents: [
{
userId: myInfo.userId,
name: myInfo.name,
lentHistoryId: 0,
startedAt: new Date(),
expiredAt: new Date(),
},
] as LentDto[],
statusNote: "",
});
const TopNavButtonGroup = ({ isAdmin }: { isAdmin?: boolean }) => {
const { toggleCabinet, toggleMap, openCabinet, closeAll } = useMenu();
const [currentCabinetId, setCurrentCabinetId] = useRecoilState(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/admin/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const SearchPage = () => {
searchValue.current,
currentPage.current
);

setSearchListByIntraId(searchResult.data.result ?? []);
setTotalSearchList(Math.ceil(searchResult.data.totalLength / 10) ?? 0);
setTimeout(() => {
Expand Down
Loading

0 comments on commit d44f1c3

Please sign in to comment.