diff --git a/src/components/pages/HomePage/CategoryProduct.tsx b/src/components/pages/HomePage/CategoryProduct.tsx index 946b18b..efec6cf 100644 --- a/src/components/pages/HomePage/CategoryProduct.tsx +++ b/src/components/pages/HomePage/CategoryProduct.tsx @@ -58,19 +58,19 @@ const CategoryProduct: React.FC = ({ {displayedProducts.map((product) => ( - + {product.name} {' '} - + ${product.originalPrice.toFixed(2)} - ${product.discountedPrice.toFixed(2)} + ${product.discountPrice.toFixed(2)} diff --git a/src/components/pages/HomePage/HomePage.tsx b/src/components/pages/HomePage/HomePage.tsx index 054f7b5..bed0b1b 100644 --- a/src/components/pages/HomePage/HomePage.tsx +++ b/src/components/pages/HomePage/HomePage.tsx @@ -4,311 +4,14 @@ import RecommendProduct from './RecommendProduct'; import PopularProduct from './PopularProduct'; import CategoryProduct from './CategoryProduct'; import ScrollToTopButton from '../../common/ScrollToTopButton'; -// import { getProducts } from './api/productApi'; -// import { useQuery } from '@tanstack/react-query'; -// import { fetchUser, User } from './api/userApi'; -// import { Product } from '../Payment/api/paymentApi'; +import { categories, popularProduct, products } from '../../../mocks/products'; +// import { QueryHandler, useProductsQuery } from '../../../hooks/useGetProduct'; const HomePage: React.FC = () => { - // const { - // data: product, - // isLoading, - // isError, - // } = useQuery({ - // queryKey: ['product'], - // queryFn: () => getProducts(), - // }); - - // // 로딩 상태 처리 - // if (isLoading) return
Loading...
; - - // // 에러 상태 처리 - // if (isError) return
Error
; - - const categories = [ - '식료품', - '생활용품', - '패션/의류', - '전자제품', - '가구/인테리어', - '유아/아동용품', - '스포츠', - ]; - const popularProduct = { - id: '1', - name: '다이슨 드라이기', - stars: 5, - category: '전자제품', - originalPrice: 95.5, - discountedPrice: 79.98, - description: - '최고의 성능을 가진 드라이기 어쩌구 저쩌구 어쩌구 저쩌구 어쩌구 저쩌구 어쩌구 저쩌구 어쩌구 저쩌구 어쩌구 저쩌구', - image: 'https://via.placeholder.com/200', - comments: [ - { - comment: 'asd', - }, - { - comment: 'asd', - }, - ], - likes: false, - }; - const products = [ - { - id: '1', - name: '다이슨 드라이기', - stars: 5, - originalPrice: 95.5, - discountedPrice: 79.98, - image: 'https://via.placeholder.com/200', - category: '전자제품', - comments: [], - likes: false, - }, - { - id: '2', - name: '에어팟 프로', - stars: 4, - originalPrice: 250.0, - category: '전자제품', - discountedPrice: 199.99, - image: 'https://via.placeholder.com/200', - - comments: [{ comment: '좋아요!' }], - likes: false, - }, - { - id: '3', - name: '샤오미 전기포트', - stars: 4.5, - originalPrice: 50.0, - discountedPrice: 39.99, - image: 'https://via.placeholder.com/200', - category: '전자제품', - comments: [{ comment: '좋은 제품이에요!' }, { comment: '가성비 최고!' }], - likes: false, - }, - { - id: '4', - name: 'LG 모니터', - stars: 4, - originalPrice: 300.0, - discountedPrice: 259.99, - image: 'https://via.placeholder.com/200', - category: '전자제품', - comments: [ - { comment: '화질 좋아요!' }, - { comment: '디자인이 예뻐요!' }, - { comment: '조금 무겁지만 괜찮아요.' }, - ], - likes: false, - }, - { - id: '5', - name: '삼성 TV', - stars: 5, - originalPrice: 1200.0, - discountedPrice: 999.99, - image: 'https://via.placeholder.com/200', - category: '전자제품', - comments: [], - likes: false, - }, - { - id: '6', - name: '닌텐도 스위치', - stars: 4.5, - originalPrice: 350.0, - discountedPrice: 299.99, - image: 'https://via.placeholder.com/200', - category: '전자제품', - comments: [{ comment: '아이들이 너무 좋아해요!' }], - likes: true, - }, - { - id: '7', - name: '스타벅스 아메리카노', - stars: 4.5, - originalPrice: 5.0, - discountedPrice: 4.5, - image: 'https://via.placeholder.com/200', - category: '식료품', - comments: [], - likes: false, - }, - { - id: '8', - name: '캘리포니아 치즈', - stars: 4, - originalPrice: 15.0, - discountedPrice: 12.99, - image: 'https://via.placeholder.com/200', - category: '식료품', - comments: [{ comment: '맛있어요!' }], - likes: false, - }, - { - id: '9', - name: '라면 3개입', - stars: 5, - originalPrice: 3.0, - discountedPrice: 2.5, - image: 'https://via.placeholder.com/200', - category: '식료품', - comments: [ - { comment: '항상 먹는 맛!' }, - { comment: '간편해서 좋아요.' }, - { comment: '가격 대비 최고!' }, - ], - likes: true, - }, - { - id: '10', - name: '소형 청소기', - stars: 4.5, - originalPrice: 120.0, - discountedPrice: 99.99, - image: 'https://via.placeholder.com/200', - category: '생활용품', - comments: [], - likes: true, - }, - { - id: '11', - name: '다용도 걸이', - stars: 4, - originalPrice: 20.0, - discountedPrice: 15.99, - image: 'https://via.placeholder.com/200', - category: '생활용품', - comments: [{ comment: '실용적이에요.' }], - likes: false, - }, - { - id: '12', - name: '스탠드 조명', - stars: 4.5, - originalPrice: 50.0, - discountedPrice: 45.99, - image: 'https://via.placeholder.com/200', - category: '생활용품', - comments: [ - { comment: '조명이 예뻐요.' }, - { comment: '편안한 분위기를 만들어줘요.' }, - ], - likes: false, - }, - { - id: '13', - name: '여성용 티셔츠', - stars: 4.5, - originalPrice: 20.0, - discountedPrice: 16.99, - image: 'https://via.placeholder.com/200', - category: '패션/의류', - comments: [ - { comment: '편안해요.' }, - { comment: '디자인이 마음에 들어요.' }, - { comment: '색상이 예뻐요.' }, - ], - likes: false, - }, - { - id: '14', - name: '남성용 청바지', - stars: 4, - originalPrice: 40.0, - discountedPrice: 35.99, - image: 'https://via.placeholder.com/200', - category: '패션/의류', - comments: [], - likes: false, - }, - { - id: '15', - name: '여성용 핸드백', - stars: 5, - originalPrice: 120.0, - discountedPrice: 99.99, - image: 'https://via.placeholder.com/200', - category: '패션/의류', - comments: [ - { comment: '디자인 최고!' }, - { comment: '가죽이 고급스러워요.' }, - ], - likes: true, - }, - { - id: '16', - name: '삼나무 책상', - stars: 4.5, - originalPrice: 250.0, - discountedPrice: 199.99, - image: 'https://via.placeholder.com/200', - category: '가구/인테리어', - comments: [ - { comment: '튼튼해요.' }, - { comment: '디자인이 멋져요.' }, - { comment: '조립이 쉬워요.' }, - ], - likes: true, - }, - { - id: '17', - name: '라탄 의자', - stars: 4, - originalPrice: 150.0, - discountedPrice: 129.99, - image: 'https://via.placeholder.com/200', - category: '가구/인테리어', - comments: [], - likes: false, - }, - { - id: '18', - name: '스틸 책장', - stars: 4.5, - originalPrice: 120.0, - discountedPrice: 99.99, - image: 'https://via.placeholder.com/200', - category: '가구/인테리어', - comments: [ - { comment: '스타일리시해요.' }, - { comment: '높이가 딱 좋아요.' }, - ], - likes: true, - }, - { - id: '19', - name: '유아용 기저귀', - stars: 5, - originalPrice: 30.0, - discountedPrice: 25.99, - image: 'https://via.placeholder.com/200', - category: '유아/아동용품', - comments: [ - { comment: '아기가 잘 사용해요.' }, - { comment: '흡수력이 좋아요.' }, - { comment: '가격이 저렴해요.' }, - ], - likes: true, - }, - { - id: '20', - name: '유아용 장난감 세트', - stars: 4.5, - originalPrice: 45.0, - discountedPrice: 39.99, - image: 'https://via.placeholder.com/200', - category: '유아/아동용품', - comments: [], - likes: true, - }, - ]; - + // const { data: products, isLoading, isError } = useProductsQuery(); return ( <> + {/* */} @@ -325,6 +28,7 @@ const HomePage: React.FC = () => { + {/* */} ); }; diff --git a/src/components/pages/HomePage/PopularProduct.tsx b/src/components/pages/HomePage/PopularProduct.tsx index 30f25f1..cacf859 100644 --- a/src/components/pages/HomePage/PopularProduct.tsx +++ b/src/components/pages/HomePage/PopularProduct.tsx @@ -14,11 +14,11 @@ const PopularProduct: React.FC = ({ product }) => { - + - + @@ -26,17 +26,7 @@ const PopularProduct: React.FC = ({ product }) => { {product.category} - - {' '} - 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 - 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 - 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 - 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 - 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 - 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 - 상품설명- 추후 추가 예정 상품설명- 추후 추가 예정 상품설명- 추후 - 추가 예정 상품설명- 추후 추가 예정 - + 상품설명- 추후 추가 예정 {/* {product.description} */} diff --git a/src/components/pages/HomePage/RecommendProduct.tsx b/src/components/pages/HomePage/RecommendProduct.tsx index b9e42ae..cc26086 100644 --- a/src/components/pages/HomePage/RecommendProduct.tsx +++ b/src/components/pages/HomePage/RecommendProduct.tsx @@ -14,7 +14,7 @@ const RecommendProduct: React.FC = ({ products }) => { const getTopProducts = (products: Product[]): Product[] => { // comments.length를 기준으로 내림차순 정렬 const sortedByComments = [...products].sort( - (a, b) => b.comments.length - a.comments.length + (a, b) => b.reviews.length - a.reviews.length ); // 상위 8개 선택 return sortedByComments.slice(0, 8); @@ -30,18 +30,18 @@ const RecommendProduct: React.FC = ({ products }) => { {displayedProducts.map((product) => ( - + {product.name} - + ${product.originalPrice.toFixed(2)} - ${product.discountedPrice.toFixed(2)} + ${product.discountPrice.toFixed(2)} diff --git a/src/components/pages/HomePage/api/productApi.ts b/src/components/pages/HomePage/api/productApi.ts index fe9e3dd..129b9ee 100644 --- a/src/components/pages/HomePage/api/productApi.ts +++ b/src/components/pages/HomePage/api/productApi.ts @@ -3,7 +3,7 @@ import { Product } from '../model/productSchema'; export const getProducts = async (): Promise => { try { - const URL = `/products`; + const URL = `/homepage`; const { data } = await axiosInstance.get(URL); return data; } catch { diff --git a/src/components/pages/HomePage/model/productSchema.ts b/src/components/pages/HomePage/model/productSchema.ts index fbdf17c..db4b566 100644 --- a/src/components/pages/HomePage/model/productSchema.ts +++ b/src/components/pages/HomePage/model/productSchema.ts @@ -1,16 +1,20 @@ -interface Comment { - comment: string; +interface Review { + review: string; } export interface Product { - id: string; + id: number; name: string; - stars: number; + rating: number; originalPrice: number; - discountedPrice: number; - image: string; + discountPrice: number; + url: string; category: string; - // description: string; - comments: Comment[]; + minamount: number; + deadline: string; + now: number; + stock: number; + description: string; + reviews: Review[]; likes: boolean; } diff --git a/src/components/pages/Payment/PaymentForm.tsx b/src/components/pages/Payment/PaymentForm.tsx index 6df8fc0..2bb7b78 100644 --- a/src/components/pages/Payment/PaymentForm.tsx +++ b/src/components/pages/Payment/PaymentForm.tsx @@ -1,137 +1,171 @@ -import React from 'react'; +import React, { useState } from 'react'; import { Link, + // useLocation, useNavigate, - // useParams + useParams, } from 'react-router-dom'; import styled from 'styled-components'; import { handlePayment } from './api/paymentApi'; +import { products } from '../../../mocks/products'; +// import { QueryHandler, useProductQuery } from '../../../hooks/useGetProduct'; const PaymentForm = () => { - const product = { - id: '1', - name: '다이슨 드라이기', - stars: 5, - minimum: 5, - now: 3, - stock: 10, - originalPrice: 95.5, - discountedPrice: 79.98, - image: 'https://via.placeholder.com/200', - }; - // const { id } = useParams(); - // if (!id) { - // return

상품 번호가 유실되었습니다.

; - // } - // const { - // data: product, - // isLoading, - // isError, - // } = useQuery({ - // queryKey: ['product', id], - // queryFn: () => getProductbyId(id), - // }); - // // 로딩 상태 처리 - // if (isLoading) { - // return ( - // - // - // 상품 정보 로딩 중... - // - // - // ); - // } - - // // 에러 상태 처리 - // if (isError) { - // return ( - // - // - // 상품 정보를 불러오지 못했습니다. - // 잠시 후 다시 시도해주세요. - // - // - // ); - // } + //URL 쿼리 스트링을 통한 데이터 수신 + // const location = useLocation(); + // const query = new URLSearchParams(location.search); + // const data = query.get('data') || ''; // null일 경우 빈 문자열 반환 + // const product = JSON.parse(decodeURIComponent(data)); + const { id } = useParams(); + if (!id) { + return

상품 번호가 유실되었습니다.

; + } + const productId = Number(id); + // const { data: product, isLoading, isError } = useProductQuery(productId); + const product = products.find((p) => p.id === productId); + if (!product) { + return

해당 상품을 찾을 수 없습니다.

; + } + const navigate = useNavigate(); + const [userName, setName] = useState(''); + const [basicAddress, setBasicAddress] = useState(''); + const [detailAddress, setDetailAddress] = useState(''); + const [needed, setNeeded] = useState(''); + const [payment, setPayment] = useState(''); + const payload = { + productName: product.name, + url: product.url, + price: product.discountPrice, + // amount : product.amount, + finalPrice: product.discountPrice * product.now, + // now를 amount로 + // postId : product.postId, + payMethod: payment, + needed: needed, + name: userName, + address: { + city: basicAddress, + detail: detailAddress, + }, + }; + const handleRadio = (e: React.ChangeEvent) => { + setPayment(e.target.value); + }; const onPaymentSubmit = async () => { try { - await handlePayment(); - navigate('/payment-success'); + const paymentResult = await handlePayment(payload); + if (paymentResult == 'success') { + navigate('/payment-success'); + } } catch (e) { alert(`결제에 실패하였습니다 ${e}`); } }; return ( - -
- 주문 상품 정보 - - - {product.name} - ₩{product.discountedPrice.toLocaleString()} - - - 수량: 1개 - - - 합계: - ₩{product.discountedPrice.toLocaleString()} - - -
- -
- 배송 정보 확인 - - - - - - - - -