Skip to content

Commit

Permalink
買い物かごの中身を出力するコンテナを作成しよう:その2
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yoshiii committed Sep 13, 2022
1 parent a1721c2 commit 602f43d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/components/CartContainer.tsx
@@ -1,9 +1,10 @@
import { Box, Container, Typography } from "@mui/material";
import React from "react";
import { useAppSelector } from "../store";
import { CartItem } from "./CartItem";

const CartContainer = () => {
const { amount } = useAppSelector((store) => store.cart);
const { amount, cartItems } = useAppSelector((store) => store.cart);
if (amount < 1) {
return (
<Container>
Expand All @@ -18,6 +19,20 @@ const CartContainer = () => {
</Container>
);
}
return (
<Container>
<Box sx={{ my: 14 }}>
<Typography variant="h2" gutterBottom>
Cart
</Typography>
<div>
{cartItems.map((item) => {
return <CartItem key={item.id} />;
})}
</div>
</Box>
</Container>
);
};

export default CartContainer;
13 changes: 13 additions & 0 deletions src/components/CartItem.tsx
@@ -0,0 +1,13 @@
import React from "react";
import { Snackbar, Alert, Stack } from "@mui/material";
export const CartItem = () => {
return (
<Stack spacing={2} sx={{ width: "100%" }}>
<Snackbar open>
<Alert severity="success" sx={{ width: "100%" }}>
This is a success message!
</Alert>
</Snackbar>
</Stack>
);
};
6 changes: 3 additions & 3 deletions src/features/cart/CartSlice.ts
Expand Up @@ -10,14 +10,14 @@ interface CartItemState {
amount: number;
}
interface CartState {
cartItem: CartItemState[];
cartItems: CartItemState[];
amount: number;
total: number;
}

const initialState = {
cartItem: cartItems,
amount: 0,
cartItems: cartItems,
amount: 4,
total: 0,
};
const cartSlice = createSlice({
Expand Down

0 comments on commit 602f43d

Please sign in to comment.