Skip to content

Commit ed11d06

Browse files
committed
Replace config with .env variables
1 parent 1685190 commit ed11d06

File tree

8 files changed

+18
-37
lines changed

8 files changed

+18
-37
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1+
NEXT_PUBLIC_GRAPHQL_URL="https://woocommerce.url.com/graphql"
2+
NEXT_PUBLIC_ALGOLIA_INDEX_NAME= "algolia"
3+
NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL="https://res.cloudinary.com/placeholder-337_utsb7h.jpg"
4+
NEXT_PUBLIC_PLACEHOLDER_LARGE_IMAGE_URL="https://res.cloudinary.com/placeholder-616-616_beecp5.jpg"
5+
NEXT_PUBLIC_ALGOLIA_APP_ID = "changeme"
6+
NEXT_PUBLIC_ALGOLIA_PUBLIC_API_KEY = "changeme"
17
NODE_ENV="development"

components/AlgoliaSearch/AlgoliaSearchBox.component.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import algoliasearch from 'algoliasearch';
22
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';
33
import { useState } from 'react';
44

5-
import WOO_CONFIG from 'utils/config/nextConfig';
5+
66
import SearchResults from './SearchResults.component';
77

88
const searchClient = algoliasearch(
@@ -23,7 +23,7 @@ const AlgoliaSearchBox = () => {
2323
<div className="hidden mt-2 md:inline xl:inline">
2424
<div className="">
2525
<InstantSearch
26-
indexName={WOO_CONFIG.ALGOLIA_INDEX_NAME}
26+
indexName={process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME}
2727
searchClient={searchClient}
2828
>
2929
{/*We need to conditionally add a border because the element has position:fixed*/}

components/AlgoliaSearch/MobileSearch.component.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import algoliasearch from 'algoliasearch';
22
import { InstantSearch, SearchBox, Hits } from 'react-instantsearch-dom';
33
import { useState } from 'react';
44

5-
import WOO_CONFIG from 'utils/config/nextConfig';
5+
66
import SearchResults from './SearchResults.component';
77

88
const searchClient = algoliasearch(
@@ -19,7 +19,7 @@ const MobileSearch = () => {
1919
return (
2020
<div className="inline mt-4">
2121
<InstantSearch
22-
indexName={WOO_CONFIG.ALGOLIA_INDEX_NAME}
22+
indexName={process.env.NEXT_PUBLIC_ALGOLIA_INDEX_NAME}
2323
searchClient={searchClient}
2424
>
2525
<SearchBox

components/Product/IndexProducts.component.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const IndexProducts = ({ products }) => (
4545
id="product-image"
4646
className="transition duration-500 ease-in-out transform cursor-pointer hover:grow hover:shadow-lg hover:scale-105"
4747
alt={name}
48-
src={WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL}
48+
src={process.env.NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL}
4949
/>
5050
)}
5151
</a>

components/Product/SingleProduct.component.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
33
import AddToCartButton from 'components/Cart/AddToCartButton.component';
44
import LoadingSpinner from 'components/LoadingSpinner/LoadingSpinner.component';
55

6-
import WOO_CONFIG from 'utils/config/nextConfig';
6+
77

88
import { filteredVariantPrice } from 'utils/functions/functions';
99

@@ -55,7 +55,7 @@ const SingleProduct = ({ product }) => {
5555
id="product-image"
5656
className="h-auto p-8 transition duration-500 ease-in-out transform xl:p-2 md:p-2 lg:p-2 hover:grow hover:shadow-lg hover:scale-105"
5757
alt={name}
58-
src={WOO_CONFIG.PLACEHOLDER_LARGE_IMAGE_URL}
58+
src={process.env.NEXT_PUBLIC_PLACEHOLDER_LARGE_IMAGE_URL}
5959
/>
6060
)}
6161
<div className="ml-8">

utils/apollo/ApolloClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ApolloLink,
88
} from '@apollo/client';
99

10-
import WOO_CONFIG from 'utils/config/nextConfig';
10+
1111

1212
/**
1313
* Middleware operation
@@ -79,7 +79,7 @@ const client = new ApolloClient({
7979
link: middleware.concat(
8080
afterware.concat(
8181
createHttpLink({
82-
uri: WOO_CONFIG.GRAPHQL_URL,
82+
uri: process.env.NEXT_PUBLIC_GRAPHQL_URL,
8383
fetch,
8484
})
8585
)

utils/config/nextConfig.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

utils/functions/functions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { v4 as uuidv4 } from 'uuid';
22

3-
import WOO_CONFIG from 'utils/config/nextConfig';
3+
44

55
/**
66
* Shorten inputted string (usually product description) to a maximum of length
@@ -77,8 +77,8 @@ export const getFormattedCart = (data) => {
7777
title: givenProduct.image.title,
7878
}
7979
: {
80-
sourceUrl: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
81-
srcSet: WOO_CONFIG.PLACEHOLDER_SMALL_IMAGE_URL,
80+
sourceUrl: process.env.NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL,
81+
srcSet: process.env.NEXT_PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL,
8282
title: givenProduct.name,
8383
};
8484

0 commit comments

Comments
 (0)