Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giftable donations #470

Merged
merged 28 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e80151a
feat: enhance project details types with classification & purpose var…
mohitb35 Nov 12, 2024
330aeda
feat: refactor project details handling with createProjectDetails uti…
mohitb35 Nov 12, 2024
4827176
feat: update GiftForm display logic
mohitb35 Nov 12, 2024
e508a6f
feat: removes unneeded GiftForm fields for membership projects
mohitb35 Nov 12, 2024
56a6baa
feat: refine DonationsForm gift handling while paying through planet …
mohitb35 Nov 12, 2024
562fa92
feat: prevent initialization of direct gift for membership projects
mohitb35 Nov 12, 2024
66552ec
feat: rename projectDetails `classification` to `category`
mohitb35 Nov 13, 2024
09ccd93
feat: prevent GiftForm display for planet-cash donations
mohitb35 Nov 13, 2024
10fbef4
fix: remove unneeded `onBehalf` while creating prepaid donation
mohitb35 Nov 13, 2024
fa0c770
feat: prevent gifts to non giftable project purposes
mohitb35 Nov 13, 2024
9ca3909
feat: update gift message to clarify dedication to recipient
mohitb35 Nov 13, 2024
92d62ab
chore: update @planet-sdk/common to version 0.1.42
mohitb35 Nov 13, 2024
62b38ac
feat: remove support link from query params when not applicable
mohitb35 Nov 14, 2024
416b7a4
feat: update gift types and usage to resolve TS warnings
mohitb35 Nov 14, 2024
ed270b3
feat: ensure donation amounts are treated as numbers for consistency
mohitb35 Nov 14, 2024
dd2b8e3
fix: standardize casing for setIsGift
mohitb35 Nov 14, 2024
e84df9b
revert: rename projectDetails `category` to `classification` for cons…
mohitb35 Nov 18, 2024
448c65d
refactor: remove conditional onBehalf donor assignment in DonationsForm
mohitb35 Nov 18, 2024
fb98cd9
fix: minor code cleanup and fixes
mohitb35 Nov 18, 2024
bc4af28
fix: fixes visible currency selector for non tree donations while dis…
mohitb35 Nov 21, 2024
83e1544
fix: resolves intermittent layout issue with MaterialTextField
mohitb35 Nov 22, 2024
c379166
fix: add validation for recipient name length in GiftForm
mohitb35 Nov 26, 2024
2890661
feat: update logic to show PlanetCashSelector
mohitb35 Nov 26, 2024
071785c
refactor: remove unused _onBehalfDonor assignment in DonationsForm
mohitb35 Nov 28, 2024
2839bc1
feat: add check for PlanetCash gateway while permitting planet cash d…
mohitb35 Dec 3, 2024
2eced0a
feat: add authentication to loadPaymentSetup
mohitb35 Dec 3, 2024
b7cb75c
Merge pull request #471 from Plant-for-the-Planet-org/feature/expand-…
mariahosfeld Dec 3, 2024
8546ebb
Merge pull request #472 from Plant-for-the-Planet-org/feature/restric…
mariahosfeld Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.42",
"@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 { 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 @@
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 @@
setSelectedProjects,
loadselectedProjects,
setGiftDetails,
setisGift,
setIsGift,
setpaymentSetup,
setcurrency,
setContactDetails,
Expand Down Expand Up @@ -129,7 +131,7 @@
// If gift details are present, initialize gift in context
if (giftDetails && isGift) {
setGiftDetails(giftDetails);
setisGift(true);
setIsGift(true);
}
}, []);

Expand Down Expand Up @@ -208,36 +210,36 @@

export default index;

