Skip to content

Commit

Permalink
Refactor: startPage
Browse files Browse the repository at this point in the history
  • Loading branch information
cuconveniencestore authored and hookor committed Jun 5, 2024
1 parent 78ce427 commit 74d38e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/components/start/InitialForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import EditProfileImg from '@/components/mypage/EditProfileImg';
import { useComposeHeader } from '@/hooks/useComposeHeader';
import { useImageCropper } from '@/hooks/post/useImageCropper';
import { useCompressImage } from '@/hooks/useCompressImage';
import { useCancelSignUp } from '@/hooks/start/useCancelSignUp';

import { TEXT } from '@/constants/texts';
import { BUTTON_TEXTS } from '@/constants/common';
Expand All @@ -34,6 +35,7 @@ const { message } = INITIAL_FORM_TEXTS;

const InitialForm = () => {
useComposeHeader(false, '기본정보', 'close');
useCancelSignUp();
const navigate = useNavigate();
const inputRef = useRef<HTMLTextAreaElement | null>(null);
const [userInit, setUserInit] = useRecoilState(authState);
Expand Down
2 changes: 2 additions & 0 deletions src/components/start/SelectFavBrand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useGetCoffeeList from '@/hooks/useGetCoffeeList';
import { useCloudStorage } from '@/hooks/useCloudStorage';
import { useComposeHeader } from '@/hooks/useComposeHeader';
import { useDeleteCacheData } from '@/hooks/useDeleteCacheData';
import { useCancelSignUp } from '@/hooks/start/useCancelSignUp';

import { authState } from '@/atoms/atoms';
import { InitialformTypes } from '@/types/types';
Expand All @@ -36,6 +37,7 @@ const { message } = SELECTFAVBRAND_TEXTS;

const SelectFavBrand = () => {
useComposeHeader(false, '기본정보', 'close');
useCancelSignUp();
const navigateToHome = useNavigateTo('/');
const { state: imageFile } = useLocation();
const { uploadStorage } = useCloudStorage();
Expand Down
36 changes: 2 additions & 34 deletions src/components/start/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';

import Icon from '@/components/common/Icon';
import { SIGININ_TEXTS } from '@/constants/start';
import { getSocialAuth, ddockerSignIn, getMyInfo } from '@/api/user';
import { getSocialAuth } from '@/api/user';
import { iconPropsGenerator } from '@/utils/iconPropsGenerator';
import { useNavigateTo } from '@/hooks/useNavigateTo';
import { useCachedUserInfo } from '@/hooks/useCachedUserInfo';
import useGetCacheData from '@/hooks/useGetCacheData';
import { ddockerSignInType } from '@/types/types';
import { useVerifyMembership } from '@/hooks/start/useVerifyMembership';

import { styled } from 'styled-system/jsx';
import { cx } from 'styled-system/css';
Expand All @@ -25,12 +20,6 @@ import { StartBtn, NoneBtn, SignInBtn } from '@/styles/styles';
const { signInBtn, startText } = SIGININ_TEXTS;

const SignIn = () => {
const [searchParams] = useSearchParams();
const { accessToken } = useCachedUserInfo();
const code = searchParams.get('code');
const navToHome = useNavigateTo('/');
const navToSignUp = useNavigateTo('/start/2');

const handleSocialAuth: React.MouseEventHandler<HTMLButtonElement> = async (
e: React.MouseEvent<HTMLButtonElement>
) => {
Expand All @@ -42,27 +31,6 @@ const SignIn = () => {
}
};

const verifyMembership = async (accessToken: string | null) => {
const social = await useGetCacheData('user', '/social');
const res =
!accessToken &&
code &&
social &&
(await ddockerSignIn(code, social.cacheData));
if (res) {
const { accessToken } = res as ddockerSignInType;
const singIn = async () => {
(await getMyInfo()) && navToHome();
};
return accessToken ? singIn() : navToSignUp();
}
accessToken && navToHome();
};

useEffect(() => {
verifyMembership(accessToken);
}, []);

return (
<Container>
<AppLogoContainer
Expand Down
13 changes: 9 additions & 4 deletions src/pages/Page-Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, lazy, Suspense } from 'react';
import { useParams } from 'react-router-dom';
import { useNavigateTo } from '@/hooks/useNavigateTo';
import { useShowFooter } from '@/hooks/useShowFooter';
import { useCancelSignUp } from '@/hooks/start/useCancelSignUp';
import { useVerifyMembership } from '@/hooks/start/useVerifyMembership';
import { useCachedUserInfo } from '@/hooks/useCachedUserInfo';
import SEOMeta from '@/components/common/SEOMeta';
import SEO_DATA from '@/constants/SEOData';
Expand All @@ -14,10 +14,9 @@ const allowedPages = ['1', '2', '3'];

const Start = () => {
useShowFooter(false);
useCancelSignUp();
useVerifyMembership();
const { userData } = useCachedUserInfo();
const { id } = useParams();

const notAllowedPages = id && !allowedPages.includes(id);
const notSignUp = !userData && (id === '2' || '3');
const goToHomePage = useNavigateTo('/');
Expand All @@ -28,9 +27,15 @@ const Start = () => {
notSignUp ? goToStartPage() : goToHomePage();
}, []);

const page = id === '1' ? 'start' : 'signUp';
const pageData = {
...SEO_DATA[page],
pageUrl: `${SEO_DATA.start.pageUrl}/${id}`
};

return (
<>
<SEOMeta pageData={id === '1' ? SEO_DATA.start : SEO_DATA.signUp} />
<SEOMeta pageData={pageData} />
<div>
{id === '1' && (
<Suspense>
Expand Down

0 comments on commit 74d38e9

Please sign in to comment.