Skip to content

Commit

Permalink
Merge pull request #166 from innovationacademy-kr/sharedPeople_161
Browse files Browse the repository at this point in the history
FEAT: show all users in sharing cabinet #161
  • Loading branch information
Oris482 authored Dec 15, 2022
2 parents e48419b + c4e262d commit 79708fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
46 changes: 41 additions & 5 deletions frontend/src/Components/CabinetDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import LentDisabledInfo from "./LentDisabled";
import styled from "styled-components";
import { useState } from "react";
import * as API from "../Networks/APIType";
import { singleCircleCabinetInfo } from "../type";
import { singleCircleCabinetInfo, singleShareCabinetInfo } from "../type";

interface circleData {
circleName: string;
Expand Down Expand Up @@ -44,6 +44,9 @@ const CabinetDetail = () => {
circleMaster: "",
});

const [isShare, setIsShare] = useState<boolean>(false);
const [sharingUsers, setSharingUsers] = useState<string[]>([]);

useEffect(() => {
if (currentPage === "search" && data?.length === 0) {
navigate("/saerom/search/invalidSearchResult", {
Expand Down Expand Up @@ -80,6 +83,7 @@ const CabinetDetail = () => {
const res = getTargetCabinetData(data[0].cabinet_id).then((res) => {
const data: singleCircleCabinetInfo | null = res?.data;
if (data !== null && data.lent_type === "CIRCLE") setIsCircle(true);
else if (data !== null && data.lent_type === "SHARE") setIsShare(true);
});
}
}, [data]);
Expand Down Expand Up @@ -111,6 +115,31 @@ const CabinetDetail = () => {
setCircleData({ circleName: "", circleMaster: "" });
}, []);

useEffect(() => {
if (
data !== undefined &&
data[0] !== undefined &&
data[0].cabinet_id &&
isShare &&
sharingUsers.length === 0
) {
const res = getTargetCabinetData(data[0].cabinet_id).then((res) => {
const data: singleShareCabinetInfo | null = res?.data;
if (
data !== null &&
data.lent_info !== null &&
data.lent_info.length !== 0
) {
let sharingUserList: string[] = [];
for (let i = 0; i < data?.lent_info.length; i++) {
sharingUserList.push(data.lent_info[i].intra_id);
}
setSharingUsers(sharingUserList);
}
});
}
});

const CabinetInfo =
data !== undefined && data[0] !== undefined
? data[0].floor?.toString() +
Expand Down Expand Up @@ -200,16 +229,23 @@ const CabinetDetail = () => {
<DetailBox>
<LentDisabledInfo />
<BigFontSize>{CabinetInfo}</BigFontSize>
{isCircle ? (
{!isCircle && !isShare && (
<>
<p>현재 대여자 : {CabinetUserInfo}</p>
<p>대여 기간 : {CabinetLentInfo}</p>
</>
)}
{isCircle && (
<>
<p>동아리 사물함입니다.</p>
<p>동아리 : {circleData.circleName}</p>
<p>동아리장 : {circleData.circleMaster}</p>
</>
) : (
)}
{isShare && (
<>
<p>현재 대여자 : {CabinetUserInfo}</p>
<p>대여 기간 : {CabinetLentInfo}</p>
<p>공유 사물함입니다.</p>
<p>현재 대여자 : {sharingUsers.join(", ")}</p>
</>
)}
<CabinetStatusMessage>{CabinetActivationInfo}</CabinetStatusMessage>
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,14 @@ export type singleCircleCabinetInfo = {
section: string;
lent_info: singleCabinetLentData | null;
};

export type singleShareCabinetInfo = {
cabinet_id: number;
cabinet_num: number;
lent_type: string;
cabinet_title: string | null;
status_note: string | null;
status: string;
section: string;
lent_info: singleCabinetLentData[];
};

0 comments on commit 79708fb

Please sign in to comment.