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

Refactor/tutorial #231

Merged
merged 4 commits into from
Sep 11, 2022
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
.env.test.local
.env.production.local
.env
.env.development
.env.production

npm-debug.log*
yarn-debug.log*
yarn-error.log*
node_modules
node_modules
12 changes: 6 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Route, Routes } from 'react-router-dom';
import { useQueryClient } from 'react-query';
import Layout from './components/layout/Layout';
import RequireAuth from '@components/auth/RequireAuth';
import PersistLogin from '@components/auth/PersistLogin';
import OnBoardingRouter from './pages/OnBoarding';
import HomeRouter from './pages/Home';
import WalkRouter from './pages/Walk';
import MypageRouter from './pages/Mypage';
import NotFound from './pages/NotFound';
import RequireAuth from '@components/auth/RequireAuth';
import PersistLogin from '@components/auth/PersistLogin';
import TestPage from './pages/Test/TestPage';
import { useQueryClient } from 'react-query';
import GroupLink from './components/mypage/GroupLink';
import ManageRouter from './pages/Manage';
import InterestRouter from './pages/Interest';
import NotFound from './pages/NotFound';
import TestPage from './pages/Test/TestPage';

function App() {
const queryClient = useQueryClient();
Expand All @@ -32,7 +32,7 @@ function App() {
<Route element={<Layout />}>
<Route path="/auth/*" element={<OnBoardingRouter />} />
<Route path="/link/:groupCode" element={<GroupLink />} />
<Route path="/test/*" element={<TestPage />} />
{/* <Route path="/test/*" element={<TestPage />} /> */}
<Route element={<PersistLogin />}>
<Route element={<RequireAuth />}>
<Route path="/*" element={<HomeRouter />} />
Expand Down
20 changes: 7 additions & 13 deletions src/apis/axios.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BASE_URL } from '@lib/constants/BASE_URL';
import getLocalStorage from '@lib/utils/localStorage/getLocalStorage';
import axios, { AxiosRequestConfig } from 'axios';
import axios from 'axios';

export const axiosPublic = axios.create({
baseURL: BASE_URL,
headers: { 'Content-Type': 'application/json' },
withCredentials: true,
// withCredentials: true,
});

// axiosPrivateInstanceλŠ” useAxiosPrivate hookμ—μ„œ import 되고,
Expand All @@ -16,18 +16,11 @@ export const axiosPrivateInstance = axios.create({
withCredentials: true,
});

export interface ApiResponse<T> {
data: T | null;
statusCode: string | null;
responseMessage: string | null;
}

// μž„μ‹œ axiosPrivate
export const axiosPrivateTemp = axios.create({
baseURL: BASE_URL,
headers: { 'Content-Type': 'application/json' },
});

axiosPrivateTemp.interceptors.request.use((request) => {
const accessToken = getLocalStorage('accessToken');
// @ts-expect-error
Expand All @@ -37,11 +30,12 @@ axiosPrivateTemp.interceptors.request.use((request) => {
}
return request;
});

axiosPrivateTemp.interceptors.response.use((response) => {
return response.data;
});

// https://2mojurmoyang.tistory.com/212
// https://velog.io/@bang9dev/axios-interceptor-with-ts
// https://github.com/Team-MailedIt/mailedit-client/blob/master/src/utils/API.js
export interface ApiResponse<T> {
data: T | null;
statusCode: string | null;
responseMessage: string | null;
}
8 changes: 5 additions & 3 deletions src/components/auth/PersistLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
setLevel,
} from '@store/slices/authSlice';
import CustomSyncLoader from '@components/common/CustomSyncLoader';
import registerEXPOToken from '@lib/utils/registerEXPOToken';

function PersistLogin() {
const accessToken = useAppSelector(selectAccessToken);
const isKid = useAppSelector(selectIsKid);
const [isLoading, setIsLoading] = useState(true);
const [isFetching, setIsFetching] = useState(true);
const dispatch = useAppDispatch();
const axiosPrivate = useAxiosPrivate();
const navigate = useNavigate();
Expand All @@ -32,15 +33,16 @@ function PersistLogin() {
} catch (error) {
navigate('/auth/login'); // access token expired
} finally {
isMounted && setIsLoading(false); // escape memory leak
isMounted && setIsFetching(false); // escape memory leak
}
}
console.log('aT in fetchLevel: ', accessToken);
isRegisteredUser && fetchLevel();
registerEXPOToken();
return () => (isMounted = false);
}, []);

