Skip to content

Commit 9da2439

Browse files
committed
adds new environment variables
1 parent ebb7dd6 commit 9da2439

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

.env.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ NEXT_PUBLIC_SPREE_API_HOST=http://web:4000
1919
NEXT_PUBLIC_SPREE_CLIENT_HOST=http://localhost:4000
2020
NEXT_PUBLIC_SPREE_IMAGE_HOST=http://localhost:4000
2121
NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN=localhost
22+
# for local development (on localhost)
2223
NEXT_PUBLIC_ADS_PORT=7676
2324
NEXT_PUBLIC_DISCOUNTS_PORT=2814
2425
NEXT_PUBLIC_ADS_ROUTE="http://localhost"
2526
NEXT_PUBLIC_DISCOUNTS_ROUTE="http://localhost"
27+
# for labs/public use
28+
NEXT_PUBLIC_ADS_URL_FULL="http://localhost:7676"
29+
NEXT_PUBLIC_DISCOUNTS_URL_FULL="http://localhost:2814"
30+
2631
NEXT_PUBLIC_DD_APPLICATION_ID=""
2732
NEXT_PUBLIC_DD_CLIENT_TOKEN=""
2833
NEXT_PUBLIC_DD_SITE="datadoghq.com"

services/frontend/components/common/Ad/Ad.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export interface AdDataResults {
1010
function Ad() {
1111
const [data, setData] = useState<AdDataResults | null>(null)
1212
const [isLoading, setLoading] = useState(false)
13-
const adsPath = `${process.env.NEXT_PUBLIC_ADS_ROUTE}:${process.env.NEXT_PUBLIC_ADS_PORT}`
13+
const adsPath =
14+
`${process.env.NEXT_PUBLIC_ADS_URL_FULL}` ||
15+
`${process.env.NEXT_PUBLIC_ADS_ROUTE}:${process.env.NEXT_PUBLIC_ADS_PORT}`
1416
const [codeFlag, setCodeFlag] = useState<boolean>(false)
1517

1618
const getRandomArbitrary = useCallback((min: number, max: number) => {
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import * as React from 'react'
22

33
export interface DiscountCodeResults {
44
data: string | null
@@ -7,21 +7,27 @@ export interface DiscountCodeResults {
77
function Discount() {
88
const [data, setData] = React.useState<DiscountCodeResults | null>(null)
99
const [isLoading, setLoading] = React.useState(false)
10-
const discountPath = `${process.env.NEXT_PUBLIC_DISCOUNTS_ROUTE}:${process.env.NEXT_PUBLIC_DISCOUNTS_PORT}`
10+
const discountPath =
11+
`${process.env.NEXT_PUBLIC_DISCOUNTS_URL_FULL}` ||
12+
`${process.env.NEXT_PUBLIC_DISCOUNTS_ROUTE}:${process.env.NEXT_PUBLIC_DISCOUNTS_PORT}`
1113

1214
function getRandomArbitrary(min: number, max: number) {
13-
return Math.floor(Math.random() * (max - min) + min);
15+
return Math.floor(Math.random() * (max - min) + min)
1416
}
1517

1618
function fetchDiscountCode() {
1719
fetch(`${discountPath}/discount`)
1820
.then((res) => res.json())
1921
.then((data) => {
20-
const index = getRandomArbitrary(0, data.length);
21-
setData(data[index]["code"])
22+
const index = getRandomArbitrary(0, data.length)
23+
setData(data[index]['code'])
24+
})
25+
.catch((e) => {
26+
console.error(e.message)
27+
})
28+
.finally(() => {
29+
setLoading(false)
2230
})
23-
.catch(e => { console.error(e.message) })
24-
.finally(() => { setLoading(false) })
2531
}
2632

2733
React.useEffect(() => {
@@ -30,16 +36,21 @@ function Discount() {
3036
// eslint-disable-next-line react-hooks/exhaustive-deps
3137
}, [])
3238

33-
3439
return (
3540
<div className="flex flex-row justify-center py-4 bg-primary-2 text-white">
36-
{
37-
isLoading ? (<span>GET FREE SHIPPING WITH DISCOUNT CODE</span>) :
38-
!data ? (<span>GET FREE SHIPPING WITH DISCOUNT CODE <strong>STOREDOG</strong></span>) : (<span>GET FREE SHIPPING WITH DISCOUNT CODE &nbsp; <strong>{data}</strong></span>)
39-
}
41+
{isLoading ? (
42+
<span>GET FREE SHIPPING WITH DISCOUNT CODE</span>
43+
) : !data ? (
44+
<span>
45+
GET FREE SHIPPING WITH DISCOUNT CODE <strong>STOREDOG</strong>
46+
</span>
47+
) : (
48+
<span>
49+
GET FREE SHIPPING WITH DISCOUNT CODE &nbsp; <strong>{data}</strong>
50+
</span>
51+
)}
4052
</div>
4153
)
42-
4354
}
4455

45-
export default Discount
56+
export default Discount

0 commit comments

Comments
 (0)