forked from hygraph/gatsby-graphcms-ecommerce-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-browser.js
56 lines (49 loc) · 1.41 KB
/
gatsby-browser.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'isomorphic-fetch';
import 'react-toastify/dist/ReactToastify.css';
import React from 'react';
import { CartProvider } from 'react-use-cart';
import { GraphQLClient, ClientContext } from 'graphql-hooks';
import { ToastContainer } from 'react-toastify';
import StripeProvider from './src/components/StripeProvider';
import Layout from './src/components/Layout';
import {
handleItemAdded,
handleItemUpdated,
handleItemRemoved,
} from './src/utils/cart-helpers';
const toastOptions = {
position: 'top-right',
draggable: false,
toastClassName:
'bg-primary text-white text-center px-2 py-3 shadow-none rounded-lg',
progressClassName: 'h-0',
closeButton: false,
autoClose: 2000,
};
const client = new GraphQLClient({
url: '/.netlify/functions/graphql',
});
const randomCartId = () =>
Math.random()
.toString(36)
.substring(7);
export const wrapPageElement = ({ element, props }) => {
return <Layout {...props}>{element}</Layout>;
};
export const wrapRootElement = ({ element }) => {
return (
<StripeProvider>
<ClientContext.Provider value={client}>
<CartProvider
id={randomCartId()}
onItemAdd={handleItemAdded}
onItemUpdate={handleItemUpdated}
onItemRemove={handleItemRemoved}
>
{element}
</CartProvider>
<ToastContainer {...toastOptions} />
</ClientContext.Provider>
</StripeProvider>
);
};