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

[feat/CK-136] 로그인 유지와 UI 버그를 해결한다 #97

Merged
merged 6 commits into from
Aug 9, 2023
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
73 changes: 39 additions & 34 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,50 @@ import ToastProvider from '@components/_common/toastProvider/ToastProvider';
import GoalRoomListPage from './pages/goalRoomListPage/GoalRoomListPage';
import GoalRoomCreatePage from './pages/goalRoomCreatePage/GoalRoomCreatePage';
import MyPage from '@pages/myPage/MyPage';
import UserInfoProvider from './components/_providers/UserInfoProvider';

const App = () => {
return (
<ThemeProvider theme={theme}>
<GlobalStyle />

<ToastProvider>
<BrowserRouter>
<ResponsiveContainer>
<PageLayout>
<Routes>
<Route path='/' element={<RoadmapListPage />} />
<Route path='/login' element={<LoginPage />} />
<Route path='/join' element={<SignUpPage />} />
<Route path='/roadmap-list' element={<RoadmapListPage />} />
<Route
path='/roadmap/:id'
element={
<Suspense fallback={<Fallback />}>
<RoadmapDetailPage />
</Suspense>
}
/>
<Route path='/roadmap/:id/goalroom-list' element={<GoalRoomListPage />} />
<Route path='/roadmap-create' element={<RoadmapCreatePage />} />
<Route
path='/roadmap/:id/goalroom-create'
element={<GoalRoomCreatePage />}
/>
<Route
path='/goalroom-dashboard/:goalroomId'
element={<GoalRoomDashboardPage />}
/>
<Route path='/myPage' element={<MyPage />} />
</Routes>
</PageLayout>
</ResponsiveContainer>
</BrowserRouter>
</ToastProvider>
<UserInfoProvider>
<ToastProvider>
Comment on lines +25 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃🙃🙃🙃🙃

<BrowserRouter>
<ResponsiveContainer>
<PageLayout>
<Routes>
<Route path='/' element={<RoadmapListPage />} />
<Route path='/login' element={<LoginPage />} />
<Route path='/join' element={<SignUpPage />} />
<Route path='/roadmap-list' element={<RoadmapListPage />} />
<Route
path='/roadmap/:id'
element={
<Suspense fallback={<Fallback />}>
<RoadmapDetailPage />
</Suspense>
}
/>
<Route
path='/roadmap/:id/goalroom-list'
element={<GoalRoomListPage />}
/>
<Route path='/roadmap-create' element={<RoadmapCreatePage />} />
<Route
path='/roadmap/:id/goalroom-create'
element={<GoalRoomCreatePage />}
/>
<Route
path='/goalroom-dashboard/:goalroomId'
element={<GoalRoomDashboardPage />}
/>
<Route path='/myPage' element={<MyPage />} />
</Routes>
</PageLayout>
</ResponsiveContainer>
</BrowserRouter>
</ToastProvider>
</UserInfoProvider>
</ThemeProvider>
);
};
Expand Down
6 changes: 4 additions & 2 deletions client/src/apis/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const login = (body: UserLoginRequest) => {
return client.post<UserLoginResponse>('/auth/login', body);
};

