Skip to content

Commit

Permalink
Merge pull request #473 from Plant-for-the-Planet-org/develop
Browse files Browse the repository at this point in the history
Release Giftable donations
  • Loading branch information
mariahosfeld authored Dec 3, 2024
2 parents 7178da1 + 0f124bf commit 0892f98
Show file tree
Hide file tree
Showing 36 changed files with 602 additions and 359 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@mui/material": "^5.11.8",
"@next/bundle-analyzer": "^10.1.3",
"@paypal/react-paypal-js": "^7.8.2",
"@planet-sdk/common": "^0.1.34",
"@planet-sdk/common": "^0.1.47",
"@sentry/browser": "^6.2.5",
"@sentry/integrations": "^6.2.5",
"@sentry/node": "^6.2.5",
Expand Down
102 changes: 51 additions & 51 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import countriesData from "./../src/Utils/countriesData.json";
import { setCountryCode } from "src/Utils/setCountryCode";
import { DONATE } from "src/Utils/donationStepConstants";
import {
SentGift,
GiftDetails,
FetchedProjectDetails,
PaymentOptions,
} from "src/Common/Types";
Expand All @@ -20,11 +20,13 @@ import {
ContactDetails,
} from "@planet-sdk/common/build/types/donation";
import { GetServerSideProps } from "next/types";
import { createProjectDetails } from "src/Utils/createProjectDetails";
import { NON_GIFTABLE_PROJECT_PURPOSES } from "src/Utils/projects/constants";

