From 0972c21da8f3c8a93ce202f839160e9cbb39ec43 Mon Sep 17 00:00:00 2001 From: mohitb35 <44917347+mohitb35@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:49:52 +0530 Subject: [PATCH 1/3] feat: adds profile param to paymentOptions API call --- .../sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx | 3 +++ src/features/user/BulkCodes/components/ProjectSelector.tsx | 3 +++ 2 files changed, 6 insertions(+) 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 a8357bd7c9..a0a3608832 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx @@ -26,6 +26,7 @@ import { } from 'next'; import { defaultTenant } from '../../../../../../../tenant.config'; import getMessagesForPage from '../../../../../../../src/utils/language/getMessagesForPage'; +import { useUserProps } from '../../../../../../../src/features/common/Layout/UserPropsContext'; interface Props { pageProps: PageProps; @@ -41,6 +42,7 @@ export default function BulkCodeIssueCodesPage({ const { project, setProject, bulkMethod, setBulkMethod, planetCashAccount } = useBulkCode(); + const { user } = useUserProps(); // Checks context and sets project, bulk method if not already set within context const checkContext = useCallback(async () => { @@ -53,6 +55,7 @@ export default function BulkCodeIssueCodesPage({ `/app/paymentOptions/${router.query.id}`, { currency: planetCashAccount.country, + ...(user !== null && { profile: user.id }), } ); diff --git a/src/features/user/BulkCodes/components/ProjectSelector.tsx b/src/features/user/BulkCodes/components/ProjectSelector.tsx index af36273f17..0dadfd7a0d 100644 --- a/src/features/user/BulkCodes/components/ProjectSelector.tsx +++ b/src/features/user/BulkCodes/components/ProjectSelector.tsx @@ -8,6 +8,7 @@ import { useTenant } from '../../../common/Layout/TenantContext'; import ProjectSelectAutocomplete from './ProjectSelectAutocomplete'; import UnitCostDisplay from './UnitCostDisplay'; import { handleError, APIError } from '@planet-sdk/common'; +import { useUserProps } from '../../../common/Layout/UserPropsContext'; interface ProjectSelectorProps { projectList: ProjectOption[]; @@ -31,6 +32,7 @@ const ProjectSelector = ({ return 'tree'; }; + const { user } = useUserProps(); const fetchPaymentOptions = async (guid: string) => { const paymentOptions = await getRequest( @@ -38,6 +40,7 @@ const ProjectSelector = ({ `/app/paymentOptions/${guid}`, { country: planetCashAccount?.country || '', + ...(user !== null && { profile: user.id }), } ); return paymentOptions; From 73914f655c4debbd2e603c7ee32e0bb69c1675a6 Mon Sep 17 00:00:00 2001 From: mohitb35 <44917347+mohitb35@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:48:51 +0530 Subject: [PATCH 2/3] feat: adds authentication for /paymentOptions API req --- .../profile/bulk-codes/[method]/[id].tsx | 28 +++++++++++-------- .../BulkCodes/components/ProjectSelector.tsx | 11 +++++--- 2 files changed, 23 insertions(+), 16 deletions(-) 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 a0a3608832..a4853ea12f 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx @@ -8,7 +8,7 @@ import Head from 'next/head'; import { BulkCodeMethods } from '../../../../../../../src/utils/constants/bulkCodeConstants'; import { useBulkCode } from '../../../../../../../src/features/common/Layout/BulkCodeContext'; import { ErrorHandlingContext } from '../../../../../../../src/features/common/Layout/ErrorHandlingContext'; -import { getRequest } from '../../../../../../../src/utils/apiRequests/api'; +import { getAuthenticatedRequest } from '../../../../../../../src/utils/apiRequests/api'; import { useRouter } from 'next/router'; import { AbstractIntlMessages, useTranslations } from 'next-intl'; import { handleError, APIError } from '@planet-sdk/common'; @@ -42,22 +42,26 @@ export default function BulkCodeIssueCodesPage({ const { project, setProject, bulkMethod, setBulkMethod, planetCashAccount } = useBulkCode(); - const { user } = useUserProps(); + const { token, user, logoutUser, contextLoaded } = useUserProps(); // Checks context and sets project, bulk method if not already set within context const checkContext = useCallback(async () => { - if (planetCashAccount) { + if (planetCashAccount && token && contextLoaded) { if (!project) { if (router.isReady) { try { - const paymentOptions = await getRequest( - pageProps.tenantConfig.id, - `/app/paymentOptions/${router.query.id}`, - { - currency: planetCashAccount.country, - ...(user !== null && { profile: user.id }), - } - ); + const paymentOptions = + await getAuthenticatedRequest( + pageProps.tenantConfig.id, + `/app/paymentOptions/${router.query.id}`, + token, + logoutUser, + undefined, + { + country: planetCashAccount.country, + ...(user !== null && { profile: user.id }), + } + ); if (paymentOptions) { const _project = { @@ -95,7 +99,7 @@ export default function BulkCodeIssueCodesPage({ } } } - }, [router.isReady, planetCashAccount]); + }, [router.isReady, planetCashAccount, token, contextLoaded]); React.useEffect(() => { if (router.isReady) { diff --git a/src/features/user/BulkCodes/components/ProjectSelector.tsx b/src/features/user/BulkCodes/components/ProjectSelector.tsx index 0dadfd7a0d..17a84ec0af 100644 --- a/src/features/user/BulkCodes/components/ProjectSelector.tsx +++ b/src/features/user/BulkCodes/components/ProjectSelector.tsx @@ -1,5 +1,5 @@ import React, { ReactElement } from 'react'; -import { getRequest } from '../../../../utils/apiRequests/api'; +import { getAuthenticatedRequest } from '../../../../utils/apiRequests/api'; import { PlanetCashAccount } from '../../../common/Layout/BulkCodeContext'; import { ErrorHandlingContext } from '../../../common/Layout/ErrorHandlingContext'; import { PaymentOptions } from '../BulkCodesTypes'; @@ -32,12 +32,15 @@ const ProjectSelector = ({ return 'tree'; }; - const { user } = useUserProps(); + const { user, token, logoutUser, contextLoaded } = useUserProps(); const fetchPaymentOptions = async (guid: string) => { - const paymentOptions = await getRequest( + const paymentOptions = await getAuthenticatedRequest( `${tenantConfig?.id}`, `/app/paymentOptions/${guid}`, + token, + logoutUser, + undefined, { country: planetCashAccount?.country || '', ...(user !== null && { profile: user.id }), @@ -48,7 +51,7 @@ const ProjectSelector = ({ const handleProjectChange = async (project: ProjectOption | null) => { // fetch project details - if (project) { + if (project && user && token && contextLoaded) { try { const paymentOptions = await fetchPaymentOptions(project.guid); // Add to project object From 8bbd18dc7b583d46d328368529c8a79e056348a5 Mon Sep 17 00:00:00 2001 From: mohitb35 <44917347+mohitb35@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:52:37 +0530 Subject: [PATCH 3/3] refactor: renames `profile` param to `legacyPriceFor` for /paymentOptions --- .../sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx | 2 +- src/features/user/BulkCodes/components/ProjectSelector.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 a4853ea12f..03864062df 100644 --- a/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx +++ b/pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx @@ -59,7 +59,7 @@ export default function BulkCodeIssueCodesPage({ undefined, { country: planetCashAccount.country, - ...(user !== null && { profile: user.id }), + ...(user !== null && { legacyPriceFor: user.id }), } ); diff --git a/src/features/user/BulkCodes/components/ProjectSelector.tsx b/src/features/user/BulkCodes/components/ProjectSelector.tsx index 17a84ec0af..d1ffa340ef 100644 --- a/src/features/user/BulkCodes/components/ProjectSelector.tsx +++ b/src/features/user/BulkCodes/components/ProjectSelector.tsx @@ -43,7 +43,7 @@ const ProjectSelector = ({ undefined, { country: planetCashAccount?.country || '', - ...(user !== null && { profile: user.id }), + ...(user !== null && { legacyPriceFor: user.id }), } ); return paymentOptions;