Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV TO MAIN #1664

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions frontend/src/Cabinet/components/Modals/StoreModal/ExtendModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IInventoryInfo } from "@/Cabinet/components/Store/Inventory/Inventory";
import { additionalModalType, modalPropsMap } from "@/Cabinet/assets/data/maps";
import { MyCabinetInfoResponseDto } from "@/Cabinet/types/dto/cabinet.dto";
import { IItemDetail, IItemStore } from "@/Cabinet/types/dto/store.dto";
import CabinetStatus from "@/Cabinet/types/enum/cabinet.status.enum";
import IconType from "@/Cabinet/types/enum/icon.type.enum";
import {
axiosCabinetById,
Expand Down Expand Up @@ -49,6 +50,7 @@ const ExtendModal: React.FC<{
const [itemDropdownOptions, setItemDropdownOptions] = useState<
IDropdownOptions[]
>([]);
const [url, setUrl] = useState<string | null>(null);
const [currentCabinetId] = useRecoilState(currentCabinetIdState);
const [myInfo, setMyInfo] = useRecoilState(userState);
const [myLentInfo, setMyLentInfo] =
Expand All @@ -73,8 +75,10 @@ const ExtendModal: React.FC<{
연장권 사용은 취소할 수 없습니다.`;
const extendInfoDetail = `사물함을 대여하시면 연장권 사용이 가능합니다.
연장권은 <strong>${extensionExpiredDate} 23:59</strong> 이후 만료됩니다.`;
const noExtensionMsg = `현재 연장권을 보유하고 있지 않습니다.
const noItemMsg = `현재 연장권을 보유하고 있지 않습니다.
연장권은 까비 상점에서 구매하실 수 있습니다.`;
const overdueMsg = "연체 중에는 연장권을 사용하실 수 없습니다.";
const defaultFailureModalTitle = "연장권 사용실패";

useEffect(() => {
fetchData();
Expand All @@ -84,7 +88,7 @@ const ExtendModal: React.FC<{
if (myItems?.extensionItems.length === 0) {
setShowResponseModal(true);
setHasErrorOnResponse(true);
setModalContents(noExtensionMsg);
setModalContents(noItemMsg);
} else {
setShowResponseModal(false);
setHasErrorOnResponse(false);
Expand Down Expand Up @@ -187,7 +191,15 @@ const ExtendModal: React.FC<{
const extensionItemUse = async (item: string) => {
if (currentCabinetId === 0 || myInfo.cabinetId === null) {
setHasErrorOnResponse(true);
setModalTitle("현재 대여중인 사물함이 없습니다.");
setModalTitle(defaultFailureModalTitle);
setModalContents("현재 대여중인 사물함이 없습니다.");
setShowResponseModal(true);
return;
}
if (myLentInfo.status === CabinetStatus.OVERDUE) {
setHasErrorOnResponse(true);
setModalTitle(defaultFailureModalTitle);
setModalContents(overdueMsg);
setShowResponseModal(true);
return;
}
Expand All @@ -214,8 +226,12 @@ const ExtendModal: React.FC<{
} catch (error: any) {
setHasErrorOnResponse(true);
if (error.response.status === 400) {
setModalTitle("연장권 사용실패");
setModalContents(noExtensionMsg);
setModalTitle(defaultFailureModalTitle);
setModalContents(noItemMsg);
setUrl("/store");
} else if (error.response.status === 403) {
setModalTitle(defaultFailureModalTitle);
setModalContents(overdueMsg);
} else {
setModalTitle(error.response?.data.message || error.data.message);
}
Expand Down Expand Up @@ -259,7 +275,7 @@ const ExtendModal: React.FC<{
modalTitle={modalTitle}
modalContents={modalContents}
closeModal={props.onClose}
url={"/store"}
url={url}
urlTitle={"까비상점으로 이동"}
/>
) : (
Expand Down
Loading