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

Fix/300 피커 버그 수정 #305

Merged
merged 4 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/layouts/App/Header/LogoutModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import clsx from 'clsx';
import { useNavigate } from 'react-router-dom';

import { useSelectedFriendsStore } from 'store/useSelectedFriendsStore';
import { useUserStore } from 'store/useUserStore';

import {
Expand All @@ -24,13 +25,17 @@ const LogoutModal = ({ modalState, userState }: LogoutModalProps) => {
const navigate = useNavigate();

const clearUser = useUserStore((state) => state.clearUserInfo);
const clearSelectedFiends = useSelectedFriendsStore(
(state) => state.clearSelectedFriends,
);
const accessToken = getSessionStorageItem('accessToken');
const refreshToken = getLocalStorageItem('refreshToken');

const handleLogout = async () => {
await logout({ accessToken, refreshToken });

clearUser();
clearSelectedFiends();
clearSessionStorageItem();
clearLocalStorageItem('refreshToken');

Expand Down
2 changes: 2 additions & 0 deletions src/services/api/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';

import { useSelectedFriendsStore } from 'store/useSelectedFriendsStore';
import { useUserStore } from 'store/useUserStore';

import {
Expand Down Expand Up @@ -68,6 +69,7 @@ apiV1.interceptors.response.use(

if (response.status === 404) {
useUserStore.getState().clearUserInfo();
useSelectedFriendsStore.getState().clearSelectedFriends();
clearSessionStorageItem();
clearLocalStorageItem('refreshToken');
window.location.replace('/');
Expand Down
23 changes: 17 additions & 6 deletions src/store/useSelectedFriendsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { persist } from 'zustand/middleware';

import { PickerResponseData, User } from 'types/user';

const defaultImgUrl =
'https://github.com/KakaoFunding/front-end/blob/dev/src/assets/bg_profile_default.png?raw=true';
const peopleImgUrl = 'src/assets/profile_people.png';
import defaultImgUrl from 'assets/bg_profile_default.png';
import friendsDefaultImgUrl from 'assets/profile_default.png';
import peopleImgUrl from 'assets/profile_people.png';

type SelectedFriendsState = {
isSelected: boolean;
Expand Down Expand Up @@ -55,9 +55,20 @@ export const useSelectedFriendsStore = create<
}),

getImgUrl: () => {
if (get().selectedHeadCount > 1) return peopleImgUrl;
if (get().selectedHeadCount === 1)
return get().selectedFriends[0].profile_thumbnail_image!;
const selectCount = get().selectedHeadCount;

if (selectCount > 1) return peopleImgUrl;
if (selectCount === 1) {
const friendsProfileImgUrl =
get().selectedFriends[0].profile_thumbnail_image;

if (!friendsProfileImgUrl) {
return friendsDefaultImgUrl;
}

return friendsProfileImgUrl;
}

return defaultImgUrl;
},
}),
Expand Down
Loading