Skip to content

Commit

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

Feat: ๋‹‰๋„ค์ž„, ํ™˜๋ถˆ ์†Œ์…œ๋กœ๊ทธ์ธ api ์ ์šฉ, api ์‹คํŒจ ์‹œ ์•Œ๋žŒ ์ถ”๊ฐ€, ์ฃผ์†Œ ํ’€๋„ค์ž„์œผ๋กœ ๋ณ€๊ฒฝ
  • Loading branch information
OpenS3same authored Dec 9, 2024
2 parents 1ad09dc + fc330e8 commit 52d2317
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 63 deletions.
17 changes: 17 additions & 0 deletions src/api/mypageApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import axiosInstance from './axiosInstance';

export type RefundType = {
productName: string;
quantity: number;
price: number;
url: string;
paymentStatus: string;
postId: number;
};

export type MyPostType = {
availableNumber: number;
category: string;
Expand Down Expand Up @@ -136,3 +145,11 @@ export const putEditProfile = async (file: File) => {

return response.data;
};

export const putChangeNickname = async (nickname: string) => {
const response = await axiosInstance.put(
`/api/mypage/change_nickname?nickName=${nickname}`
);

return response.data;
};
7 changes: 5 additions & 2 deletions src/components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Header = () => {
{isLoggedIn && (
<StyledLink
to={isAdmin ? '#' : '/mypage/setting'}
onClick={(e) => {
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => {
if (isAdmin) {
e.preventDefault(); // Admin์ผ ๊ฒฝ์šฐ ๋งํฌ ๋™์ž‘ ์ฐจ๋‹จ
} else {
Expand Down Expand Up @@ -92,7 +92,10 @@ const Header = () => {
</LogOut>
<LogOut>
<CartIcon>
<StyledLink to="/cart" onClick={toggleMobileMenu}>
<StyledLink
to="/mypage/wishlist"
onClick={toggleMobileMenu}
>
<img src={cart} alt="์žฅ๋ฐ”๊ตฌ๋‹ˆ ์•„์ด์ฝ˜" />
</StyledLink>
</CartIcon>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/login/FindPasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const FindPasswordPage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/login/LoginCompletePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LoginCompletePage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/login/ResetPasswordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ResetPasswordPage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down
6 changes: 4 additions & 2 deletions src/components/pages/login/SetLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function SetLocationPage() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(result: any, status: any) => {
if (status === window.kakao.maps.services.Status.OK) {
const primaryRegion = result[0]?.region_3depth_name || '';
setRegion(primaryRegion);
const fullRegion = `${result[0]?.region_1depth_name || ''} ${
result[0]?.region_2depth_name || ''
} ${result[0]?.region_3depth_name || ''}`;
setRegion(fullRegion);
setCalled(true);
} else {
console.error('์ฃผ์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.');
Expand Down
28 changes: 21 additions & 7 deletions src/components/pages/login/SetNicknamePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
Expand Down Expand Up @@ -29,7 +30,7 @@ const SetNicknamePage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand All @@ -53,14 +54,27 @@ const SetNicknamePage = () => {
<NextButton
onClick={async () => {
if (isValidLength && isValidFormat) {
const response = await postSignUpNickname({ nickname: nickname });
try {
const response = await postSignUpNickname({
nickname: nickname,
});

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

navigate('/setprofile');
} else {
alert('๋‹‰๋„ค์ž„์ด ์ค‘๋ณต์ž…๋‹ˆ๋‹ค.');
navigate('/setprofile');
} else {
alert('๋‹‰๋„ค์ž„์ด ์ค‘๋ณต์ž…๋‹ˆ๋‹ค.');
}
} catch (err) {
if (
axios.isAxiosError(err) &&
err.response &&
err.response.data &&
err.response.data.error
) {
alert(err.response.data.error);
}
}
} else {
alert('๋‹‰๋„ค์ž„ ์กฐ๊ฑด์„ ๋งŒ์กฑ์‹œ์ผœ ์ฃผ์„ธ์š”.');
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/login/SetProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SetProfilePage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down
15 changes: 13 additions & 2 deletions src/components/pages/login/SignInPage.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import React, { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { postSignIn } from '../../../api/loginApi';
import { useAuth } from '../../../context/AuthContext';

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

useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const accessToken = searchParams.get('accessToken');
if (accessToken) {
localStorage.setItem('token', accessToken);
navigate('/');
}
}, [location, navigate]);

return (
<Wrapper>
<LeftContent>
Expand Down
46 changes: 29 additions & 17 deletions src/components/pages/login/SignUpPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import axios from 'axios';
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
Expand All @@ -20,7 +21,7 @@ function SignUpPage() {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down Expand Up @@ -71,24 +72,35 @@ function SignUpPage() {
if (pw !== cpw) {
alert('๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.');
} else {
const response = await postSignUp({
email: email,
password: pw,
password_confirm: cpw,
name: name,
phone: phone,
});
try {
const response = await postSignUp({
email: email,
password: pw,
password_confirm: cpw,
name: name,
phone: phone,
});

if (response.message === '์ด๋ฉ”์ผ, ์ „ํ™”๋ฒˆํ˜ธ ์ค‘๋ณต ํ™•์ธ ์™„๋ฃŒ') {
localStorage.setItem('email', email);
localStorage.setItem('password', pw);
localStorage.setItem('password_confirm', cpw);
localStorage.setItem('name', name);
localStorage.setItem('phone', phone);
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('์ด๋ฉ”์ผ ๋˜๋Š” ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ์ค‘๋ณต ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
navigate('/termsandservice');
} else {
alert('์ด๋ฉ”์ผ ๋˜๋Š” ์ „ํ™”๋ฒˆํ˜ธ๊ฐ€ ์ค‘๋ณต ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
}
} catch (err) {
if (
axios.isAxiosError(err) &&
err.response &&
err.response.data &&
err.response.data.error
) {
alert(err.response.data.error);
}
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/login/TermsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const TermsPage = () => {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand Down
6 changes: 4 additions & 2 deletions src/components/pages/myPage/LocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function LocationPage() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(result: any, status: any) => {
if (status === window.kakao.maps.services.Status.OK) {
const primaryRegion = result[0]?.region_3depth_name || '';
setRegion(primaryRegion);
const fullRegion = `${result[0]?.region_1depth_name || ''} ${
result[0]?.region_2depth_name || ''
} ${result[0]?.region_3depth_name || ''}`;
setRegion(fullRegion);
setCalled(true);
} else {
console.error('์ฃผ์†Œ๋ฅผ ๊ฐ€์ ธ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.');
Expand Down
30 changes: 18 additions & 12 deletions src/components/pages/myPage/OrderListComponents/OrderHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const OrderHistory = () => {
return '๊ฒฐ์ œ ์™„๋ฃŒ';
case 'FAILED':
return '๊ฒฐ์ œ ์‹คํŒจ';
case 'CANCELD':
case 'CANCELED':
return '๊ฒฐ์ œ ์ทจ์†Œ';
case 'PARTIAL_CANCELED':
return '๋ถ€๋ถ„ ์ทจ์†Œ';
Expand Down Expand Up @@ -78,18 +78,24 @@ const OrderHistory = () => {
>
์ƒํ’ˆ ํŽ˜์ด์ง€ ์ด๋™
</ActionButton>
<CancelButton
onClick={() => {
handleCancelClick();
if (order.payment_key) {
setPk(order.payment_key);
}
}}
>
์ฃผ๋ฌธ ์ทจ์†Œ/ํ™˜๋ถˆ
</CancelButton>
{order.paymentStatus === 'DONE' && (
<ReviewLink>
<CancelButton
onClick={() => {
handleCancelClick();
if (order.payment_key) {
setPk(order.payment_key);
}
}}
>
์ฃผ๋ฌธ ์ทจ์†Œ/ํ™˜๋ถˆ
</CancelButton>
)}
{order.paymentStatus === 'DONE' && (
<ReviewLink
onClick={() => {
navigate(`/products/${order.postId}`);
}}
>
<ReviewIcon src="/images/qricon.png" alt="review icon" />
<span>๋ฆฌ๋ทฐ ์ž‘์„ฑํ•˜๊ธฐ</span>
</ReviewLink>
Expand Down
31 changes: 20 additions & 11 deletions src/components/pages/myPage/OrderListComponents/RefundHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';
import { getRefundList } from '../../../../api/mypageApi';
import { refundHistoryData } from '../mockData';
import { getRefundList, RefundType } from '../../../../api/mypageApi';

const RefundHistory = () => {
const [refundList, setRefundList] = useState<RefundType[]>([]);
const navigate = useNavigate();

useEffect(() => {
const fetchOrderList = async () => {
const response = await getRefundList();

console.log(response);
setRefundList(response);
};
fetchOrderList();
}, []);
return (
<Container>
<RefundList>
{refundHistoryData.map((refund) => (
<RefundItem key={refund.id}>
{refundList.map((refund, idx) => (
<RefundItem key={idx}>
<RefundWrapper>
<ImageContainer>
<ImagePlaceholder />
</ImageContainer>
<RefundDetails>
<ProductName>{refund.name}</ProductName>
<ProductName>{refund.productName}</ProductName>
<ProductInfo>Quantity: {refund.quantity}</ProductInfo>
<StatusBadge status={refund.status}>
{refund.status}
<StatusBadge status={refund.paymentStatus}>
{refund.paymentStatus === 'CANCELED' ? '์ทจ์†Œ' : '๋Œ€๊ธฐ ์ค‘'}
</StatusBadge>
</RefundDetails>
</RefundWrapper>
<Price>{refund.price}</Price>
<Price>{refund.price}์›</Price>
<Actions>
<ActionButton>์ƒํ’ˆ ํŽ˜์ด์ง€ ์ด๋™</ActionButton>
<ActionButton
onClick={() => {
navigate(`/products/${refund.postId}`);
}}
>
์ƒํ’ˆ ํŽ˜์ด์ง€ ์ด๋™
</ActionButton>
</Actions>
</RefundItem>
))}
Expand Down
Loading

0 comments on commit 52d2317

Please sign in to comment.