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 4827176 commit ae80293
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Donations/Components/DonationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,28 @@ function DonationsForm(): ReactElement {
utm_source: utmSource,
};

const _gift = {
...giftDetails,
};

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

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 ae80293

Please sign in to comment.