From 962799259d34b6c4bb6b853b52b5fd4b96dc1f43 Mon Sep 17 00:00:00 2001
From: w3bdesign <45217974+w3bdesign@users.noreply.github.com>
Date: Wed, 2 Feb 2022 22:13:52 +0100
Subject: [PATCH 1/4] Refactor
---
components/SVG/SVGCloseX.component.jsx | 104 ++++++++++++-------------
components/SVG/SVGX.component.jsx | 46 +++++------
pages/_app.js | 20 ++---
pages/handlekurv.js | 16 ++--
pages/index.js | 18 ++---
5 files changed, 94 insertions(+), 110 deletions(-)
diff --git a/components/SVG/SVGCloseX.component.jsx b/components/SVG/SVGCloseX.component.jsx
index 61cddc3ad..5661f92ff 100644
--- a/components/SVG/SVGCloseX.component.jsx
+++ b/components/SVG/SVGCloseX.component.jsx
@@ -1,59 +1,55 @@
/**
* The SVG that we display to close the cart or the mobile search
*/
-const SVGCloseX = ({ setisExpanded }) => {
- return (
- <>
-
- >
- );
-};
+const SVGCloseX = ({ setisExpanded }) => (
+
+);
export default SVGCloseX;
diff --git a/components/SVG/SVGX.component.jsx b/components/SVG/SVGX.component.jsx
index 44e456f4c..0b3bf366c 100644
--- a/components/SVG/SVGX.component.jsx
+++ b/components/SVG/SVGX.component.jsx
@@ -2,30 +2,26 @@
* The SVG that we display inside of the cart to remove items
*/
-const SVGX = ({ cartKey, products, handleRemoveProductClick }) => {
- return (
- <>
-
- >
- );
-};
+const SVGX = ({ cartKey, products, handleRemoveProductClick }) => (
+
+);
export default SVGX;
diff --git a/pages/_app.js b/pages/_app.js
index e86a7baa5..b5997013f 100644
--- a/pages/_app.js
+++ b/pages/_app.js
@@ -16,17 +16,13 @@ Router.events.on('routeChangeStart', () => NProgress.start());
Router.events.on('routeChangeComplete', () => NProgress.done());
Router.events.on('routeChangeError', () => NProgress.done());
-const App = ({ Component, pageProps }) => {
- return (
- <>
-
-
-
-
-
-
- >
- );
-};
+const App = ({ Component, pageProps }) => (
+
+
+
+
+
+
+);
export default App;
diff --git a/pages/handlekurv.js b/pages/handlekurv.js
index 62037e2d0..15f6f44a6 100644
--- a/pages/handlekurv.js
+++ b/pages/handlekurv.js
@@ -2,14 +2,12 @@ import Header from 'components/Header/Header.component';
import CartItemsContainer from 'components/Cart/CartPage/CartItemsContainer.component';
import PageTitle from 'components/Title/PageTitle.component';
-const Handlekurv = () => {
- return (
- <>
-
-
-
- >
- );
-};
+const Handlekurv = () => (
+ <>
+
+
+
+ >
+);
export default Handlekurv;
diff --git a/pages/index.js b/pages/index.js
index 21c0d0a8b..9ee7a168b 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -12,16 +12,14 @@ import { FETCH_ALL_PRODUCTS_QUERY } from 'utils/gql/GQL_QUERIES';
* @param {Object} products
* Initial static data is sent as props from getStaticProps and loaded through 'utils/gql/INITIAL_PRODUCTS'
*/
-const HomePage = ({ products }) => {
- return (
- <>
-
-
-
- {products && }
- >
- );
-};
+const HomePage = ({ products }) => (
+ <>
+
+
+
+ {products && }
+ >
+);
export default HomePage;
From 1b558f2446147e50502aeec36ca1196072395283 Mon Sep 17 00:00:00 2001
From: w3bdesign <45217974+w3bdesign@users.noreply.github.com>
Date: Wed, 2 Feb 2022 22:16:33 +0100
Subject: [PATCH 2/4] Refactor
---
pages/kategori/[slug].js | 2 +-
pages/produkt/[slug].js | 2 +-
utils/constants/LINKS.js | 1 -
utils/functions/functions.js | 2 +-
4 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/pages/kategori/[slug].js b/pages/kategori/[slug].js
index 4f4192494..bf0bce4c5 100644
--- a/pages/kategori/[slug].js
+++ b/pages/kategori/[slug].js
@@ -12,7 +12,7 @@ import { GET_PRODUCTS_FROM_CATEGORY } from 'utils/gql/GQL_QUERIES';
* Display a single product with dynamic pretty urls
*/
const Produkt = ({ categoryName, products }) => {
- let error = false;
+ const error = false;
return (
<>
diff --git a/pages/produkt/[slug].js b/pages/produkt/[slug].js
index 31ed848ab..dc9420f94 100644
--- a/pages/produkt/[slug].js
+++ b/pages/produkt/[slug].js
@@ -11,7 +11,7 @@ import { GET_SINGLE_PRODUCT } from 'utils/gql/GQL_QUERIES';
* Display a single product with dynamic pretty urls
*/
const Produkt = ({ product }) => {
- let error = false;
+ const error = false;
return (
<>
diff --git a/utils/constants/LINKS.js b/utils/constants/LINKS.js
index 7020f9dfe..0500010a0 100644
--- a/utils/constants/LINKS.js
+++ b/utils/constants/LINKS.js
@@ -1,4 +1,3 @@
-//exports.default = [
const LINKS = [
{
id: 0,
diff --git a/utils/functions/functions.js b/utils/functions/functions.js
index 60ace7bc1..4bb6a901a 100644
--- a/utils/functions/functions.js
+++ b/utils/functions/functions.js
@@ -10,7 +10,7 @@ import WOO_CONFIG from 'utils/config/nextConfig';
export const trimmedStringToLength = (string, length) => {
if (string.length > length) {
const subStr = string.substring(0, length);
- return subStr + '...';
+ return `${subStr}...`;
}
return string;
};
From d64c926358288fb5b3c382f2e167ee89fd8dac25 Mon Sep 17 00:00:00 2001
From: w3bdesign <45217974+w3bdesign@users.noreply.github.com>
Date: Wed, 2 Feb 2022 22:17:45 +0100
Subject: [PATCH 3/4] Refactor
---
utils/apollo/ApolloClient.js | 42 +++++++++++++++++-------------------
1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/utils/apollo/ApolloClient.js b/utils/apollo/ApolloClient.js
index f0c3df2d3..d53280700 100644
--- a/utils/apollo/ApolloClient.js
+++ b/utils/apollo/ApolloClient.js
@@ -45,31 +45,29 @@ export const middleware = new ApolloLink((operation, forward) => {
*
* This catches the incoming session token and stores it in localStorage, for future GraphQL requests.
*/
-export const afterware = new ApolloLink((operation, forward) => {
- return forward(operation).map((response) => {
- /**
- * Check for session header and update session in local storage accordingly.
- */
- const context = operation.getContext();
- const {
- response: { headers },
- } = context;
+export const afterware = new ApolloLink((operation, forward) => forward(operation).map((response) => {
+ /**
+ * Check for session header and update session in local storage accordingly.
+ */
+ const context = operation.getContext();
+ const {
+ response: { headers },
+ } = context;
- const session = headers.get('woocommerce-session');
+ const session = headers.get('woocommerce-session');
- if (session && process.browser) {
- // Remove session data if session destroyed.
- if ('false' === session) {
- localStorage.removeItem('woo-session');
- // Update session new data if changed.
- } else if (localStorage.getItem('woo-session') !== session) {
- localStorage.setItem('woo-session', headers.get('woocommerce-session'));
- localStorage.setItem('woo-session-expiry', new Date());
- }
+ if (session && process.browser) {
+ // Remove session data if session destroyed.
+ if ('false' === session) {
+ localStorage.removeItem('woo-session');
+ // Update session new data if changed.
+ } else if (localStorage.getItem('woo-session') !== session) {
+ localStorage.setItem('woo-session', headers.get('woocommerce-session'));
+ localStorage.setItem('woo-session-expiry', new Date());
}
- return response;
- });
-});
+ }
+ return response;
+}));
const clientSide = typeof window === 'undefined';
From 43f66142a415c1f46be98daad2a12c8be917f56d Mon Sep 17 00:00:00 2001
From: w3bdesign <45217974+w3bdesign@users.noreply.github.com>
Date: Wed, 2 Feb 2022 22:20:07 +0100
Subject: [PATCH 4/4] Refactor
---
utils/functions/functions.js | 93 +++++++++++++++++-------------------
1 file changed, 44 insertions(+), 49 deletions(-)
diff --git a/utils/functions/functions.js b/utils/functions/functions.js
index 4bb6a901a..26600c22a 100644
--- a/utils/functions/functions.js
+++ b/utils/functions/functions.js
@@ -70,66 +70,61 @@ export const getFormattedCart = (data) => {
product.price = convertedCurrency / product.qty;
product.totalPrice = givenProducts[parseInt(i, 10)].total;
// Ensure we can add products without images to the cart
- if (givenProduct.image) {
- product.image = {
- sourceUrl: givenProduct.image.sourceUrl,
- srcSet: givenProduct.image.srcSet,
- title: givenProduct.image.title,
- };
- } else {
- product.image = {
- sourceUrl: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
- srcSet: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
- title: givenProduct.name,
- };
- }
+ product.image = givenProduct.image
+ ? {
+ sourceUrl: givenProduct.image.sourceUrl,
+ srcSet: givenProduct.image.srcSet,
+ title: givenProduct.image.title,
+ }
+ : {
+ sourceUrl: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
+ srcSet: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
+ title: givenProduct.name,
+ };
totalProductsCount += givenProducts[parseInt(i, 10)].quantity;
// Push each item into the products array.
formattedCart.products.push(product);
i++;
});
-
formattedCart.totalProductsCount = totalProductsCount;
formattedCart.totalProductsPrice = data.cart.total;
return formattedCart;
};
-export const createCheckoutData = (order) => {
- return {
- clientMutationId: uuidv4(),
- billing: {
- firstName: order.firstName,
- lastName: order.lastName,
- address1: order.address1,
- address2: order.address2,
- city: order.city,
- country: order.country,
- state: order.state,
- postcode: order.postcode,
- email: order.email,
- phone: order.phone,
- company: order.company,
- },
- shipping: {
- firstName: order.firstName,
- lastName: order.lastName,
- address1: order.address1,
- address2: order.address2,
- city: order.city,
- country: order.country,
- state: order.state,
- postcode: order.postcode,
- email: order.email,
- phone: order.phone,
- company: order.company,
- },
- shipToDifferentAddress: false,
- paymentMethod: order.paymentMethod,
- isPaid: false,
- transactionId: 'hjkhjkhsdsdiui',
- };
-};
+export const createCheckoutData = (order) => ({
+ clientMutationId: uuidv4(),
+ billing: {
+ firstName: order.firstName,
+ lastName: order.lastName,
+ address1: order.address1,
+ address2: order.address2,
+ city: order.city,
+ country: order.country,
+ state: order.state,
+ postcode: order.postcode,
+ email: order.email,
+ phone: order.phone,
+ company: order.company,
+ },
+ shipping: {
+ firstName: order.firstName,
+ lastName: order.lastName,
+ address1: order.address1,
+ address2: order.address2,
+ city: order.city,
+ country: order.country,
+ state: order.state,
+ postcode: order.postcode,
+ email: order.email,
+ phone: order.phone,
+ company: order.company,
+ },
+ shipToDifferentAddress: false,
+ paymentMethod: order.paymentMethod,
+ isPaid: false,
+ transactionId: 'hjkhjkhsdsdiui',
+});
/**
* Get the updated items in the below format required for mutation input.