Skip to content

Commit 4734f75

Browse files
authored
Merge pull request #2347 from Plant-for-the-Planet-org/feature/object-param-api-helper-function
Refactor API helper function param structure
2 parents b5d2798 + b578413 commit 4734f75

File tree

73 files changed

+644
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+644
-591
lines changed

pages/sites/[slug]/[locale]/all.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ export default function Home({ pageProps }: Props) {
5050
React.useEffect(() => {
5151
async function loadLeaderboard() {
5252
try {
53-
const newLeaderboard = await getRequest<LeaderBoardList>(
54-
pageProps.tenantConfig.id,
55-
`/app/leaderboard/${pageProps.tenantConfig.id}`
56-
);
53+
const newLeaderboard = await getRequest<LeaderBoardList>({
54+
tenant: pageProps.tenantConfig.id,
55+
url: `/app/leaderboard/${pageProps.tenantConfig.id}`,
56+
});
5757
setLeaderboard(newLeaderboard);
5858
} catch (err) {
5959
setErrors(handleError(err as APIError));
@@ -69,10 +69,10 @@ export default function Home({ pageProps }: Props) {
6969
React.useEffect(() => {
7070
async function loadTenantScore() {
7171
try {
72-
const newTenantScore = await getRequest<TenantScore>(
73-
pageProps.tenantConfig.id,
74-
`/app/tenantScore/${pageProps.tenantConfig.id}`
75-
);
72+
const newTenantScore = await getRequest<TenantScore>({
73+
tenant: pageProps.tenantConfig.id,
74+
url: `/app/tenantScore/${pageProps.tenantConfig.id}`,
75+
});
7676
setTenantScore(newTenantScore);
7777
} catch (err) {
7878
setErrors(handleError(err as APIError));
@@ -88,10 +88,10 @@ export default function Home({ pageProps }: Props) {
8888
React.useEffect(() => {
8989
async function loadTreesDonated() {
9090
try {
91-
const newTreesDonated = await getRequest<TreesDonated>(
92-
pageProps.tenantConfig.id,
93-
`${process.env.WEBHOOK_URL}/platform/total-tree-count`
94-
);
91+
const newTreesDonated = await getRequest<TreesDonated>({
92+
tenant: pageProps.tenantConfig.id,
93+
url: `${process.env.WEBHOOK_URL}/platform/total-tree-count`,
94+
});
9595
setTreesDonated(newTreesDonated);
9696
} catch (err) {
9797
setErrors(handleError(err as APIError));

pages/sites/[slug]/[locale]/claim/[type]/[code].tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ function ClaimDonation({ pageProps }: Props): ReactElement {
8484
};
8585
if (contextLoaded && user) {
8686
try {
87-
const res = await postAuthenticatedRequest<RedeemedCodeData>(
88-
pageProps.tenantConfig.id,
89-
`/app/redeem`,
90-
submitData,
87+
const res = await postAuthenticatedRequest<RedeemedCodeData>({
88+
tenant: pageProps.tenantConfig.id,
89+
url: `/app/redeem`,
90+
data: submitData,
9191
token,
92-
logoutUser
93-
);
92+
logoutUser,
93+
});
9494
setRedeemedCodeData(res);
9595
} catch (err) {
9696
const serializedErrors = handleError(err as APIError);

pages/sites/[slug]/[locale]/home.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export default function Home({ pageProps }: Props) {
5555
React.useEffect(() => {
5656
async function loadTenantScore() {
5757
try {
58-
const newTenantScore = await getRequest<TenantScore>(
59-
pageProps.tenantConfig.id,
60-
`/app/tenantScore`
61-
);
58+
const newTenantScore = await getRequest<TenantScore>({
59+
tenant: pageProps.tenantConfig.id,
60+
url: `/app/tenantScore`,
61+
});
6262
setTenantScore(newTenantScore);
6363
} catch (err) {
6464
setErrors(handleError(err as APIError));
@@ -70,10 +70,10 @@ export default function Home({ pageProps }: Props) {
7070
React.useEffect(() => {
7171
async function loadLeaderboard() {
7272
try {
73-
const newLeaderBoard = await getRequest<LeaderBoardList>(
74-
pageProps.tenantConfig.id,
75-
`/app/leaderboard`
76-
);
73+
const newLeaderBoard = await getRequest<LeaderBoardList>({
74+
tenant: pageProps.tenantConfig.id,
75+
url: `/app/leaderboard`,
76+
});
7777
setLeaderboard(newLeaderBoard);
7878
} catch (err) {
7979
setErrors(handleError(err as APIError));

pages/sites/[slug]/[locale]/profile/bulk-codes/[method]/[id].tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,16 @@ export default function BulkCodeIssueCodesPage({
6464
if (router.isReady) {
6565
try {
6666
const paymentOptions =
67-
await getAuthenticatedRequest<PaymentOptions>(
68-
pageProps.tenantConfig.id,
69-
`/app/paymentOptions/${router.query.id}`,
67+
await getAuthenticatedRequest<PaymentOptions>({
68+
tenant: pageProps.tenantConfig.id,
69+
url: `/app/paymentOptions/${router.query.id}`,
7070
token,
7171
logoutUser,
72-
undefined,
73-
{
74-
country: planetCashAccount.country,
72+
queryParams: {
73+
country: planetCashAccount?.country ?? '',
7574
...(user !== null && { legacyPriceFor: user.id }),
76-
}
77-
);
75+
},
76+
});
7877

7978
if (paymentOptions) {
8079
const retrievedProject = projectList.find(

pages/sites/[slug]/[locale]/profile/history.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ function AccountHistory({ pageProps }: Props): ReactElement {
6666
if (next && paymentHistory?._links?.next) {
6767
try {
6868
const newPaymentHistory = await getAuthenticatedRequest<PaymentHistory>(
69-
tenantConfig?.id,
70-
`${
71-
filter && accountingFilters
72-
? accountingFilters[filter] +
73-
'&' +
74-
paymentHistory?._links?.next.split('?').pop()
75-
: paymentHistory?._links?.next
76-
}`,
77-
token,
78-
logoutUser
69+
{
70+
tenant: tenantConfig.id,
71+
url: `${
72+
filter && accountingFilters
73+
? accountingFilters[filter] +
74+
'&' +
75+
paymentHistory?._links?.next.split('?').pop()
76+
: paymentHistory?._links?.next
77+
}`,
78+
token,
79+
logoutUser,
80+
}
7981
);
8082
setPaymentHistory({
8183
...paymentHistory,
@@ -92,12 +94,12 @@ function AccountHistory({ pageProps }: Props): ReactElement {
9294
} else {
9395
if (filter === null) {
9496
try {
95-
const paymentHistory = await getAuthenticatedRequest<PaymentHistory>(
96-
tenantConfig?.id,
97-
'/app/paymentHistory?limit=15',
97+
const paymentHistory = await getAuthenticatedRequest<PaymentHistory>({
98+
tenant: tenantConfig?.id,
99+
url: '/app/paymentHistory?limit=15',
98100
token,
99-
logoutUser
100-
);
101+
logoutUser,
102+
});
101103
setPaymentHistory(paymentHistory);
102104
setProgress(100);
103105
setIsDataLoading(false);
@@ -109,16 +111,16 @@ function AccountHistory({ pageProps }: Props): ReactElement {
109111
}
110112
} else {
111113
try {
112-
const paymentHistory = await getAuthenticatedRequest<PaymentHistory>(
113-
tenantConfig?.id,
114-
`${
114+
const paymentHistory = await getAuthenticatedRequest<PaymentHistory>({
115+
tenant: tenantConfig?.id,
116+
url: `${
115117
filter && accountingFilters
116118
? accountingFilters[filter] + '&limit=15'
117119
: '/app/paymentHistory?limit=15'
118120
}`,
119121
token,
120-
logoutUser
121-
);
122+
logoutUser,
123+
});
122124
setPaymentHistory(paymentHistory);
123125
setProgress(100);
124126
setIsDataLoading(false);

pages/sites/[slug]/[locale]/profile/projects/[id].tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ function ManageSingleProject({
7373
try {
7474
const result = await getAuthenticatedRequest<
7575
ProfileProjectTrees | ProfileProjectConservation
76-
>(
77-
tenantConfig.id,
78-
`/app/profile/projects/${projectGUID}`,
76+
>({
77+
tenant: tenantConfig.id,
78+
url: `/app/profile/projects/${projectGUID}`,
7979
token,
80-
logoutUser
81-
);
80+
logoutUser,
81+
});
8282
setProject(result);
8383
setSetupAccess(true);
8484
} catch (err) {

pages/sites/[slug]/[locale]/profile/recurrency.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ function RecurrentDonations({
5757
setIsDataLoading(true);
5858
setProgress(70);
5959
try {
60-
const recurrencies = await getAuthenticatedRequest<Subscription[]>(
61-
tenantConfig.id,
62-
'/app/subscriptions',
60+
const recurrencies = await getAuthenticatedRequest<Subscription[]>({
61+
tenant: tenantConfig.id,
62+
url: '/app/subscriptions',
6363
token,
64-
logoutUser
65-
);
64+
logoutUser,
65+
});
6666
if (recurrencies && Array.isArray(recurrencies)) {
6767
const activeRecurrencies = recurrencies?.filter(
6868
(obj) => obj.status == 'active' || obj.status == 'trialing'

pages/sites/[slug]/[locale]/profile/redeem/[code].tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ const RedeemCode = ({ pageProps: { tenantConfig } }: Props) => {
7979

8080
if (contextLoaded && user) {
8181
try {
82-
const res = await postAuthenticatedRequest<RedeemedCodeData>(
83-
tenantConfig?.id,
84-
`/app/redeem`,
85-
submitData,
82+
const res = await postAuthenticatedRequest<RedeemedCodeData>({
83+
tenant: tenantConfig?.id,
84+
url: `/app/redeem`,
85+
data: submitData,
8686
token,
87-
logoutUser
88-
);
87+
logoutUser,
88+
});
8989
setRedeemedCodeData(res);
9090
} catch (err) {
9191
const serializedErrors = handleError(err as APIError);

pages/sites/[slug]/[locale]/projects-archive/[p].tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ export default function Donate({
9595
setCurrencyCode(currency);
9696
try {
9797
const { p } = router.query;
98-
const project = await getRequest<ProjectExtended>(
99-
pageProps.tenantConfig.id,
100-
encodeURI(`/app/projects/${p}`),
101-
{
98+
const project = await getRequest<ProjectExtended>({
99+
tenant: pageProps.tenantConfig.id,
100+
url: encodeURI(`/app/projects/${p}`),
101+
queryParams: {
102102
_scope: 'extended',
103103
currency: currency || '',
104104
locale: locale,
105-
}
106-
);
105+
},
106+
});
107107
if (
108108
project.purpose === 'conservation' ||
109109
project.purpose === 'trees'

pages/sites/[slug]/[locale]/projects-archive/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ export default function Donate({
115115
setCurrencyCode(currency);
116116
setInternalLanguage(locale);
117117
try {
118-
const projects = await getRequest<MapProject[]>(
119-
pageProps.tenantConfig.id,
120-
`/app/projects`,
121-
{
118+
const projects = await getRequest<MapProject[]>({
119+
tenant: pageProps.tenantConfig.id,
120+
url: `/app/projects`,
121+
queryParams: {
122122
_scope: 'map',
123123
currency: currency,
124124
tenant: pageProps.tenantConfig.id,
125125
'filter[purpose]': 'trees,conservation',
126126
locale: locale,
127-
}
128-
);
127+
},
128+
});
129129
setProjects(projects);
130130
setProject(null);
131131
setShowSingleProject(false);

0 commit comments

Comments
 (0)