Skip to content

Commit 2f5be42

Browse files
committed
Fix mobile checkout page on mobile
1 parent ac47dee commit 2f5be42

File tree

5 files changed

+74
-8
lines changed

5 files changed

+74
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- Pretty URLs with builtin Nextjs functionality
4343
- Tailwind CSS for styling
4444
- JSDoc comments
45+
- WooCommerce cart session is automatically deleted after 48 hours to prevent GraphQL session expiration errors
4546

4647
## TODO
4748

components/Checkout/CheckoutForm.component.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useQuery, useMutation } from '@apollo/react-hooks';
33

44
import Billing from './Billing.component';
55
import OrderDetails from './OrderDetails.component';
6+
import MobileOrderDetails from './MobileOrderDetails.component';
67
import LoadingSpinner from '../LoadingSpinner/LoadingSpinner.component';
78
//import Payment from './Payment.component';
89

@@ -18,7 +19,7 @@ import {
1819

1920
const CheckoutForm = () => {
2021
const [cart, setCart] = useContext(AppContext);
21-
22+
2223
const [orderData, setOrderData] = useState(null);
2324
const [requestError, setRequestError] = useState(null);
2425
const [orderCompleted, setorderCompleted] = useState(false);
@@ -73,10 +74,11 @@ const CheckoutForm = () => {
7374
<div className="container mx-auto">
7475
{/* Order*/}
7576
<OrderDetails cart={cart} />
77+
<MobileOrderDetails cart={cart} />
78+
7679
{/*Payment Details*/}
77-
<div className="">
78-
<Billing onSubmit={onSubmit} />
79-
</div>
80+
<Billing onSubmit={onSubmit} />
81+
8082
{/* Checkout Loading*/}
8183
{checkoutLoading && (
8284
<div className="text-xl text-center">
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { v4 } from 'uuid';
2+
3+
import MobileOrderDetailsItem from './MobileOrderDetailsItem.component';
4+
import CheckoutTitle from 'components/Header/CheckoutTitle.component';
5+
6+
const MobileOrderDetails = ({ cart }) => {
7+
return (
8+
<section className="block py-8 bg-white lg:hidden xl:hidden md:hidden">
9+
<div className="flex items-center justify-center">
10+
<div className="p-6 mx-auto mt-5">
11+
<CheckoutTitle title="Din Ordre" />
12+
<table className="flex flex-row flex-no-wrap mx-auto my-5 overflow-hidden rounded-lg sm:bg-white sm:shadow-lg">
13+
<thead className="text-black">
14+
{cart.products.length &&
15+
cart.products.map(() => (
16+
<tr
17+
key={v4()}
18+
className="flex flex-col mb-2 bg-white rounded-l-lg flex-no wrap sm:table-row sm:rounded-none sm:mb-0"
19+
>
20+
<th className="p-3 text-left">Navn</th>
21+
<th className="p-3 text-left">Pris</th>
22+
<th className="p-3 text-left">Antall</th>
23+
<th className="p-3 text-left">Totalpris</th>
24+
</tr>
25+
))}
26+
</thead>
27+
<tbody className="flex-1 sm:flex-none">
28+
{cart.products.length &&
29+
cart.products.map((item) => (
30+
<MobileOrderDetailsItem
31+
key={item.productId}
32+
item={item}
33+
products={cart.products}
34+
/>
35+
))}
36+
</tbody>
37+
</table>
38+
</div>
39+
</div>
40+
</section>
41+
);
42+
};
43+
44+
export default MobileOrderDetails;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const MobileOrderDetailsCartItem = ({ item }) => (
2+
<>
3+
<tr className="flex flex-col mb-2 flex-no wrap sm:table-row sm:mb-0">
4+
5+
<td className="h-12 p-3">{item.name}</td>
6+
<td className="h-12 p-3">
7+
kr{'string' !== typeof item.price ? item.price.toFixed(2) : item.price}
8+
</td>
9+
<td className="h-12 p-3">{item.qty}</td>
10+
<td className="h-12 p-3">
11+
{'string' !== typeof item.totalPrice
12+
? item.totalPrice.toFixed(2)
13+
: item.totalPrice}
14+
</td>
15+
</tr>
16+
</>
17+
);
18+
19+
export default MobileOrderDetailsCartItem;

components/Checkout/OrderDetails.component.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import OrderDetailsCartItem from './OrderDetailsCartItem.component';
44
const OrderDetails = ({ cart }) => {
55
return (
66
<>
7-
<section className="py-8 bg-white">
7+
<section className="hidden py-8 bg-white xs:hidden md:block lg:block xl:block">
88
<div className="container flex flex-wrap items-center mx-auto">
99
{cart ? (
1010
<div className="p-6 mx-auto mt-5">
11-
<CheckoutTitle title="Handlekurv" />
11+
<CheckoutTitle title="Din Ordre" />
1212
<table className="table-auto">
1313
<thead>
14-
<tr>
14+
<tr>
1515
<th className="px-4 py-2" scope="col" />
1616
<th className="px-4 py-2" scope="col">
1717
Produkt
@@ -33,7 +33,7 @@ const OrderDetails = ({ cart }) => {
3333
<OrderDetailsCartItem
3434
key={item.productId}
3535
item={item}
36-
products={cart.products}
36+
products={cart.products}
3737
/>
3838
))}
3939
</tbody>

0 commit comments

Comments
 (0)