Skip to content

Commit

Permalink
fix: fixes local next config warnings
Browse files Browse the repository at this point in the history
- Expected string, received boolean at "env.ENABLE_ANALYTICS"
- "env.VERCEL_URL" is missing, expected string
  • Loading branch information
mohitb35 committed Oct 31, 2023
1 parent 528965e commit 9e58440
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ SITE_IMAGERY_API_URL=https://raster.plant-for-the-planet.org
WIDGET_URL=https://widgets.plant-for-the-planet.org
NEXT_PUBLIC_DONATION_URL=https://donate.plant-for-the-planet.org
CONFIG_URL=https://app.plant-for-the-planet.org/app/config
VERCEL_URL=localhost

DB_CONN_URL=
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const nextConfig = {
SITE_IMAGERY_API_URL: SITE_IMAGERY_API_URL,
WIDGET_URL: process.env.WIDGET_URL,
CONFIG_URL: process.env.CONFIG_URL,
ENABLE_ANALYTICS: DB_CONN_URL ? true : false,
ENABLE_ANALYTICS: DB_CONN_URL ? 'true' : 'false',
},
trailingSlash: false,
reactStrictMode: true,
Expand Down
6 changes: 5 additions & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ const PlanetWeb = ({
gtmId: process.env.NEXT_PUBLIC_GA_TRACKING_ID,
};

if (process.env.VERCEL_URL && typeof window !== 'undefined') {
if (
process.env.VERCEL_URL &&
process.env.VERCEL_URL !== 'localhost' &&
typeof window !== 'undefined'
) {
if (process.env.VERCEL_URL !== window.location.hostname) {
router.replace(`https://${process.env.VERCEL_URL}`);
}
Expand Down
2 changes: 1 addition & 1 deletion pages/profile/treemapper/data-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function TreeMapperAnalytics(): ReactElement {
const { push } = useRouter();

useEffect(() => {
if (!(process.env.ENABLE_ANALYTICS && user?.type === 'tpo')) {
if (!(process.env.ENABLE_ANALYTICS === 'true' && user?.type === 'tpo')) {
push('/profile');
}
});
Expand Down
4 changes: 3 additions & 1 deletion src/features/common/Layout/UserLayout/UserLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ const UserLayout: FC = ({ children }) => {
{
title: t('me:dataExplorer'),
path: '/profile/treemapper/data-explorer',
hideItem: !(process.env.ENABLE_ANALYTICS && user?.type === 'tpo'),
hideItem: !(
process.env.ENABLE_ANALYTICS === 'true' && user?.type === 'tpo'
),
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const SpeciesPlanted = () => {
});
}, 2000);

if (process.env.ENABLE_ANALYTICS && project) {
if (process.env.ENABLE_ANALYTICS === 'true' && project) {
fetchPlantedSpecies();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,11 @@ export const TreePlanted = () => {

const isValidTimeFrame =
timeFrame && getTimeFrames(toDate, fromDate).includes(timeFrame);
if (process.env.ENABLE_ANALYTICS && isValidTimeFrame && project) {
if (
process.env.ENABLE_ANALYTICS === 'true' &&
isValidTimeFrame &&
project
) {
fetchPlantedTrees();
}
}, [project, fromDate, toDate, timeFrame]);
Expand Down

0 comments on commit 9e58440

Please sign in to comment.