Skip to content

Commit

Permalink
feat: refine DonationsForm gift handling while paying through planet …
Browse files Browse the repository at this point in the history
…cash

- explicitly sets `gift` based on type
  • Loading branch information
mohitb35 committed Nov 12, 2024
1 parent e508a6f commit 56a6baa
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ function DonationsForm(): ReactElement {
!(isGift && giftDetails.recipientName === "") &&
!(onBehalf && onBehalfDonor.firstName === "");

const canSendInvitationGift =
(projectDetails?.classification !== "membership" && frequency === "once") ||
(projectDetails?.classification === "membership" && frequency !== "once");

const canSendDirectGift = projectDetails?.classification !== "membership";
const hasDirectGift = giftDetails.type === "direct";
const canSendInvitationGift =
!hasDirectGift &&
((projectDetails?.classification !== "membership" &&
frequency === "once") ||
(projectDetails?.classification === "membership" &&
frequency !== "once"));

//Only used for native pay. Is this still applicable, or should this be removed?
const onPaymentFunction = async (
Expand Down Expand Up @@ -301,14 +303,28 @@ function DonationsForm(): ReactElement {
utm_source: utmSource,
};

const _gift = {
...giftDetails,
};
// Determine if gift info is complete
const isDirectGiftComplete =
giftDetails.type === "direct" && giftDetails.recipient.length > 0;

if (giftDetails.type === "direct") {
delete _gift.message;
delete _gift.recipientName;
}
const isInvitationGiftComplete =
giftDetails.type === "invitation" &&
giftDetails.recipientName.length > 0;

// Set _gift to null if incomplete, otherwise construct gift object
const _gift = isDirectGiftComplete
? {
type: "direct",
recipient: giftDetails.recipient,
}
: isInvitationGiftComplete
? {
type: "invitation",
recipientName: giftDetails.recipientName,
recipientEmail: giftDetails.recipientEmail,
message: giftDetails.message,
}
: null;

// create Donation data
const donationData = {
Expand Down

0 comments on commit 56a6baa

Please sign in to comment.