-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3350b05
commit 2586fc3
Showing
7 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from "react"; | ||
import Image from "next/image"; | ||
import { LineItem } from "shopify-buy"; | ||
|
||
type Props = { | ||
item: any; | ||
}; | ||
|
||
const CartItemRow: React.FC<Props> = ({ item }) => { | ||
console.log("CartItemRow rendered"); | ||
console.log(JSON.stringify(item)); | ||
const { handle, quantity, title } = item; | ||
const price = Number(item.variant.price); | ||
const subtotal = price * quantity; | ||
const imgSrc = item.variant.image.src; | ||
|
||
return ( | ||
<tr> | ||
<td> | ||
<figure style={{ margin: 0 }}> | ||
<a href={`/products/${handle}`}> | ||
<Image priority src={imgSrc} height={150} width={150} /> | ||
</a> | ||
</figure> | ||
{title} | ||
</td> | ||
<td>¥{price.toLocaleString("ja-JP")}</td> | ||
<td>{quantity}</td> | ||
<td>¥{subtotal.toLocaleString("ja-JP")}</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default CartItemRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useContext } from "react"; | ||
import { CheckoutContext } from "pages/cart"; | ||
import CartItemRow from "components/cart/CartItemRow"; | ||
|
||
const CartItemTable = () => { | ||
console.log("CartItemTable rendered"); | ||
|
||
const checkout = useContext(CheckoutContext); | ||
console.log(checkout?.lineItems?.length); | ||
|
||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>商品名</th> | ||
<th>価格</th> | ||
<th>数量</th> | ||
<th>合計</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{checkout?.lineItems?.map((item, idx) => ( | ||
<CartItemRow item={item} key={idx} /> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
export default CartItemTable; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,60 @@ | ||
import React from "react"; | ||
import React, { createContext } from "react"; | ||
import { GetServerSideProps } from "next"; | ||
import { Cart } from "shopify-buy"; | ||
import { CircularProgress } from "@material-ui/core"; | ||
import Layout from "components/common/Layout"; | ||
import CartItemTable from "components/cart/CartItemTable"; | ||
import useCheckout from 'lib/useCheckout'; | ||
|
||
const Cart: React.FC = () => <div>カートページです</div>; | ||
export const CheckoutContext = createContext<Cart | null>(null); | ||
|
||
export default Cart; | ||
const CartPage: React.FC = () => { | ||
|
||
const { checkout } = useCheckout(); | ||
|
||
return ( | ||
<CheckoutContext.Provider value={checkout}> | ||
<Layout> | ||
<article className="collections-all"> | ||
<header> | ||
<h1 className="font-semibold mb-9 md:mb-14 text-center text-gray-700 text-4xl"> | ||
ショッピングカート | ||
</h1> | ||
</header> | ||
<section> | ||
<div className="container"> | ||
{checkout ? ( | ||
checkout.lineItems.length > 0 ? ( | ||
<CartItemTable /> | ||
) : ( | ||
<> | ||
<div>カート内に商品がありません</div> | ||
<div> | ||
<a | ||
className="bg-gray-700 flex-grow inline-block px-4 py-3 text-sm text-white" | ||
href="/collections/all" | ||
> | ||
買い物を続ける | ||
</a> | ||
</div> | ||
</> | ||
) | ||
) : ( | ||
<div className="flex items-center justify-center"> | ||
<CircularProgress | ||
classes={{ svg: "font-bold text-gray-400" }} | ||
size="1.25rem" | ||
thickness={6} | ||
/> | ||
</div> | ||
)} | ||
{} | ||
</div> | ||
</section> | ||
</article> | ||
</Layout> | ||
</CheckoutContext.Provider> | ||
); | ||
}; | ||
|
||
export default CartPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters