Skip to content

Commit

Permalink
fix: api ์ˆ˜์ • (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenS3same committed Dec 5, 2024
1 parent de151bc commit 305953a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 4 deletions.
45 changes: 45 additions & 0 deletions src/api/loginApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,45 @@ export const postSignUpNickname = async (body: { nickname: string }) => {
return response.data;
};

export const postSignUpLast = async (profile: File | null) => {
const email = localStorage.getItem('email');
const password = localStorage.getItem('password');
const password_confirm = localStorage.getItem('password_confirm');
const name = localStorage.getItem('name');
const phone = localStorage.getItem('phone');
const nickname = localStorage.getItem('nickname');
const address = localStorage.getItem('address');

let profileBase64: string | null = null;
if (profile) {
profileBase64 = await new Promise<string | null>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.onerror = reject;
reader.readAsDataURL(profile);
});
}

const body = {
email,
password,
password_confirm,
name,
phone,
nickname,
address,
profile: profileBase64,
};

const response = await axiosInstance.post(`/users`, body, {
headers: {
'Content-Type': 'application/json',
},
});

return response.data;
};

export const postSignIn = async (body: { email: string; password: string }) => {
const response = await axiosInstance.post(`/users/login`, body);

Expand All @@ -47,3 +86,9 @@ export const postResetPassword = async (

return response.data;
};

export const postSignInSNS = async () => {
const response = await axiosInstance.post(`/users/sociallogin`);

return response.data;
};
1 change: 1 addition & 0 deletions src/components/pages/login/SetLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function SetLocationPage() {
const response = await postSignUpLocation({ address: region });

if (response.message === '์ฃผ์†Œ ํ™•์ธ ์™„๋ฃŒ') {
localStorage.setItem('address', region);
navigate('/setnickname');
} else {
alert('์ฃผ์†Œ๋ฅผ ๋‹ค์‹œ ํ™•์ธํ•ด์ฃผ์„ธ์š”.');
Expand Down
2 changes: 2 additions & 0 deletions src/components/pages/login/SetNicknamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const SetNicknamePage = () => {
const response = await postSignUpNickname({ nickname: nickname });

if (response.message === '๋‹‰๋„ค์ž„ ์ค‘๋ณต ํ™•์ธ ์™„๋ฃŒ') {
localStorage.setItem('nickname', nickname);

navigate('/setprofile');
} else {
alert('๋‹‰๋„ค์ž„์ด ์ค‘๋ณต์ž…๋‹ˆ๋‹ค.');
Expand Down
9 changes: 7 additions & 2 deletions src/components/pages/login/SetProfilePage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postSignUpLast } from '../../../api/loginApi';

const SetProfilePage = () => {
const navigate = useNavigate();
const [previewImage, setPreviewImage] = useState<string | null>(null);
const [selectedFile, setSelectedFile] = useState<File | null>(null);

const handleImageUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
Expand All @@ -14,6 +16,7 @@ const SetProfilePage = () => {
setPreviewImage(reader.result as string);
};
reader.readAsDataURL(file);
setSelectedFile(file);
}
};

Expand Down Expand Up @@ -56,15 +59,17 @@ const SetProfilePage = () => {
</ImageWrapper>

<NextButton
onClick={() => {
onClick={async () => {
await postSignUpLast(selectedFile);
navigate('/logincomplete');
}}
>
Next
</NextButton>
<SkipWrapper>
<SkipButton
onClick={() => {
onClick={async () => {
await postSignUpLast(null);
navigate('/logincomplete');
}}
>
Expand Down
8 changes: 6 additions & 2 deletions src/components/pages/login/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postSignIn } from '../../../api/loginApi';
import { postSignIn, postSignInSNS } from '../../../api/loginApi';

const SignInPage = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -50,7 +50,11 @@ const SignInPage = () => {
>
Login
</LoginButton>
<SNSButton>
<SNSButton
onClick={async () => {
await postSignInSNS();
}}
>
<img
src="/images/googlelogo.png"
alt="Google Logo"
Expand Down
6 changes: 6 additions & 0 deletions src/components/pages/login/SignUpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ function SignUpPage() {
});

if (response.message === '์ด๋ฉ”์ผ, ์ „ํ™”๋ฒˆํ˜ธ ์ค‘๋ณต ํ™•์ธ ์™„๋ฃŒ') {
localStorage.setItem('email', email);
localStorage.setItem('password', pw);
localStorage.setItem('password_confirm', cpw);
localStorage.setItem('name', name);
localStorage.setItem('phone', phone);

navigate('/termsandservice');
} else {
alert('์ด๋ฉ”์ผ ๋˜๋Š” ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ์ค‘๋ณต ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
Expand Down

0 comments on commit 305953a

Please sign in to comment.