Skip to content

Commit

Permalink
Merge pull request #107 from innovationacademy-kr/ReturnUpdateError_105
Browse files Browse the repository at this point in the history
FIX: Search - print undefined after return
  • Loading branch information
joohongpark authored Oct 21, 2022
2 parents f3960e1 + ff35f97 commit c094e40
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
50 changes: 37 additions & 13 deletions frontend/src/Modals/ReturnModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import {
CancleButton,
} from "./ModalStyleComponent";
import * as API from "../Networks/APIType";
import { useNavigate } from "react-router-dom";
import { useNavigate, useSearchParams } from "react-router-dom";
import { useDispatch } from "react-redux";
import { GetTargetResponse } from "../ReduxModules/SearchResponse";
import { GetExpiredResponse } from "../ReduxModules/StatusExpired";
import { SearchQueryBody } from "../type";

const ReturnModal = (props: any) => {
const dispatch = useDispatch();
const navigate = useNavigate();

const [searchParams] = useSearchParams();

const { data, state, close, originPage } = props;

const CabinetInfo =
Expand All @@ -30,30 +33,40 @@ const ReturnModal = (props: any) => {
"번"
: "";

const UpdateInfo = async (params: SearchQueryBody) => {
try {
const token = localStorage.getItem("accessToken");
const resSearch = await API.axiosFormat(
{
method: "GET",
url: API.url("/api/search"),
params,
},
token
);
dispatch(GetTargetResponse(resSearch.data));
} catch (e) {
console.log(e);
const axiosError = e as API.axiosError;
API.HandleError(navigate, axiosError);
} finally {
close(true);
}
};

const ReturnAPI = async () => {
try {
const cabinetIdx = data !== undefined ? data.cabinet_id : "";
const urlReturn = "/api/return?cabinetIdx=" + cabinetIdx;
const token = localStorage.getItem("accessToken");
let params: SearchQueryBody;
await API.axiosFormat(
{
method: "PATCH",
url: API.url(urlReturn),
},
token
);
const params = {
intraId: data !== undefined ? data.intra_id : "",
};
const resSearch = await API.axiosFormat(
{
method: "GET",
url: API.url("/api/search"),
params,
},
token
);
dispatch(GetTargetResponse(resSearch.data));
if (originPage === "status") {
const resExpired = await API.axiosFormat(
{
Expand All @@ -64,6 +77,17 @@ const ReturnModal = (props: any) => {
);
dispatch(GetExpiredResponse(resExpired.data));
}
if (searchParams.get("intraId") !== null) {
params = {
intraId: data !== undefined ? data.intra_id : "",
};
} else {
params = {
cabinetNum: data !== undefined ? data.cabinet_num : "",
floor: data !== undefined ? data.floor : "",
};
}
UpdateInfo(params);
} catch (e) {
console.log(e);
const axiosError = e as API.axiosError;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Pages/SearchDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GrayBgBox,
ButtonBox,
} from "../Components/DashboardStyleComponent";
import { SearchQueryBody } from "../type";

const SearchDashboard = () => {
const [isLoading, setisLoading] = useState(true);
Expand All @@ -35,7 +36,7 @@ const SearchDashboard = () => {

const getSearchData = useCallback(async () => {
try {
let params = {};
let params: SearchQueryBody;
if (searchParams.get("intraId") !== null) {
params = {
intraId: searchParams.get("intraId"),
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ export type FloorStateData = {
};

export type PieData = { name: string; value: number };

export type SearchQueryBody =
| { intraId: string | null }
| { floor: string | null; cabinetNum: string | null };

0 comments on commit c094e40

Please sign in to comment.