Skip to content

Commit e816530

Browse files
authored
Refactor constants, remove duplicate configuration code (#2248)
1 parent 1cfcf3b commit e816530

25 files changed

+205
-210
lines changed

client/src/appReducer.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { getTenantId } from "contexts/siteContext";
2-
import { TENANT_CONFIG } from "helpers/Constants";
1+
import { DEFAULT_VIEWPORT } from "helpers/Constants";
32
import { createContext, useContext, useMemo, useReducer } from "react";
43

5-
const tenantId = getTenantId();
6-
export const DEFAULT_COORDINATES =
7-
TENANT_CONFIG[tenantId].defaultViewport.center;
4+
export const DEFAULT_COORDINATES = DEFAULT_VIEWPORT.center;
85

96
function stakeholdersReducer(state, action) {
107
switch (action.type) {

client/src/components/Admin/LocationAutocomplete.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Grid, TextField, Typography } from "@mui/material";
22
import { useState } from "react";
33
import * as awsService from "../../services/aws-service";
4+
import { TENANT_ID } from "helpers/Constants";
45

56
let latestSearchString = "";
67

@@ -18,9 +19,8 @@ const LocationAutocomplete = (props) => {
1819
// this request starts executing after the
1920
// setTimeout delay, this request is stale
2021
// and we don't want to run it.
21-
const tenantId = process.env.REACT_APP_TENANT_ID;
2222
if (s.length > 8 && s === latestSearchString) {
23-
const result = await awsService.autoComplete(s, tenantId);
23+
const result = await awsService.autoComplete(s, TENANT_ID);
2424
setGeocodeResults(result);
2525
}
2626
}, 500);

client/src/components/Admin/ParentOrganizations.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
TextField,
1515
} from "@mui/material";
1616
import { Formik } from "formik";
17-
import { tenantId } from "helpers/Configuration";
17+
import { TENANT_ID } from "helpers/Constants";
1818
import { useParentOrganizations } from "hooks/useParentOrganizations";
1919
import { useEffect, useState } from "react";
2020
import { Navigate, useLocation } from "react-router-dom";
@@ -101,7 +101,7 @@ function ParentOrganizations(props) {
101101
setActiveOrg({
102102
code: "",
103103
name: "",
104-
tenantId,
104+
TENANT_ID,
105105
});
106106
};
107107

