Skip to content

Commit

Permalink
Merge pull request #231 from Strong-Potato/200-feat-seperate-api-requ…
Browse files Browse the repository at this point in the history
…est-to-authts

Feat: seperate api request to auth
  • Loading branch information
NamgungJongMin authored Jan 27, 2024
2 parents 24fdf1f + 17d0579 commit 5bbf00f
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 36 deletions.
File renamed without changes
File renamed without changes
31 changes: 31 additions & 0 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,37 @@ export const authRequest = {
token,
}),

/* ------------------------------ FIND PASSWORD ----------------------------- */
lostPassword_sendEmail: (email?: string) =>
axios.post('/api/auth/modify/lost-password/send-email', {
email,
}),

lostPassword_emailSert: (email?: string, code?: string) =>
axios.post('/api/auth/modify/lost-password/check-token', {
email,
code,
}),

lostPassword_submit: (email?: string, password?: string, token?: string) =>
axios.post('/api/auth/modify/lost-password', {
email,
password,
token,
}),

/* ----------------------------- MODIFY PASSWORD ---------------------------- */
modifyPassword_check: (password?: string) =>
axios.post('/api/auth/modify/password/check', {
password,
}),

modifyPassword_submit: (token?: string, password?: string) =>
axios.post('/api/auth/modify/password', {
token,
password,
}),

