diff --git a/pages/sites/[slug]/[locale]/[p].tsx b/pages/sites/[slug]/[locale]/[p].tsx index 04ac3135c4..7a6a88deb9 100644 --- a/pages/sites/[slug]/[locale]/[p].tsx +++ b/pages/sites/[slug]/[locale]/[p].tsx @@ -1,4 +1,5 @@ import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -60,18 +61,19 @@ ProjectDetailsPage.getLayout = function getLayout( export default ProjectDetailsPage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - p: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + p: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/all.tsx b/pages/sites/[slug]/[locale]/all.tsx index 1e7059f5c3..12d59da3f2 100644 --- a/pages/sites/[slug]/[locale]/all.tsx +++ b/pages/sites/[slug]/[locale]/all.tsx @@ -6,6 +6,7 @@ import type { } from '../../../../src/features/common/types/leaderboard'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -49,10 +50,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadLeaderboard() { try { - const newLeaderboard = await getRequest( - pageProps.tenantConfig.id, - `/app/leaderboard/${pageProps.tenantConfig.id}` - ); + const newLeaderboard = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/leaderboard/${pageProps.tenantConfig.id}`, + }); setLeaderboard(newLeaderboard); } catch (err) { setErrors(handleError(err as APIError)); @@ -68,10 +69,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTenantScore() { try { - const newTenantScore = await getRequest( - pageProps.tenantConfig.id, - `/app/tenantScore/${pageProps.tenantConfig.id}` - ); + const newTenantScore = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/tenantScore/${pageProps.tenantConfig.id}`, + }); setTenantScore(newTenantScore); } catch (err) { setErrors(handleError(err as APIError)); @@ -87,10 +88,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTreesDonated() { try { - const newTreesDonated = await getRequest( - pageProps.tenantConfig.id, - `${process.env.WEBHOOK_URL}/platform/total-tree-count` - ); + const newTreesDonated = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `${process.env.WEBHOOK_URL}/platform/total-tree-count`, + }); setTreesDonated(newTreesDonated); } catch (err) { setErrors(handleError(err as APIError)); @@ -136,17 +137,18 @@ export default function Home({ pageProps }: Props) { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx b/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx index 5ce505ae9b..d03d2f96c4 100644 --- a/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx +++ b/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx @@ -1,5 +1,6 @@ import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -83,13 +84,13 @@ function ClaimDonation({ pageProps }: Props): ReactElement { }; if (contextLoaded && user) { try { - const res = await postAuthenticatedRequest( - pageProps.tenantConfig.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/redeem`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setRedeemedCodeData(res); } catch (err) { const serializedErrors = handleError(err as APIError); @@ -185,19 +186,20 @@ function ClaimDonation({ pageProps }: Props): ReactElement { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - type: v4(), - code: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + type: v4(), + code: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/complete-signup.tsx b/pages/sites/[slug]/[locale]/complete-signup.tsx index 4608a7f8f3..a2920b9e9e 100644 --- a/pages/sites/[slug]/[locale]/complete-signup.tsx +++ b/pages/sites/[slug]/[locale]/complete-signup.tsx @@ -1,5 +1,6 @@ import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -44,17 +45,18 @@ export default function UserProfile({ pageProps }: Props) { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/home.tsx b/pages/sites/[slug]/[locale]/home.tsx index 354054b8ec..2166cd93fc 100644 --- a/pages/sites/[slug]/[locale]/home.tsx +++ b/pages/sites/[slug]/[locale]/home.tsx @@ -5,6 +5,7 @@ import type { } from '../../../../src/features/common/types/leaderboard'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -54,10 +55,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTenantScore() { try { - const newTenantScore = await getRequest( - pageProps.tenantConfig.id, - `/app/tenantScore` - ); + const newTenantScore = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/tenantScore`, + }); setTenantScore(newTenantScore); } catch (err) { setErrors(handleError(err as APIError)); @@ -69,10 +70,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadLeaderboard() { try { - const newLeaderBoard = await getRequest( - pageProps.tenantConfig.id, - `/app/leaderboard` - ); + const newLeaderBoard = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/leaderboard`, + }); setLeaderboard(newLeaderBoard); } catch (err) { setErrors(handleError(err as APIError)); @@ -131,17 +132,18 @@ export default function Home({ pageProps }: Props) { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/index.tsx b/pages/sites/[slug]/[locale]/index.tsx index 20dbd2dc70..15fa8c4475 100644 --- a/pages/sites/[slug]/[locale]/index.tsx +++ b/pages/sites/[slug]/[locale]/index.tsx @@ -1,4 +1,5 @@ import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -56,17 +57,18 @@ ProjectListPage.getLayout = function getLayout( export default ProjectListPage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/login.tsx b/pages/sites/[slug]/[locale]/login.tsx index 5d8acd2fc9..a8a966e38f 100644 --- a/pages/sites/[slug]/[locale]/login.tsx +++ b/pages/sites/[slug]/[locale]/login.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -85,17 +86,18 @@ export default function Login({ pageProps }: Props): ReactElement { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/mangrove-challenge.tsx b/pages/sites/[slug]/[locale]/mangrove-challenge.tsx index 9e91bb8ea1..5cda634ed5 100644 --- a/pages/sites/[slug]/[locale]/mangrove-challenge.tsx +++ b/pages/sites/[slug]/[locale]/mangrove-challenge.tsx @@ -5,6 +5,7 @@ import type { import type { AbstractIntlMessages } from 'next-intl'; import type { Tenant } from '@planet-sdk/common'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -99,7 +100,7 @@ export default function MangroveChallenge({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { return { paths: [{ params: { slug: 'salesforce', locale: 'en' } }], fallback: 'blocking', diff --git a/pages/sites/[slug]/[locale]/mangroves.tsx b/pages/sites/[slug]/[locale]/mangroves.tsx index c21b3d532f..d6ade371df 100644 --- a/pages/sites/[slug]/[locale]/mangroves.tsx +++ b/pages/sites/[slug]/[locale]/mangroves.tsx @@ -1,14 +1,15 @@ import type { AbstractIntlMessages } from 'next-intl'; import type { Tenant } from '@planet-sdk/common'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, } from 'next'; import React, { useEffect } from 'react'; -import Mangroves from '../../../../src/tenants/salesforce/Mangroves'; import GetHomeMeta from '../../../../src/utils/getMetaTags/GetHomeMeta'; +import Mangroves from '../../../../src/tenants/salesforce/Mangroves'; import { getTenantConfig } from '../../../../src/utils/multiTenancy/helpers'; import { defaultTenant } from '../../../../tenant.config'; import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage'; @@ -51,7 +52,7 @@ export default function MangrovesLandingPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { return { paths: [{ params: { slug: 'salesforce', locale: 'en' } }], fallback: 'blocking', diff --git a/pages/sites/[slug]/[locale]/profile/api-key.tsx b/pages/sites/[slug]/[locale]/profile/api-key.tsx index 193dd3d880..59e1a6c0b6 100644 --- a/pages/sites/[slug]/[locale]/profile/api-key.tsx +++ b/pages/sites/[slug]/[locale]/profile/api-key.tsx @@ -1,5 +1,6 @@ import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -50,17 +51,18 @@ function EditProfilePage({ pageProps: { tenantConfig } }: Props): ReactElement { export default EditProfilePage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx index 56371bdba7..741a1154a6 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx @@ -1,5 +1,6 @@ import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -63,17 +64,16 @@ export default function BulkCodeIssueCodesPage({ if (router.isReady) { try { const paymentOptions = - await getAuthenticatedRequest( - pageProps.tenantConfig.id, - `/app/paymentOptions/${router.query.id}`, + await getAuthenticatedRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/paymentOptions/${router.query.id}`, token, logoutUser, - undefined, - { - country: planetCashAccount.country, + queryParams: { + country: planetCashAccount?.country ?? '', ...(user !== null && { legacyPriceFor: user.id }), - } - ); + }, + }); if (paymentOptions) { const retrievedProject = projectList.find( @@ -135,19 +135,20 @@ export default function BulkCodeIssueCodesPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - method: v4(), - id: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + method: v4(), + id: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/index.tsx b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/index.tsx index a40bd87365..46e531c8d0 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -73,18 +74,19 @@ export default function BulkCodeSelectProjectPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - method: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + method: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/profile/bulk-codes/index.tsx b/pages/sites/[slug]/[locale]/profile/bulk-codes/index.tsx index 1b7fcfd053..ddf35349a2 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -50,17 +51,18 @@ export default function BulkCodePage({ pageProps }: Props): ReactElement { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/delete-account.tsx b/pages/sites/[slug]/[locale]/profile/delete-account.tsx index fa135da271..fb2b3b8b7d 100644 --- a/pages/sites/[slug]/[locale]/profile/delete-account.tsx +++ b/pages/sites/[slug]/[locale]/profile/delete-account.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -52,17 +53,18 @@ function DeleteProfilePage({ export default DeleteProfilePage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/donation-link.tsx b/pages/sites/[slug]/[locale]/profile/donation-link.tsx index 82163250ba..0221f15ac1 100644 --- a/pages/sites/[slug]/[locale]/profile/donation-link.tsx +++ b/pages/sites/[slug]/[locale]/profile/donation-link.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -50,17 +51,18 @@ export default function DonationLinkPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/edit.tsx b/pages/sites/[slug]/[locale]/profile/edit.tsx index 1e0c1740e4..b0d7dbfe16 100644 --- a/pages/sites/[slug]/[locale]/profile/edit.tsx +++ b/pages/sites/[slug]/[locale]/profile/edit.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -50,17 +51,18 @@ function EditProfilePage({ pageProps: { tenantConfig } }: Props): ReactElement { export default EditProfilePage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/giftfund/index.tsx b/pages/sites/[slug]/[locale]/profile/giftfund/index.tsx index d160279b25..af0f93d11a 100644 --- a/pages/sites/[slug]/[locale]/profile/giftfund/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/giftfund/index.tsx @@ -1,5 +1,6 @@ import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -8,10 +9,10 @@ import type { AbstractIntlMessages } from 'next-intl'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import React from 'react'; +import GiftFunds from '../../../../../../src/features/user/GiftFunds'; import UserLayout from '../../../../../../src/features/common/Layout/UserLayout/UserLayout'; import Head from 'next/head'; import { useTranslations } from 'next-intl'; -import GiftFunds from '../../../../../../src/features/user/GiftFunds'; import { constructPathsForTenantSlug, getTenantConfig, @@ -51,17 +52,18 @@ export default function Register({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/history.tsx b/pages/sites/[slug]/[locale]/profile/history.tsx index d761e2a5e7..33af865b37 100644 --- a/pages/sites/[slug]/[locale]/profile/history.tsx +++ b/pages/sites/[slug]/[locale]/profile/history.tsx @@ -19,6 +19,7 @@ import { ErrorHandlingContext } from '../../../../../src/features/common/Layout/ import { handleError } from '@planet-sdk/common'; import DashboardView from '../../../../../src/features/common/Layout/DashboardView'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -65,16 +66,18 @@ function AccountHistory({ pageProps }: Props): ReactElement { if (next && paymentHistory?._links?.next) { try { const newPaymentHistory = await getAuthenticatedRequest( - tenantConfig?.id, - `${ - filter && accountingFilters - ? accountingFilters[filter] + - '&' + - paymentHistory?._links?.next.split('?').pop() - : paymentHistory?._links?.next - }`, - token, - logoutUser + { + tenant: tenantConfig.id, + url: `${ + filter && accountingFilters + ? accountingFilters[filter] + + '&' + + paymentHistory?._links?.next.split('?').pop() + : paymentHistory?._links?.next + }`, + token, + logoutUser, + } ); setPaymentHistory({ ...paymentHistory, @@ -91,12 +94,12 @@ function AccountHistory({ pageProps }: Props): ReactElement { } else { if (filter === null) { try { - const paymentHistory = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/paymentHistory?limit=15', + const paymentHistory = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/paymentHistory?limit=15', token, - logoutUser - ); + logoutUser, + }); setPaymentHistory(paymentHistory); setProgress(100); setIsDataLoading(false); @@ -108,16 +111,16 @@ function AccountHistory({ pageProps }: Props): ReactElement { } } else { try { - const paymentHistory = await getAuthenticatedRequest( - tenantConfig?.id, - `${ + const paymentHistory = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `${ filter && accountingFilters ? accountingFilters[filter] + '&limit=15' : '/app/paymentHistory?limit=15' }`, token, - logoutUser - ); + logoutUser, + }); setPaymentHistory(paymentHistory); setProgress(100); setIsDataLoading(false); @@ -177,17 +180,18 @@ function AccountHistory({ pageProps }: Props): ReactElement { export default AccountHistory; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/impersonate-user.tsx b/pages/sites/[slug]/[locale]/profile/impersonate-user.tsx index ba987a8ef5..1325843250 100644 --- a/pages/sites/[slug]/[locale]/profile/impersonate-user.tsx +++ b/pages/sites/[slug]/[locale]/profile/impersonate-user.tsx @@ -1,6 +1,7 @@ import type { AbstractIntlMessages } from 'next-intl'; import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -59,17 +60,18 @@ const ImpersonateUserPage = ({ export default ImpersonateUserPage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/index.tsx b/pages/sites/[slug]/[locale]/profile/index.tsx index a5b828d18d..7607a5420e 100644 --- a/pages/sites/[slug]/[locale]/profile/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/index.tsx @@ -1,12 +1,13 @@ +import { MyForestProvider } from '../../../../../src/features/common/Layout/MyForestContext'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, } from 'next'; import type { AbstractIntlMessages } from 'next-intl'; -import { MyForestProvider } from '../../../../../src/features/common/Layout/MyForestContext'; import { useTranslations } from 'next-intl'; import { constructPathsForTenantSlug, @@ -44,17 +45,18 @@ const MyForestPage = ({ pageProps: { tenantConfig } }: Props) => { export default MyForestPage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/payouts/add-bank-details.tsx b/pages/sites/[slug]/[locale]/profile/payouts/add-bank-details.tsx index 9f6c28b51d..2ca02d5ab1 100644 --- a/pages/sites/[slug]/[locale]/profile/payouts/add-bank-details.tsx +++ b/pages/sites/[slug]/[locale]/profile/payouts/add-bank-details.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -59,17 +60,18 @@ export default function AddBankDetailsPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/payouts/edit-bank-details/[id].tsx b/pages/sites/[slug]/[locale]/profile/payouts/edit-bank-details/[id].tsx index e2f10a4c9c..c18047f3df 100644 --- a/pages/sites/[slug]/[locale]/profile/payouts/edit-bank-details/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/payouts/edit-bank-details/[id].tsx @@ -1,7 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; -import { useTranslations } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -14,6 +14,7 @@ import Head from 'next/head'; import ManagePayouts, { ManagePayoutTabs, } from '../../../../../../../src/features/user/ManagePayouts'; +import { useTranslations } from 'next-intl'; import { constructPathsForTenantSlug, getTenantConfig, @@ -53,18 +54,19 @@ export default function EditBankDetailsPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - id: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + id: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/profile/payouts/index.tsx b/pages/sites/[slug]/[locale]/profile/payouts/index.tsx index 9e8df8f47b..522a9354b8 100644 --- a/pages/sites/[slug]/[locale]/profile/payouts/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/payouts/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -71,17 +72,18 @@ export default function OverviewPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/payouts/schedule.tsx b/pages/sites/[slug]/[locale]/profile/payouts/schedule.tsx index d630e51045..5262e63649 100644 --- a/pages/sites/[slug]/[locale]/profile/payouts/schedule.tsx +++ b/pages/sites/[slug]/[locale]/profile/payouts/schedule.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -60,17 +61,18 @@ export default function PayoutSchedulePage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/planetcash/index.tsx b/pages/sites/[slug]/[locale]/profile/planetcash/index.tsx index 3620296748..e999a65833 100644 --- a/pages/sites/[slug]/[locale]/profile/planetcash/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/planetcash/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -68,17 +69,18 @@ export default function PlanetCashPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/planetcash/new.tsx b/pages/sites/[slug]/[locale]/profile/planetcash/new.tsx index b766b65035..054c494c54 100644 --- a/pages/sites/[slug]/[locale]/profile/planetcash/new.tsx +++ b/pages/sites/[slug]/[locale]/profile/planetcash/new.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -72,17 +73,18 @@ export default function PlanetCashCreatePage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/planetcash/transactions.tsx b/pages/sites/[slug]/[locale]/profile/planetcash/transactions.tsx index d839a98e00..8c85d40653 100644 --- a/pages/sites/[slug]/[locale]/profile/planetcash/transactions.tsx +++ b/pages/sites/[slug]/[locale]/profile/planetcash/transactions.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -72,17 +73,18 @@ export default function PlanetCashTransactionsPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/projects/[id].tsx b/pages/sites/[slug]/[locale]/profile/projects/[id].tsx index 91d0462c7b..90e6a64c94 100644 --- a/pages/sites/[slug]/[locale]/profile/projects/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/projects/[id].tsx @@ -7,6 +7,7 @@ import type { } from '../../../../../../src/features/common/types/project'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -72,12 +73,12 @@ function ManageSingleProject({ try { const result = await getAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig.id, - `/app/profile/projects/${projectGUID}`, + >({ + tenant: tenantConfig.id, + url: `/app/profile/projects/${projectGUID}`, token, - logoutUser - ); + logoutUser, + }); setProject(result); setSetupAccess(true); } catch (err) { @@ -128,18 +129,19 @@ function ManageSingleProject({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - id: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + id: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/profile/projects/index.tsx b/pages/sites/[slug]/[locale]/profile/projects/index.tsx index 94fa20839f..9ad7e040d8 100644 --- a/pages/sites/[slug]/[locale]/profile/projects/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/projects/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -53,17 +54,18 @@ export default function Register({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/projects/new-project.tsx b/pages/sites/[slug]/[locale]/profile/projects/new-project.tsx index 0ce119fefd..07e9beb9b4 100644 --- a/pages/sites/[slug]/[locale]/profile/projects/new-project.tsx +++ b/pages/sites/[slug]/[locale]/profile/projects/new-project.tsx @@ -1,6 +1,7 @@ import type { AbstractIntlMessages } from 'next-intl'; import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -99,17 +100,18 @@ export default function AddProjectType({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/recurrency.tsx b/pages/sites/[slug]/[locale]/profile/recurrency.tsx index 957bcf77c5..c2a434d71d 100644 --- a/pages/sites/[slug]/[locale]/profile/recurrency.tsx +++ b/pages/sites/[slug]/[locale]/profile/recurrency.tsx @@ -3,6 +3,7 @@ import type { AbstractIntlMessages } from 'next-intl'; import type { APIError } from '@planet-sdk/common'; import type { Subscription } from '../../../../../src/features/common/types/payments'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -56,12 +57,12 @@ function RecurrentDonations({ setIsDataLoading(true); setProgress(70); try { - const recurrencies = await getAuthenticatedRequest( - tenantConfig.id, - '/app/subscriptions', + const recurrencies = await getAuthenticatedRequest({ + tenant: tenantConfig.id, + url: '/app/subscriptions', token, - logoutUser - ); + logoutUser, + }); if (recurrencies && Array.isArray(recurrencies)) { const activeRecurrencies = recurrencies?.filter( (obj) => obj.status == 'active' || obj.status == 'trialing' @@ -121,17 +122,18 @@ function RecurrentDonations({ export default RecurrentDonations; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx b/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx index 9855b64586..2f3303cc2e 100644 --- a/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx +++ b/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx @@ -1,4 +1,5 @@ import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -78,13 +79,13 @@ const RedeemCode = ({ pageProps: { tenantConfig } }: Props) => { if (contextLoaded && user) { try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/redeem`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setRedeemedCodeData(res); } catch (err) { const serializedErrors = handleError(err as APIError); @@ -195,18 +196,19 @@ const RedeemCode = ({ pageProps: { tenantConfig } }: Props) => { ); }; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - code: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + code: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/profile/register-trees.tsx b/pages/sites/[slug]/[locale]/profile/register-trees.tsx index d6f0d4c6ae..58ccebbe67 100644 --- a/pages/sites/[slug]/[locale]/profile/register-trees.tsx +++ b/pages/sites/[slug]/[locale]/profile/register-trees.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -8,10 +9,10 @@ import type { import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import React from 'react'; -import dynamic from 'next/dynamic'; import UserLayout from '../../../../../src/features/common/Layout/UserLayout/UserLayout'; import Head from 'next/head'; import { useTranslations } from 'next-intl'; +import dynamic from 'next/dynamic'; import { constructPathsForTenantSlug, getTenantConfig, @@ -53,17 +54,18 @@ export default function Register({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/treemapper/data-explorer.tsx b/pages/sites/[slug]/[locale]/profile/treemapper/data-explorer.tsx index 00367f66d1..6c481efa47 100644 --- a/pages/sites/[slug]/[locale]/profile/treemapper/data-explorer.tsx +++ b/pages/sites/[slug]/[locale]/profile/treemapper/data-explorer.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -65,17 +66,18 @@ function TreeMapperAnalytics({ export default TreeMapperAnalytics; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/treemapper/import.tsx b/pages/sites/[slug]/[locale]/profile/treemapper/import.tsx index 21d3d85752..83d5bf1f4b 100644 --- a/pages/sites/[slug]/[locale]/profile/treemapper/import.tsx +++ b/pages/sites/[slug]/[locale]/profile/treemapper/import.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -53,17 +54,18 @@ export default function Import({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/treemapper/index.tsx b/pages/sites/[slug]/[locale]/profile/treemapper/index.tsx index 5d0a9e25e8..89dfde34ee 100644 --- a/pages/sites/[slug]/[locale]/profile/treemapper/index.tsx +++ b/pages/sites/[slug]/[locale]/profile/treemapper/index.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -54,17 +55,18 @@ function TreeMapperPage({ pageProps: { tenantConfig } }: Props): ReactElement { export default TreeMapperPage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/treemapper/my-species.tsx b/pages/sites/[slug]/[locale]/profile/treemapper/my-species.tsx index 221503361e..97edecda1d 100644 --- a/pages/sites/[slug]/[locale]/profile/treemapper/my-species.tsx +++ b/pages/sites/[slug]/[locale]/profile/treemapper/my-species.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -53,17 +54,18 @@ export default function MySpeciesPage({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/profile/widgets.tsx b/pages/sites/[slug]/[locale]/profile/widgets.tsx index a960ebc581..2e763cc097 100644 --- a/pages/sites/[slug]/[locale]/profile/widgets.tsx +++ b/pages/sites/[slug]/[locale]/profile/widgets.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { AbstractIntlMessages } from 'next-intl'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -71,17 +72,18 @@ function ProfilePage({ pageProps: { tenantConfig } }: Props): ReactElement { export default ProfilePage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/projects-archive/[p].tsx b/pages/sites/[slug]/[locale]/projects-archive/[p].tsx index 21388a09f9..01d2a2f374 100644 --- a/pages/sites/[slug]/[locale]/projects-archive/[p].tsx +++ b/pages/sites/[slug]/[locale]/projects-archive/[p].tsx @@ -3,6 +3,7 @@ import type { SetState } from '../../../../../src/features/common/types/common'; import type { PlantLocation } from '../../../../../src/features/common/types/plantLocation'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -94,15 +95,15 @@ export default function Donate({ setCurrencyCode(currency); try { const { p } = router.query; - const project = await getRequest( - pageProps.tenantConfig.id, - encodeURI(`/app/projects/${p}`), - { + const project = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: encodeURI(`/app/projects/${p}`), + queryParams: { _scope: 'extended', currency: currency || '', locale: locale, - } - ); + }, + }); if ( project.purpose === 'conservation' || project.purpose === 'trees' @@ -221,18 +222,19 @@ export default function Donate({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - p: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + p: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/projects-archive/index.tsx b/pages/sites/[slug]/[locale]/projects-archive/index.tsx index 2d2abdad50..5d5602a978 100644 --- a/pages/sites/[slug]/[locale]/projects-archive/index.tsx +++ b/pages/sites/[slug]/[locale]/projects-archive/index.tsx @@ -4,6 +4,12 @@ import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { DirectGiftI } from '../../../../../src/features/donations/components/DirectGift'; import type { SetState } from '../../../../../src/features/common/types/common'; import type { MapProject } from '../../../../../src/features/common/types/ProjectPropsContextInterface'; +import type { + GetStaticPaths, + GetStaticProps, + GetStaticPropsContext, + GetStaticPropsResult, +} from 'next'; import { useRouter } from 'next/router'; import React from 'react'; @@ -23,11 +29,6 @@ import { getTenantConfig, } from '../../../../../src/utils/multiTenancy/helpers'; import { useTenant } from '../../../../../src/features/common/Layout/TenantContext'; -import type { - GetStaticProps, - GetStaticPropsContext, - GetStaticPropsResult, -} from 'next'; import { defaultTenant } from '../../../../../tenant.config'; import getMessagesForPage from '../../../../../src/utils/language/getMessagesForPage'; @@ -114,17 +115,17 @@ export default function Donate({ setCurrencyCode(currency); setInternalLanguage(locale); try { - const projects = await getRequest( - pageProps.tenantConfig.id, - `/app/projects`, - { + const projects = await getRequest({ + tenant: pageProps.tenantConfig.id, + url: `/app/projects`, + queryParams: { _scope: 'map', currency: currency, tenant: pageProps.tenantConfig.id, 'filter[purpose]': 'trees,conservation', locale: locale, - } - ); + }, + }); setProjects(projects); setProject(null); setShowSingleProject(false); @@ -175,17 +176,18 @@ export default function Donate({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/s/[id].tsx b/pages/sites/[slug]/[locale]/s/[id].tsx index 2b37ae1a1e..9882b064c9 100644 --- a/pages/sites/[slug]/[locale]/s/[id].tsx +++ b/pages/sites/[slug]/[locale]/s/[id].tsx @@ -1,5 +1,6 @@ import type { ReactElement } from 'react'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -41,10 +42,10 @@ export default function DirectGift({ async function loadPublicUserData() { try { - const newProfile = await getRequest( - tenantConfig.id, - `/app/profiles/${router.query.id}` - ); + const newProfile = await getRequest({ + tenant: tenantConfig.id, + url: `/app/profiles/${router.query.id}`, + }); if (newProfile.type !== 'tpo') { localStorage.setItem( 'directGift', @@ -72,18 +73,19 @@ export default function DirectGift({ return tenantConfig ?
: <>; } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - id: v4(), - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + id: v4(), + locale: 'en', + }, + }; + }) ?? []; return { paths: paths, diff --git a/pages/sites/[slug]/[locale]/t/[profile].tsx b/pages/sites/[slug]/[locale]/t/[profile].tsx index d31a8e8662..1706ae1b13 100644 --- a/pages/sites/[slug]/[locale]/t/[profile].tsx +++ b/pages/sites/[slug]/[locale]/t/[profile].tsx @@ -1,6 +1,7 @@ // This page will be moved to a different place in the future, as it is not a part of the user dashboard import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -45,10 +46,10 @@ const PublicProfilePage = ({ pageProps: { tenantConfig } }: Props) => { async function loadPublicProfile(slug: string) { try { - const profileData = await getRequest( - tenantConfig.id, - `/app/profiles/${slug}` - ); + const profileData = await getRequest({ + tenant: tenantConfig.id, + url: `/app/profiles/${slug}`, + }); setProfile(profileData); } catch (err) { setErrors(handleError(err as APIError)); @@ -85,18 +86,19 @@ const PublicProfilePage = ({ pageProps: { tenantConfig } }: Props) => { export default PublicProfilePage; -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths?.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - profile: v4(), - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + profile: v4(), + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/verify-email.tsx b/pages/sites/[slug]/[locale]/verify-email.tsx index 7bd9142d1e..8a0f7eb464 100644 --- a/pages/sites/[slug]/[locale]/verify-email.tsx +++ b/pages/sites/[slug]/[locale]/verify-email.tsx @@ -1,6 +1,7 @@ import type { ReactElement } from 'react'; import type { Tenant } from '@planet-sdk/common/build/types/tenant'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -46,17 +47,18 @@ export default function VerifyEmail({ pageProps }: Props): ReactElement { ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { const subDomainPaths = await constructPathsForTenantSlug(); - const paths = subDomainPaths.map((path) => { - return { - params: { - slug: path.params.slug, - locale: 'en', - }, - }; - }); + const paths = + subDomainPaths?.map((path) => { + return { + params: { + slug: path.params.slug, + locale: 'en', + }, + }; + }) ?? []; return { paths, diff --git a/pages/sites/[slug]/[locale]/vto-fitness-challenge-2023.tsx b/pages/sites/[slug]/[locale]/vto-fitness-challenge-2023.tsx index cd8284daee..599faef0dd 100644 --- a/pages/sites/[slug]/[locale]/vto-fitness-challenge-2023.tsx +++ b/pages/sites/[slug]/[locale]/vto-fitness-challenge-2023.tsx @@ -5,6 +5,7 @@ import type { import type { AbstractIntlMessages } from 'next-intl'; import type { Tenant } from '@planet-sdk/common'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -102,7 +103,7 @@ export default function VTOFitnessChallenge({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { return { paths: [{ params: { slug: 'salesforce', locale: 'en' } }], fallback: 'blocking', diff --git a/pages/sites/[slug]/[locale]/vto-fitness-challenge.tsx b/pages/sites/[slug]/[locale]/vto-fitness-challenge.tsx index 9f754cf35d..a9ae636160 100644 --- a/pages/sites/[slug]/[locale]/vto-fitness-challenge.tsx +++ b/pages/sites/[slug]/[locale]/vto-fitness-challenge.tsx @@ -5,6 +5,7 @@ import type { import type { AbstractIntlMessages } from 'next-intl'; import type { Tenant } from '@planet-sdk/common'; import type { + GetStaticPaths, GetStaticProps, GetStaticPropsContext, GetStaticPropsResult, @@ -102,7 +103,7 @@ export default function VTOFitnessChallenge({ ); } -export const getStaticPaths = async () => { +export const getStaticPaths: GetStaticPaths = async () => { return { paths: [{ params: { slug: 'salesforce', locale: 'en' } }], fallback: 'blocking', diff --git a/public/static/locales/en/profile.json b/public/static/locales/en/profile.json index a7033f0fa1..3eabd28583 100644 --- a/public/static/locales/en/profile.json +++ b/public/static/locales/en/profile.json @@ -112,7 +112,8 @@ "m2": "m²" }, "infoAndCtaContainer": { - "sdgCardsSectionHeading": "Restoring Ecosystems & Fighting the Climate Crisis for the SDGs", + "sdgSectionHeadingPrimary": "Restoring Ecosystems & Fighting the Climate Crisis.", + "sdgSectionHeadingSecondary": "Contributing to the Sustainable Development Goals.", "pfpDonorCircleMember": "Plant-for-the-Planet donor circle member", "publicProfileActions": { "becomeAMember": "Become a Member", diff --git a/src/features/common/CarouselSlider/index.tsx b/src/features/common/CarouselSlider/index.tsx index 1abb424430..4d324910c0 100644 --- a/src/features/common/CarouselSlider/index.tsx +++ b/src/features/common/CarouselSlider/index.tsx @@ -41,7 +41,10 @@ const CarouselArrow = (props: { }; interface CarouselSliderProps { - carouselTitle: string; + carouselTitles: { + primary: string; + secondary: string; + }; carouselData: ReactElement[]; settings: Settings; currentSlide: number; @@ -50,7 +53,7 @@ interface CarouselSliderProps { } const CarouselSlider = ({ - carouselTitle, + carouselTitles, carouselData, settings, currentSlide, @@ -108,7 +111,8 @@ const CarouselSlider = ({
-

{carouselTitle}

+

{carouselTitles.primary}

+

{carouselTitles.secondary}

{ const fetchCurrencies = async () => { try { - const currencyData = await getRequest( - undefined, - '/app/currencies' - ); + const currencyData = await getRequest({ + url: '/app/currencies', + }); setFetchCount(fetchCount + 1); setSupportedCurrencies( new Set(Object.keys(currencyData) as CurrencyCode[]) diff --git a/src/features/common/Layout/UserPropsContext.tsx b/src/features/common/Layout/UserPropsContext.tsx index 86583ce623..a5ac076819 100644 --- a/src/features/common/Layout/UserPropsContext.tsx +++ b/src/features/common/Layout/UserPropsContext.tsx @@ -102,7 +102,7 @@ export const UserPropsProvider: FC = ({ children }) => { try { // TODO: Add error handling after figuring out the nature of getAccountInfo function call with impersonatedEmail - const res = await getAccountInfo(tenantConfig?.id, token); + const res = await getAccountInfo({ tenant: tenantConfig?.id, token }); if (res.status === 200) { const resJson = await res.json(); setUser(resJson as User); diff --git a/src/features/projects/screens/Projects.tsx b/src/features/projects/screens/Projects.tsx index 053ad6b895..82816abb42 100644 --- a/src/features/projects/screens/Projects.tsx +++ b/src/features/projects/screens/Projects.tsx @@ -175,10 +175,10 @@ function ProjectsList({ React.useEffect(() => { async function setListOrder() { try { - const res = await getRequest( - tenantConfig.id, - `/app/tenants/${tenantConfig.id}` - ); + const res = await getRequest({ + tenant: tenantConfig.id, + url: `/app/tenants/${tenantConfig.id}`, + }); setShouldSortProjectList(res.topProjectsOnly); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/projectsV2/ProjectDetails/index.tsx b/src/features/projectsV2/ProjectDetails/index.tsx index d373a71d62..ba77f307cf 100644 --- a/src/features/projectsV2/ProjectDetails/index.tsx +++ b/src/features/projectsV2/ProjectDetails/index.tsx @@ -60,15 +60,15 @@ const ProjectDetails = ({ setIsLoading(true); setIsError(false); try { - const fetchedProject = await getRequest( - tenantConfig.id, - `/app/projects/${projectSlug}`, - { + const fetchedProject = await getRequest({ + tenant: tenantConfig.id, + url: `/app/projects/${projectSlug}`, + queryParams: { _scope: 'extended', currency: currency, locale: locale, - } - ); + }, + }); const { purpose } = fetchedProject; if (purpose === 'conservation' || purpose === 'trees') { setSingleProject(fetchedProject); @@ -95,14 +95,14 @@ const ProjectDetails = ({ async function loadPlantLocations() { setIsLoading(true); try { - const result = await getRequest( - tenantConfig.id, - `/app/plantLocations/${singleProject?.id}`, - { + const result = await getRequest({ + tenant: tenantConfig.id, + url: `/app/plantLocations/${singleProject?.id}`, + queryParams: { _scope: 'extended', }, - '1.0.4' - ); + version: '1.0.4', + }); setPlantLocations(result); } catch (err) { setErrors(handleError(err as APIError | ClientError)); diff --git a/src/features/projectsV2/ProjectsContext.tsx b/src/features/projectsV2/ProjectsContext.tsx index 3bdcc675ae..73936c827b 100644 --- a/src/features/projectsV2/ProjectsContext.tsx +++ b/src/features/projectsV2/ProjectsContext.tsx @@ -195,17 +195,17 @@ export const ProjectsProvider: FC = ({ setIsLoading(true); setIsError(false); try { - const fetchedProjects = await getRequest( - tenantConfig.id, - `/app/projects`, - { + const fetchedProjects = await getRequest({ + tenant: tenantConfig.id, + url: `/app/projects`, + queryParams: { _scope: 'map', currency: currencyCode, tenant: tenantConfig.id, 'filter[purpose]': 'trees,conservation', locale: locale, - } - ); + }, + }); setProjects(fetchedProjects); setProjectsLocale(locale); } catch (err) { diff --git a/src/features/user/Account/CancelModal.tsx b/src/features/user/Account/CancelModal.tsx index 9596e2fd2c..eae5e96bdf 100644 --- a/src/features/user/Account/CancelModal.tsx +++ b/src/features/user/Account/CancelModal.tsx @@ -83,13 +83,13 @@ export const CancelModal = ({ }; try { - await putAuthenticatedRequest( - tenantConfig?.id, - `/app/subscriptions/${record.id}?scope=cancel`, - bodyToSend, + await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/subscriptions/${record.id}?scope=cancel`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); handleCancelModalClose(); fetchRecurrentDonations(); } catch (err) { diff --git a/src/features/user/Account/EditModal.tsx b/src/features/user/Account/EditModal.tsx index 98a1b035ad..17f0e90536 100644 --- a/src/features/user/Account/EditModal.tsx +++ b/src/features/user/Account/EditModal.tsx @@ -131,13 +131,13 @@ export const EditModal = ({ if (Object.keys(bodyToSend).length !== 0) { try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/subscriptions/${record?.id}?scope=modify`, - bodyToSend, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/subscriptions/${record?.id}?scope=modify`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); if (res?.status === 'action_required') { window.open(res.response.confirmationUrl, '_blank'); } diff --git a/src/features/user/Account/PauseModal.tsx b/src/features/user/Account/PauseModal.tsx index c4df4c5ee1..9b6048b2d6 100644 --- a/src/features/user/Account/PauseModal.tsx +++ b/src/features/user/Account/PauseModal.tsx @@ -90,13 +90,13 @@ export const PauseModal = ({ }; try { - await putAuthenticatedRequest( - tenantConfig?.id, - `/app/subscriptions/${record.id}?scope=pause`, - bodyToSend, + await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/subscriptions/${record.id}?scope=pause`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); handlePauseModalClose(); fetchRecurrentDonations(); } catch (err) { diff --git a/src/features/user/Account/ReactivateModal.tsx b/src/features/user/Account/ReactivateModal.tsx index 1f23468c31..e453781024 100644 --- a/src/features/user/Account/ReactivateModal.tsx +++ b/src/features/user/Account/ReactivateModal.tsx @@ -42,13 +42,13 @@ export const ReactivateModal = ({ setDisabled(true); try { - await putAuthenticatedRequest( - tenantConfig?.id, - `/app/subscriptions/${record.id}?scope=reactivate`, - bodyToSend, + await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/subscriptions/${record.id}?scope=reactivate`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); handleReactivateModalClose(); fetchRecurrentDonations(); } catch (err) { diff --git a/src/features/user/Account/components/DownloadCodes.tsx b/src/features/user/Account/components/DownloadCodes.tsx index ac8a47c1be..e0e0dafd4e 100644 --- a/src/features/user/Account/components/DownloadCodes.tsx +++ b/src/features/user/Account/components/DownloadCodes.tsx @@ -41,7 +41,7 @@ const DownloadCodes = ({ codesUrl }: DownloadCodesProps): ReactElement => { type: string; numberOfItems: number; items: []; - }>(tenantConfig?.id, codesUrl); + }>({ tenant: tenantConfig?.id, url: codesUrl }); if (response) { if (response.items.length) { downloadCSV(response.items, 'codes.csv'); diff --git a/src/features/user/BulkCodes/components/ProjectSelector.tsx b/src/features/user/BulkCodes/components/ProjectSelector.tsx index 994fee594c..83c6217b2c 100644 --- a/src/features/user/BulkCodes/components/ProjectSelector.tsx +++ b/src/features/user/BulkCodes/components/ProjectSelector.tsx @@ -19,7 +19,6 @@ interface ProjectSelectorProps { active?: boolean; planetCashAccount: PlanetCashAccount | null; } - const ProjectSelector = ({ projectList, project, @@ -32,17 +31,16 @@ const ProjectSelector = ({ const { user, token, logoutUser, contextLoaded } = useUserProps(); const fetchPaymentOptions = async (guid: string) => { - const paymentOptions = await getAuthenticatedRequest( - `${tenantConfig?.id}`, - `/app/paymentOptions/${guid}`, + const paymentOptions = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/paymentOptions/${guid}`, token, logoutUser, - undefined, - { + queryParams: { country: planetCashAccount?.country || '', ...(user !== null && { legacyPriceFor: user.id }), - } - ); + }, + }); return paymentOptions; }; diff --git a/src/features/user/BulkCodes/forms/IssueCodesForm.tsx b/src/features/user/BulkCodes/forms/IssueCodesForm.tsx index 1c4b45e251..9641007ec7 100644 --- a/src/features/user/BulkCodes/forms/IssueCodesForm.tsx +++ b/src/features/user/BulkCodes/forms/IssueCodesForm.tsx @@ -152,16 +152,16 @@ const IssueCodesForm = (): ReactElement | null => { const cleanedData = cleanObject(donationData); try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/donations`, - cleanedData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/donations`, + data: cleanedData, token, logoutUser, - { + headers: { 'IDEMPOTENCY-KEY': uuidv4(), - } - ); + }, + }); // if request is successful, it will have a uid if (res?.uid) { resetBulkContext(); diff --git a/src/features/user/BulkCodes/index.tsx b/src/features/user/BulkCodes/index.tsx index 9f6cddba66..3e675f4c67 100644 --- a/src/features/user/BulkCodes/index.tsx +++ b/src/features/user/BulkCodes/index.tsx @@ -72,10 +72,10 @@ export default function BulkCodes({ const fetchProjectList = useCallback(async () => { if (planetCashAccount && !projectList) { try { - const fetchedProjects = await getRequest( - `${tenantConfig?.id}`, - `/app/countryProjects/${planetCashAccount.country}` - ); + const fetchedProjects = await getRequest({ + tenant: tenantConfig?.id, + url: `/app/countryProjects/${planetCashAccount.country}`, + }); // map fetchedProjects to desired form and setProject if ( diff --git a/src/features/user/CompleteSignup/index.tsx b/src/features/user/CompleteSignup/index.tsx index 64e53eb69e..daaaaca270 100644 --- a/src/features/user/CompleteSignup/index.tsx +++ b/src/features/user/CompleteSignup/index.tsx @@ -178,11 +178,11 @@ export default function CompleteSignup(): ReactElement | null { setRequestSent(true); setIsProcessing(true); try { - const res = await postRequest( - tenantConfig?.id, - `/app/profile`, - bodyToSend - ); + const res = await postRequest({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, + }); setRequestSent(false); // successful signup -> goto me page setUser(res); diff --git a/src/features/user/ManagePayouts/index.tsx b/src/features/user/ManagePayouts/index.tsx index 77487e4596..76dd657c58 100644 --- a/src/features/user/ManagePayouts/index.tsx +++ b/src/features/user/ManagePayouts/index.tsx @@ -52,10 +52,10 @@ export default function ManagePayouts({ const fetchPayoutMinAmounts = useCallback(async () => { if (!payoutMinAmounts) { try { - const res = await getRequest( - tenantConfig?.id, - '/app/payoutMinAmounts' - ); + const res = await getRequest({ + tenant: tenantConfig?.id, + url: '/app/payoutMinAmounts', + }); setPayoutMinAmounts(res); } catch (err) { setErrors(handleError(err as APIError)); @@ -72,12 +72,12 @@ export default function ManagePayouts({ setIsDataLoading(true); setProgress && setProgress(70); try { - const res = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/accounts`, + const res = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/accounts`, token, - logoutUser - ); + logoutUser, + }); setAccounts(res); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/ManagePayouts/screens/AddBankAccount.tsx b/src/features/user/ManagePayouts/screens/AddBankAccount.tsx index b30c82ef4b..93c52aa133 100644 --- a/src/features/user/ManagePayouts/screens/AddBankAccount.tsx +++ b/src/features/user/ManagePayouts/screens/AddBankAccount.tsx @@ -39,13 +39,13 @@ const AddBankAccount = (): ReactElement | null => { data.currency === PayoutCurrency.DEFAULT ? '' : data.payoutMinAmount, }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - '/app/accounts', - accountData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/accounts', + data: accountData, token, - logoutUser - ); + logoutUser, + }); if (accounts) { setAccounts([...accounts, res]); } else { diff --git a/src/features/user/ManagePayouts/screens/EditBankAccount.tsx b/src/features/user/ManagePayouts/screens/EditBankAccount.tsx index fdf2d0bad1..39570949ca 100644 --- a/src/features/user/ManagePayouts/screens/EditBankAccount.tsx +++ b/src/features/user/ManagePayouts/screens/EditBankAccount.tsx @@ -45,13 +45,13 @@ const EditBankAccount = (): ReactElement | null => { }; try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/accounts/${accountToEdit?.id}`, - accountData, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/accounts/${accountToEdit?.id}`, + data: accountData, token, - logoutUser - ); + logoutUser, + }); // update accounts in context if (accounts) { const updatedAccounts = accounts.map((account) => { diff --git a/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx b/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx index 7e2a88bd27..75ce412ada 100644 --- a/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx +++ b/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx @@ -47,13 +47,13 @@ const PayoutScheduleForm = (): ReactElement | null => { setIsProcessing(true); try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - '/app/profile', - { scheduleFrequency: data.scheduleFrequency }, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile', + data: { scheduleFrequency: data.scheduleFrequency }, token, - logoutUser - ); + logoutUser, + }); setUser(res); setIsSaved(true); setIsProcessing(false); diff --git a/src/features/user/ManageProjects/ProjectsContainer.tsx b/src/features/user/ManageProjects/ProjectsContainer.tsx index 052dd5c081..b953d96e16 100644 --- a/src/features/user/ManageProjects/ProjectsContainer.tsx +++ b/src/features/user/ManageProjects/ProjectsContainer.tsx @@ -114,12 +114,12 @@ export default function ProjectsContainer() { async function loadProjects() { if (user) { try { - const projects = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/projects?version=1.2', + const projects = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/projects?version=1.2', token, - logoutUser - ); + logoutUser, + }); setProjects(projects); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/ManageProjects/components/BasicDetails.tsx b/src/features/user/ManageProjects/components/BasicDetails.tsx index 1407eedcef..b8dc673ed4 100644 --- a/src/features/user/ManageProjects/components/BasicDetails.tsx +++ b/src/features/user/ManageProjects/components/BasicDetails.tsx @@ -362,13 +362,13 @@ export default function BasicDetails({ try { const res = await putAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/projects/${projectGUID}`, - submitData, + >({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); setIsUploadingData(false); handleNext(ProjectCreationTabs.PROJECT_MEDIA); @@ -380,7 +380,13 @@ export default function BasicDetails({ try { const res = await postAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >(tenantConfig?.id, `/app/projects`, submitData, token, logoutUser); + >({ + tenant: tenantConfig?.id, + url: `/app/projects`, + data: submitData, + token, + logoutUser, + }); setProjectGUID(res.id); setProjectDetails(res); router.push(`/profile/projects/${res.id}?type=media`); diff --git a/src/features/user/ManageProjects/components/DetailedAnalysis.tsx b/src/features/user/ManageProjects/components/DetailedAnalysis.tsx index e1542258fc..fcab29a3e3 100644 --- a/src/features/user/ManageProjects/components/DetailedAnalysis.tsx +++ b/src/features/user/ManageProjects/components/DetailedAnalysis.tsx @@ -371,13 +371,13 @@ export default function DetailedAnalysis({ try { const res = await putAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/projects/${projectGUID}`, - submitData, + >({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); setIsUploadingData(false); setIsInterventionsMissing(null); diff --git a/src/features/user/ManageProjects/components/ProjectCertificates.tsx b/src/features/user/ManageProjects/components/ProjectCertificates.tsx index 77ab746618..ae3e5bb8c8 100644 --- a/src/features/user/ManageProjects/components/ProjectCertificates.tsx +++ b/src/features/user/ManageProjects/components/ProjectCertificates.tsx @@ -85,13 +85,13 @@ function ProjectCertificates({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/certificates`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/certificates`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); let newUploadedFiles = uploadedFiles; if (newUploadedFiles === undefined) { @@ -131,12 +131,12 @@ function ProjectCertificates({ const fetchCertificates = async () => { try { - const result = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=certificates`, + const result = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=certificates`, token, - logoutUser - ); + logoutUser, + }); setShowForm(false); setShowToggle(false); setUploadedFiles(result.certificates); @@ -172,12 +172,12 @@ function ProjectCertificates({ const deleteProjectCertificate = async (id: string) => { try { - await deleteAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/certificates/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/certificates/${id}`, token, - logoutUser - ); + logoutUser, + }); const uploadedFilesTemp = uploadedFiles.filter((item) => item.id !== id); setUploadedFiles(uploadedFilesTemp); } catch (err) { diff --git a/src/features/user/ManageProjects/components/ProjectMedia.tsx b/src/features/user/ManageProjects/components/ProjectMedia.tsx index cca292e1d7..72aeb0fb46 100644 --- a/src/features/user/ManageProjects/components/ProjectMedia.tsx +++ b/src/features/user/ManageProjects/components/ProjectMedia.tsx @@ -63,12 +63,12 @@ export default function ProjectMedia({ try { // Fetch images of the project if (projectGUID && token) { - const result = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=images`, + const result = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=images`, token, - logoutUser - ); + logoutUser, + }); setUploadedImages(result.images); } } catch (err) { @@ -91,13 +91,13 @@ export default function ProjectMedia({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/images`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/images`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); let newUploadedImages = [...uploadedImages]; if (!newUploadedImages) { @@ -148,12 +148,12 @@ export default function ProjectMedia({ const deleteProjectCertificate = async (id: string) => { try { - await deleteAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/images/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/images/${id}`, token, - logoutUser - ); + logoutUser, + }); const uploadedFilesTemp = uploadedImages.filter((item) => item.id !== id); setUploadedImages(uploadedFilesTemp); } catch (err) { @@ -172,13 +172,13 @@ export default function ProjectMedia({ try { const res = await putAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/projects/${projectGUID}`, - submitData, + >({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); setIsUploadingData(false); handleNext(ProjectCreationTabs.DETAILED_ANALYSIS); @@ -196,13 +196,13 @@ export default function ProjectMedia({ }; try { - await putAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/images/${id}`, - submitData, + await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/images/${id}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const tempUploadedData = uploadedImages; tempUploadedData.forEach((image) => { image.isDefault = false; @@ -228,13 +228,13 @@ export default function ProjectMedia({ }; try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/images/${id}`, - submitData, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/images/${id}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const tempUploadedData = uploadedImages; tempUploadedData[index].description = res.description; setUploadedImages(tempUploadedData); diff --git a/src/features/user/ManageProjects/components/ProjectSites.tsx b/src/features/user/ManageProjects/components/ProjectSites.tsx index 17d10eada2..c0d36d2b84 100644 --- a/src/features/user/ManageProjects/components/ProjectSites.tsx +++ b/src/features/user/ManageProjects/components/ProjectSites.tsx @@ -105,13 +105,13 @@ function EditSite({ }; try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/sites/${siteGUID}`, - submitData, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/sites/${siteGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const temp = siteList; let siteIndex = 0; temp.find((site: Site, index: number) => { @@ -338,12 +338,12 @@ export default function ProjectSites({ try { if (projectGUID) { // Fetch sites of the project - const result = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=sites`, + const result = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=sites`, token, - logoutUser - ); + logoutUser, + }); const geoLocation = { geoLatitude: result.geoLatitude, geoLongitude: result.geoLongitude, @@ -376,13 +376,13 @@ export default function ProjectSites({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/sites`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/sites`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const temp = siteList ? siteList : []; const _submitData = { id: res.id, @@ -413,12 +413,12 @@ export default function ProjectSites({ const deleteProjectSite = async (id: string) => { try { setIsUploadingData(true); - await deleteAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/sites/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/sites/${id}`, token, - logoutUser - ); + logoutUser, + }); const siteListTemp = siteList.filter((item) => item.id !== id); setSiteList(siteListTemp); setIsUploadingData(false); diff --git a/src/features/user/ManageProjects/components/ProjectSpending.tsx b/src/features/user/ManageProjects/components/ProjectSpending.tsx index 81bd36df7c..89e81c419c 100644 --- a/src/features/user/ManageProjects/components/ProjectSpending.tsx +++ b/src/features/user/ManageProjects/components/ProjectSpending.tsx @@ -95,13 +95,13 @@ export default function ProjectSpending({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/expenses`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/expenses`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const newUploadedFiles = uploadedFiles; newUploadedFiles.push(res); setUploadedFiles(newUploadedFiles); @@ -152,12 +152,12 @@ export default function ProjectSpending({ const deleteProjectSpending = async (id: string) => { try { setIsUploadingData(true); - await deleteAuthenticatedRequest( - tenantConfig?.id, - `/app/projects/${projectGUID}/expenses/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/expenses/${id}`, token, - logoutUser - ); + logoutUser, + }); const uploadedFilesTemp = uploadedFiles.filter((item) => item.id !== id); setUploadedFiles(uploadedFilesTemp); setIsUploadingData(false); @@ -171,12 +171,12 @@ export default function ProjectSpending({ try { // Fetch spending of the project if (projectGUID && token) { - const result = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=expenses`, + const result = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=expenses`, token, - logoutUser - ); + logoutUser, + }); if (result?.expenses && result.expenses.length > 0) { setShowForm(false); } diff --git a/src/features/user/ManageProjects/index.tsx b/src/features/user/ManageProjects/index.tsx index 583ed3c72e..af63490ee7 100644 --- a/src/features/user/ManageProjects/index.tsx +++ b/src/features/user/ManageProjects/index.tsx @@ -107,13 +107,13 @@ export default function ManageProjects({ try { const res = await putAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/projects/${projectGUID}`, - submitData, + >({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); setIsUploadingData(false); } catch (err) { @@ -131,13 +131,13 @@ export default function ManageProjects({ try { const res = await putAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/projects/${projectGUID}`, - submitData, + >({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); setIsUploadingData(false); } catch (err) { @@ -152,12 +152,12 @@ export default function ManageProjects({ try { const res = await getAuthenticatedRequest< ProfileProjectTrees | ProfileProjectConservation - >( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}`, + >({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}`, token, - logoutUser - ); + logoutUser, + }); setProjectDetails(res); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/PlanetCash/components/CreateAccountForm.tsx b/src/features/user/PlanetCash/components/CreateAccountForm.tsx index b559340b1c..a4181247c3 100644 --- a/src/features/user/PlanetCash/components/CreateAccountForm.tsx +++ b/src/features/user/PlanetCash/components/CreateAccountForm.tsx @@ -46,13 +46,13 @@ const CreateAccountForm = ({ setIsProcessing(true); try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - '/app/planetCash', + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/planetCash', data, token, - logoutUser - ); + logoutUser, + }); setIsAccountCreated(true); setAccounts([res]); // go to accounts tab diff --git a/src/features/user/PlanetCash/index.tsx b/src/features/user/PlanetCash/index.tsx index 333453da96..3ff93c91cf 100644 --- a/src/features/user/PlanetCash/index.tsx +++ b/src/features/user/PlanetCash/index.tsx @@ -82,12 +82,12 @@ export default function PlanetCash({ try { setIsDataLoading(true); setProgress && setProgress(70); - const accounts = await getAuthenticatedRequest( - tenantConfig?.id, - `/app/planetCash`, + const accounts = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/planetCash`, token, - logoutUser - ); + logoutUser, + }); redirectIfNeeded(accounts); const sortedAccounts = sortAccountsByActive(accounts); setIsPlanetCashActive(accounts.some((account) => account.isActive)); diff --git a/src/features/user/PlanetCash/screens/Transactions.tsx b/src/features/user/PlanetCash/screens/Transactions.tsx index 19b6af81ef..ef4c66e6c6 100644 --- a/src/features/user/PlanetCash/screens/Transactions.tsx +++ b/src/features/user/PlanetCash/screens/Transactions.tsx @@ -59,12 +59,12 @@ const Transactions = ({ : `/app/paymentHistory?filter=planet-cash&limit=15`; const newTransactionHistory = - await getAuthenticatedRequest( - tenantConfig?.id, - apiUrl, + await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: apiUrl, token, - logoutUser - ); + logoutUser, + }); if (transactionHistory) { setTransactionHistory({ diff --git a/src/features/user/Profile/ForestProgress/TargetsModal.tsx b/src/features/user/Profile/ForestProgress/TargetsModal.tsx index 27a2157238..ca6f8ec966 100644 --- a/src/features/user/Profile/ForestProgress/TargetsModal.tsx +++ b/src/features/user/Profile/ForestProgress/TargetsModal.tsx @@ -80,13 +80,13 @@ const TargetsModal = ({ }, }; try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); const newUserInfo = { profileId: res.id, slug: res.slug, diff --git a/src/features/user/Profile/InfoAndCTA/SDGCardList/index.tsx b/src/features/user/Profile/InfoAndCTA/SDGCardList/index.tsx index 12016f4679..cf1c288bdf 100644 --- a/src/features/user/Profile/InfoAndCTA/SDGCardList/index.tsx +++ b/src/features/user/Profile/InfoAndCTA/SDGCardList/index.tsx @@ -106,7 +106,10 @@ const SDGCardList = () => { return ( ( - tenantConfig?.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/redeem`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setRedeemedCodeData(res); setRefetchUserData(true); setIsLoading(false); diff --git a/src/features/user/Profile/TpoProjects/index.tsx b/src/features/user/Profile/TpoProjects/index.tsx index 3dbc8039b2..5aa3fe2255 100644 --- a/src/features/user/Profile/TpoProjects/index.tsx +++ b/src/features/user/Profile/TpoProjects/index.tsx @@ -33,13 +33,13 @@ export default function ProjectsContainer({ profile }: Props) { async function loadProjects() { try { - const projects = await getRequest( - `${tenantConfig?.id}`, - `/app/profiles/${profile.id}/projects`, - { + const projects = await getRequest({ + tenant: tenantConfig?.id, + url: `/app/profiles/${profile.id}/projects`, + queryParams: { locale: locale, - } - ); + }, + }); setProjects(projects); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx b/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx index 34d3b14d52..7f91ebfd66 100644 --- a/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx +++ b/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx @@ -42,13 +42,13 @@ export default function UploadImages({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/contributions/${contributionGUID}/images`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/contributions/${contributionGUID}/images`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const newUploadedImages: Image[] = uploadedImages; newUploadedImages.push(res); setUploadedImages(newUploadedImages); @@ -85,12 +85,12 @@ export default function UploadImages({ const deleteContributionImage = async (id: string) => { try { - await deleteAuthenticatedRequest( - tenantConfig?.id, - `/app/contributions/${contributionGUID}/images/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/contributions/${contributionGUID}/images/${id}`, token, - logoutUser - ); + logoutUser, + }); const uploadedImagesTemp = uploadedImages; const index = uploadedImagesTemp.findIndex((item) => { return item.id === id; diff --git a/src/features/user/RegisterTrees/RegisterTreesWidget.tsx b/src/features/user/RegisterTrees/RegisterTreesWidget.tsx index 53c4dc64a0..519d449efd 100644 --- a/src/features/user/RegisterTrees/RegisterTreesWidget.tsx +++ b/src/features/user/RegisterTrees/RegisterTreesWidget.tsx @@ -191,13 +191,13 @@ function RegisterTreesForm({ geometry: geometry, }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/app/contributions`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/contributions`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setErrorMessage(''); setContributionGUID(res.id); setContributionDetails(res); @@ -218,12 +218,12 @@ function RegisterTreesForm({ }; async function loadProjects() { try { - const projects = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/projects', + const projects = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/projects', token, - logoutUser - ); + logoutUser, + }); setProjects(projects); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/Settings/ApiKey/ApiKeyForm.tsx b/src/features/user/Settings/ApiKey/ApiKeyForm.tsx index 3275a05194..20067e97fb 100644 --- a/src/features/user/Settings/ApiKey/ApiKeyForm.tsx +++ b/src/features/user/Settings/ApiKey/ApiKeyForm.tsx @@ -50,12 +50,12 @@ export default function ApiKey() { const getApiKey = async () => { setIsUploadingData(true); try { - const res = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/apiKey', + const res = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/apiKey', token, - logoutUser - ); + logoutUser, + }); if (res) { setApiKey(res.apiKey || ''); } @@ -71,13 +71,12 @@ export default function ApiKey() { e.preventDefault(); setIsUploadingData(true); try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/apiKey', - undefined, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/apiKey', token, - logoutUser - ); + logoutUser, + }); if (res) { setApiKey(res.apiKey || ''); } diff --git a/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx b/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx index fbaf9c1d2e..70e98251fb 100644 --- a/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx +++ b/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx @@ -28,12 +28,12 @@ export default function DeleteProfileForm() { const handleDeleteAccount = async () => { setIsUploadingData(true); try { - await deleteAuthenticatedRequest( - tenantConfig?.id, - '/app/profile', + await deleteAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile', token, - logoutUser - ); + logoutUser, + }); setIsUploadingData(false); logoutUser(`${window.location.origin}/`); } catch (err) { diff --git a/src/features/user/Settings/EditProfile/AddressManagement/AddAddress.tsx b/src/features/user/Settings/EditProfile/AddressManagement/AddAddress.tsx index bada5fb106..e9981098bf 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/AddAddress.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/AddAddress.tsx @@ -63,13 +63,13 @@ const AddAddress = ({ type: ADDRESS_TYPE.OTHER, }; try { - const res = await postAuthenticatedRequest
( - tenantConfig.id, - '/app/addresses', - bodyToSend, + const res = await postAuthenticatedRequest
({ + tenant: tenantConfig.id, + url: '/app/addresses', + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); if (res && setUserAddresses) { setUserAddresses((prevAddresses) => [...prevAddresses, res]); } diff --git a/src/features/user/Settings/EditProfile/AddressManagement/DeleteAddress.tsx b/src/features/user/Settings/EditProfile/AddressManagement/DeleteAddress.tsx index 11402f07b7..795e16697f 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/DeleteAddress.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/DeleteAddress.tsx @@ -37,12 +37,12 @@ const DeleteAddress = ({ if (!contextLoaded || !user || !token) return; try { setIsLoading(true); - await deleteAuthenticatedRequest( - tenantConfig.id, - `/app/addresses/${addressId}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig.id, + url: `/app/addresses/${addressId}`, token, - logoutUser - ); + logoutUser, + }); updateUserAddresses(); } catch (error) { setErrors(handleError(error as APIError)); diff --git a/src/features/user/Settings/EditProfile/AddressManagement/EditAddress.tsx b/src/features/user/Settings/EditProfile/AddressManagement/EditAddress.tsx index 25ab975bcc..537dd85ebb 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/EditAddress.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/EditAddress.tsx @@ -54,13 +54,13 @@ const EditAddress = ({ type: selectedAddressForAction?.type, }; try { - const res = await putAuthenticatedRequest
( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction?.id}`, - bodyToSend, + const res = await putAuthenticatedRequest
({ + tenant: tenantConfig.id, + url: `/app/addresses/${selectedAddressForAction?.id}`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); if (res && updateUserAddresses) updateUserAddresses(); } catch (error) { setErrors(handleError(error as APIError)); diff --git a/src/features/user/Settings/EditProfile/AddressManagement/UnsetBillingAddress.tsx b/src/features/user/Settings/EditProfile/AddressManagement/UnsetBillingAddress.tsx index f83b4dae4e..e4461371c7 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/UnsetBillingAddress.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/UnsetBillingAddress.tsx @@ -43,13 +43,13 @@ const UnsetBillingAddress = ({ type: ADDRESS_TYPE.OTHER, }; try { - const res = await putAuthenticatedRequest
( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction.id}`, - bodyToSend, + const res = await putAuthenticatedRequest
({ + tenant: tenantConfig.id, + url: `/app/addresses/${selectedAddressForAction.id}`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); if (res) updateUserAddresses(); } catch (error) { setErrors(handleError(error as APIError)); diff --git a/src/features/user/Settings/EditProfile/AddressManagement/UpdateAddressType.tsx b/src/features/user/Settings/EditProfile/AddressManagement/UpdateAddressType.tsx index e3e92a9f47..01cbc4669e 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/UpdateAddressType.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/UpdateAddressType.tsx @@ -45,13 +45,13 @@ const UpdateAddressType = ({ type: addressType, }; try { - const res = await putAuthenticatedRequest
( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction.id}`, - bodyToSend, + const res = await putAuthenticatedRequest
({ + tenant: tenantConfig.id, + url: `/app/addresses/${selectedAddressForAction.id}`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); if (res) updateUserAddresses(); } catch (error) { setErrors(handleError(error as APIError)); diff --git a/src/features/user/Settings/EditProfile/AddressManagement/index.tsx b/src/features/user/Settings/EditProfile/AddressManagement/index.tsx index 6cbc44f0be..d767d4b9cc 100644 --- a/src/features/user/Settings/EditProfile/AddressManagement/index.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagement/index.tsx @@ -52,12 +52,12 @@ const AddressManagement = () => { const updateUserAddresses = useCallback(async () => { if (!user || !token || !contextLoaded) return; try { - const res = await getAuthenticatedRequest( - tenantConfig.id, - '/app/addresses', + const res = await getAuthenticatedRequest({ + tenant: tenantConfig.id, + url: '/app/addresses', token, - logoutUser - ); + logoutUser, + }); if (res) setUserAddresses(res); } catch (error) { setErrors(handleError(error as APIError)); diff --git a/src/features/user/Settings/EditProfile/EditProfileForm.tsx b/src/features/user/Settings/EditProfile/EditProfileForm.tsx index 0187fce07f..bd9bdc9ef4 100644 --- a/src/features/user/Settings/EditProfile/EditProfileForm.tsx +++ b/src/features/user/Settings/EditProfile/EditProfileForm.tsx @@ -164,13 +164,14 @@ export default function EditProfileForm() { imageFile: string | ArrayBuffer | null | undefined; }) => { try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); + if (user) { const newUserInfo = { ...user, image: res.image }; setUpdatingPic(false); @@ -235,13 +236,13 @@ export default function EditProfileForm() { if (contextLoaded && token) { try { - const res: User = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res: User = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); setSeverity('success'); setSnackbarMessage(t('profileSaved')); handleSnackbarOpen(); diff --git a/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx b/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx index 1531161211..2e4053aefa 100644 --- a/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx +++ b/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx @@ -74,7 +74,11 @@ const ImpersonateUserForm = (): ReactElement => { if (data.targetEmail && data.supportPin) { setIsProcessing(true); try { - const res = await getAccountInfo(tenantConfig?.id, token, data); + const res = await getAccountInfo({ + tenant: tenantConfig?.id, + token, + impersonationData: data, + }); const resJson = await res.json(); if (res.status === 200) { setIsInvalidEmail(false); diff --git a/src/features/user/Settings/ImpersonateUser/SupportPin.tsx b/src/features/user/Settings/ImpersonateUser/SupportPin.tsx index e43cc377e6..ff72fe6d51 100644 --- a/src/features/user/Settings/ImpersonateUser/SupportPin.tsx +++ b/src/features/user/Settings/ImpersonateUser/SupportPin.tsx @@ -15,13 +15,12 @@ const SupportPin = () => { const { tenantConfig } = useTenant(); const handleNewPin = async () => { try { - const response = await putAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/supportPin', - undefined, + const response = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/supportPin', token, - logoutUser - ); + logoutUser, + }); if (response) { const updateUserData = { ...user }; updateUserData['supportPin'] = response?.supportPin; diff --git a/src/features/user/TreeMapper/Analytics/index.tsx b/src/features/user/TreeMapper/Analytics/index.tsx index 14f05ad3b0..4cd6318161 100644 --- a/src/features/user/TreeMapper/Analytics/index.tsx +++ b/src/features/user/TreeMapper/Analytics/index.tsx @@ -26,12 +26,12 @@ const Analytics = () => { const fetchProjects = async () => { try { // TODO - update project type, this does not match completely - const res = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/projects?scope=map', + const res = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/projects?scope=map', token, - logoutUser - ); + logoutUser, + }); const projects: Project[] = []; res.forEach((_proj) => { diff --git a/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx b/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx index 1b49bcd80c..fb3a9debc3 100644 --- a/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx +++ b/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx @@ -212,12 +212,12 @@ export default function PlantingLocation({ const loadProjects = async () => { try { - const projects = await getAuthenticatedRequest( - tenantConfig?.id, - '/app/profile/projects', + const projects = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/app/profile/projects', token, - logoutUser - ); + logoutUser, + }); setProjects(projects); } catch (err) { setErrors(handleError(err as APIError)); @@ -226,12 +226,12 @@ export default function PlantingLocation({ const loadMySpecies = async () => { try { - const species = await getAuthenticatedRequest( - tenantConfig?.id, - '/treemapper/species', + const species = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/treemapper/species', token, - logoutUser - ); + logoutUser, + }); setMySpecies(species); } catch (err) { setErrors(handleError(err as APIError)); @@ -340,13 +340,13 @@ export default function PlantingLocation({ }; try { - const res = await postAuthenticatedRequest( - tenantConfig?.id, - `/treemapper/interventions`, - submitData, + const res = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/treemapper/interventions`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setPlantLocation(res); setIsUploadingData(false); handleNext(); diff --git a/src/features/user/TreeMapper/Import/components/SampleTrees.tsx b/src/features/user/TreeMapper/Import/components/SampleTrees.tsx index 29c21453f6..7f884c8c16 100644 --- a/src/features/user/TreeMapper/Import/components/SampleTrees.tsx +++ b/src/features/user/TreeMapper/Import/components/SampleTrees.tsx @@ -143,13 +143,13 @@ export default function SampleTrees({ setUploadStatus(newStatus); try { - const res: SampleTree = await postAuthenticatedRequest( - tenantConfig?.id, - `/treemapper/interventions`, - sampleTree, + const res: SampleTree = await postAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/treemapper/interventions`, + data: sampleTree, token, - logoutUser - ); + logoutUser, + }); const newSampleTrees = [...sampleTrees]; newSampleTrees[index] = res; setSampleTrees(newSampleTrees); diff --git a/src/features/user/TreeMapper/Import/index.tsx b/src/features/user/TreeMapper/Import/index.tsx index 617af4cbf8..1bdb6f3c61 100644 --- a/src/features/user/TreeMapper/Import/index.tsx +++ b/src/features/user/TreeMapper/Import/index.tsx @@ -68,12 +68,12 @@ export default function ImportData(): ReactElement { const fetchPlantLocation = async (id: string) => { try { - const result = await getAuthenticatedRequest( - tenantConfig?.id, - `/treemapper/interventions/${id}?_scope=extended`, + const result = await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/treemapper/interventions/${id}?_scope=extended`, token, - logoutUser - ); + logoutUser, + }); setPlantLocation(result); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx b/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx index 9949f8397a..ad067ecf8d 100644 --- a/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx +++ b/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx @@ -53,12 +53,12 @@ export default function MySpeciesForm() { const fetchMySpecies = async () => { try { - const result = await getAuthenticatedRequest( - tenantConfig.id, - '/treemapper/species', + const result = await getAuthenticatedRequest({ + tenant: tenantConfig.id, + url: '/treemapper/species', token, - logoutUser - ); + logoutUser, + }); setSpecies(result); } catch (err) { setErrors(handleError(err as APIError)); @@ -67,12 +67,12 @@ export default function MySpeciesForm() { const deleteSpecies = async (id: string) => { try { - await deleteAuthenticatedRequest( - tenantConfig.id, - `/treemapper/species/${id}`, + await deleteAuthenticatedRequest({ + tenant: tenantConfig.id, + url: `/treemapper/species/${id}`, token, - logoutUser - ); + logoutUser, + }); fetchMySpecies(); } catch (err) { setErrors(handleError(err as APIError)); @@ -89,13 +89,13 @@ export default function MySpeciesForm() { scientificSpecies: species.scientificSpecies?.id, }; try { - await postAuthenticatedRequest( - tenantConfig.id, - `/treemapper/species`, + await postAuthenticatedRequest({ + tenant: tenantConfig.id, + url: `/treemapper/species`, data, token, - logoutUser - ); + logoutUser, + }); } catch (err) { setErrors(handleError(err as APIError)); } diff --git a/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx b/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx index 143ea68add..59c21a791a 100644 --- a/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx +++ b/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx @@ -62,14 +62,14 @@ export default function SpeciesSelect< // Todo: debouncing if (value.length > 2) { try { - const res = await postRequest( - tenantConfig?.id, - `/suggest.php`, - { + const res = await postRequest({ + tenant: tenantConfig?.id, + url: `/suggest.php`, + data: { q: value, t: 'species', - } - ); + }, + }); if (res && res.length > 0) { const species = res.map((item) => ({ id: item.id, diff --git a/src/features/user/TreeMapper/index.tsx b/src/features/user/TreeMapper/index.tsx index 39a75ac5f0..40d35cfb02 100644 --- a/src/features/user/TreeMapper/index.tsx +++ b/src/features/user/TreeMapper/index.tsx @@ -49,15 +49,13 @@ function TreeMapper(): ReactElement { if (next && links?.next) { try { const response = - await getAuthenticatedRequest( - tenantConfig?.id, - links.next, + await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: links.next, token, logoutUser, - {}, - undefined, - '1.0.4' - ); + version: '1.0.4', + }); if (response?.items) { const newPlantLocations = response.items; for (const itr in newPlantLocations) { @@ -95,16 +93,13 @@ function TreeMapper(): ReactElement { } else { try { const response = - await getAuthenticatedRequest( - tenantConfig?.id, - '/treemapper/interventions?_scope=extended&limit=15', + await getAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: '/treemapper/interventions?_scope=extended&limit=15', token, logoutUser, - - {}, - undefined, - '1.0.4' - ); + version: '1.0.4', + }); if (response?.items) { const plantLocations = response.items; if (plantLocations?.length === 0) { diff --git a/src/features/user/Widget/DonationLink/index.tsx b/src/features/user/Widget/DonationLink/index.tsx index 2739e4c8d8..51a76b6872 100644 --- a/src/features/user/Widget/DonationLink/index.tsx +++ b/src/features/user/Widget/DonationLink/index.tsx @@ -23,16 +23,16 @@ export default function DonationLink(): ReactElement | null { async function fetchProjectList() { try { - const projectsList = await getRequest( - tenantConfig?.id, - `/app/projects`, - { + const projectsList = await getRequest({ + tenant: tenantConfig?.id, + url: `/app/projects`, + queryParams: { _scope: 'map', 'filter[purpose]': 'trees,restoration', tenant: tenantConfig?.id, locale: locale, - } - ); + }, + }); if ( projectsList && Array.isArray(projectsList) && diff --git a/src/features/user/Widget/EmbedModal.tsx b/src/features/user/Widget/EmbedModal.tsx index 4c1b9a865f..d8a880c38a 100644 --- a/src/features/user/Widget/EmbedModal.tsx +++ b/src/features/user/Widget/EmbedModal.tsx @@ -61,13 +61,13 @@ export default function EmbedModal({ }; if (contextLoaded && token) { try { - const res = await putAuthenticatedRequest( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); setSeverity('success'); setSnackbarMessage(t('profileSaved')); handleSnackbarOpen(); diff --git a/src/tenants/planet/LeaderBoard/components/Score.tsx b/src/tenants/planet/LeaderBoard/components/Score.tsx index 8a1c83999f..a46a25af10 100644 --- a/src/tenants/planet/LeaderBoard/components/Score.tsx +++ b/src/tenants/planet/LeaderBoard/components/Score.tsx @@ -31,8 +31,12 @@ export default function LeaderBoardSection(leaderboard: Props) { const { tenantConfig } = useTenant(); const fetchUsers = async (query: any) => { try { - const res = await postRequest(tenantConfig?.id, '/suggest.php', { - q: query, + const res = await postRequest({ + tenant: tenantConfig?.id, + url: '/suggest.php', + data: { + q: query, + }, }); const result = res.filter((item) => item.type !== 'competition'); setUsers(result); diff --git a/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx b/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx index 0fddbcfa75..bf0eaa9050 100644 --- a/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx @@ -34,16 +34,16 @@ export default function ProjectGrid() { async function loadProjects() { const currencyCode = getStoredCurrency(); try { - const projects = await getRequest( - tenantConfig.id, - `/app/projects`, - { + const projects = await getRequest({ + tenant: tenantConfig.id, + url: `/app/projects`, + queryParams: { _scope: 'map', currency: currencyCode, tenant: tenantConfig.id, 'filter[purpose]': 'trees,conservation', - } - ); + }, + }); setProjects(projects); setIsLoaded(true); } catch (err) { diff --git a/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx b/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx index 29637e80eb..6d120cffc3 100644 --- a/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx +++ b/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx @@ -28,9 +28,13 @@ export default function ContentSection() { try { const project = await getRequest< TreeProjectExtended | ConservationProjectExtended - >(tenantConfig.id, `/app/projects/${projectSlug}`, { - _scope: 'extended', - currency: currencyCode, + >({ + tenant: tenantConfig.id, + url: `/app/projects/${projectSlug}`, + queryParams: { + _scope: 'extended', + currency: currencyCode, + }, }); setProject(project); } catch (err) { diff --git a/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx b/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx index 7df24a2160..d9caec7839 100644 --- a/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx @@ -20,11 +20,15 @@ export default function ProjectGrid() { async function loadProjects() { const currencyCode = getStoredCurrency(); try { - const projects = await getRequest(tenantConfig.id, `/app/projects`, { - _scope: 'map', - currency: currencyCode, + const projects = await getRequest({ tenant: tenantConfig.id, - 'filter[purpose]': 'trees,conservation', + url: `/app/projects`, + queryParams: { + _scope: 'map', + currency: currencyCode, + tenant: tenantConfig.id, + 'filter[purpose]': 'trees,conservation', + }, }); setProjects(projects as MapProject[]); } catch (err) { diff --git a/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx b/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx index 16daddbb46..573ee45c8e 100644 --- a/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx @@ -20,11 +20,15 @@ export default function ProjectGrid() { async function loadProjects() { const currencyCode = getStoredCurrency(); try { - const projects = await getRequest(tenantConfig.id, `/app/projects`, { - _scope: 'map', - currency: currencyCode, + const projects = await getRequest({ tenant: tenantConfig.id, - 'filter[purpose]': 'trees,conservation', + url: `/app/projects`, + queryParams: { + _scope: 'map', + currency: currencyCode, + tenant: tenantConfig.id, + 'filter[purpose]': 'trees,conservation', + }, }); setProjects(projects as MapProject[]); } catch (err) { diff --git a/src/utils/apiRequests/api.ts b/src/utils/apiRequests/api.ts index c7f13e3851..8dba539abb 100644 --- a/src/utils/apiRequests/api.ts +++ b/src/utils/apiRequests/api.ts @@ -8,12 +8,52 @@ import { setHeaderForImpersonation } from './setHeader'; const INVALID_TOKEN_STATUS_CODE = 498; +interface BaseRequestOptions { + tenant?: string | undefined; + url: string; +} + +interface GetAccountInfoOptions { + token: string | null; + tenant: string | undefined; + impersonationData?: ImpersonationData; +} + +interface GetAuthRequestOptions extends BaseRequestOptions { + token: string | null; + logoutUser: (value?: string | undefined) => void; + header?: Record | null; + queryParams?: { [key: string]: string }; + version?: string; +} +interface PostAuthRequestOptions extends BaseRequestOptions { + token: string | null; + data: any; + logoutUser: (value?: string | undefined) => void; + headers?: Record; +} +interface DeleteAuthRequestOptions extends BaseRequestOptions { + token: string | null; + logoutUser: (value?: string | undefined) => void; +} +interface PutAuthRequestOptions extends BaseRequestOptions { + token: string | null; + data?: any; + logoutUser: (value?: string | undefined) => void; +} +interface PostRequestOptions extends BaseRequestOptions { + data: any; +} +interface GetRequestOptions extends BaseRequestOptions { + queryParams?: { [key: string]: string }; + version?: string; +} // API call to private /profile endpoint -export async function getAccountInfo( - tenant: string | undefined, - token: string | null, - impersonationData?: ImpersonationData -): Promise { +export async function getAccountInfo({ + tenant, + token, + impersonationData, +}: GetAccountInfoOptions): Promise { const lang = localStorage.getItem('language') || 'en'; const header = { 'tenant-key': `${tenant}`, @@ -36,12 +76,12 @@ function isAbsoluteUrl(url: string) { return pattern.test(url); } -export function getRequest( - tenant: string | undefined, - url: string, - queryParams?: { [key: string]: string }, - version?: string -) { +export function getRequest({ + tenant, + url, + queryParams = {}, + version, +}: GetRequestOptions): Promise { const lang = localStorage.getItem('language') || 'en'; const query = { ...queryParams }; const queryString = getQueryString(query); @@ -76,16 +116,15 @@ export function getRequest( })(); }); } - -export function getAuthenticatedRequest( - tenant: string | undefined, - url: string, - token: string | null, - logoutUser: (value?: string | undefined) => void, - header: Record | null = null, - queryParams?: { [key: string]: string }, - version?: string -) { +export function getAuthenticatedRequest({ + tenant, + url, + token, + logoutUser, + header = null, + queryParams = {}, + version = '1.0.3', +}: GetAuthRequestOptions): Promise { const lang = localStorage.getItem('language') || 'en'; const query = { ...queryParams }; const queryString = getQueryString(query); @@ -132,14 +171,14 @@ export function getAuthenticatedRequest( }); } -export function postAuthenticatedRequest( - tenant: string | undefined, - url: string, - data: any, - token: string | null, - logoutUser: (value?: string | undefined) => void, - headers?: Record -) { +export function postAuthenticatedRequest({ + tenant, + url, + data, + token, + logoutUser, + headers, +}: PostAuthRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise((resolve, reject) => { (async () => { @@ -182,11 +221,7 @@ export function postAuthenticatedRequest( }); } -export function postRequest( - tenant: string | undefined, - url: string, - data: any -) { +export function postRequest({ tenant, url, data }: PostRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise((resolve, reject) => { (async () => { @@ -218,12 +253,12 @@ export function postRequest( }); } -export function deleteAuthenticatedRequest( - tenant: string | undefined, - url: string, - token: string | null, - logoutUser: (value?: string | undefined) => void -) { +export function deleteAuthenticatedRequest({ + tenant, + url, + token, + logoutUser, +}: DeleteAuthRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise((resolve, reject) => { (async () => { @@ -264,13 +299,13 @@ export function deleteAuthenticatedRequest( }); } -export function putAuthenticatedRequest( - tenant: string | undefined, - url: string, - data: any, - token: string | null, - logoutUser: (value?: string | undefined) => void -) { +export function putAuthenticatedRequest({ + tenant, + url, + data, + token, + logoutUser, +}: PutAuthRequestOptions) { return new Promise((resolve, reject) => { const lang = localStorage.getItem('language') || 'en'; (async () => { diff --git a/src/utils/maps/plantLocations.ts b/src/utils/maps/plantLocations.ts index 4f70f6c6d3..7085cb5531 100644 --- a/src/utils/maps/plantLocations.ts +++ b/src/utils/maps/plantLocations.ts @@ -70,14 +70,14 @@ export async function getAllPlantLocations( redirect: (url: string) => void ): Promise { try { - const result = await getRequest( + const result = await getRequest({ tenant, - `/app/plantLocations/${project}`, - { + url: `/app/plantLocations/${project}`, + queryParams: { _scope: 'extended', }, - '1.0.4' - ); + version: '1.0.4', + }); if (result) { return result; } else {