Skip to content

Commit

Permalink
Merge pull request #424 from Plant-for-the-Planet-org/feature/integra…
Browse files Browse the repository at this point in the history
…te-unit-type

Integrate `unitType`
  • Loading branch information
mariahosfeld authored Nov 29, 2023
2 parents 2b0dc06 + f01b7e8 commit de42253
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 56 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.27",
"@planet-sdk/common": "^0.1.29",
"@sentry/browser": "^6.2.5",
"@sentry/integrations": "^6.2.5",
"@sentry/node": "^6.2.5",
Expand Down
13 changes: 10 additions & 3 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"fortreeCountTrees_other": "for {{treeCount}} Trees",
"forQuantitym2": "for {{quantity}} m²",
"m2": "",
"tree_one": "tree",
"tree_other": "trees",
"recipientName": "Recipient Name",
"recipientNameRequired": "Recipient Name is required",
"email": "Email",
Expand Down Expand Up @@ -44,6 +46,10 @@
"orgNamePublishedTax": "Company name is visible on our leaderboard and app. Tax-deduction receipts will be issued for the same name.",
"orgNamePublished": "Company name is visible on our leaderboard and app.",
"paymentDetails": "Payment Details",
"perUnit": {
"tree": "per tree",
"m2": "per m²"
},
"perTree": "per tree",
"perm2": "per m²",
"youWillReceiveTaxDeduction": "You will receive a tax deduction receipt for ",
Expand Down Expand Up @@ -78,9 +84,10 @@
"contributionMessage": "Maybe you'll visit them some day? In the mean time, maybe hook up your friends with some trees of their own by telling them about yours?",
"fundingDonationSuccess": "Thank you for your contribution! You’ll receive a confirmation for your contribution on your email.",
"fundingContributionMessage": "We will keep you posted about our actions, in the mean time maybe share with your friends about your contribution.",
"yourTreesPlantedByOnLocation": "Your {{treeCount}} trees will be planted by {{projectName}} in {{location}}.",
"restorationDonationUsage": "Your donation will be used to restore {{units}} {{unitType}} by {{projectName}} in {{location}}.",
"m2conservedByOnLocation": "{{quantity}} m² forest will be conserved by {{projectName}} in {{location}}.",
"myTreesPlantedByOnLocation": "My {{treeCount}} trees are being planted in {{location}}.",
"restorationDonationShareDetails": "I donated {{amount}} for forest restoration in {{location}}.",
"iDonatedForestOnLocation": "I donated {{amount}} for forest conservation in {{location}}.",
"weDonatedForestOnLocation": "We donated {{amount}} for forest conservation in {{location}}.",
"plantTreesAtURL": "Restore & protect trees at {{url}}",
Expand Down Expand Up @@ -172,7 +179,7 @@
"lowBalance": "Balance is low",
"oneTimePay": "Donation with PlanetCash is a one time payment",
"currency": "Currency",
"treesPurpose": "tree donation",
"treesPurpose": "restoration donation",
"fundsPurpose": "donation",
"bouquetPurpose": "donation",
"conservationPurpose": "conservation donation",
Expand Down Expand Up @@ -216,4 +223,4 @@
"top_project_standards_fulfilled": "The project inspection revealed that this project fulfilled at least 12 of the 19 Top Project <2>standards.</2>",
"standardsLink": "https://www.plant-for-the-planet.org/standards/",
"enterValidEmail": "Please enter a valid email"
}
}
7 changes: 5 additions & 2 deletions src/Common/Types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ContactDetails,
BankTransferDetails,
PaymentGateway,
CurrencyCode,
} from "@planet-sdk/common";

/** planet-donations only allows direct or invitation gifts */
Expand Down Expand Up @@ -145,14 +146,16 @@ export interface PaymentOptions extends FetchedProjectDetails {
frequencies: Frequencies;
gateways: Gateways;
recurrency: Recurrency;
/** @deprecated - use unitType instead */
unit: string;
unitType: UnitType;
unitCost: number;
currency: string;
destination: string;
isApproved: boolean;
isTopProject: boolean;
}

export type UnitType = "tree" | "m2" | "currency" | CurrencyCode;