interface Props {
projectDetails?: FetchedProjectDetails;
donationStep: number | null;
giftDetails: SentGift | null;
giftDetails: GiftDetails | null;
isGift: boolean;
resolvedUrl?: string;
isDirectDonation: boolean;
Expand Down Expand Up @@ -79,7 +81,7 @@ function index({
setSelectedProjects,
loadselectedProjects,
setGiftDetails,
setisGift,
setIsGift,
setpaymentSetup,
setcurrency,
setContactDetails,
Expand Down Expand Up @@ -129,7 +131,7 @@ function index({
// If gift details are present, initialize gift in context
if (giftDetails && isGift) {
setGiftDetails(giftDetails);
setisGift(true);
setIsGift(true);
}
}, []);

Expand Down Expand Up @@ -215,7 +217,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

// Variables that will be affected with Gift details
let isGift = false;
let giftDetails: SentGift | null = null;
let giftDetails: GiftDetails | null = null;
let frequency = "once";
// Variables that will be affected with context
let hideTaxDeduction = false;
Expand Down Expand Up @@ -250,7 +252,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const queryCountry = context.query.country;
const found = countriesData.some(
(country) =>
country.countryCode?.toUpperCase() === queryCountry.toUpperCase(),
country.countryCode?.toUpperCase() === queryCountry.toUpperCase()
);
if (found) {
country = queryCountry.toUpperCase();
Expand All @@ -276,18 +278,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
const paymentOptionsResponse = await apiRequest(requestParams);
const paymentOptionsData: PaymentOptions = paymentOptionsResponse?.data;
if (paymentOptionsData) {
projectDetails = {
id: paymentOptionsData.id,
name: paymentOptionsData.name,
description: paymentOptionsData.description,
purpose: paymentOptionsData.purpose,
ownerName: paymentOptionsData.ownerName,
taxDeductionCountries: paymentOptionsData.taxDeductionCountries,
image: paymentOptionsData.image,
ownerAvatar: paymentOptionsData.ownerAvatar,
isApproved: paymentOptionsData.isApproved ? true : false,
isTopProject: paymentOptionsData.isTopProject ? true : false,
};
projectDetails = createProjectDetails(paymentOptionsData);
donationStep = 1;
}
} catch (err) {
Expand Down Expand Up @@ -360,26 +351,15 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
if (paymentSetupData) {
currency = paymentSetupData.currency;
paymentSetup = paymentSetupData;
projectDetails = {
id: paymentSetupData.id,
name: paymentSetupData.name,
description: paymentSetupData.description,
purpose: paymentSetupData.purpose,
ownerName: paymentSetupData.ownerName,
taxDeductionCountries: paymentSetupData.taxDeductionCountries,
image: paymentSetupData.image,
ownerAvatar: paymentSetupData.ownerAvatar,
isApproved: paymentSetupData.isApproved ? true : false,
isTopProject: paymentSetupData.isTopProject ? true : false,
};
projectDetails = createProjectDetails(paymentSetupData);
donationStep = 3;
}
} catch (err) {
// console.log(err);
}
allowTaxDeductionChange = false;
units = donation.units;
amount = donation.amount;
amount = Number(donation.amount);
// Setting contact details from donor details
if (donorData) {
contactDetails = {
Expand Down Expand Up @@ -429,29 +409,49 @@ 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 (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.classification === "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,
type: "direct",
recipient: newProfile.data.id,
recipientProfile: newProfile.data.slug,
};
}
} catch (err) {
console.log("Error", err);
}
} catch (err) {
console.log("Error", err);
}
}

Expand Down
1 change: 0 additions & 1 deletion public/locales/cs/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
"selectLanguage": "Zvolit jazyk",
"trees": "stromů",
"logout": "Odhlásit se",
"directGiftRecipient": "Tento dar podporuje Les od {{name}}",
"saveGiftDetails": "Uloži darovací údaje",
"giftSomeone": "Můj dar je někomu věnován ",
"or": "NEBO",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"tree_other": "Bäume",
"recipientName": "Name des Empfängers",
"recipientNameRequired": "Name des Empfängers ist erforderlich",
"recipientNameTooLong": "Der Name des Empfängers darf höchstens 35 Zeichen lang sein",
"email": "E-Mail",
"recipientEmail": "E-Mail des Empfängers",
"emailRequired": "E-Mail ist erforderlich",
Expand Down Expand Up @@ -118,7 +119,7 @@
"selectLanguage": "Sprache auswählen",
"trees": "Bäume",
"logout": "Abmelden",
"directGiftRecipient": "Diese Spende unterstützt den Wald von {{name}}",
"giftDedicatedTo": "Diese Spende ist {{name}} gewidmet",
"saveGiftDetails": "Geschenkdetails speichern",
"giftSomeone": "Meine Spende ist ein Geschenk an jemanden",
"or": "ODER",
Expand All @@ -134,6 +135,7 @@
"billingAddress": "Kontaktdetails",
"treesInCountry": "{{treeCount}} Bäume, Plant-for-the-Planet",
"fundingPaymentLabel": "Spende {{amount}}, Plant-for-the-Planet",
"pcashPaymentLabel": "Laden Sie {{amount}} PlanetCash, Plant-for-the-Planet",
"bouquetPaymentLabel": "Spende {{amount}}, Plant-for-the-Planet",
"errorOccurred": "Etwas ist schief gelaufen. Bitte mache einen Screenshot und schicke ihn uns als E-Mail an [email protected].",
"dedicatedTo": "Unterstützt den Wald von",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"tree_other": "trees",
"recipientName": "Recipient Name",
"recipientNameRequired": "Recipient Name is required",
"recipientNameTooLong": "Recipient Name must be 35 characters or less",
"email": "Email",
"recipientEmail": "Recipient Email",
"emailRequired": "Email is required",
Expand Down Expand Up @@ -118,7 +119,7 @@
"selectLanguage": "Select Language",
"trees": "trees",
"logout": "Logout",
"directGiftRecipient": "This donation supports {{name}}'s Forest",
"giftDedicatedTo": "This donation is dedicated to {{name}}",
"saveGiftDetails": "Save Gift Details",
"giftSomeone": "My donation is dedicated to someone",
"or": "OR",
Expand Down
1 change: 0 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"selectLanguage": "Seleccione el idioma",
"trees": "árboles",
"logout": "Cierre de sesión",
"directGiftRecipient": "Esta donación apoya {{name}}",
"saveGiftDetails": "Guardar detalles de los regalos",
"giftSomeone": "Mi donación es un regalo para alguien",
"or": "O",
Expand Down
1 change: 0 additions & 1 deletion public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"selectLanguage": "Sélectionnez une langue",
"trees": "arbres",
"logout": "Déconnexion",
"directGiftRecipient": "Ce don soutient {{name}}",
"saveGiftDetails": "Save Gift Details",
"giftSomeone": "Mon don est un cadeau pour quelqu'un",
"or": "OU",
Expand Down
1 change: 0 additions & 1 deletion public/locales/it/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
"selectLanguage": "Seleziona la lingua",
"trees": "alberi",
"logout": "Logout",
"directGiftRecipient": "Questa donazione sostiene {{name}}",
"saveGiftDetails": "Salva i dettagli del regalo",
"giftSomeone": "La mia donazione è un regalo a qualcuno",
"or": "O",
Expand Down
1 change: 0 additions & 1 deletion public/locales/pt-BR/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"selectLanguage": "Selecione o Idioma",
"trees": "árvores",
"logout": "Sair",
"directGiftRecipient": "Esta doação apoia a Floresta {{name}}",
"saveGiftDetails": "Salvar Detalhes do Presente",
"giftSomeone": "A minha doação é um presente para alguém",
"or": "OU",
Expand Down
Loading

0 comments on commit 0892f98

Please sign in to comment.