diff --git a/app.json b/app.json index b1d2f42967..42bd035f89 100644 --- a/app.json +++ b/app.json @@ -59,6 +59,11 @@ "SITE_IMAGERY_API_URL": { "required": false, "description": "For showing vegetation change" + }, + "WEBHOOK_URL": { + "required": true, + "description": "URL for webhooks of automation service", + "value": "https://automate.plant-for-the-planet.org/webhook" } }, "formation": { diff --git a/next.config.js b/next.config.js index 3b476cf901..095f2e6093 100644 --- a/next.config.js +++ b/next.config.js @@ -122,6 +122,7 @@ const nextConfig = { ENABLE_ANALYTICS: DB_CONN_URL ? true : false, REDIS_URL: process.env.REDIS_URL, REDIS_TOKEN: process.env.REDIS_TOKEN, + WEBHOOK_URL: process.env.WEBHOOK_URL, }, trailingSlash: false, reactStrictMode: true, diff --git a/pages/sites/[slug]/[locale]/all.tsx b/pages/sites/[slug]/[locale]/all.tsx index 2e57ff2bac..7d28be43ca 100644 --- a/pages/sites/[slug]/[locale]/all.tsx +++ b/pages/sites/[slug]/[locale]/all.tsx @@ -7,6 +7,7 @@ import { handleError, APIError } from '@planet-sdk/common'; import { LeaderBoardList, TenantScore, + TreesDonated, } from '../../../../src/features/common/types/leaderboard'; import { useTenant } from '../../../../src/features/common/Layout/TenantContext'; import { Tenant } from '@planet-sdk/common/build/types/tenant'; @@ -32,7 +33,7 @@ export default function Home({ pageProps }: Props) { const [leaderboard, setLeaderboard] = React.useState( null ); - const { redirect, setErrors } = React.useContext(ErrorHandlingContext); + const { setErrors } = React.useContext(ErrorHandlingContext); const router = useRouter(); const { setTenantConfig } = useTenant(); @@ -77,17 +78,37 @@ export default function Home({ pageProps }: Props) { loadTenantScore(); }, []); + + const [treesDonated, setTreesDonated] = React.useState( + null + ); + + React.useEffect(() => { + async function loadTreesDonated() { + try { + const newTreesDonated = await getRequest( + pageProps.tenantConfig.id, + `${process.env.WEBHOOK_URL}/platform/total-tree-count` + ); + setTreesDonated(newTreesDonated); + } catch (err) { + setErrors(handleError(err as APIError)); + } + } + loadTreesDonated(); + }, []); + let AllPage; function getAllPage() { switch (pageProps.tenantConfig.config.slug) { case 'planet': AllPage = ( - + ); return AllPage; case 'ttc': AllPage = ( - + ); return AllPage; default: diff --git a/src/features/common/types/leaderboard.d.ts b/src/features/common/types/leaderboard.d.ts index fd24eacbbf..4982c2cb3b 100644 --- a/src/features/common/types/leaderboard.d.ts +++ b/src/features/common/types/leaderboard.d.ts @@ -12,3 +12,8 @@ export type LeaderBoardList = { mostRecent: LeaderBoardItem[]; mostDonated: LeaderBoardItem[]; }; + +export type TreesDonated = { + trees_since_2019: number; + updated_on: string; +}; diff --git a/src/tenants/planet/LeaderBoard/components/Stats.tsx b/src/tenants/planet/LeaderBoard/components/Stats.tsx index 6645646047..0eefb88400 100644 --- a/src/tenants/planet/LeaderBoard/components/Stats.tsx +++ b/src/tenants/planet/LeaderBoard/components/Stats.tsx @@ -6,12 +6,17 @@ import StatsInfoModal from './StatsInfoModal'; import { useLocale, useTranslations } from 'next-intl'; import { localizedAbbreviatedNumber } from '../../../../utils/getFormattedNumber'; import { ThemeContext } from '../../../../theme/themeContext'; +import { + TenantScore, + TreesDonated, +} from '../../../../features/common/types/leaderboard'; interface Props { - tenantScore: any; + tenantScore: TenantScore; + treesDonated: TreesDonated; } -export default function Stats({ tenantScore }: Props): ReactElement { - const [infoExpanded, setInfoExpanded] = React.useState(null); +export default function Stats({ tenantScore, treesDonated }: Props): ReactElement { + const [infoExpanded, setInfoExpanded] = React.useState(null); const tPlanet = useTranslations('Planet'); const locale = useLocale(); const [openModal, setModalOpen] = React.useState(false); @@ -25,7 +30,7 @@ export default function Stats({ tenantScore }: Props): ReactElement {

- {localizedAbbreviatedNumber(locale, Number(79586370), 2)} + {localizedAbbreviatedNumber(locale, Number(treesDonated.trees_since_2019), 2)}

{tPlanet('treesDonated')}