export const getUserInfo = () => {
return client.get<UserInfoResponse>('/members/me');
export const getUserInfo = (signal?: AbortSignal) => {
return client.get<UserInfoResponse>('/members/me', {
signal,
});
};
2 changes: 0 additions & 2 deletions client/src/components/_common/navBar/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SVGIcon from '@components/icons/SVGIcon';
import * as S from './NavBar.styles';
import { useUserInfoContext } from '@components/_providers/UserInfoProvider';
import useValidationCheck from '@hooks/user/useValidationCheck';
import isValidUserInfo from '@utils/user/isValidUserInfo';
import { BASE_URL } from '@apis/axios/client';

Expand All @@ -10,7 +9,6 @@ type NavBarProps = {
};

const NavBar = ({ isSwitchOn }: NavBarProps) => {
useValidationCheck();
const { userInfo } = useUserInfoContext();

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export const RoadmapTitle = styled.div`
export const Description = styled.div`
${({ theme }) => theme.fonts.description5}
margin: 1.6rem 0 3rem 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
`;

export const ItemExtraInfos = styled.div`
Expand Down
1 change: 0 additions & 1 deletion client/src/components/_common/roadmapItem/RoadmapItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const RoadmapItem = ({ item, hasBorder = true, roadmapId }: RoadmapItemProps) =>
{item.tags.map((tag) => {
return <span># {tag.name}</span>;
})}

</S.Tags>
</S.ItemFooter>
</S.RoadmapItem>
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/_providers/UserInfoProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createContext, PropsWithChildren, useContext, useState } from 'react';
import { createContext, PropsWithChildren, useContext } from 'react';
import { UserInfoResponse } from '@myTypes/user/remote';
import { UserInfoContextType } from '@myTypes/_common/user';
import { useIdentifyUser } from '@/hooks/_common/useIdentifyUser';

export const defaultUserInfo: UserInfoResponse = {
id: null,
Expand All @@ -18,7 +19,7 @@ export const userInfoContext = createContext<UserInfoContextType>({
});

const UserInfoProvider = ({ children }: PropsWithChildren) => {
const [userInfo, setUserInfo] = useState<UserInfoResponse>(defaultUserInfo);
const { userInfo, setUserInfo } = useIdentifyUser();

return (
<userInfoContext.Provider value={{ userInfo, setUserInfo }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ListWrapper = styled.div`
display: grid;
grid-row-gap: 6rem;
grid-template-columns: repeat(2, 1fr);
min-height: 100vh;

${media.mobile`
grid-template-columns: repeat(1, 1fr);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import media from '@/styles/media';
import styled from 'styled-components';

export const RoadmapList = styled.div`
display: flex;
flex-wrap: wrap;
row-gap: 3rem;
justify-content: space-around;
display: grid;
grid-gap: 3rem;
grid-template-columns: 1fr 1fr;
justify-items: center;

margin-bottom: 8rem;
min-height: 100vh;

${media.mobile`
grid-template-columns: 1fr;

`}
`;

export const CreateRoadmapButton = styled.button`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const RoadmapList = ({ selectedCategoryId }: RoadmapListProps) => {

return (
<S.RoadmapList aria-label='로드맵 목록'>
{roadmapList?.map((item) => (
{roadmapList.map((item) => (
<RoadmapItem key={item.roadmapId} item={item} roadmapId={item.roadmapId} />
))}
<S.CreateRoadmapButton onClick={moveRoadmapCreatePage}>
Expand Down
46 changes: 46 additions & 0 deletions client/src/hooks/_common/useIdentifyUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getUserInfo } from '@/apis/user';
import { UserInfoResponse } from '@/myTypes/user/remote';
import { getCookie } from '@/utils/_common/cookies';
import { useEffect, useState } from 'react';

export const defaultUserInfo: UserInfoResponse = {
id: null,
nickname: '',
profileImageUrl: '',
gender: null,
identifier: '',
phoneNumber: '',
birthday: '',
};

export const useIdentifyUser = () => {
const [userInfo, setUserInfo] = useState(defaultUserInfo);

useEffect(() => {
const fetchController = new AbortController();
const { signal } = fetchController;

const fetchUserInfo = async () => {
try {
const accessToken = getCookie('access_token');

if (!accessToken) return;

const userInfo = (await getUserInfo(signal)).data;

setUserInfo(userInfo);
} catch (e) {
// 실패시 로직
}
};

fetchUserInfo();

return () => fetchController.abort();
}, []);

return {
userInfo,
setUserInfo,
};
};
4 changes: 2 additions & 2 deletions client/src/hooks/queries/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
UserLoginRequest,
} from '@myTypes/user/remote';
import { getUserInfo, login, signUp } from '@apis/user';
import { setCookie } from '@utils/_common/cookies';
import useToast from '@hooks/_common/useToast';
import { useUserInfoContext } from '@components/_providers/UserInfoProvider';
import { useUserInfoContext } from '@/components/_providers/UserInfoProvider';
import { AxiosResponse } from 'axios';
import { setCookie } from '@/utils/_common/cookies';

export const useSignUp = () => {
const { mutate } = useMutation(
Expand Down
16 changes: 0 additions & 16 deletions client/src/hooks/user/useValidationCheck.ts

This file was deleted.

Loading