Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c4b75c5
remove: 리코일 제거
Seoin02 Aug 4, 2024
1e8ee4d
chore: 리덕스, 리덕스 툴킷 설치?
Seoin02 Aug 4, 2024
4c40e28
remove: 리코일로직 제거
Seoin02 Aug 4, 2024
415ba05
chore: 리덕스, 리덕스 툴킷 추가 설치
Seoin02 Aug 4, 2024
7f97493
feat: store.ts 파일 생성
Seoin02 Aug 4, 2024
c978542
feat: cartSlice 생성
Seoin02 Aug 4, 2024
cd268d5
feat: Redux 스토어 설정
Seoin02 Aug 4, 2024
f084baa
remove: 불필요한 코드 제거
Seoin02 Aug 4, 2024
1532369
refactor: 상품 api 로직 정리
Seoin02 Aug 4, 2024
cba8b0d
refactor: 상품 뷰 로직 수정
Seoin02 Aug 4, 2024
82f7430
remove: 불필요한 recoil 코드 제거
Seoin02 Aug 4, 2024
b4f808d
feat: 상품 상세 페이지 장바구니 담기 로직 추가
Seoin02 Aug 4, 2024
310f3d6
feat: 카트 store type 지정
Seoin02 Aug 4, 2024
61b2c76
refactor: 장바구니 담는 item 타입 수정
Seoin02 Aug 5, 2024
b4657c4
feat: 상품 담은 cart 뷰 구현
Seoin02 Aug 5, 2024
81a4a90
feat: 로컬 스토리지 동기화
Seoin02 Aug 5, 2024
6ce718a
design: 상품 담은 cart 뷰 css 적용
Seoin02 Aug 5, 2024
900f6cb
feat: 장바구니 총액 로컬 스토리지 저장
Seoin02 Aug 5, 2024
850399f
feat: 장바구니 수량 조절 액션 함수 내보내기
Seoin02 Aug 5, 2024
62ea7da
design: 장바구니 상품 담긴 뷰 css 수정
Seoin02 Aug 5, 2024
7862975
feat: nav바 장바구니 수량 표시 구현
Seoin02 Aug 5, 2024
7dde88c
refactor: 불필요한 코드 제거
Seoin02 Aug 5, 2024
b4d832d
style: 카트 리스트 컴포넌트 분리
Seoin02 Aug 5, 2024
0babd69
style: 달러 표기 유틸 함수 적용
Seoin02 Aug 5, 2024
eb6d3f8
design: nav바 카트 css 수정
Seoin02 Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions api/fetchProductsData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { AxiosRequestConfig } from "axios";
import { useQuery } from "@tanstack/react-query";
import { axiosInstance } from "./../src/utils/axiosInstance";

export interface IProduct {
readonly id: number;
readonly title: string;
readonly description: string;
readonly category: string;
readonly price: number;
readonly image: string;
readonly rating: IRating;
}

export interface Item extends AxiosRequestConfig {
id: number;
title: string;
Expand All @@ -10,13 +21,18 @@ export interface Item extends AxiosRequestConfig {
image: string;
}

const fetchProductsData = async () => {
try {
const res = await axiosInstance.get("products");
return res.data;
} catch (error) {
throw new Error(`"Error fetching data:", ${error}`);
}
interface IRating {
readonly rate?: number;
readonly count?: number;
}

const fetchProductsData = async (): Promise<IProduct[]> => {
const response = await axiosInstance.get("products");
return response.data;
};

export const useProducts = () => {
return useQuery<IProduct[]>({ queryKey: ["products"], queryFn: fetchProductsData });
};

export default fetchProductsData;
128 changes: 91 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
"react-dom": "^18.2.0",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.11.2",
"recoil": "^0.7.7",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.4",
"vite": "^4.3.9"
},
"dependencies": {
"@reduxjs/toolkit": "^2.2.7",
"@tanstack/react-query": "^5.37.1",
"@tanstack/react-query-devtools": "^5.37.1",
"@vercel/node": "^2.15.10",
"axios": "^1.6.8"
"axios": "^1.6.8",
"react-redux": "^9.1.2",
"redux": "^5.0.1"
}
}
8 changes: 0 additions & 8 deletions src/atom.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/components/cart/CartList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useDispatch, useSelector } from "react-redux";
import { AppDispatch, RootState } from "../../store";
import { increaseItemCount, decreaseItemCount } from "../../store/cart";
import { toCurrencyFormat } from "../../utils/toCurrencyFormat";

const CartList = (): JSX.Element => {
const dispatch: AppDispatch = useDispatch();
const { items, totalAmount } = useSelector((state: RootState) => state.cart);

const handleAddCount = (id: number) => {
dispatch(increaseItemCount(id));
};

const handleDecreaseCount = (id: number) => {
dispatch(decreaseItemCount(id));
};

return (
<div className="lg:flex lg:items-center mt-4 px-2 lg:px-0">
<div className="mt-6 md:mt-14 px-2 lg:px-0 lg:flex">
<ul>
{items.map((item) => (
<div key={item.id} className="lg:flex lg:items-center mt-4 px-2 lg:px-0">
<figure className="w-10% flex-shrink-0 rounded-2xl overflow-hidden px-4 py-4 bg-white flex justify-center">
<img src={item.image} alt={item.title} className="transition-transform duration-300 w-28" />
</figure>
<div className="card-body px-1 lg:px-12">
<h2 className="card-title">{item.title}</h2>
<br />
<span className="mt-2 mb-4 text-3xl">{toCurrencyFormat(item.price)}</span>
<br />
<div className="card-actions">
<button className="btn btn-primary" onClick={() => handleDecreaseCount(item.id)}>
-
</button>
<button className="btn btn-ghost no-animation">{item.count}</button>
<button className="btn btn-primary" onClick={() => handleAddCount(item.id)}>
+
</button>
</div>
</div>
</div>
))}
</ul>
<div className="self-start shrink-0 flex items-center mt-10 mb-20">
<span className="text-xl md:text-2xl">총: {toCurrencyFormat(totalAmount)}</span>
<button className="modal-button btn btn-primary ml-5">구매하기</button>
</div>
</div>
</div>
);
};

export default CartList;
31 changes: 31 additions & 0 deletions src/components/cart/CartView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Link } from "react-router-dom";
import { useSelector } from "react-redux";
import BreadCrumb from "../common/Breadcrumb";
import Confirm from "../common/Confirm";
import { RootState } from "../../store";
import CartList from "./CartList";

const CartView = (): JSX.Element => {
const { items } = useSelector((state: RootState) => state.cart);

return (
<section className="pt-4 lg:pt-5 pb-4 lg:pb-8 px-4 xl:px-2 xl:container mx-auto">
<BreadCrumb category="홈" crumb="장바구니" />
<div className="mt-6 md:mt-14 px-2 lg:px-0">
{!items.length ? (
<div>
<h1 className="text-2xl">장바구니에 물품이 없습니다.</h1>
<Link to="/" className="btn btn-primary mt-10">
담으러 가기
</Link>
</div>
) : (
<CartList />
)}
</div>
<Confirm />
</section>
);
};

export default CartView;
19 changes: 0 additions & 19 deletions src/components/carts/CartList.tsx

This file was deleted.

Loading