if (isRegisteredUser && isLoading) {
if (isRegisteredUser && isFetching) {
return <CustomSyncLoader />;
} else {
return <Outlet />;
Expand Down
4 changes: 2 additions & 2 deletions src/components/register/RegisterBirthday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function RegisterBirthday() {
const dayInputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
const parsedIntYear = parseInt(year);
if (1923 <= parsedIntYear && parsedIntYear <= 2022) {
if (1923 <= parsedIntYear && parsedIntYear <= 2021) {
setIsValidYear(true);
monthInputRef.current!.focus();
} else {
Expand Down Expand Up @@ -75,7 +75,7 @@ function RegisterBirthday() {
e.preventDefault();
const parsedIntYear = parseInt(year);
let temp1 = false;
if (1923 <= parsedIntYear && parsedIntYear <= 2022) {
if (1923 <= parsedIntYear && parsedIntYear <= 2021) {
temp1 = true;
}
const temp2 = MONTH_REGEX.test(month);
Expand Down
125 changes: 56 additions & 69 deletions src/components/register/RegisterRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import { TFetchStatus } from '@lib/types/TFetchStatus';
import useGlobalBottomSheet from '@lib/hooks/useGlobalBottomSheet';
import setLocalStorage from '@lib/utils/localStorage/setLocalStorage';
import getLocalStorage from '@lib/utils/localStorage/getLocalStorage';
import GuideTemplate from '@components/manage/guides/GuideTemplate';

function RegisterRole() {
const birthday = useAppSelector(selectBirthday);
const [isKid, setIsKid] = useState<boolean | null>(null);
const [isFemale, setIsFemale] = useState<boolean | null>(null);
const [isTutorial, setIsTutorial] = useState<boolean>(false);

const { openModal } = useModals();
const navigate = useNavigate();
function handleModalOpen(isKid: boolean, isFemale: boolean) {
openModal(modals.primaryModal, {
onSubmit: () => {
navigate('/', { replace: true });
setIsTutorial(true);
},
isKid,
isFemale,
Expand Down Expand Up @@ -80,54 +81,60 @@ function RegisterRole() {

return (
<Wrapper>
<span>ν”„λ‘œν•„μ„ μ„ νƒν•΄μš”</span>
<RoleButtonWrapper>
{/* μ•„λΉ  */}
<RoleButton
onClick={() => {
openSelectProfileSheet(false, false);
setIsKid(false);
setIsFemale(false);
}}
isKid={false}
isFemale={false}
isSelected={isOpen && isKid === false && isFemale === false}
/>
{/* μ—„λ§ˆ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(false, true);
setIsKid(false);
setIsFemale(true);
}}
isKid={false}
isFemale={true}
isSelected={isOpen && isKid === false && isFemale === true}
/>
{/* μ•„λ“€ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(true, false);
setIsKid(true);
setIsFemale(false);
}}
isKid={true}
isFemale={false}
isSelected={isOpen && isKid === true && isFemale === false}
/>
{/* λ”Έ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(true, true);
setIsKid(true);
setIsFemale(true);
}}
isKid={true}
isFemale={true}
isSelected={isOpen && isKid === true && isFemale === true}
/>
</RoleButtonWrapper>
<Modals />
{isTutorial ? (
<GuideTemplate page="onboarding" isKid={isKid!} />
) : (
<>
<span>ν”„λ‘œν•„μ„ μ„ νƒν•΄μš”</span>
<RoleButtonWrapper>
{/* μ•„λΉ  */}
<RoleButton
onClick={() => {
openSelectProfileSheet(false, false);
setIsKid(false);
setIsFemale(false);
}}
isKid={false}
isFemale={false}
isSelected={isOpen && isKid === false && isFemale === false}
/>
{/* μ—„λ§ˆ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(false, true);
setIsKid(false);
setIsFemale(true);
}}
isKid={false}
isFemale={true}
isSelected={isOpen && isKid === false && isFemale === true}
/>
{/* μ•„λ“€ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(true, false);
setIsKid(true);
setIsFemale(false);
}}
isKid={true}
isFemale={false}
isSelected={isOpen && isKid === true && isFemale === false}
/>
{/* λ”Έ */}
<RoleButton
onClick={() => {
openSelectProfileSheet(true, true);
setIsKid(true);
setIsFemale(true);
}}
isKid={true}
isFemale={true}
isSelected={isOpen && isKid === true && isFemale === true}
/>
</RoleButtonWrapper>
</>
)}
</Wrapper>
);
}
Expand All @@ -152,23 +159,3 @@ const RoleButtonWrapper = styled.div`
row-gap: 16px;
column-gap: 16px;
`;

// let accessToken;
// let level: TLevel | null = null;
// if (isKid === false && isFemale === false) {
// accessToken =
// 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjE0ODQyMTQsInN1YiI6IjUiLCJleHAiOjE2NjI2OTM4MTQsImlkIjo1LCJyb2xlcyI6IlVTRVIifQ.5fKVlH-BGRRXiSP2WFtiLGheiNThQAC8wc7yj38MAG8';
// } else if (isKid === false && isFemale === true) {
// accessToken =
// 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjE0MTMxNTcsInN1YiI6IjIiLCJleHAiOjE2NjI2MjI3NTcsImlkIjoyLCJyb2xlcyI6IlVTRVIifQ.ev6Jy4r-sgdOmASOLQ2aioMVhkYhXFZz3HXeyBzvYwU';
// } else if (isKid === true && isFemale === false) {
// accessToken =
// 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjIxOTg5NTQsInN1YiI6IjQiLCJleHAiOjE2NjM0MDg1NTQsImlkIjo0LCJyb2xlcyI6IlVTRVIifQ.F3tKrx-cVOHqPeU-a8opyLVK6oHbm83eAmh12HDNji0';
// level = -4;
// } else if (isKid === true && isFemale === true) {
// accessToken =
// 'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NjI0Nzk4MzksInN1YiI6IjMiLCJleHAiOjE2NjI0Nzk4OTksImlkIjozLCJyb2xlcyI6IlVTRVIifQ.KmzWCJfLq_b2pJ_O1NaahjDStoYWa1PB7cG4PAUZnX0';
// level = 2;
// }
// accessToken &&
// dispatch(setCredentials({ accessToken, isKid, level, provider: 'kakao' }));
3 changes: 2 additions & 1 deletion src/lib/constants/BASE_URL.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const BASE_URL = 'https://api.bankidz.com'; // 배포 ν™˜κ²½
// export const BASE_URL = 'https://api.bankidz.com'; // 배포 ν™˜κ²½
// export const BASE_URL = 'https://bankids.click'; // ν…ŒμŠ€νŠΈ ν™˜κ²½
export const BASE_URL = `${process.env.REACT_APP_BASE_URL}`;
3 changes: 2 additions & 1 deletion src/lib/constants/KAKAO_AUTH_URL.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const DOMAIN = 'https://bankidz.com'; // 배포 ν™˜κ²½(κ³ μ •)
// const DOMAIN = 'https://bankidz.com'; // 배포 ν™˜κ²½(κ³ μ •)
// const DOMAIN = 'http://localhost:3000'; // ν…ŒμŠ€νŠΈ ν™˜κ²½
const DOMAIN = `${process.env.REACT_APP_DOMAIN}`;
const REST_API_KEY = `${process.env.REACT_APP_KAKAO_REST_API_KEY}`;
const REDIRECT_URI = `${DOMAIN}/auth/kakao/callback`;
export const KAKAO_AUTH_URL = `https://kauth.kakao.com/oauth/authorize?client_id=${REST_API_KEY}&redirect_uri=${REDIRECT_URI}&response_type=code`;
8 changes: 0 additions & 8 deletions src/pages/OnBoarding/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ import MarginTemplate from '@components/layout/MarginTemplate';
import { ReactComponent as Logo } from '@assets/icons/logo.svg';
import { KAKAO_AUTH_URL } from '@lib/constants/KAKAO_AUTH_URL';
import { APPLE_AUTH_URL } from '@lib/constants/APPLE_AUTH_URL';
import { axiosPrivateTemp } from '@apis/axios';

function LoginPage() {
const handleClick = async () => {
const response = await axiosPrivateTemp.get('/user');
console.log(response);
};

return (
<Wrapper>
<MarginTemplate>
<TextWrapper>
<Logo />
<p>λ±…ν‚€μ¦ˆμ— μ˜€μ‹  것을 ν™˜μ˜ν•©λ‹ˆλ‹€!</p>
</TextWrapper>
<span>09090619</span>
<button onClick={handleClick}>axios private test</button>
<ButtonWithMarginBottom
label="카카였둜 μ‹œμž‘ν•˜κΈ°"
onClick={() => (window.location.href = KAKAO_AUTH_URL)}
Expand Down
Loading