Skip to content

Commit

Permalink
feat: remove support link from query params when not applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitb35 committed Nov 14, 2024
1 parent 92d62ab commit 62b38ac
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,34 +409,51 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
if (typeof context.query.utm_source === "string")
utmSource = context.query.utm_source;

// Set gift details if there is s (support link) in the query params
if (
projectDetails !== null &&
projectDetails.category !== "membership" &&
!NON_GIFTABLE_PROJECT_PURPOSES.includes(projectDetails.purpose) &&
context.query.s
) {
try {
const requestParams = {
url: `/app/profiles/${context.query.s}`,
setshowErrorCard,
tenant,
locale,
// Handle s (support link) in the query params
if (typeof context.query.s === "string" && context.query.s.length > 0) {
if (
projectDetails === null ||
projectDetails.category === "membership" ||
NON_GIFTABLE_PROJECT_PURPOSES.includes(projectDetails.purpose)
) {
// If project cannot have direct gift, remove 's' parameter by redirecting
const pathname = context.resolvedUrl.split("?")[0];
const query = { ...context.query };
delete query.s;
const queryString = new URLSearchParams(
query as Record<string, string>
).toString();

return {
redirect: {
destination: `${pathname}${queryString ? `?${queryString}` : ""}`,
permanent: true,
},
};
const newProfile = await apiRequest(requestParams);
if (newProfile.data.type !== "tpo") {
isGift = true;
giftDetails = {
recipientName: newProfile.data.displayName,
recipientEmail: "",
message: "",
type: "direct",
recipient: newProfile.data.id,
recipientTreecounter: newProfile.data.slug,
} else {
// Set gift details if there is s (support link) in the query params for an eligible project
try {
const requestParams = {
url: `/app/profiles/${context.query.s}`,
setshowErrorCard,
tenant,
locale,
};
const newProfile = await apiRequest(requestParams);
if (newProfile.data.type !== "tpo") {
isGift = true;
giftDetails = {
recipientName: newProfile.data.displayName,
recipientEmail: "",
message: "",
type: "direct",
recipient: newProfile.data.id,
recipientTreecounter: newProfile.data.slug,
};
}
} catch (err) {
console.log("Error", err);
}
} catch (err) {
console.log("Error", err);
}
}

Expand Down

0 comments on commit 62b38ac

Please sign in to comment.