interface Frequencies {
[key: string]: Frequency;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function DonationsForm(): ReactElement {
projectDetails !== null &&
projectDetails.purpose !== "funds" &&
projectDetails.purpose !== "planet-cash" &&
paymentSetup?.unitType === "tree" && //Enables planetcash for restoration projects with unitType tree only (TEMP)
profile !== null &&
isSignedUp &&
profile.planetCash !== null &&
Expand Down Expand Up @@ -339,7 +340,9 @@ function DonationsForm(): ReactElement {
{/* show PlanetCashSelector only if user is signed up and have a planetCash account */}
{canPayWithPlanetCash && <PlanetCashSelector />}
{!(onBehalf && onBehalfDonor.firstName === "") &&
(projectDetails.purpose === "trees" ? (
(projectDetails.purpose === "trees" &&
(paymentSetup?.unitType !== "m2" ||
giftDetails.type === "direct") ? (
<div className="donations-gift-container mt-10">
<GiftForm />
</div>
Expand Down
25 changes: 16 additions & 9 deletions src/Donations/LeftPanel/TransactionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactElement } from "react";
import { useTranslation } from "next-i18next";
import getFormatedCurrency from "src/Utils/getFormattedCurrency";
import { getFormattedNumber } from "src/Utils/getFormattedNumber";
import { PaymentOptions, ProjectPurpose } from "src/Common/Types";
import { PaymentOptions, UnitType } from "src/Common/Types";
import styles from "./LeftPanel.module.scss";

interface Props {
Expand All @@ -22,26 +22,28 @@ const TransactionSummary = ({

/** Generates unit/frequency info when needed */
const getAdditionalInfo = (
purpose: ProjectPurpose,
frequency: string
unitType: UnitType,
frequency: string,
language: string,
quantity: number
): string => {
let info = "";
switch (purpose) {
case "trees":
switch (unitType) {
case "tree":
info =
info +
" " +
t("fortreeCountTrees", {
count: Number(quantity),
treeCount: getFormattedNumber(i18n.language, Number(quantity)),
treeCount: getFormattedNumber(language, Number(quantity)),
});
break;
case "conservation":
case "m2":
info =
info +
" " +
t("forQuantitym2", {
quantity: getFormattedNumber(i18n.language, Number(quantity)),
quantity: getFormattedNumber(language, Number(quantity)),
});
break;
default:
Expand Down Expand Up @@ -72,7 +74,12 @@ const TransactionSummary = ({
paymentSetup.unitCost * quantity
)}
</strong>
{getAdditionalInfo(paymentSetup.purpose, frequency)}
{getAdditionalInfo(
paymentSetup.unitType,
frequency,
i18n.language,
quantity
)}
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/Donations/Micros/DonationAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function DonationAmount(): ReactElement {
paymentSetup.unitCost * quantity
)}
</span>
{paymentSetup.purpose === "trees"
{paymentSetup.unitType === "tree"
? t("fortreeCountTrees", {
count: Number(quantity),
treeCount: getFormattedNumber(i18n.language, Number(quantity)),
})
: paymentSetup.purpose === "conservation"
: paymentSetup.unitType === "m2"
? t("forQuantitym2", {
quantity: getFormattedNumber(i18n.language, Number(quantity)),
})
Expand Down
22 changes: 16 additions & 6 deletions src/Donations/Micros/DonationTypes/BouquetDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function BouquetDonations({ setopenCurrencyModal }: Props): ReactElement {
setCustomInputValue(
getFormattedNumber(
i18n.language,
paymentSetup.unit !== "currency"
paymentSetup.unitType !== "currency"
? newQuantity
: newQuantity * paymentSetup.unitCost
)
Expand Down Expand Up @@ -165,7 +165,11 @@ function BouquetDonations({ setopenCurrencyModal }: Props): ReactElement {
currency,
option.quantity * paymentSetup.unitCost
)}{" "}
{paymentSetup.purpose === "conservation" ? t("m2") : []}
{/* Below condition is redundant currently, but is left here as a reminder while refactoring */}
{paymentSetup.purpose === "conservation" &&
paymentSetup.unitType === "m2"
? t(paymentSetup.unitType)
: []}
</span>
</div>
</div>
Expand Down Expand Up @@ -226,8 +230,10 @@ function BouquetDonations({ setopenCurrencyModal }: Props): ReactElement {
fontWeight: "800",
}}
>
{paymentSetup.purpose === "conservation"
? t(paymentSetup.unit)
{/* Below condition is redundant currently, but is left here as a reminder while refactoring */}
{paymentSetup.purpose === "conservation" &&
paymentSetup.unitType === "m2"
? t(paymentSetup.unitType)
: []}
</p>
</div>
Expand All @@ -238,7 +244,7 @@ function BouquetDonations({ setopenCurrencyModal }: Props): ReactElement {
>
<p style={{ margin: "5px" }}>
{" "}
{paymentSetup.unit === "currency"
{paymentSetup.unitType === "currency"
? t("customAmount")
: t("custom")}
</p>
Expand Down Expand Up @@ -282,7 +288,11 @@ function BouquetDonations({ setopenCurrencyModal }: Props): ReactElement {
)
: []}{" "}
</button>
{paymentSetup.purpose === "conservation" ? t("perm2") : []}
{/* Below condition is redundant currently, but is left here as a reminder while refactoring */}
{paymentSetup.purpose === "conservation" &&
paymentSetup.unitType === "m2"
? t("perUnit.m2")
: []}
</p>
) : (
<div className={"mt-20"}>
Expand Down
16 changes: 12 additions & 4 deletions src/Donations/Micros/DonationTypes/TreeDonation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function TreeDonation({ setopenCurrencyModal }: Props): ReactElement {
}, [quantity]);

const customInputRef = React.useRef<HTMLInputElement>(null);
return (
return paymentSetup !== null ? (
<div
className={`donations-tree-selection ${
isGift && giftDetails.recipientName === "" ? "display-none" : ""
Expand All @@ -99,7 +99,9 @@ function TreeDonation({ setopenCurrencyModal }: Props): ReactElement {
{option.iconFile}
<div className="tree-selection-option-text">
<p>{option.quantity}</p>
<span>{t("trees")}</span>
<span>
{t(paymentSetup.unitType, { count: option.quantity })}
</span>
</div>
</div>
);
Expand Down Expand Up @@ -136,7 +138,11 @@ function TreeDonation({ setopenCurrencyModal }: Props): ReactElement {
}}
ref={customInputRef}
/>
<span>{t("trees")}</span>
<span>
{t(paymentSetup.unitType, {
count: parseInt(customTreeInputValue),
})}
</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -165,14 +171,16 @@ function TreeDonation({ setopenCurrencyModal }: Props): ReactElement {
Number(paymentSetup.unitCost)
)}{" "}
</button>
{t("perTree")}
{t(`perUnit.${paymentSetup.unitType}`)}
</p>
) : (
<div className={"mt-20"}>
<TreeCostLoader width={150} />
</div>
)}
</div>
) : (
<></>
);
}

Expand Down
29 changes: 20 additions & 9 deletions src/Donations/Micros/PaymentStatus/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,26 @@ const ImageComponent = ({
return (
<div className={"donation-count p-20"}>
{projectDetails?.purpose === "trees" &&
t("common:myTreesPlantedByOnLocation", {
treeCount: getFormattedNumber(
i18n.language,
Number(donation.treeCount)
),
location: t(
"country:" + donation.destination.country.toLowerCase()
),
})}
(donation.unitType === "tree"
? t("common:myTreesPlantedByOnLocation", {
treeCount: getFormattedNumber(
i18n.language,
Number(donation.treeCount)
),
location: t(
"country:" + donation.destination.country.toLowerCase()
),
})
: t("common:restorationDonationShareDetails", {
amount: getFormattedCurrency(
i18n.language,
donation.currency,
Number(donation.amount)
),
location: t(
"country:" + donation.destination.country.toLowerCase()
),
}))}
{projectDetails?.purpose === "conservation" &&
t(
`common:${
Expand Down
24 changes: 12 additions & 12 deletions src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ function ThankyouMessage({
})
: null;

// EXAMPLE: Your 50 trees will be planted by AMU EcoVillage Project, Ethiopia in Ethiopia.
const donationProjectMessage = donation.destination
? " " +
t("common:yourTreesPlantedByOnLocation", {
treeCount: getFormattedNumber(
i18n.language,
Number(donation.treeCount)
),
projectName: donation.destination.name,
location: t("country:" + donation.destination.country.toLowerCase()),
})
: null;
// EXAMPLE: Your donation will be used to restore 1,000 trees by Yucatán Restoration in Mexico.
// EXAMPLE: Your donation will be used to restore 2,000 m² by Saving Sumatra’s Last Refuge in Indonesia.
const donationProjectMessage =
donation.destination && donation.units
? " " +
t("common:restorationDonationUsage", {
units: getFormattedNumber(i18n.language, donation.units),
unitType: t(`common:${donation.unitType}`, { count: donation.units }),
projectName: donation.destination.name,
location: t("country:" + donation.destination.country.toLowerCase()),
})
: null;

const Message = () => {
return (
Expand Down
1 change: 1 addition & 0 deletions src/Donations/PaymentMethods/PaymentFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ export async function handleStripeSCAPayment({
}
try {
const payDonationData = {
// method not sent here as it was already captured in the 1st request.
paymentProviderRequest: {
account: paymentSetup.gateways.stripe.account,
gateway: "stripe" as const,
Expand Down

0 comments on commit de42253

Please sign in to comment.