diff --git a/pages/sites/[slug]/[locale]/all.tsx b/pages/sites/[slug]/[locale]/all.tsx index 7d28be43ca..216931c958 100644 --- a/pages/sites/[slug]/[locale]/all.tsx +++ b/pages/sites/[slug]/[locale]/all.tsx @@ -47,10 +47,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadLeaderboard() { try { - const newLeaderboard = await getRequest<LeaderBoardList>( - pageProps.tenantConfig.id, - `/app/leaderboard/${pageProps.tenantConfig.id}` - ); + const newLeaderboard = await getRequest<LeaderBoardList>({ + tenant: pageProps.tenantConfig.id, + url: `/app/leaderboard/${pageProps.tenantConfig.id}`, + }); setLeaderboard(newLeaderboard); } catch (err) { setErrors(handleError(err as APIError)); @@ -66,10 +66,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTenantScore() { try { - const newTenantScore = await getRequest<TenantScore>( - pageProps.tenantConfig.id, - `/app/tenantScore/${pageProps.tenantConfig.id}` - ); + const newTenantScore = await getRequest<TenantScore>({ + tenant: pageProps.tenantConfig.id, + url: `/app/tenantScore/${pageProps.tenantConfig.id}`, + }); setTenantScore(newTenantScore); } catch (err) { setErrors(handleError(err as APIError)); @@ -78,7 +78,6 @@ export default function Home({ pageProps }: Props) { loadTenantScore(); }, []); - const [treesDonated, setTreesDonated] = React.useState<TreesDonated | null>( null ); @@ -86,10 +85,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTreesDonated() { try { - const newTreesDonated = await getRequest<TreesDonated>( - pageProps.tenantConfig.id, - `${process.env.WEBHOOK_URL}/platform/total-tree-count` - ); + const newTreesDonated = await getRequest<TreesDonated>({ + tenant: pageProps.tenantConfig.id, + url: `${process.env.WEBHOOK_URL}/platform/total-tree-count`, + }); setTreesDonated(newTreesDonated); } catch (err) { setErrors(handleError(err as APIError)); @@ -103,12 +102,20 @@ export default function Home({ pageProps }: Props) { switch (pageProps.tenantConfig.config.slug) { case 'planet': AllPage = ( - <LeaderBoard leaderboard={leaderboard} tenantScore={tenantScore} treesDonated={treesDonated} /> + <LeaderBoard + leaderboard={leaderboard} + tenantScore={tenantScore} + treesDonated={treesDonated} + /> ); return AllPage; case 'ttc': AllPage = ( - <LeaderBoard leaderboard={leaderboard} tenantScore={tenantScore} treesDonated={treesDonated}/> + <LeaderBoard + leaderboard={leaderboard} + tenantScore={tenantScore} + treesDonated={treesDonated} + /> ); return AllPage; default: diff --git a/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx b/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx index 5ce505ae9b..a839ae9e54 100644 --- a/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx +++ b/pages/sites/[slug]/[locale]/claim/[type]/[code].tsx @@ -83,13 +83,13 @@ function ClaimDonation({ pageProps }: Props): ReactElement { }; if (contextLoaded && user) { try { - const res = await postAuthenticatedRequest<RedeemedCodeData>( - pageProps.tenantConfig.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest<RedeemedCodeData>({ + tenant: pageProps.tenantConfig.id, + url: `/app/redeem`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setRedeemedCodeData(res); } catch (err) { const serializedErrors = handleError(err as APIError); diff --git a/pages/sites/[slug]/[locale]/home.tsx b/pages/sites/[slug]/[locale]/home.tsx index 57c52209cb..dcc8fe1368 100644 --- a/pages/sites/[slug]/[locale]/home.tsx +++ b/pages/sites/[slug]/[locale]/home.tsx @@ -52,10 +52,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadTenantScore() { try { - const newTenantScore = await getRequest<TenantScore>( - pageProps.tenantConfig.id, - `/app/tenantScore` - ); + const newTenantScore = await getRequest<TenantScore>({ + tenant: pageProps.tenantConfig.id, + url: `/app/tenantScore`, + }); setTenantScore(newTenantScore); } catch (err) { setErrors(handleError(err as APIError)); @@ -67,10 +67,10 @@ export default function Home({ pageProps }: Props) { React.useEffect(() => { async function loadLeaderboard() { try { - const newLeaderBoard = await getRequest<LeaderBoardList>( - pageProps.tenantConfig.id, - `/app/leaderboard` - ); + const newLeaderBoard = await getRequest<LeaderBoardList>({ + tenant: pageProps.tenantConfig.id, + url: `/app/leaderboard`, + }); setLeaderboard(newLeaderBoard); } catch (err) { setErrors(handleError(err as APIError)); 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..782b0adb6e 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx @@ -63,17 +63,16 @@ export default function BulkCodeIssueCodesPage({ if (router.isReady) { try { const paymentOptions = - await getAuthenticatedRequest<PaymentOptions>( - pageProps.tenantConfig.id, - `/app/paymentOptions/${router.query.id}`, + await getAuthenticatedRequest<PaymentOptions>({ + 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( diff --git a/pages/sites/[slug]/[locale]/profile/history.tsx b/pages/sites/[slug]/[locale]/profile/history.tsx index d761e2a5e7..1191db344c 100644 --- a/pages/sites/[slug]/[locale]/profile/history.tsx +++ b/pages/sites/[slug]/[locale]/profile/history.tsx @@ -65,16 +65,18 @@ function AccountHistory({ pageProps }: Props): ReactElement { if (next && paymentHistory?._links?.next) { try { const newPaymentHistory = await getAuthenticatedRequest<PaymentHistory>( - 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 +93,12 @@ function AccountHistory({ pageProps }: Props): ReactElement { } else { if (filter === null) { try { - const paymentHistory = await getAuthenticatedRequest<PaymentHistory>( - tenantConfig?.id, - '/app/paymentHistory?limit=15', + const paymentHistory = await getAuthenticatedRequest<PaymentHistory>({ + tenant: tenantConfig?.id, + url: '/app/paymentHistory?limit=15', token, - logoutUser - ); + logoutUser, + }); setPaymentHistory(paymentHistory); setProgress(100); setIsDataLoading(false); @@ -108,16 +110,16 @@ function AccountHistory({ pageProps }: Props): ReactElement { } } else { try { - const paymentHistory = await getAuthenticatedRequest<PaymentHistory>( - tenantConfig?.id, - `${ + const paymentHistory = await getAuthenticatedRequest<PaymentHistory>({ + tenant: tenantConfig?.id, + url: `${ filter && accountingFilters ? accountingFilters[filter] + '&limit=15' : '/app/paymentHistory?limit=15' }`, token, - logoutUser - ); + logoutUser, + }); setPaymentHistory(paymentHistory); setProgress(100); setIsDataLoading(false); diff --git a/pages/sites/[slug]/[locale]/profile/projects/[id].tsx b/pages/sites/[slug]/[locale]/profile/projects/[id].tsx index f464cd340f..19276cbf9d 100644 --- a/pages/sites/[slug]/[locale]/profile/projects/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/projects/[id].tsx @@ -68,12 +68,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) { diff --git a/pages/sites/[slug]/[locale]/profile/recurrency.tsx b/pages/sites/[slug]/[locale]/profile/recurrency.tsx index 417c5e1567..782f99a543 100644 --- a/pages/sites/[slug]/[locale]/profile/recurrency.tsx +++ b/pages/sites/[slug]/[locale]/profile/recurrency.tsx @@ -52,12 +52,12 @@ function RecurrentDonations({ setIsDataLoading(true); setProgress(70); try { - const recurrencies = await getAuthenticatedRequest<Subscription[]>( - tenantConfig.id, - '/app/subscriptions', + const recurrencies = await getAuthenticatedRequest<Subscription[]>({ + 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' diff --git a/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx b/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx index 9855b64586..7bec275df5 100644 --- a/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx +++ b/pages/sites/[slug]/[locale]/profile/redeem/[code].tsx @@ -78,13 +78,13 @@ const RedeemCode = ({ pageProps: { tenantConfig } }: Props) => { if (contextLoaded && user) { try { - const res = await postAuthenticatedRequest<RedeemedCodeData>( - tenantConfig?.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest<RedeemedCodeData>({ + tenant: tenantConfig?.id, + url: `/app/redeem`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setRedeemedCodeData(res); } catch (err) { const serializedErrors = handleError(err as APIError); diff --git a/pages/sites/[slug]/[locale]/projects-archive/[p].tsx b/pages/sites/[slug]/[locale]/projects-archive/[p].tsx index bd3d764eca..1f13da6958 100644 --- a/pages/sites/[slug]/[locale]/projects-archive/[p].tsx +++ b/pages/sites/[slug]/[locale]/projects-archive/[p].tsx @@ -93,15 +93,15 @@ export default function Donate({ setCurrencyCode(currency); try { const { p } = router.query; - const project = await getRequest<ProjectExtended>( - pageProps.tenantConfig.id, - encodeURI(`/app/projects/${p}`), - { + const project = await getRequest<ProjectExtended>({ + tenant: pageProps.tenantConfig.id, + url: encodeURI(`/app/projects/${p}`), + queryParams: { _scope: 'extended', currency: currency || '', locale: locale, - } - ); + }, + }); if ( project.purpose === 'conservation' || project.purpose === 'trees' diff --git a/pages/sites/[slug]/[locale]/projects-archive/index.tsx b/pages/sites/[slug]/[locale]/projects-archive/index.tsx index 3b939b50a7..6f904f2969 100644 --- a/pages/sites/[slug]/[locale]/projects-archive/index.tsx +++ b/pages/sites/[slug]/[locale]/projects-archive/index.tsx @@ -113,17 +113,17 @@ export default function Donate({ setCurrencyCode(currency); setInternalLanguage(locale); try { - const projects = await getRequest<MapProject[]>( - pageProps.tenantConfig.id, - `/app/projects`, - { + const projects = await getRequest<MapProject[]>({ + 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); diff --git a/pages/sites/[slug]/[locale]/s/[id].tsx b/pages/sites/[slug]/[locale]/s/[id].tsx index 6ab7f124a1..2888b9d1ec 100644 --- a/pages/sites/[slug]/[locale]/s/[id].tsx +++ b/pages/sites/[slug]/[locale]/s/[id].tsx @@ -38,10 +38,10 @@ export default function DirectGift({ async function loadPublicUserData() { try { - const newProfile = await getRequest<UserPublicProfile>( - tenantConfig.id, - `/app/profiles/${router.query.id}` - ); + const newProfile = await getRequest<UserPublicProfile>({ + tenant: tenantConfig.id, + url: `/app/profiles/${router.query.id}`, + }); if (newProfile.type !== 'tpo') { localStorage.setItem( 'directGift', diff --git a/pages/sites/[slug]/[locale]/t/[profile].tsx b/pages/sites/[slug]/[locale]/t/[profile].tsx index 6392cfbdcc..a52a061ae9 100644 --- a/pages/sites/[slug]/[locale]/t/[profile].tsx +++ b/pages/sites/[slug]/[locale]/t/[profile].tsx @@ -43,10 +43,10 @@ const PublicProfilePage = ({ pageProps: { tenantConfig } }: Props) => { async function loadPublicProfile(slug: string) { try { - const profileData = await getRequest<UserPublicProfile>( - tenantConfig.id, - `/app/profiles/${slug}` - ); + const profileData = await getRequest<UserPublicProfile>({ + tenant: tenantConfig.id, + url: `/app/profiles/${slug}`, + }); setProfile(profileData); } catch (err) { setErrors(handleError(err as APIError)); diff --git a/src/features/common/Layout/CurrencyContext.tsx b/src/features/common/Layout/CurrencyContext.tsx index 055952a07c..b203d1b2fd 100644 --- a/src/features/common/Layout/CurrencyContext.tsx +++ b/src/features/common/Layout/CurrencyContext.tsx @@ -24,10 +24,9 @@ export const CurrencyProvider: FC = ({ children }) => { const fetchCurrencies = async () => { try { - const currencyData = await getRequest<CurrencyList>( - undefined, - '/app/currencies' - ); + const currencyData = await getRequest<CurrencyList>({ + 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 8615bb7578..815d1ca656 100644 --- a/src/features/common/Layout/UserPropsContext.tsx +++ b/src/features/common/Layout/UserPropsContext.tsx @@ -100,7 +100,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 dfa2d0aff4..65b1a5f004 100644 --- a/src/features/projects/screens/Projects.tsx +++ b/src/features/projects/screens/Projects.tsx @@ -172,10 +172,10 @@ function ProjectsList({ React.useEffect(() => { async function setListOrder() { try { - const res = await getRequest<Tenant>( - tenantConfig.id, - `/app/tenants/${tenantConfig.id}` - ); + const res = await getRequest<Tenant>({ + 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<ExtendedProject>( - tenantConfig.id, - `/app/projects/${projectSlug}`, - { + const fetchedProject = await getRequest<ExtendedProject>({ + 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<PlantLocation[]>( - tenantConfig.id, - `/app/plantLocations/${singleProject?.id}`, - { + const result = await getRequest<PlantLocation[]>({ + 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<ProjectsProviderProps> = ({ setIsLoading(true); setIsError(false); try { - const fetchedProjects = await getRequest<MapProject[]>( - tenantConfig.id, - `/app/projects`, - { + const fetchedProjects = await getRequest<MapProject[]>({ + 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 d14f5d030b..7775d96d99 100644 --- a/src/features/user/Account/CancelModal.tsx +++ b/src/features/user/Account/CancelModal.tsx @@ -82,13 +82,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 e2db5104bf..426b76731a 100644 --- a/src/features/user/Account/EditModal.tsx +++ b/src/features/user/Account/EditModal.tsx @@ -126,13 +126,13 @@ export const EditModal = ({ if (Object.keys(bodyToSend).length !== 0) { try { - const res = await putAuthenticatedRequest<ModifyDonations>( - tenantConfig?.id, - `/app/subscriptions/${record?.id}?scope=modify`, - bodyToSend, + const res = await putAuthenticatedRequest<ModifyDonations>({ + 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 16c8c13c78..ca2a115541 100644 --- a/src/features/user/Account/PauseModal.tsx +++ b/src/features/user/Account/PauseModal.tsx @@ -88,13 +88,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 e640ef8a44..5a7a9d5d2e 100644 --- a/src/features/user/Account/ReactivateModal.tsx +++ b/src/features/user/Account/ReactivateModal.tsx @@ -40,13 +40,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 b269834bdc..c424c65bcf 100644 --- a/src/features/user/Account/components/DownloadCodes.tsx +++ b/src/features/user/Account/components/DownloadCodes.tsx @@ -38,7 +38,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<PaymentOptions>( - `${tenantConfig?.id}`, - `/app/paymentOptions/${guid}`, + const paymentOptions = await getAuthenticatedRequest<PaymentOptions>({ + 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<Donation>( - tenantConfig?.id, - `/app/donations`, - cleanedData, + const res = await postAuthenticatedRequest<Donation>({ + 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<CountryProject[]>( - `${tenantConfig?.id}`, - `/app/countryProjects/${planetCashAccount.country}` - ); + const fetchedProjects = await getRequest<CountryProject[]>({ + 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 e236c8c975..3b2374ab33 100644 --- a/src/features/user/CompleteSignup/index.tsx +++ b/src/features/user/CompleteSignup/index.tsx @@ -176,11 +176,11 @@ export default function CompleteSignup(): ReactElement | null { setRequestSent(true); setIsProcessing(true); try { - const res = await postRequest<User>( - tenantConfig?.id, - `/app/profile`, - bodyToSend - ); + const res = await postRequest<User>({ + 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 d39670d426..0b027c8185 100644 --- a/src/features/user/ManagePayouts/index.tsx +++ b/src/features/user/ManagePayouts/index.tsx @@ -56,10 +56,10 @@ export default function ManagePayouts({ const fetchPayoutMinAmounts = useCallback(async () => { if (!payoutMinAmounts) { try { - const res = await getRequest<PayoutMinAmounts>( - tenantConfig?.id, - '/app/payoutMinAmounts' - ); + const res = await getRequest<PayoutMinAmounts>({ + tenant: tenantConfig?.id, + url: '/app/payoutMinAmounts', + }); setPayoutMinAmounts(res); } catch (err) { setErrors(handleError(err as APIError)); @@ -76,12 +76,12 @@ export default function ManagePayouts({ setIsDataLoading(true); setProgress && setProgress(70); try { - const res = await getAuthenticatedRequest<BankAccount[]>( - tenantConfig?.id, - `/app/accounts`, + const res = await getAuthenticatedRequest<BankAccount[]>({ + 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 ced3484c0a..efa29c3448 100644 --- a/src/features/user/ManagePayouts/screens/AddBankAccount.tsx +++ b/src/features/user/ManagePayouts/screens/AddBankAccount.tsx @@ -35,13 +35,13 @@ const AddBankAccount = (): ReactElement | null => { data.currency === PayoutCurrency.DEFAULT ? '' : data.payoutMinAmount, }; try { - const res = await postAuthenticatedRequest<BankAccount>( - tenantConfig?.id, - '/app/accounts', - accountData, + const res = await postAuthenticatedRequest<BankAccount>({ + 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 c8bd87c49e..579b79f283 100644 --- a/src/features/user/ManagePayouts/screens/EditBankAccount.tsx +++ b/src/features/user/ManagePayouts/screens/EditBankAccount.tsx @@ -41,13 +41,13 @@ const EditBankAccount = (): ReactElement | null => { }; try { - const res = await putAuthenticatedRequest<BankAccount>( - tenantConfig?.id, - `/app/accounts/${accountToEdit?.id}`, - accountData, + const res = await putAuthenticatedRequest<BankAccount>({ + 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 0f32c7377c..0faa5601bf 100644 --- a/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx +++ b/src/features/user/ManagePayouts/screens/PayoutScheduleForm.tsx @@ -44,13 +44,13 @@ const PayoutScheduleForm = (): ReactElement | null => { setIsProcessing(true); try { - const res = await putAuthenticatedRequest<User>( - tenantConfig?.id, - '/app/profile', - { scheduleFrequency: data.scheduleFrequency }, + const res = await putAuthenticatedRequest<User>({ + 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 e1cc8207d4..9e47e105eb 100644 --- a/src/features/user/ManageProjects/ProjectsContainer.tsx +++ b/src/features/user/ManageProjects/ProjectsContainer.tsx @@ -112,12 +112,12 @@ export default function ProjectsContainer() { async function loadProjects() { if (user) { try { - const projects = await getAuthenticatedRequest<UserProjectsType[]>( - tenantConfig?.id, - '/app/profile/projects?version=1.2', + const projects = await getAuthenticatedRequest<UserProjectsType[]>({ + 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 e9fd823a06..127ab16fb7 100644 --- a/src/features/user/ManageProjects/components/BasicDetails.tsx +++ b/src/features/user/ManageProjects/components/BasicDetails.tsx @@ -366,13 +366,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); @@ -384,7 +384,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 4e58ef2018..a2b0acba4d 100644 --- a/src/features/user/ManageProjects/components/DetailedAnalysis.tsx +++ b/src/features/user/ManageProjects/components/DetailedAnalysis.tsx @@ -367,13 +367,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 6405ecd85f..a02fe94eed 100644 --- a/src/features/user/ManageProjects/components/ProjectCertificates.tsx +++ b/src/features/user/ManageProjects/components/ProjectCertificates.tsx @@ -87,13 +87,13 @@ function ProjectCertificates({ }; try { - const res = await postAuthenticatedRequest<Certificate>( - tenantConfig?.id, - `/app/projects/${projectGUID}/certificates`, - submitData, + const res = await postAuthenticatedRequest<Certificate>({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/certificates`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); let newUploadedFiles = uploadedFiles; if (newUploadedFiles === undefined) { @@ -133,12 +133,12 @@ function ProjectCertificates({ const fetchCertificates = async () => { try { - const result = await getAuthenticatedRequest<CertificateScopeProjects>( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=certificates`, + const result = await getAuthenticatedRequest<CertificateScopeProjects>({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=certificates`, token, - logoutUser - ); + logoutUser, + }); setShowForm(false); setShowToggle(false); setUploadedFiles(result.certificates); @@ -174,12 +174,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 fa3e1bd50e..a843787272 100644 --- a/src/features/user/ManageProjects/components/ProjectMedia.tsx +++ b/src/features/user/ManageProjects/components/ProjectMedia.tsx @@ -67,12 +67,12 @@ export default function ProjectMedia({ try { // Fetch images of the project if (projectGUID && token) { - const result = await getAuthenticatedRequest<ImagesScopeProjects>( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=images`, + const result = await getAuthenticatedRequest<ImagesScopeProjects>({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=images`, token, - logoutUser - ); + logoutUser, + }); setUploadedImages(result.images); } } catch (err) { @@ -95,13 +95,13 @@ export default function ProjectMedia({ }; try { - const res = await postAuthenticatedRequest<UploadImage>( - tenantConfig?.id, - `/app/projects/${projectGUID}/images`, - submitData, + const res = await postAuthenticatedRequest<UploadImage>({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/images`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); let newUploadedImages = [...uploadedImages]; if (!newUploadedImages) { @@ -152,12 +152,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) { @@ -176,13 +176,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); @@ -200,13 +200,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; @@ -232,13 +232,13 @@ export default function ProjectMedia({ }; try { - const res = await putAuthenticatedRequest<UploadImage>( - tenantConfig?.id, - `/app/projects/${projectGUID}/images/${id}`, - submitData, + const res = await putAuthenticatedRequest<UploadImage>({ + 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 2f6d070306..55b4ba0c53 100644 --- a/src/features/user/ManageProjects/components/ProjectSites.tsx +++ b/src/features/user/ManageProjects/components/ProjectSites.tsx @@ -102,13 +102,13 @@ function EditSite({ }; try { - const res = await putAuthenticatedRequest<Site>( - tenantConfig?.id, - `/app/projects/${projectGUID}/sites/${siteGUID}`, - submitData, + const res = await putAuthenticatedRequest<Site>({ + 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) => { @@ -335,12 +335,12 @@ export default function ProjectSites({ try { if (projectGUID) { // Fetch sites of the project - const result = await getAuthenticatedRequest<SitesScopeProjects>( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=sites`, + const result = await getAuthenticatedRequest<SitesScopeProjects>({ + tenant: tenantConfig?.id, + url: `/app/profile/projects/${projectGUID}?_scope=sites`, token, - logoutUser - ); + logoutUser, + }); const geoLocation = { geoLatitude: result.geoLatitude, geoLongitude: result.geoLongitude, @@ -373,13 +373,13 @@ export default function ProjectSites({ }; try { - const res = await postAuthenticatedRequest<Site>( - tenantConfig?.id, - `/app/projects/${projectGUID}/sites`, - submitData, + const res = await postAuthenticatedRequest<Site>({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/sites`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const temp = siteList ? siteList : []; const _submitData = { id: res.id, @@ -410,12 +410,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 a9fcd0499b..abbefe5f73 100644 --- a/src/features/user/ManageProjects/components/ProjectSpending.tsx +++ b/src/features/user/ManageProjects/components/ProjectSpending.tsx @@ -91,13 +91,13 @@ export default function ProjectSpending({ }; try { - const res = await postAuthenticatedRequest<ProjectExpense>( - tenantConfig?.id, - `/app/projects/${projectGUID}/expenses`, - submitData, + const res = await postAuthenticatedRequest<ProjectExpense>({ + tenant: tenantConfig?.id, + url: `/app/projects/${projectGUID}/expenses`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const newUploadedFiles = uploadedFiles; newUploadedFiles.push(res); setUploadedFiles(newUploadedFiles); @@ -148,12 +148,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); @@ -167,12 +167,12 @@ export default function ProjectSpending({ try { // Fetch spending of the project if (projectGUID && token) { - const result = await getAuthenticatedRequest<ExpensesScopeProjects>( - tenantConfig?.id, - `/app/profile/projects/${projectGUID}?_scope=expenses`, + const result = await getAuthenticatedRequest<ExpensesScopeProjects>({ + 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 ad5b4ff677..4409cb1453 100644 --- a/src/features/user/ManageProjects/index.tsx +++ b/src/features/user/ManageProjects/index.tsx @@ -105,13 +105,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) { @@ -129,13 +129,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) { @@ -150,12 +150,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 99ece1900e..225534d41c 100644 --- a/src/features/user/PlanetCash/components/CreateAccountForm.tsx +++ b/src/features/user/PlanetCash/components/CreateAccountForm.tsx @@ -43,13 +43,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 8b956b4b6f..6b3f1032e2 100644 --- a/src/features/user/PlanetCash/index.tsx +++ b/src/features/user/PlanetCash/index.tsx @@ -86,12 +86,12 @@ export default function PlanetCash({ try { setIsDataLoading(true); setProgress && setProgress(70); - const accounts = await getAuthenticatedRequest<PlanetCashAccount[]>( - tenantConfig?.id, - `/app/planetCash`, + const accounts = await getAuthenticatedRequest<PlanetCashAccount[]>({ + 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 a76bb17f56..ebf56e870c 100644 --- a/src/features/user/PlanetCash/screens/Transactions.tsx +++ b/src/features/user/PlanetCash/screens/Transactions.tsx @@ -63,12 +63,12 @@ const Transactions = ({ : `/app/paymentHistory?filter=planet-cash&limit=15`; const newTransactionHistory = - await getAuthenticatedRequest<PaymentHistory>( - tenantConfig?.id, - apiUrl, + await getAuthenticatedRequest<PaymentHistory>({ + 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 b4ce795df4..d17c95f1ed 100644 --- a/src/features/user/Profile/ForestProgress/TargetsModal.tsx +++ b/src/features/user/Profile/ForestProgress/TargetsModal.tsx @@ -78,13 +78,13 @@ const TargetsModal = ({ }, }; try { - const res = await putAuthenticatedRequest<User>( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest<User>({ + 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/ProfileCard/RedeemModal/index.tsx b/src/features/user/Profile/ProfileCard/RedeemModal/index.tsx index 4e2f43b8e6..7c3cc94d2f 100644 --- a/src/features/user/Profile/ProfileCard/RedeemModal/index.tsx +++ b/src/features/user/Profile/ProfileCard/RedeemModal/index.tsx @@ -50,13 +50,13 @@ export default function RedeemModal({ }; if (contextLoaded && user) { try { - const res = await postAuthenticatedRequest<RedeemedCodeData>( - tenantConfig?.id, - `/app/redeem`, - submitData, + const res = await postAuthenticatedRequest<RedeemedCodeData>({ + 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 05774bccd2..1f101c63e4 100644 --- a/src/features/user/Profile/TpoProjects/index.tsx +++ b/src/features/user/Profile/TpoProjects/index.tsx @@ -31,13 +31,13 @@ export default function ProjectsContainer({ profile }: Props) { async function loadProjects() { try { - const projects = await getRequest<MapProject[]>( - `${tenantConfig?.id}`, - `/app/profiles/${profile.id}/projects`, - { + const projects = await getRequest<MapProject[]>({ + 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 74969cbbcc..0c75774526 100644 --- a/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx +++ b/src/features/user/RegisterTrees/RegisterTrees/UploadImages.tsx @@ -39,13 +39,13 @@ export default function UploadImages({ }; try { - const res = await postAuthenticatedRequest<Image>( - tenantConfig?.id, - `/app/contributions/${contributionGUID}/images`, - submitData, + const res = await postAuthenticatedRequest<Image>({ + tenant: tenantConfig?.id, + url: `/app/contributions/${contributionGUID}/images`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); const newUploadedImages: Image[] = uploadedImages; newUploadedImages.push(res); setUploadedImages(newUploadedImages); @@ -82,12 +82,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 453deb118b..b0e0288627 100644 --- a/src/features/user/RegisterTrees/RegisterTreesWidget.tsx +++ b/src/features/user/RegisterTrees/RegisterTreesWidget.tsx @@ -189,13 +189,13 @@ function RegisterTreesForm({ geometry: geometry, }; try { - const res = await postAuthenticatedRequest<ContributionProperties>( - tenantConfig?.id, - `/app/contributions`, - submitData, + const res = await postAuthenticatedRequest<ContributionProperties>({ + tenant: tenantConfig?.id, + url: `/app/contributions`, + data: submitData, token, - logoutUser - ); + logoutUser, + }); setErrorMessage(''); setContributionGUID(res.id); setContributionDetails(res); @@ -216,12 +216,12 @@ function RegisterTreesForm({ }; async function loadProjects() { try { - const projects = await getAuthenticatedRequest<ProjectGeoJsonProps[]>( - tenantConfig?.id, - '/app/profile/projects', + const projects = await getAuthenticatedRequest<ProjectGeoJsonProps[]>({ + 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 8886884903..b8d38f2b8e 100644 --- a/src/features/user/Settings/ApiKey/ApiKeyForm.tsx +++ b/src/features/user/Settings/ApiKey/ApiKeyForm.tsx @@ -48,12 +48,12 @@ export default function ApiKey() { const getApiKey = async () => { setIsUploadingData(true); try { - const res = await getAuthenticatedRequest<ApiKeyResponse>( - tenantConfig?.id, - '/app/profile/apiKey', + const res = await getAuthenticatedRequest<ApiKeyResponse>({ + tenant: tenantConfig?.id, + url: '/app/profile/apiKey', token, - logoutUser - ); + logoutUser, + }); if (res) { setApiKey(res.apiKey || ''); } @@ -69,13 +69,12 @@ export default function ApiKey() { e.preventDefault(); setIsUploadingData(true); try { - const res = await putAuthenticatedRequest<ApiKeyResponse>( - tenantConfig?.id, - '/app/profile/apiKey', - undefined, + const res = await putAuthenticatedRequest<ApiKeyResponse>({ + 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 815e043a02..e7a44c05a8 100644 --- a/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx +++ b/src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx @@ -26,12 +26,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<Address>( - tenantConfig.id, - '/app/addresses', - bodyToSend, + const res = await postAuthenticatedRequest<Address>({ + 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<Address>( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction?.id}`, - bodyToSend, + const res = await putAuthenticatedRequest<Address>({ + 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<Address>( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction.id}`, - bodyToSend, + const res = await putAuthenticatedRequest<Address>({ + 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<Address>( - tenantConfig.id, - `/app/addresses/${selectedAddressForAction.id}`, - bodyToSend, + const res = await putAuthenticatedRequest<Address>({ + 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<Address[]>( - tenantConfig.id, - '/app/addresses', + const res = await getAuthenticatedRequest<Address[]>({ + 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 424aefe17c..cc9fcf158b 100644 --- a/src/features/user/Settings/EditProfile/EditProfileForm.tsx +++ b/src/features/user/Settings/EditProfile/EditProfileForm.tsx @@ -162,13 +162,14 @@ export default function EditProfileForm() { imageFile: string | ArrayBuffer | null | undefined; }) => { try { - const res = await putAuthenticatedRequest<User>( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest<User>({ + tenant: tenantConfig?.id, + url: `/app/profile`, + data: bodyToSend, token, - logoutUser - ); + logoutUser, + }); + if (user) { const newUserInfo = { ...user, image: res.image }; setUpdatingPic(false); @@ -233,13 +234,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 2357bca024..47d7eb79b0 100644 --- a/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx +++ b/src/features/user/Settings/ImpersonateUser/ImpersonateUserForm.tsx @@ -72,7 +72,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<SupportPin>( - tenantConfig?.id, - '/app/profile/supportPin', - undefined, + const response = await putAuthenticatedRequest<SupportPin>({ + 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 aea8d0cf2c..23bbace1f1 100644 --- a/src/features/user/TreeMapper/Analytics/index.tsx +++ b/src/features/user/TreeMapper/Analytics/index.tsx @@ -23,12 +23,12 @@ const Analytics = () => { const fetchProjects = async () => { try { // TODO - update project type, this does not match completely - const res = await getAuthenticatedRequest<MapProject[]>( - tenantConfig?.id, - '/app/profile/projects?scope=map', + const res = await getAuthenticatedRequest<MapProject[]>({ + 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 283103cba7..a53684e8f1 100644 --- a/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx +++ b/src/features/user/TreeMapper/Import/components/PlantingLocation.tsx @@ -213,12 +213,12 @@ export default function PlantingLocation({ const loadProjects = async () => { try { - const projects = await getAuthenticatedRequest<MapProject[]>( - tenantConfig?.id, - '/app/profile/projects', + const projects = await getAuthenticatedRequest<MapProject[]>({ + tenant: tenantConfig?.id, + url: '/app/profile/projects', token, - logoutUser - ); + logoutUser, + }); setProjects(projects); } catch (err) { setErrors(handleError(err as APIError)); @@ -227,12 +227,12 @@ export default function PlantingLocation({ const loadMySpecies = async () => { try { - const species = await getAuthenticatedRequest<Species[]>( - tenantConfig?.id, - '/treemapper/species', + const species = await getAuthenticatedRequest<Species[]>({ + tenant: tenantConfig?.id, + url: '/treemapper/species', token, - logoutUser - ); + logoutUser, + }); setMySpecies(species); } catch (err) { setErrors(handleError(err as APIError)); @@ -341,13 +341,13 @@ export default function PlantingLocation({ }; try { - const res = await postAuthenticatedRequest<PlantLocationType>( - tenantConfig?.id, - `/treemapper/interventions`, - submitData, + const res = await postAuthenticatedRequest<PlantLocationType>({ + 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 1d9d8e62ca..d8e9607529 100644 --- a/src/features/user/TreeMapper/Import/components/SampleTrees.tsx +++ b/src/features/user/TreeMapper/Import/components/SampleTrees.tsx @@ -140,13 +140,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 5673981169..eb08b55d08 100644 --- a/src/features/user/TreeMapper/Import/index.tsx +++ b/src/features/user/TreeMapper/Import/index.tsx @@ -65,12 +65,12 @@ export default function ImportData(): ReactElement { const fetchPlantLocation = async (id: string) => { try { - const result = await getAuthenticatedRequest<PlantLocationType>( - tenantConfig?.id, - `/treemapper/interventions/${id}?_scope=extended`, + const result = await getAuthenticatedRequest<PlantLocationType>({ + 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 742022b191..b7b531bae0 100644 --- a/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx +++ b/src/features/user/TreeMapper/MySpecies/MySpeciesForm.tsx @@ -51,12 +51,12 @@ export default function MySpeciesForm() { const fetchMySpecies = async () => { try { - const result = await getAuthenticatedRequest<Species[]>( - tenantConfig.id, - '/treemapper/species', + const result = await getAuthenticatedRequest<Species[]>({ + tenant: tenantConfig.id, + url: '/treemapper/species', token, - logoutUser - ); + logoutUser, + }); setSpecies(result); } catch (err) { setErrors(handleError(err as APIError)); @@ -65,12 +65,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)); @@ -87,13 +87,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 ef1a28bc30..0b8d9b852b 100644 --- a/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx +++ b/src/features/user/TreeMapper/MySpecies/SpeciesAutoComplete.tsx @@ -59,14 +59,14 @@ export default function SpeciesSelect< // Todo: debouncing if (value.length > 2) { try { - const res = await postRequest<SpeciesSuggestionType[]>( - tenantConfig?.id, - `/suggest.php`, - { + const res = await postRequest<SpeciesSuggestionType[]>({ + 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 df5f5592cd..74e0e66e8f 100644 --- a/src/features/user/TreeMapper/index.tsx +++ b/src/features/user/TreeMapper/index.tsx @@ -46,15 +46,13 @@ function TreeMapper(): ReactElement { if (next && links?.next) { try { const response = - await getAuthenticatedRequest<ExtendedScopePlantLocations>( - tenantConfig?.id, - links.next, + await getAuthenticatedRequest<ExtendedScopePlantLocations>({ + 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) { @@ -92,16 +90,13 @@ function TreeMapper(): ReactElement { } else { try { const response = - await getAuthenticatedRequest<ExtendedScopePlantLocations>( - tenantConfig?.id, - '/treemapper/interventions?_scope=extended&limit=15', + await getAuthenticatedRequest<ExtendedScopePlantLocations>({ + 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 b77979f08b..586ada5d2a 100644 --- a/src/features/user/Widget/DonationLink/index.tsx +++ b/src/features/user/Widget/DonationLink/index.tsx @@ -20,16 +20,16 @@ export default function DonationLink(): ReactElement | null { async function fetchProjectList() { try { - const projectsList = await getRequest<MapProject[]>( - tenantConfig?.id, - `/app/projects`, - { + const projectsList = await getRequest<MapProject[]>({ + 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 70acb6969c..218f3fe0dd 100644 --- a/src/features/user/Widget/EmbedModal.tsx +++ b/src/features/user/Widget/EmbedModal.tsx @@ -59,13 +59,13 @@ export default function EmbedModal({ }; if (contextLoaded && token) { try { - const res = await putAuthenticatedRequest<User>( - tenantConfig?.id, - `/app/profile`, - bodyToSend, + const res = await putAuthenticatedRequest<User>({ + 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 c59eb7de4d..aee2519aab 100644 --- a/src/tenants/planet/LeaderBoard/components/Score.tsx +++ b/src/tenants/planet/LeaderBoard/components/Score.tsx @@ -30,8 +30,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 84a91a9ba3..acf528e641 100644 --- a/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx @@ -33,16 +33,16 @@ export default function ProjectGrid() { async function loadProjects() { const currencyCode = getStoredCurrency(); try { - const projects = await getRequest<MapProject[]>( - tenantConfig.id, - `/app/projects`, - { + const projects = await getRequest<MapProject[]>({ + 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 e3f14a04d7..018f184a27 100644 --- a/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx +++ b/src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx @@ -27,9 +27,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 1e50844bbc..0bc43c22f7 100644 --- a/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/VTOCampaign/components/ProjectGrid.tsx @@ -19,11 +19,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 b2c384671f..1e93c5a642 100644 --- a/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx +++ b/src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx @@ -19,11 +19,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 13c9b04be6..8dba539abb 100644 --- a/src/utils/apiRequests/api.ts +++ b/src/utils/apiRequests/api.ts @@ -1,18 +1,59 @@ +import type { ImpersonationData } from '../../features/user/Settings/ImpersonateUser/ImpersonateUserForm'; + import { getQueryString } from './getQueryString'; import getsessionId from './getSessionId'; import { APIError, ClientError } from '@planet-sdk/common'; import { validateToken } from './validateToken'; -import { ImpersonationData } from '../../features/user/Settings/ImpersonateUser/ImpersonateUserForm'; 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<string, string> | null; + queryParams?: { [key: string]: string }; + version?: string; +} +interface PostAuthRequestOptions extends BaseRequestOptions { + token: string | null; + data: any; + logoutUser: (value?: string | undefined) => void; + headers?: Record<string, string>; +} +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<any> { +export async function getAccountInfo({ + tenant, + token, + impersonationData, +}: GetAccountInfoOptions): Promise<any> { const lang = localStorage.getItem('language') || 'en'; const header = { 'tenant-key': `${tenant}`, @@ -35,12 +76,12 @@ function isAbsoluteUrl(url: string) { return pattern.test(url); } -export function getRequest<T>( - tenant: string | undefined, - url: string, - queryParams?: { [key: string]: string }, - version?: string -) { +export function getRequest<T>({ + tenant, + url, + queryParams = {}, + version, +}: GetRequestOptions): Promise<T> { const lang = localStorage.getItem('language') || 'en'; const query = { ...queryParams }; const queryString = getQueryString(query); @@ -75,16 +116,15 @@ export function getRequest<T>( })(); }); } - -export function getAuthenticatedRequest<T>( - tenant: string | undefined, - url: string, - token: string | null, - logoutUser: (value?: string | undefined) => void, - header: Record<string, string> | null = null, - queryParams?: { [key: string]: string }, - version?: string -) { +export function getAuthenticatedRequest<T>({ + tenant, + url, + token, + logoutUser, + header = null, + queryParams = {}, + version = '1.0.3', +}: GetAuthRequestOptions): Promise<T> { const lang = localStorage.getItem('language') || 'en'; const query = { ...queryParams }; const queryString = getQueryString(query); @@ -131,14 +171,14 @@ export function getAuthenticatedRequest<T>( }); } -export function postAuthenticatedRequest<T>( - tenant: string | undefined, - url: string, - data: any, - token: string | null, - logoutUser: (value?: string | undefined) => void, - headers?: Record<string, string> -) { +export function postAuthenticatedRequest<T>({ + tenant, + url, + data, + token, + logoutUser, + headers, +}: PostAuthRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise<T>((resolve, reject) => { (async () => { @@ -181,11 +221,7 @@ export function postAuthenticatedRequest<T>( }); } -export function postRequest<T>( - tenant: string | undefined, - url: string, - data: any -) { +export function postRequest<T>({ tenant, url, data }: PostRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise<T>((resolve, reject) => { (async () => { @@ -217,12 +253,12 @@ export function postRequest<T>( }); } -export function deleteAuthenticatedRequest<T>( - tenant: string | undefined, - url: string, - token: string | null, - logoutUser: (value?: string | undefined) => void -) { +export function deleteAuthenticatedRequest<T>({ + tenant, + url, + token, + logoutUser, +}: DeleteAuthRequestOptions) { const lang = localStorage.getItem('language') || 'en'; return new Promise<T>((resolve, reject) => { (async () => { @@ -263,13 +299,13 @@ export function deleteAuthenticatedRequest<T>( }); } -export function putAuthenticatedRequest<T>( - tenant: string | undefined, - url: string, - data: any, - token: string | null, - logoutUser: (value?: string | undefined) => void -) { +export function putAuthenticatedRequest<T>({ + tenant, + url, + data, + token, + logoutUser, +}: PutAuthRequestOptions) { return new Promise<T>((resolve, reject) => { const lang = localStorage.getItem('language') || 'en'; (async () => { diff --git a/src/utils/maps/plantLocations.ts b/src/utils/maps/plantLocations.ts index 50d28f639a..a1f4538d16 100644 --- a/src/utils/maps/plantLocations.ts +++ b/src/utils/maps/plantLocations.ts @@ -68,14 +68,14 @@ export async function getAllPlantLocations( redirect: (url: string) => void ): Promise<PlantLocation[] | null | void> { try { - const result = await getRequest<PlantLocation[]>( + const result = await getRequest<PlantLocation[]>({ tenant, - `/app/plantLocations/${project}`, - { + url: `/app/plantLocations/${project}`, + queryParams: { _scope: 'extended', }, - '1.0.4' - ); + version: '1.0.4', + }); if (result) { return result; } else {