Skip to content

Commit

Permalink
fix: 식자재 추가 시 해당 냉장고로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
a-honey committed Feb 29, 2024
1 parent c0edd0b commit e03356f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/organisms/FridgeInfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const FridgeInfoBox: React.FC<{
isOkIngredientAdd?: boolean;
}> = ({ currentFridgeInfo, fridgeName, userName = '', toggleIsOpenFridgeListModal, isOkIngredientAdd }) => {
const router = useRouter();
const { fridgeid, name } = router.query;

return (
<div className="flex justify-between items-end mb-[28px]">
<div className="flex flex-col gap-[12px]">
Expand All @@ -27,7 +27,7 @@ const FridgeInfoBox: React.FC<{
className="rounded-6 w-[100px] p-[10px] body1-semibold bg-primary2 text-white"
text="식자재 추가"
onClick={() => {
void router.push(`/fridge/add?fridgeid=${fridgeid as string}&name=${name as string}`);
void router.push(`/fridge/add?fridgeid=${currentFridgeInfo.fridgeId}&name=${currentFridgeInfo.fridgeName}`);
}}
/>
)}
Expand Down
8 changes: 8 additions & 0 deletions src/pages/fridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { useEffect, useState } from 'react';
import withLogin from '@/components/templates/withLogin';
import useGetMyFridgeList from '@/hooks/queries/fridge/useGetFridgeList';
import type { CurrentFridgeInfoType } from '@/types/fridge';
import { useRouter } from 'next/router';

const FridgePage: NextPage = () => {
const router = useRouter();
const [currentFridgeInfo, setCurrentFridgeInfo] = useState<CurrentFridgeInfoType>({
username: null,
fridgeId: 0,
Expand All @@ -23,10 +25,16 @@ const FridgePage: NextPage = () => {
const fridgeList = useGetMyFridgeList();
const { nickname } = useGetMe();

const { fridgeid, name } = router.query;

useEffect(() => {
if (!fridgeList || fridgeList.length < 0) {
return;
}
if (fridgeid) {
setCurrentFridgeInfo({ username: null, fridgeId: Number(fridgeid), fridgeName: name as string });
return;
}
setCurrentFridgeInfo({ username: null, fridgeId: fridgeList[0].id, fridgeName: fridgeList[0].name });
}, [fridgeList]);

Expand Down

0 comments on commit e03356f

Please sign in to comment.