export const getServerSideProps: GetServerSideProps = async (context) => {
let donationStep = 0;
let showErrorCard = false;
let projectDetails: FetchedProjectDetails | null = null;

// 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;
let isTaxDeductible = false;
let donationID = null;
let shouldCreateDonation = false;
let country = "";
let isDirectDonation = false;
let contactDetails: ContactDetails | null = null;
let units: number | null = 50;
let allowTaxDeductionChange = true;
let currency = "EUR";
let paymentSetup: PaymentOptions | null = null;
let amount = 0;
let tenant = "ten_I9TW3ncG";
let callbackUrl = "";
let callbackMethod = "";
let utmCampaign = "";
let utmMedium = "";
let utmSource = "";
const locale = context.locale || "en";

Check warning on line 242 in pages/index.tsx

View check run for this annotation

codefactor.io / CodeFactor

pages/index.tsx#L213-L242

Very Complex Method
function setshowErrorCard() {
showErrorCard = true;
}
Expand All @@ -250,7 +252,7 @@
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 @@
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 @@
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 @@
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
4 changes: 2 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"selectLanguage": "Select Language",
"trees": "trees",
"logout": "Logout",
"directGiftRecipient": "This donation supports {{name}}'s Forest",
"giftDedicatedTo": "This donation is dedicated to {{name}}",
mohitb35 marked this conversation as resolved.
Show resolved Hide resolved
"saveGiftDetails": "Save Gift Details",
"giftSomeone": "My donation is dedicated to someone",
"or": "OR",
Expand Down Expand Up @@ -223,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"
}
}
101 changes: 71 additions & 30 deletions src/Common/InputTypes/MaterialTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,102 @@ import themeProperties from "./../../../styles/themeProperties";
const MaterialTextField = styled(TextField)({
width: "100%",
color: "var(--primary-font-color)",
"& .MuiInputBase-input.MuiOutlinedInput-input": {

// Label styles
"& label": {
color: "var(--primary-font-color)",
height: "1.1876em",
lineHeight: "1.1876em",
fontFamily: themeProperties.fontFamily,
fontSize: "14px",
lineHeight: "1",
},
"& .MuiInputAdornment-root": {
color: "var(--primary-font-color)",

// Base label positioning
"& .MuiInputLabel-root": {
transform: "translate(14px, 16px) scale(1)", // Matches original position
transformOrigin: "left top",
position: "absolute",
left: 0,
top: 0,
display: "block",
padding: 0,
pointerEvents: "none",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
maxWidth: "calc(100% - 24px)",
},

// Shrunk/focused label
"& label.Mui-focused": {
color: "var(--primary-font-color)",
fontFamily: themeProperties.fontFamily,
},
"& label": {
color: "var(--primary-font-color)",
fontFamily: themeProperties.fontFamily,
fontSize: "14px",
lineHeight: 1,
},

"& .MuiInputLabel-outlined.MuiInputLabel-shrink": {
transform: "translate(14px, -4px) scale(0.75)",
top: "-3px",
},
"& .MuiOutlinedInput-notchedOutline": {
border: "0px!important",
top: "-3px", // Critical for matching original position
pointerEvents: "auto",
maxWidth: "calc(133% - 32px)",
},
"& .Mui-disabled.MuiInputLabel-root": {

// Input styles
"& .MuiInputBase-input.MuiOutlinedInput-input": {
color: "var(--primary-font-color)",
height: "20px",
lineHeight: "20px",
padding: "14px",
},
"& .Mui-disabled.MuiOutlinedInput-input ": {
color: "var(--disabled-font-color)",
WebkitTextFillColor: "initial",
},

// Input container
"& .MuiOutlinedInput-root": {
backgroundColor: "var(--background-color-dark)",
border: "0px!important",
borderRadius: "10px",
fontFamily: themeProperties.fontFamily,
minHeight: "44px",

"& fieldset": {
border: "none",
},
},
mohitb35 marked this conversation as resolved.
Show resolved Hide resolved
"& .MuiOutlinedInput-input": {
padding: "14px",

// Input adornment
"& .MuiInputAdornment-root": {
color: "var(--primary-font-color)",
},

// Notched outline
"& .MuiOutlinedInput-notchedOutline": {
border: "0px!important",
},

// Disabled state
"& .Mui-disabled": {
"&.MuiInputLabel-root": {
color: "var(--primary-font-color)",
},
"&.MuiOutlinedInput-input": {
color: "var(--disabled-font-color)",
WebkitTextFillColor: "initial",
},
},

// Multiline
"& .MuiInputBase-multiline": {
padding: "0px",
},

// Autocomplete
'& .MuiAutocomplete-inputRoot[class*="MuiOutlinedInput-root"]': {
padding: "14px",
},
'& .MuiAutocomplete-inputRoot[class*="MuiOutlinedInput-root"] .MuiAutocomplete-input':
{

"& .MuiAutocomplete-input": {
padding: "0px",

"&:first-of-type": {
paddingLeft: "0px",
},
},
'& .MuiAutocomplete-inputRoot[class*="MuiOutlinedInput-root"] .MuiAutocomplete-input:first-of-type':
{
paddingLeft: "0px",
},
},
});

export default MaterialTextField;
8 changes: 4 additions & 4 deletions src/Common/Types/QueryParamContextInterface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
CurrencyList,
FetchedProjectDetails,
GiftDetails,
OnBehalfDonor,
PaymentOptions,
PlanetCashSignupDetails,
SentGift,
} from ".";
import { ProjectMapInfo as Project } from "@planet-sdk/common/build/types/project";
import { User } from "@planet-sdk/common/build/types/user";
Expand All @@ -20,9 +20,9 @@ import { Dispatch, SetStateAction } from "react";

export default interface QueryParamContextInterface {
isGift: boolean;
setisGift: Dispatch<SetStateAction<boolean>>;
giftDetails: SentGift | NoGift;
setGiftDetails: Dispatch<SetStateAction<SentGift | NoGift>>;
setIsGift: Dispatch<SetStateAction<boolean>>;
giftDetails: GiftDetails | NoGift;
setGiftDetails: Dispatch<SetStateAction<GiftDetails | NoGift>>;
mohitb35 marked this conversation as resolved.
Show resolved Hide resolved
contactDetails: ContactDetails;
setContactDetails: Dispatch<SetStateAction<ContactDetails>>;
country: string;
Expand Down
Loading
Loading