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

[FE] 로그인 상태라면 행사 생성시 로그인 페이지를 띄우지 않음 #857

Open
wants to merge 14 commits into
base: fe-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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
18 changes: 14 additions & 4 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {Outlet} from 'react-router-dom';
import {Global} from '@emotion/react';
import {ReactQueryDevtools} from '@tanstack/react-query-devtools';

import AmplitudeInitializer from '@components/AmplitudeInitializer/AmplitudeInitializer';
import ErrorCatcher from '@components/AppErrorBoundary/ErrorCatcher';
import QueryClientBoundary from '@components/QueryClientBoundary/QueryClientBoundary';
import ToastContainer from '@components/Toast/ToastContainer';

import {HDesignProvider} from '@HDesign/index';

Expand All @@ -15,10 +19,16 @@ const App: React.FC = () => {
<HDesignProvider>
<UnPredictableErrorBoundary>
<Global styles={GlobalStyle} />
<NetworkStateCatcher />
<AmplitudeInitializer>
<Outlet />
</AmplitudeInitializer>
<ErrorCatcher>
<QueryClientBoundary>
Copy link
Contributor

Choose a reason for hiding this comment

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

요구 사항이 변경되어서 랜딩 페이지에서 api 호출이 필요하게 되었으므로 다시 돌려놓는 것이 옳다고 생각합니다.
랜딩 페이지 진입 속도 증가 vs 정산 시작하기 버튼 누를 때 메인에 오래 머물기 어떤 것이 더 치명적일 지 생각했을 때 저도 후자라고 생각하기 때문이에요

<ReactQueryDevtools initialIsOpen={false} />
<NetworkStateCatcher />
<ToastContainer />
<AmplitudeInitializer>
<Outlet />
</AmplitudeInitializer>
</QueryClientBoundary>
</ErrorCatcher>
</UnPredictableErrorBoundary>
</HDesignProvider>
);
Expand Down
1 change: 1 addition & 0 deletions client/src/apis/endpointPrefix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: (@weadie) 반복되서 쓰이는 이 api/events가 추후 수정 가능성이 있어서 일단 편집하기 편하게 이 변수를 재사용하도록 했습니다.
export const USER_API_PREFIX = '/api/events';
export const ADMIN_API_PREFIX = '/api/admin/events';
export const MEMBER_API_PREFIX = '/api/users';
Copy link
Contributor

Choose a reason for hiding this comment

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

순간 제가 추가해둔 코드가 반영된 줄 알고 확인하고 와써욪.. 동일한 생각을 하셨군여

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋㅋㅋ역시 다 똑같은 생각을 하고있었습니다

12 changes: 11 additions & 1 deletion client/src/apis/request/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {UserInfo} from 'types/serviceType';

import {BASE_URL} from '@apis/baseUrl';
import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestGetWithoutResponse, requestPostWithoutResponse} from '@apis/fetcher';
import {WithEventId} from '@apis/withId.type';

Expand Down Expand Up @@ -42,3 +44,11 @@ export const requestGetKakaoLogin = async (code: string) => {

return null;
};

export const requestGetUserInfo = async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

저는 user와 관련된 부분은 user.ts 파일을 생성하여 작성해줬는데요! 이 코드 또한 user.ts 파일로 가도 좋을 것 같네용!
merge할 때 같이 논의해봐요~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 좋네요 API PREFIX도 나눠두었으니까 파일을 나눠도 괜찮겠습니다

return await requestGet<UserInfo>({
baseUrl: BASE_URL.HD,
endpoint: `${MEMBER_API_PREFIX}/mine`,
errorHandlingStrategy: 'unsubscribe',
});
};
4 changes: 2 additions & 2 deletions client/src/apis/request/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Event, EventCreationData, EventId, EventName, User} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestPatch, requestPostWithResponse} from '@apis/fetcher';
import {WithEventId} from '@apis/withId.type';

Expand Down Expand Up @@ -47,7 +47,7 @@ export type RequestPatchUser = Partial<User>;

export const requestPatchUser = async (args: RequestPatchUser) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분 또한 저도 웨디와 동일하게 변경해줬어요!
다만 해당 코드도 event.ts 파일보다 user.ts 파일에 이동되는건 어떨지 논의해봐요!

