Skip to content

Commit

Permalink
fix: 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
a-honey committed Mar 1, 2024
1 parent 3e10a43 commit 8ac1dd4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/components/organisms/FridgeInfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const FridgeInfoBox: React.FC<{
}> = ({ currentFridgeInfo, fridgeName, userName = '', toggleIsOpenFridgeListModal, isOkIngredientAdd }) => {
const router = useRouter();

console.log(currentFridgeInfo);
return (
<div className="flex justify-between items-end mb-[28px]">
<div className="flex flex-col gap-[12px]">
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/queries/login/usePostUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useBaseMutation } from '../useBaseMutation';
import { useRouter } from 'next/router';

interface PostUserBodyType {
nickName: string;
nickname: string;
kakaoId: number;
kakaoEmail: string;
googleEmail: string | null;
Expand All @@ -18,8 +18,6 @@ const usePostUser = () => {
data: {
accessToken: string;
refreshToken: string;
email: string;
nickName: string;
};
}) => {
localStorage.setItem('accessToken', data.accessToken);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/queries/useBaseMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useBaseMutation = <T>(
mutationFn: async (body: T) => {
const response = await fetchData<T>(url, body, method);

if (onSuccess) onSuccess(response.data);
if (onSuccess) onSuccess(response);
},
});
};
2 changes: 1 addition & 1 deletion src/hooks/queries/useBaseQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const fetchData = async <T>(url: string, isNotCatch: boolean) => {
if (error.response && error.response.status === 404) {
return await Promise.resolve({ data: null });
} else {
throw error;
console.error(error);
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/pages/fridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import withLogin from '@/components/templates/withLogin';
import useGetMyFridgeList from '@/hooks/queries/fridge/useGetFridgeList';
import type { CurrentFridgeInfoType } from '@/types/fridge';
import { useRouter } from 'next/router';
import { EmptyBox } from '@/components/molecules';

const FridgePage: NextPage = () => {
const router = useRouter();
const [currentFridgeInfo, setCurrentFridgeInfo] = useState<CurrentFridgeInfoType>({
username: null,
fridgeId: 0,
fridgeName: '',
fridgeName: '냉장고정보없음',
});
const {
isOpen: isOpenFridgeListModal,
Expand All @@ -28,7 +29,8 @@ const FridgePage: NextPage = () => {
const { fridgeid, name } = router.query;

useEffect(() => {
if (!fridgeList || fridgeList.length < 0) {
if (!fridgeList || fridgeList.length === 0 || !currentFridgeInfo) {
onOpenFridgeListModal();
return;
}
if (fridgeid) {
Expand Down Expand Up @@ -76,7 +78,13 @@ const FridgePage: NextPage = () => {
toggleIsOpenFridgeListModal={onOpenFridgeListModal}
isOkIngredientAdd={true}
/>
<FridgeBoard currentFridgeInfo={currentFridgeInfo} />
{!fridgeList || fridgeList.length === 0 ? (
<div>
<EmptyBox text={`냉장칸에 추가된 식자재가 없어요!`} />
</div>
) : (
<FridgeBoard currentFridgeInfo={currentFridgeInfo} />
)}
</section>
</div>
</>
Expand Down
14 changes: 7 additions & 7 deletions src/pages/mypage/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const ProfilePage: NextPage = () => {
const router = useRouter();
const { kakaoId, kakaoEmail, googleEmail } = router.query;

const MyInfo = useGetMe();
const MyInfo = kakaoId ? null : useGetMe();

const [selectedProfile, setSelectedProfile] = useState<ProfileEnum>('BLUE');
const [selectedProfile, setSelectedProfile] = useState<ProfileEnum>('GREEN');
const [nickname, setNickname] = useState(MyInfo?.nickname ?? '');
const [isNicknameAvailable, setIsNicknameAvailable] = useState<null | boolean>(null);
const [isNicknameChecked, setIsNicknameChecked] = useState<null | boolean>(null);
Expand Down Expand Up @@ -84,10 +84,10 @@ const ProfilePage: NextPage = () => {

if ((kakaoEmail && kakaoId) ?? googleEmail) {
postUser.mutate({
nickName: nickname,
kakaoId: Number(kakaoId ?? MyInfo.kakaoId),
kakaoEmail: (kakaoEmail as string) ?? MyInfo.kakaoEmail,
googleEmail: (googleEmail as string) ?? MyInfo.googleEmail,
nickname,
kakaoId: Number(kakaoId ?? MyInfo?.kakaoId),
kakaoEmail: (kakaoEmail as string) ?? MyInfo?.kakaoEmail,
googleEmail: (googleEmail as string) ?? MyInfo?.googleEmail ?? null,
profileImage: selectedProfile,
});
} else {
Expand Down Expand Up @@ -141,7 +141,7 @@ const ProfilePage: NextPage = () => {
</div>
<button
type="submit"
className={`p-18 gap-12 rounded-12 heading4-semibold ${(MyInfo?.nickname !== nickname && MyInfo.profileImage === selectedProfile) || (MyInfo?.nickname === nickname && MyInfo.profileImage !== selectedProfile) || (isNicknameAvailable && selectedProfile) ? 'bg-primary2' : 'bg-gray3'} mt-[205px] text-white`}
className={`p-18 gap-12 rounded-12 heading4-semibold ${(MyInfo?.nickname !== nickname && MyInfo?.profileImage === selectedProfile) || (MyInfo?.nickname === nickname && MyInfo.profileImage !== selectedProfile) || (isNicknameAvailable && selectedProfile) ? 'bg-primary2' : 'bg-gray3'} mt-[205px] text-white`}
>
편집완료
</button>
Expand Down

0 comments on commit 8ac1dd4

Please sign in to comment.