Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12팀 배성규] [Chapter 2-2] 디자인 패턴과 함수형 프로그래밍 #6

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"eslint": "^9.12.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.12",
"jsdom": "^26.0.0",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vitest": "^2.1.3"
Expand Down
393 changes: 355 additions & 38 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

297 changes: 163 additions & 134 deletions src/advanced/__tests__/advanced.test.tsx

Large diffs are not rendered by default.

195 changes: 147 additions & 48 deletions src/origin/components/AdminPage.tsx

Large diffs are not rendered by default.

66 changes: 9 additions & 57 deletions src/refactoring/App.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,18 @@
import { useState } from 'react';
import { CartPage } from './components/CartPage.tsx';
import { AdminPage } from './components/AdminPage.tsx';
import { Coupon, Product } from '../types.ts';
import { useCoupons, useProducts } from "./hooks";

const initialProducts: Product[] = [
{
id: 'p1',
name: '상품1',
price: 10000,
stock: 20,
discounts: [{ quantity: 10, rate: 0.1 }, { quantity: 20, rate: 0.2 }]
},
{
id: 'p2',
name: '상품2',
price: 20000,
stock: 20,
discounts: [{ quantity: 10, rate: 0.15 }]
},
{
id: 'p3',
name: '상품3',
price: 30000,
stock: 20,
discounts: [{ quantity: 10, rate: 0.2 }]
}
];

const initialCoupons: Coupon[] = [
{
name: '5000원 할인 쿠폰',
code: 'AMOUNT5000',
discountType: 'amount',
discountValue: 5000
},
{
name: '10% 할인 쿠폰',
code: 'PERCENT10',
discountType: 'percentage',
discountValue: 10
}
];
import { CartPage } from "./components/CartPage.tsx";
import { AdminPage } from "./components/AdminPage.tsx";
import { useCoupons, useProducts, useToggle } from "./hooks";
import { initialProducts } from "./mock/products.ts";
import { initialCoupons } from "./mock/coupons.ts";
import NavBar from "./components/NavBar.tsx";

const App = () => {
const { products, updateProduct, addProduct } = useProducts(initialProducts);
const { coupons, addCoupon } = useCoupons(initialCoupons);
const [isAdmin, setIsAdmin] = useState(false);
const [isAdmin, toggleIsAdmin] = useToggle(false);

return (
<div className="min-h-screen bg-gray-100">
<nav className="bg-blue-600 text-white p-4">
<div className="container mx-auto flex justify-between items-center">
<h1 className="text-2xl font-bold">쇼핑몰 관리 시스템</h1>
<button
onClick={() => setIsAdmin(!isAdmin)}
className="bg-white text-blue-600 px-4 py-2 rounded hover:bg-blue-100"
>
{isAdmin ? '장바구니 페이지로' : '관리자 페이지로'}
</button>
</div>
</nav>
<NavBar isAdmin={isAdmin} onToggle={toggleIsAdmin} />
<main className="container mx-auto mt-6">
{isAdmin ? (
<AdminPage
Expand All @@ -71,7 +23,7 @@ const App = () => {
onCouponAdd={addCoupon}
/>
) : (
<CartPage products={products} coupons={coupons}/>
<CartPage products={products} coupons={coupons} />
)}
</main>
</div>
Expand Down
Loading
Loading