/* ------------------------------- WITHDRAWAL ------------------------------- */
withdrawal: (password?: string) =>
axios.post(
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons/profile_default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Alarm/TabCapsule/Content/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styles from './Content.module.scss';

import DefaultProfile from '@/assets/profile_default.svg?react';
import DefaultProfile from '@/assets/icons/profile_default.svg?react';
import formatTimeAgo from '@/utils/formatTimeAgo';

import {ContentProps} from '@/types/alarm';
Expand Down
9 changes: 3 additions & 6 deletions src/components/Auth/FindPassword/FindPasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import {useState} from 'react';
import {SubmitHandler, useForm} from 'react-hook-form';
import {useNavigate} from 'react-router-dom';
Expand All @@ -7,6 +6,8 @@ import styles from './FindPasswordForm.module.scss';

import CustomToast from '@/components/CustomToast/CustomToast';

import {authRequest} from '@/api/auth';

import StepEmail from './Step/StepEmail';
import StepEmailSert from './Step/StepEmailSert';
import StepPassword from './Step/StepPassword';
Expand Down Expand Up @@ -43,11 +44,7 @@ function FindPasswordForm() {

try {
const {email, password} = data;
const res = await axios.post('/api/auth/modify/lost-password', {
email,
newPassword: password,
token: code,
});
const res = await authRequest.lostPassword_submit(email, password, code);
console.log(res);

if (res.data.responseCode === 204) {
Expand Down
6 changes: 2 additions & 4 deletions src/components/Auth/FindPassword/Step/StepEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import {useState} from 'react';
import {useNavigate} from 'react-router-dom';
import {useSetRecoilState} from 'recoil';
Expand All @@ -7,6 +6,7 @@ import styles from './Step.module.scss';

import CustomToast from '@/components/CustomToast/CustomToast';

import {authRequest} from '@/api/auth';
import {isModalOpenState} from '@/recoil/vote/alertModal';

import ExpireAlert from '../../Alert/ExpireAlert';
Expand All @@ -23,9 +23,7 @@ function StepEmail({setFindPasswordStep, register, watchFields: {email}, dirty,

const onClickEmail = async () => {
try {
const res = await axios.post('/api/auth/modify/lost-password/send-email', {
email,
});
const res = await authRequest.lostPassword_sendEmail(email);
console.log(res);

if (res.data.responseCode === 404) {
Expand Down
9 changes: 3 additions & 6 deletions src/components/Auth/FindPassword/Step/StepEmailSert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import {useEffect, useState} from 'react';

import styles from './Step.module.scss';
Expand All @@ -7,6 +6,8 @@ import AuthButton from '@/components/Auth/Button/AuthButton';
import InputEmailSert from '@/components/Auth/Input/InputEmailSert';
import CustomToast from '@/components/CustomToast/CustomToast';

import {authRequest} from '@/api/auth';

import {StepEmailSertProps} from '@/types/auth';

function StepEmailSert({
Expand Down Expand Up @@ -34,18 +35,14 @@ function StepEmailSert({

const onClickEmailSert = async () => {
try {
const res = await axios.post('/api/auth/modify/lost-password/check-token', {
email,
code: emailSert,
});
const res = await authRequest.lostPassword_emailSert(email, emailSert);
console.log(res);

if (res.data.responseCode === 203) {
showToast('인증코드가 일치하지 않습니다.');
return;
}

console.log(res.data.data.token);
setCode!(await res.data.data.token);
setFindPasswordStep!('password');
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions src/components/Auth/ModifyPassword/ModifyPasswordForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import axios from 'axios';
import {useState} from 'react';
import {useForm} from 'react-hook-form';
import {useNavigate} from 'react-router-dom';

import styles from './ModifyPasswordForm.module.scss';

import {authRequest} from '@/api/auth';

import StepNewPassword from './Step/StepNewPassword';
import StepOldPassword from './Step/StepOldPassword';

Expand Down Expand Up @@ -33,11 +34,10 @@ function ModifyPasswordForm() {
const navigate = useNavigate();

const onSubmit = async () => {
if (Object.keys(dirtyFields).length < 2) return;

try {
const res = axios.post('/api/auth/modify/password', {
token,
newPassword: watchFields.password,
});
const res = await authRequest.modifyPassword_submit(token, watchFields.password);

console.log(res);
navigate('/user', {replace: true});
Expand Down
7 changes: 3 additions & 4 deletions src/components/Auth/ModifyPassword/Step/StepOldPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import axios from 'axios';
import {Link} from 'react-router-dom';

import styles from './Step.module.scss';

import {authRequest} from '@/api/auth';

import AuthButton from '../../Button/AuthButton';
import InputOldPassword from '../../Input/InputOldPassword';

Expand All @@ -18,9 +19,7 @@ function StepOldPassword({
}: StepOldPasswordProps) {
const onClickNext = async () => {
try {
const res = await axios.post('/api/auth/modify/password/check', {
password: oldPassword,
});
const res = await authRequest.modifyPassword_check(oldPassword);

setToken!(await res.data.data.token);
setStep!('newPassword');
Expand Down
4 changes: 2 additions & 2 deletions src/components/Auth/Signup/Step/StepProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import styles from './Step.module.scss';

import AuthButton from '@/components/Auth/Button/AuthButton';

import defaultProfile from '@/assets/profile_default.svg';

import InputImage from '../../Input/InputImage';
import InputNickname from '../../Input/InputNickname';

import {StepProfileProps} from '@/types/auth';

const defaultProfile = '/profile_default.svg';

function StepProfile({register, resetField, dirty, error}: StepProfileProps) {
const [imageUrl, setImageUrl] = useState<string | undefined>(defaultProfile);

Expand Down
7 changes: 4 additions & 3 deletions src/components/MySpaceBody/MySpaceList/MySpaceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {useInfiniteScroll} from '@/hooks/useInfiniteScroll';

import ObserveTarget from '@/components/Route/ObserveTarget/ObserveTarget';

import defaultCity from '@/assets/icons/city_default.svg';
import {setSpaceDate} from '@/utils/formatDate';

import {Spaces} from '@/types/sidebar';
import {MySpaceListProps} from '@/types/user';

const defaultThumbnail = '/city_default.svg';

function MySpaceList({tab}: MySpaceListProps) {
const {data: upcomingData} = useGetSpaces(true);
const [outdatedData, hasNextData, inViewRef] = useInfiniteScroll(useGetSpacesOut);
Expand All @@ -33,7 +34,7 @@ function MySpaceList({tab}: MySpaceListProps) {
dueDate !== null && styles.dimmed
}`}
style={{
backgroundImage: `url(${thumbnail ? thumbnail : defaultCity})`,
backgroundImage: `url(${thumbnail ? thumbnail : defaultThumbnail})`,
}}
>
<span>{dueDate !== null ? (dueDate <= 0 ? '여행중' : `D-${dueDate}`) : ''}</span>
Expand Down Expand Up @@ -63,7 +64,7 @@ function MySpaceList({tab}: MySpaceListProps) {
<div
className={`${styles.img} ${thumbnail ? styles.city : styles.default}`}
style={{
backgroundImage: `url(${thumbnail ? thumbnail : defaultCity})`,
backgroundImage: `url(${thumbnail ? thumbnail : defaultThumbnail})`,
}}
></div>

Expand Down
3 changes: 2 additions & 1 deletion src/components/User/EditProfileForm/EditProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import InputImage from '@/components/Auth/Input/InputImage';
import InputNickname from '@/components/Auth/Input/InputNickname';

import {s3Request} from '@/api/s3';
import defaultProfile from '@/assets/profile_default.svg';

import {AuthForm} from '@/types/auth';
import {GetUserProp} from '@/types/sidebar';

const defaultProfile = '/profile_default.svg';

function EditProfileForm({data}: {data: GetUserProp | undefined}) {
const {
register,
Expand Down
5 changes: 3 additions & 2 deletions src/components/User/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {useNavigate} from 'react-router-dom';
import styles from './Profile.module.scss';

import Pencil from '@/assets/icons/pencil.svg?react';
import defaultImage from '@/assets/profile_default.svg';

import {ProfileProps} from '@/types/user';

const defaultProfile = '/profile_default.svg';

function Profile({data}: ProfileProps) {
const navigate = useNavigate();

Expand All @@ -15,7 +16,7 @@ function Profile({data}: ProfileProps) {
<div
className={styles.image}
style={{
backgroundImage: `${data?.data.profile ? `url(${data?.data.profile})` : `url(${defaultImage})`}`,
backgroundImage: `${data?.data.profile ? `url(${data?.data.profile})` : `url(${defaultProfile})`}`,
}}
>
<button
Expand Down
5 changes: 3 additions & 2 deletions src/pages/User/MyReview/MyReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import ReviewImageSlider from '@/components/Detail/Contents/Review/ReviewImageSl
import ActionList from '@/components/MyReview/ActionList/ActionList';
import ObserveTarget from '@/components/Route/ObserveTarget/ObserveTarget';

import defaultImage from '@/assets/icons/city_default.svg';
import Meatball from '@/assets/icons/meatball.svg?react';
import Star from '@/assets/icons/star_fill.svg?react';
import {setMyReviewDate} from '@/utils/formatDate';

import {Reviews} from '@/types/myReview';

const defaultThumbnail = '/city_default.svg';

function MyReview() {
const {isOpen: isBottomSlideOpen, onOpen: onBottomSlideOpen, onClose: onBottomSlideClose} = useDisclosure();
const [reviews, hasNextData, inViewRef] = useInfiniteScroll(useGetMyReview);
Expand All @@ -38,7 +39,7 @@ function MyReview() {
<div
className={`${styles.myreview__header__img} ${place.thumbnail || styles.default}`}
style={{
backgroundImage: `url(${place.thumbnail ? place.thumbnail : defaultImage})`,
backgroundImage: `url(${place.thumbnail ? place.thumbnail : defaultThumbnail})`,
}}
></div>

Expand Down

0 comments on commit 5bbf00f

Please sign in to comment.