return requestPatch({
endpoint: `/api/users`,
endpoint: MEMBER_API_PREFIX,
body: {
...args,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const QueryClientBoundary = ({children}: React.PropsWithChildren) => {
onError: (error: Error) => {
// errorBoundary로 처리해야하는 에러인 경우 updateAppError를 하지 못하도록 얼리리턴
if (error instanceof RequestGetError && error.errorHandlingStrategy === 'errorBoundary') return;
if (error instanceof RequestGetError && error.errorHandlingStrategy === 'unsubscribe') return;

updateAppError(error);
},
Expand Down
1 change: 1 addition & 0 deletions client/src/constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const QUERY_KEYS = {
images: 'images',
kakaoClientId: 'kakao-client-id',
kakaoLogin: 'kakao-login',
userInfo: 'user-info',
Copy link
Contributor

Choose a reason for hiding this comment

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

저랑 이 내용 겹칠 것 같아서 충돌 잘 해결해봐요!

};

export default QUERY_KEYS;
2 changes: 1 addition & 1 deletion client/src/errors/RequestGetError.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import RequestError from './RequestError';
import {RequestErrorType} from './requestErrorType';

type ErrorHandlingStrategy = 'toast' | 'errorBoundary';
type ErrorHandlingStrategy = 'toast' | 'errorBoundary' | 'unsubscribe';

export type WithErrorHandlingStrategy<P = unknown> = P & {
errorHandlingStrategy?: ErrorHandlingStrategy;
Expand Down
32 changes: 32 additions & 0 deletions client/src/hooks/queries/auth/useRequestGetUserInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {useQuery} from '@tanstack/react-query';
import {useEffect} from 'react';

import {requestGetUserInfo} from '@apis/request/auth';

import QUERY_KEYS from '@constants/queryKeys';

export type UseRequestGetUserInfo = ReturnType<typeof useRequestGetUserInfo>;

const useRequestGetUserInfo = () => {
const {data, ...rest} = useQuery({
queryKey: [QUERY_KEYS.userInfo],
queryFn: () => requestGetUserInfo(),
// quernFn은 ErrorCatcher 구독을 하지 않으며 오류가 났을 경우 로그인 화면을 띄워야하므로 initialData를 설정했습니다.
throwOnError: false,
initialData: {
isGuest: true,
nickname: '',
profileImage: '',
accountNumber: '',
bankName: '',
},
initialDataUpdatedAt: 0,
});

return {
...data,
...rest,
};
};

export default useRequestGetUserInfo;
13 changes: 13 additions & 0 deletions client/src/mocks/handlers/authHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ export const authHandler = [
return new HttpResponse(null, {status: 200});
}),

http.get(`${MOCK_API_PREFIX}/api/users/mine`, () => {
return HttpResponse.json(
{
nickname: '크리스마스',
Copy link
Contributor

Choose a reason for hiding this comment

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

진짜 크리스마스가 얼마 남지 않았네요;; 벌써;;;;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All I Want For Christmas Is You~~~

isGuest: false,
profileImage: '',
bankName: '',
accountNumber: '',
},
{status: 200},
);
}),

// POST /api/eventId/login (requestPostToken)
http.post<{eventId: string}, {password: string}>(
`${MOCK_API_PREFIX}${USER_API_PREFIX}/:eventId/login`,
Expand Down
9 changes: 7 additions & 2 deletions client/src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {useEffect} from 'react';

import Image from '@components/Design/components/Image/Image';
import useRequestGetUserInfo from '@hooks/queries/auth/useRequestGetUserInfo';

import usePageBackground from '@hooks/usePageBackground';

Expand All @@ -13,10 +16,12 @@ import CreatorSection from './Section/CreatorSection/CreatorSection';

const MainPage = () => {
const {isVisible} = usePageBackground();
const {isGuest} = useRequestGetUserInfo();

return (
<div css={mainContainer}>
<Nav />
<MainSection />
<Nav isGuest={isGuest} />
<MainSection isGuest={isGuest} />
<DescriptionSection />
<FeatureSection />
<CreatorSection />
Expand Down
8 changes: 6 additions & 2 deletions client/src/pages/MainPage/Nav/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import {useNavigate} from 'react-router-dom';

import {UseRequestGetUserInfo} from '@hooks/queries/auth/useRequestGetUserInfo';

import {Button, Text, Icon, TopNav, IconButton} from '@HDesign/index';

import {ROUTER_URLS} from '@constants/routerUrls';

import {navFixedStyle, navStyle, navWrapperStyle} from './Nav.style';

const Nav = () => {
type NavProps = Pick<UseRequestGetUserInfo, 'isGuest'>;

const Nav = ({isGuest}: NavProps) => {
const navigate = useNavigate();

const goLogin = () => {
navigate(ROUTER_URLS.login);
navigate(isGuest ? ROUTER_URLS.login : ROUTER_URLS.createMemberEvent);
};

return (
Expand Down
7 changes: 5 additions & 2 deletions client/src/pages/MainPage/Section/MainSection/MainSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import {useNavigate} from 'react-router-dom';

import Button from '@HDesign/components/Button/Button';
import Text from '@HDesign/components/Text/Text';
import {UseRequestGetUserInfo} from '@hooks/queries/auth/useRequestGetUserInfo';

import {Icon} from '@components/Design';

import {ROUTER_URLS} from '@constants/routerUrls';

import {animateWithDelay, chevronStyle, mainSectionStyle, sectionStyle} from './MainSection.style';

const MainSection = () => {
type NavProps = Pick<UseRequestGetUserInfo, 'isGuest'>;

const MainSection = ({isGuest}: NavProps) => {
const navigate = useNavigate();

const handleClick = () => {
navigate(ROUTER_URLS.login);
navigate(isGuest ? ROUTER_URLS.login : ROUTER_URLS.createMemberEvent);
};

return (
Expand Down
149 changes: 72 additions & 77 deletions client/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,100 +49,95 @@ const router = createBrowserRouter([
element: <MainPage />,
},
{
element: <EssentialQueryApp />,
path: ROUTER_URLS.createGuestEvent,
element: <CreateGuestEventFunnel />,
},
{
path: ROUTER_URLS.createMemberEvent,
element: <CreateMemberEventFunnel />,
},
{
path: ROUTER_URLS.login,
element: <LoginPage />,
},
{
path: ROUTER_URLS.myPage,
element: <MyPage />,
},
{
path: ROUTER_URLS.kakaoLoginRedirectUri,
element: <LoginRedirectPage />,
errorElement: <LoginFailFallback />,
},
{
path: ROUTER_URLS.event,
element: (
<EventLoader>
<EventPage />
</EventLoader>
),
children: [
{
path: ROUTER_URLS.createGuestEvent,
element: <CreateGuestEventFunnel />,
},
{
path: ROUTER_URLS.createMemberEvent,
element: <CreateMemberEventFunnel />,
},
{
path: ROUTER_URLS.login,
element: <LoginPage />,
},
{
path: ROUTER_URLS.myPage,
element: <MyPage />,
},
{
path: ROUTER_URLS.kakaoLoginRedirectUri,
element: <LoginRedirectPage />,
errorElement: <LoginFailFallback />,
},
{
path: ROUTER_URLS.event,
path: ROUTER_URLS.eventManage,
element: (
<EventLoader>
<EventPage />
</EventLoader>
<AuthGate>
<AdminPage />
</AuthGate>
),
children: [
{
path: ROUTER_URLS.eventManage,
element: (
<AuthGate>
<AdminPage />
</AuthGate>
),
},
{
path: ROUTER_URLS.home,
element: <HomePage />,
},
{
path: ROUTER_URLS.guestEventLogin,
element: <GuestEventLogin />,
},
{
path: ROUTER_URLS.memberEventLogin,
element: <MemberEventLogin />,
},
],
},
{
path: ROUTER_URLS.addBill,
element: <AddBillFunnel />,
},
{
path: ROUTER_URLS.member,
element: <EventMember />,
},
{
path: ROUTER_URLS.editBill,
element: <EditBillPage />,
},
{
path: ROUTER_URLS.eventEdit,
element: <Account />,
},
{
path: ROUTER_URLS.images,
element: <ImagesPage />,
},
{
path: ROUTER_URLS.addImages,
element: <AddImagesPage />,
path: ROUTER_URLS.home,
element: <HomePage />,
},
{
path: ROUTER_URLS.send,
element: <SendPage />,
errorElement: <SendErrorPage />,
path: ROUTER_URLS.guestEventLogin,
element: <GuestEventLogin />,
},
{
path: ROUTER_URLS.qrCode,
element: <QRCodePage />,
path: ROUTER_URLS.memberEventLogin,
element: <MemberEventLogin />,
},
],
},
{
path: '*',
element: <ErrorPage />,
path: ROUTER_URLS.addBill,
element: <AddBillFunnel />,
},
{
path: ROUTER_URLS.member,
element: <EventMember />,
},
{
path: ROUTER_URLS.editBill,
element: <EditBillPage />,
},
{
path: ROUTER_URLS.eventEdit,
element: <Account />,
},
{
path: ROUTER_URLS.images,
element: <ImagesPage />,
},
{
path: ROUTER_URLS.addImages,
element: <AddImagesPage />,
},
{
path: ROUTER_URLS.send,
element: <SendPage />,
errorElement: <SendErrorPage />,
},
{
path: ROUTER_URLS.qrCode,
element: <QRCodePage />,
},
],
},
{
path: '*',
element: <ErrorPage />,
},
]);

export default router;
Loading
Loading