Skip to content

Commit

Permalink
Merge pull request #37 from prgrms-web-devcourse-final-project/featurโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆe/loginApi

Feat: ๋กœ๊ทธ์ธ,ํšŒ์›๊ฐ€์ž…,๋น„๋ฐ€๋ฒˆํ˜ธ์ฐพ๊ธฐ,๋ฆฌ์…‹,ํ˜„์žฌ๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ, ๋™๋„ค๋ณ€๊ฒฝ api ๋กœ์ง ์ถ”๊ฐ€
  • Loading branch information
OpenS3same authored Dec 4, 2024
2 parents 4e56784 + 0f176e7 commit 54f363e
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 55 deletions.
37 changes: 37 additions & 0 deletions src/api/loginApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import axiosInstance from './axiosInstance';

export const postSignUp = async (body: {
email: string;
password: string;
password_confirm: string;
name: string;
phone: string;
}) => {
const response = await axiosInstance.post(`/users/checkemail`, body);

return response.data;
};

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

return response.data;
};

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

return response.data;
};

export const postResetPassword = async (
body: { newPassword: string },
token: string
) => {
const response = await axiosInstance.post(
`/users/reset?token=${token}`,
body
);

return response.data;
};
19 changes: 19 additions & 0 deletions src/api/mypageApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import axiosInstance from './axiosInstance';

export const postPasswordVerify = async (body: { currentPassword: string }) => {
const response = await axiosInstance.post(`/mypage/verfiy`, body);

return response.data;
};

export const postPasswordChange = async (body: { newPassword: string }) => {
const response = await axiosInstance.post(`/mypage/change`, body);

return response.data;
};

export const postLocationChange = async (body: { newAddress: string }) => {
const response = await axiosInstance.post(`/mypage/changeneighbor`, body);

return response.data;
};
21 changes: 18 additions & 3 deletions src/components/pages/login/FindPasswordPage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postFindPassword } from '../../../api/loginApi';

const FindPasswordPage = () => {
const navigate = useNavigate();
const [showModal, setShowModal] = useState(false);
const [email, setEmail] = useState<string>('');

return (
<>
<Wrapper>
Expand Down Expand Up @@ -37,9 +40,21 @@ const FindPasswordPage = () => {
๋“ฑ๋ก๋œ ์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ํ™•์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์ฃผ์„ธ์š”
</Description>
<Subtitle>email address</Subtitle>
<StyledInput placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ" />

<LoginButton onClick={() => setShowModal(true)}>ํ™•์ธ</LoginButton>
<StyledInput
placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ"
value={email}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setEmail(e.target.value);
}}
/>
<LoginButton
onClick={async () => {
setShowModal(true);
await postFindPassword({ email: email });
}}
>
ํ™•์ธ
</LoginButton>
</RightContent>
</Wrapper>
{showModal && (
Expand Down
77 changes: 38 additions & 39 deletions src/components/pages/login/ResetPasswordPage.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postResetPassword } from '../../../api/loginApi';

const ResetPasswordPage = () => {
const navigate = useNavigate();
const [password, setPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');
const [showModal, setShowModal] = useState(false);

const handleConfirm = () => {
const handleConfirm = async () => {
if (password === confirmPassword && password.length >= 8) {
await postResetPassword({ newPassword: password }, '1');
setShowModal(true);
} else {
alert('๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
}
};

return (
<>
<Wrapper>
<LeftContent>
<img
src="/images/login6.jpg"
alt="Login background"
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
}}
/>
</LeftContent>
<RightContent>
<Title>๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์„ค์ •</Title>
<Subtitle>password</Subtitle>
<StyledInput
type="password"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)"
value={password}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setPassword(e.target.value)
}
/>
<Subtitle>confirm password</Subtitle>
<StyledInput
type="password"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"
value={confirmPassword}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setConfirmPassword(e.target.value)
}
/>
<LoginButton onClick={handleConfirm}>Confirm</LoginButton>
</RightContent>
</Wrapper>

<Wrapper>
<LeftContent>
<img
src="/images/login6.jpg"
alt="Login background"
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
}}
/>
</LeftContent>
<RightContent>
<Title>๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์„ค์ •</Title>
<Subtitle>password</Subtitle>
<StyledInput
type="password"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)"
value={password}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setPassword(e.target.value)
}
/>
<Subtitle>confirm password</Subtitle>
<StyledInput
type="password"
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"
value={confirmPassword}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
setConfirmPassword(e.target.value)
}
/>
<LoginButton onClick={handleConfirm}>Confirm</LoginButton>
</RightContent>
{showModal && (
<ModalOverlay>
<ModalContent>
Expand All @@ -68,7 +67,7 @@ const ResetPasswordPage = () => {
</ModalContent>
</ModalOverlay>
)}
</>
</Wrapper>
);
};

Expand Down
34 changes: 30 additions & 4 deletions src/components/pages/login/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postSignIn } from '../../../api/loginApi';