client/src/components/Admin/SearchCriteria.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Typography,
1717
} from "@mui/material";
1818
import { useEffect, useState } from "react";
19-
import { defaultViewport } from "../../helpers/Configuration";
19+
import { DEFAULT_VIEWPORT } from "helpers/Constants";
2020
import AccountAutocomplete from "./AccountAutocomplete";
2121
import LocationAutocomplete from "./LocationAutocomplete";
2222
import Label from "./ui/Label";
@@ -49,10 +49,10 @@ const SearchCriteria = ({
4949
);
5050

5151
const [customLatitude, setCustomLatitude] = useState(
52-
defaultViewport.center.latitude
52+
DEFAULT_VIEWPORT.center.latitude
5353
);
5454
const [customLongitude, setCustomLongitude] = useState(
55-
defaultViewport.center.longitude
55+
DEFAULT_VIEWPORT.center.longitude
5656
);
5757
const [customPlaceName, setCustomPlaceName] = useState("");
5858

client/src/components/Admin/TagAdmin.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
Typography,
1616
} from "@mui/material";
1717
import { Formik } from "formik";
18-
import { tenantId } from "helpers/Configuration";
18+
import { TENANT_ID } from "helpers/Constants";
1919
import { useTags } from "hooks/useTags";
2020
import { useEffect, useState } from "react";
2121
import { Navigate, useLocation } from "react-router-dom";
@@ -100,7 +100,7 @@ function TagAdmin(props) {
100100
const handleAddNew = () => {
101101
setActiveTag({
102102
name: "",
103-
tenantId,
103+
TENANT_ID,
104104
});
105105
};
106106

client/src/components/FoodSeeker/Home.jsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,10 @@ import useGeolocation, { useLocationPermission } from "hooks/useGeolocation";
1515
import { useEffect, useState } from "react";
1616
import { Link as RouterLink, useNavigate } from "react-router-dom";
1717
import * as analytics from "services/analytics";
18-
import { useSiteContext } from "../../contexts/siteContext";
18+
import { useSiteContext } from "contexts/siteContext";
19+
import { TENANT_LOGO_URL } from "helpers/Constants";
1920
import SEO from "../SEO";
2021

21-
const logoPaths = {
22-
1: require("images/foodoasis.svg").default,
23-
2: require("images/foodoasis.svg").default,
24-
3: require("../StaticPagesHI/assets/aloha-harvest-bg-none.png"),
25-
4: require("images/foodoasis.svg").default,
26-
5: require("images/foodoasis.svg").default,
27-
6: require("images/foodoasis.svg").default,
28-
};
29-
3022
const Home = () => {
3123
const navigate = useNavigate();
3224
const { tenantId, tenantDetails } = useSiteContext();
@@ -142,7 +134,7 @@ const Home = () => {
142134
},
143135
})}
144136
>
145-
<img src={logoPaths[tenantId]} alt="logo" />
137+
<img src={TENANT_LOGO_URL} alt="logo" />
146138
</Box>
147139
<Box
148140
sx={(theme) => ({

client/src/components/FoodSeeker/SearchResults/ResultsMap/ResultsMap.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useCallback, useEffect, useState } from "react";
99
// for craco.config.js contents
1010
import { Grid } from "@mui/material";
1111
import { MAPBOX_STYLE } from "constants/map";
12-
import { defaultViewport } from "helpers/Configuration";
12+
import { MAPBOX_ACCESS_TOKEN, DEFAULT_VIEWPORT } from "helpers/Constants";
1313
import useBreakpoints from "hooks/useBreakpoints";
1414
import useFeatureFlag from "hooks/useFeatureFlag";
1515
import "mapbox-gl/dist/mapbox-gl.css";
@@ -60,7 +60,7 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
6060
const [viewport, setViewport] = useState({
6161
latitude,
6262
longitude,
63-
zoom: defaultViewport.zoom,
63+
zoom: DEFAULT_VIEWPORT.zoom,
6464
});
6565
const dispatch = useAppDispatch();
6666
const neighborhood = useNeighborhood();
@@ -140,7 +140,7 @@ const ResultsMap = ({ stakeholders, categoryIds, toggleCategory, loading }) => {
140140
ref={mapRef}
141141
{...viewport}
142142
onMove={(e) => setViewport(e.viewState)}
143-
mapboxAccessToken={process.env.REACT_APP_MAPBOX_ACCESS_TOKEN}
143+
mapboxAccessToken={MAPBOX_ACCESS_TOKEN}
144144
mapStyle={MAPBOX_STYLE}
145145
draggable={true}
146146
onLoad={onLoad}

client/src/components/Layout/Footer.jsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ import { Box, CardMedia } from "@mui/material";
22
import { MENU_ITEMS } from "helpers/Constants";
33
import useLocationHook from "hooks/useLocationHook";
44
import { Link } from "react-router-dom";
5-
import { tenantId } from "../../helpers/Configuration";
65
import Copyright from "./Copyright";
6+
import { TENANT_LOGO_URL } from "helpers/Constants";
7+
78
/*
89
This file is not used in the application at this time, but left here in
910
case the UI/UX team decides to re-instate it.
1011
*/
1112

12-
const logoPaths = {
13-
1: require("images/foodoasis.svg").default,
14-
2: require("images/foodoasis.svg").default,
15-
3: require("../StaticPagesHI/assets/aloha-harvest-bg-none.png"),
16-
4: require("images/foodoasis.svg").default,
17-
5: require("images/foodoasis.svg").default,
18-
6: require("images/foodoasis.svg").default,
19-
};
20-
2113
const Footer = () => {
2214
const { isHomePage } = useLocationHook();
2315

@@ -66,7 +58,7 @@ const Footer = () => {
6658
<CardMedia
6759
component="img"
6860
alt="logo"
69-
src={logoPaths[tenantId]}
61+
src={TENANT_LOGO_URL}
7062
sx={(theme) => ({
7163
maxWidth: "95px",
7264
height: "100%",

client/src/components/Layout/Header.jsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@ import { AppBar, Box, Toolbar, Typography } from "@mui/material";
22
import useLocationHook from "hooks/useLocationHook";
33
import PropTypes from "prop-types";
44
import { Link } from "react-router-dom";
5-
import { useSiteContext } from "../../contexts/siteContext";
6-
import { useUserContext } from "../../contexts/userContext";
5+
import { useUserContext } from "contexts/userContext";
6+
import { TENANT_LOGO_URL } from "helpers/Constants";
77
import Menu from "./Menu";
88

99
Header.propTypes = {
1010
tenantId: PropTypes.number,
1111
};
1212

13-
const logoPaths = {
14-
1: require("images/foodoasis.svg").default,
15-
2: require("images/foodoasis.svg").default,
16-
3: require("../StaticPagesHI/assets/aloha-harvest-bg-none.png"),
17-
4: require("images/foodoasis.svg").default,
18-
5: require("images/foodoasis.svg").default,
19-
6: require("images/foodoasis.svg").default,
20-
};
21-
2213
export default function Header() {
23-
const { tenantId } = useSiteContext();
2414
const { isAuthPage } = useLocationHook();
25-
const imageType = logoPaths
26-
? logoPaths[tenantId].split(".").pop()
15+
const imageType = TENANT_LOGO_URL
16+
? TENANT_LOGO_URL.split(".").pop()
2717
: "unknown";
2818

2919
const { user } = useUserContext();
@@ -64,7 +54,7 @@ export default function Header() {
6454
>
6555
<a href="/">
6656
<img
67-
src={logoPaths[tenantId]}
57+
src={TENANT_LOGO_URL}
6858
style={
6959
imageType === "svg" ? { width: "100%", height: "100%" } : {}
7060
}

client/src/components/Layout/WidgetFooter.jsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,8 @@ import { Box } from "@mui/material";
22
import { useSiteContext } from "contexts/siteContext";
33
import PropTypes from "prop-types";
44
import { useEffect, useState } from "react";
5-
import { isMobile } from "../../helpers";
6-
7-
const logoPaths = {
8-
1: require("images/foodoasis.svg"),
9-
2: require("images/foodoasis.svg"),
10-
3: require("images/foodoasis.svg"),
11-
4: require("images/foodoasis.svg"),
12-
5: require("images/foodoasis.svg"),
13-
6: require("images/foodoasis.svg"),
14-
};
5+
import { isMobile } from "helpers";
6+
import { TENANT_LOGO_URL } from "helpers/Constants";
157

168
function WidgetFooterSection(props) {
179
const {
@@ -180,7 +172,7 @@ function WidgetFooterSection(props) {
180172

181173
function WidgetFooter() {
182174
const [mobile, setMobile] = useState(null);
183-
const { tenantId, tenantDetails } = useSiteContext();
175+
const { tenantDetails } = useSiteContext();
184176
const { maintainers } = tenantDetails;
185177

186178
useEffect(() => {
@@ -203,7 +195,7 @@ function WidgetFooter() {
203195
>
204196
<WidgetFooterSection
205197
name="Food Oasis"
206-
logoPath={logoPaths[tenantId]}
198+
logoPath={TENANT_LOGO_URL}
207199
url={`${window.location.origin}`}
208200
alt="Food Oasis Logo"
209201
/>

0 commit comments

Comments
 (0)