Skip to content

Commit 2dba0aa

Browse files
authored
Npm update packages and add Woocommerce session expiration
Npm update packages and add Woocommerce session expiration
2 parents 41ee07e + 38b09d5 commit 2dba0aa

File tree

10 files changed

+139
-145
lines changed

10 files changed

+139
-145
lines changed

components/Cart/AddToCartButton.component.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useState, useContext } from 'react';
22
import { request } from 'graphql-request';
3-
import useSWR from 'swr';
3+
44
import { v4 as uuidv4 } from 'uuid';
55

66
import { useQuery, useMutation } from '@apollo/react-hooks';
@@ -87,7 +87,7 @@ const AddToCartButton = (props) => {
8787
return (
8888
<>
8989
<button
90-
onClick={() => handleAddToCartClick()}
90+
onClick={handleAddToCartClick}
9191
className="px-4 py-2 font-bold bg-white border border-gray-400 border-solid rounded hover:bg-gray-400"
9292
>
9393
KJØP

package-lock.json

Lines changed: 103 additions & 118 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-woocommerce",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
@@ -13,24 +13,23 @@
1313
"license": "ISC",
1414
"dependencies": {
1515
"@apollo/react-hooks": "^3.1.5",
16-
"algoliasearch": "^4.2.0",
16+
"algoliasearch": "^4.3.0",
1717
"apollo-boost": "^0.4.9",
1818
"apollo-cache-inmemory": "^1.6.6",
1919
"apollo-client": "^2.6.10",
2020
"apollo-link": "^1.2.14",
2121
"apollo-link-error": "^1.1.13",
2222
"apollo-link-http": "^1.5.17",
23-
"graphql": "^15.1.0",
23+
"graphql": "^15.2.0",
2424
"graphql-request": "^2.0.0",
2525
"graphql-tag": "^2.10.3",
2626
"next": "^9.4.4",
2727
"react": "^16.13.1",
2828
"react-dom": "^16.13.1",
29-
"react-instantsearch-dom": "^6.5.0",
29+
"react-instantsearch-dom": "^6.6.0",
3030
"react-spring": "^8.0.27",
3131
"styled-components": "^5.1.1",
32-
"swr": "^0.2.2",
33-
"uuid": "^8.1.0"
32+
"uuid": "^8.2.0"
3433
},
3534
"devDependencies": {
3635
"babel-plugin-styled-components": "^1.10.7",

pages/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ const HomePage = ({ products }) => {
2424
export default HomePage;
2525

2626
export async function getStaticProps() {
27-
//export async function getServerSideProps() {
28-
2927
const { data, loading, networkStatus } = await client.query({
3028
query: FETCH_ALL_PRODUCTS_QUERY,
3129
});
@@ -36,6 +34,6 @@ export async function getStaticProps() {
3634
loading: loading,
3735
networkStatus: networkStatus,
3836
},
39-
unstable_revalidate: 5,
37+
unstable_revalidate: 10,
4038
};
4139
}

pages/kasse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import PageTitle from 'components/Header/PageTitle.component';
22
import CheckoutForm from 'components/Checkout/CheckoutForm.component';
33

4-
const Handlekurv = () => (
4+
const Kasse = () => (
55
<>
66
<PageTitle title="Kasse" />
77
<CheckoutForm />
88
</>
99
);
10-
export default Handlekurv;
10+
export default Kasse;

pages/kategorier.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export async function getStaticProps() {
4747
props: {
4848
categories: result.data.productCategories.nodes,
4949
},
50+
unstable_revalidate: 10,
5051
};
5152
}

pages/produkt/[slug].js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { request } from 'graphql-request';
2-
import useSWR from 'swr';
32
import { withRouter } from 'next/router';
43

54
import SingleProduct from 'components/Product/SingleProduct.component';

pages/produkter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ export async function getStaticProps() {
5050
props: {
5151
products: result.data.products.nodes,
5252
},
53+
unstable_revalidate: 10,
5354
};
5455
}

utils/apollo/ApolloClient.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ export const middleware = new ApolloLink((operation, forward) => {
2323
* If session data exist in local storage, set value as session header.
2424
*/
2525
const session = process.browser ? localStorage.getItem('woo-session') : null;
26+
const sessionAge = process.browser
27+
? localStorage.getItem('woo-session-expiry')
28+
: null;
29+
30+
const oneDay = 60 * 60 * 24 * 1000;
31+
const olderThan24h = new Date() - sessionAge > oneDay;
32+
if (olderThan24h && process.browser) {
33+
localStorage.removeItem('woo-session');
34+
localStorage.removeItem('woo-session-expiry');
35+
}
2636

2737
if (session) {
2838
operation.setContext(({ headers = {} }) => ({
@@ -59,6 +69,7 @@ export const afterware = new ApolloLink((operation, forward) => {
5969
// Update session new data if changed.
6070
} else if (localStorage.getItem('woo-session') !== session) {
6171
localStorage.setItem('woo-session', headers.get('woocommerce-session'));
72+
localStorage.setItem('woo-session-expiry', new Date());
6273
}
6374
}
6475
return response;

utils/const/GQL_MUTATIONS.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ export const ADD_TO_CART = gql`
6262
`;
6363

6464
export const CHECKOUT_MUTATION = gql`
65-
mutation CHECKOUT_MUTATION( $input: CheckoutInput! ) {
66-
checkout(input: $input) {
67-
clientMutationId
68-
order {
69-
id
70-
orderId
71-
refunds {
72-
nodes {
73-
amount
65+
mutation CHECKOUT_MUTATION($input: CheckoutInput!) {
66+
checkout(input: $input) {
67+
clientMutationId
68+
order {
69+
id
70+
orderId
71+
refunds {
72+
nodes {
73+
amount
74+
}
7475
}
76+
status
7577
}
76-
status
78+
result
79+
redirect
7780
}
78-
result
79-
redirect
8081
}
81-
}
8282
`;

0 commit comments

Comments
 (0)