const SignInPage = () => {
const navigate = useNavigate();
const [email, setEmail] = useState<string>('');
const [pw, setPw] = useState<string>('');

return (
<Wrapper>
<LeftContent>
Expand All @@ -20,10 +24,32 @@ const SignInPage = () => {
<RightContent>
<Title>Welcome ๐Ÿ‘‹๐Ÿผ</Title>
<Subtitle>email address</Subtitle>
<StyledInput placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ" />
<StyledInput
placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ"
value={email}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setEmail(e.target.value);
}}
/>
<Subtitle>password</Subtitle>
<StyledInput placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)" />
<LoginButton>Login</LoginButton>
<StyledInput
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)"
value={pw}
type={'password'}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setPw(e.target.value);
}}
/>
<LoginButton
onClick={async () => {
await postSignIn({
email: email,
password: pw,
});
}}
>
Login
</LoginButton>
<SNSButton>
<img
src="/images/googlelogo.png"
Expand Down
58 changes: 51 additions & 7 deletions src/components/pages/login/SignUpPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postSignUp } from '../../../api/loginApi';

function SignUpPage() {
const navigate = useNavigate();
const [name, setName] = useState<string>('');
const [phone, setPhone] = useState<string>('');
const [email, setEmail] = useState<string>('');
const [pw, setPw] = useState<string>('');
const [cpw, setCpw] = useState<string>('');

return (
<Wrapper>
<LeftContent>
Expand All @@ -20,17 +27,54 @@ function SignUpPage() {
<RightContent>
<Title>ํšŒ์›๊ฐ€์ž…</Title>
<Subtitle>Name</Subtitle>
<StyledInput placeholder="์ด๋ฆ„ ์ž…๋ ฅ" />
<StyledInput
placeholder="์ด๋ฆ„ ์ž…๋ ฅ"
value={name}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setName(e.target.value);
}}
/>
<Subtitle>Phone Number</Subtitle>
<StyledInput placeholder="ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ ์ž…๋ ฅ" />
<StyledInput
placeholder="ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ ์ž…๋ ฅ"
value={phone}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setPhone(e.target.value);
}}
/>
<Subtitle>Email Address</Subtitle>
<StyledInput placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ" />
<StyledInput
placeholder="์ด๋ฉ”์ผ ์ž…๋ ฅ"
value={email}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setEmail(e.target.value);
}}
/>
<Subtitle>Password</Subtitle>
<StyledInput placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)" />
<StyledInput
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ (8 ~ 16์ž๋ฆฌ)"
value={pw}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setPw(e.target.value);
}}
/>
<Subtitle>Confirm Password</Subtitle>
<StyledInput placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ" />
<StyledInput
placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ ํ™•์ธ"
value={cpw}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setCpw(e.target.value);
}}
/>
<LoginButton
onClick={() => {
onClick={async () => {
await postSignUp({
email: email,
password: pw,
password_confirm: cpw,
name: name,
phone: phone,
});
navigate('/termsandservice');
}}
>
Expand Down
11 changes: 10 additions & 1 deletion src/components/pages/myPage/LocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Sidemenu from './SideMenu';
import GS from './GS';
import KakaoMap from '../../common/KakaoMap';
import styled from 'styled-components';
import { postLocationChange } from '../../../api/mypageApi';

function LocationPage() {
const [location, setLocation] = useState<{
Expand Down Expand Up @@ -64,7 +65,15 @@ function LocationPage() {
<AddressDesc>
ํ˜„์žฌ ์œ„์น˜๊ฐ€ ๋‚ด ๋™๋„ค๋กœ ์„ค์ •ํ•œ {region || '00๋™'}์— ์žˆ์Šต๋‹ˆ๋‹ค.
</AddressDesc>
<VerfiyButton>๋™๋„ค์ธ์ฆ ์™„๋ฃŒํ•˜๊ธฐ</VerfiyButton>
<VerfiyButton
onClick={async () => {
if (region) {
await postLocationChange({ newAddress: region });
}
}}
>
๋™๋„ค์ธ์ฆ ์™„๋ฃŒํ•˜๊ธฐ
</VerfiyButton>
</KakaoMapWrapper>
</GS.Content>
</GS.Wrapper>
Expand Down
8 changes: 7 additions & 1 deletion src/components/pages/myPage/Modal/PasswordModal.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React, { useState } from 'react';
import { styled } from 'styled-components';
import {
postPasswordChange,
postPasswordVerify,
} from '../../../../api/mypageApi';

const PasswordModal = ({ onClose }: { onClose: () => void }) => {
const [step, setStep] = useState(1);
const [currentPassword, setCurrentPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [confirmPassword, setConfirmPassword] = useState('');

const handleNextStep = () => {
const handleNextStep = async () => {
if (step === 1) {
await postPasswordVerify({ currentPassword: currentPassword });
setStep(2);
} else if (step === 2) {
if (newPassword === confirmPassword) {
await postPasswordChange({ newPassword: newPassword });
onClose();
} else {
alert('๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
Expand Down

0 comments on commit 54f363e

Please sign in to comment.