-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.tsx
36 lines (34 loc) · 1.03 KB
/
cart.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { secure, useDelete, useGet, useTranslation, withLayout } from 'onekijs-next';
import React from 'react';
import { CartResponse } from '../../data/dto/cart';
import Cart from '../modules/core/components/Cart';
import AppLayout from '../modules/core/layouts/AppLayout';
import { URL_CART } from '../modules/core/libs/constants';
const CartPage: React.FC = () => {
const [T, t] = useTranslation();
const [cart, loading, refresh] = useGet<CartResponse>(URL_CART);
const [deleleCart] = useDelete(URL_CART, {
onSuccess: () => {
refresh();
},
onError: (error) => {
window.alert(`${t('An error occured while cleaning the cart')}: ${error.message}`);
},
});
return (
<div>
{loading && (
<p>
<T>Loading</T> ...
</p>
)}
<div>
<button className="button" onClick={() => deleleCart()}>
<T>Empty the cart</T>
</button>
</div>
{cart && <Cart cart={cart} />}
</div>
);
};
export default secure(withLayout(CartPage, AppLayout));