From a07a043d7acd23212f207624b27371cad8a8d1b2 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Fri, 3 Jun 2022 02:47:09 +0530 Subject: [PATCH 01/41] Add null checks --- pages/index.tsx | 10 +++++----- src/Donations/Components/DonationsForm.tsx | 10 +++++----- src/Donations/Components/PaymentsForm.tsx | 6 +++--- .../Micros/DonationTypes/FundingDonations.tsx | 6 +++--- .../Micros/PaymentStatus/ImageComponent.tsx | 8 ++++---- .../PaymentStatus/SuccessfulDonation.tsx | 2 +- .../Micros/PaymentStatus/ThankyouMessage.tsx | 12 +++++------ src/Donations/Micros/TaxDeductionOption.tsx | 4 ++-- .../PaymentMethods/PaymentFunctions.ts | 4 ++-- .../PaymentMethods/PaymentMethodTabs.tsx | 2 +- src/Donations/index.tsx | 20 +++++++++---------- 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 270241f9..8de2ac9c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -424,17 +424,17 @@ export async function getServerSideProps(context: any) { if (projectDetails) { title = `${projectDetails.name} - Donate with Plant-for-the-Planet`; - if (projectDetails.purpose === "trees") { + if (projectDetails?.purpose === "trees") { description = `Plant trees with ${projectDetails.ownerName}. Your journey to a trillion trees starts here.`; } else if ( - projectDetails.purpose === "conservation" && + projectDetails?.purpose === "conservation" && !projectDetails.description ) { description = `Conserve forests with ${projectDetails.ownerName}. Your journey to a trillion trees starts here.`; } else if ( - (projectDetails.purpose === "bouquet" || - projectDetails.purpose === "funds" || - projectDetails.purpose === "conservation") && + (projectDetails?.purpose === "bouquet" || + projectDetails?.purpose === "funds" || + projectDetails?.purpose === "conservation") && projectDetails.description ) { description = projectDetails.description; diff --git a/src/Donations/Components/DonationsForm.tsx b/src/Donations/Components/DonationsForm.tsx index 84213e4d..dc1447f0 100644 --- a/src/Donations/Components/DonationsForm.tsx +++ b/src/Donations/Components/DonationsForm.tsx @@ -79,7 +79,7 @@ function DonationsForm() { if (projectDetails && profile) { if (profile!.planetCash) { - if (projectDetails.purpose === "planet-cash") { + if (projectDetails?.purpose === "planet-cash") { setcountry(profile!.planetCash.country); setcurrency(profile!.planetCash.currency); } @@ -294,8 +294,8 @@ function DonationsForm() { )} {/* show PlanetCashSelector only if user is signed up and have a planetCash account */} - {projectDetails.purpose !== "funds" && - projectDetails.purpose !== "planet-cash" && + {projectDetails?.purpose !== "funds" && + projectDetails?.purpose !== "planet-cash" && !(isGift && giftDetails.recipientName === "") && !(onBehalf && onBehalfDonor.firstName === "") && isSignedUp && @@ -351,8 +351,8 @@ function DonationsForm() { >
- {(projectDetails.purpose === "trees" || - projectDetails.purpose === "conservation") && } + {(projectDetails?.purpose === "trees" || + projectDetails?.purpose === "conservation") && } {/* Hide NativePay if PlanetCash is active */} diff --git a/src/Donations/Components/PaymentsForm.tsx b/src/Donations/Components/PaymentsForm.tsx index 978a0af7..369dade2 100644 --- a/src/Donations/Components/PaymentsForm.tsx +++ b/src/Donations/Components/PaymentsForm.tsx @@ -264,7 +264,7 @@ function PaymentsForm({}: Props): ReactElement { {/* TODO - When donations are coming from context, check for haspublicprofile */} - {projectDetails && projectDetails.purpose !== "funds" ? ( + {projectDetails && projectDetails?.purpose !== "funds" ? (
{!Object.keys(contactDetails).includes("companyName") ? ( askpublishName ? ( @@ -285,7 +285,7 @@ function PaymentsForm({}: Props): ReactElement {
) : (
- {projectDetails.purpose !== "planet-cash" && ( + {projectDetails?.purpose !== "planet-cash" && ( @@ -325,7 +325,7 @@ function PaymentsForm({}: Props): ReactElement { paymentMethod: "sepa_debit", currencies: ["EUR"], authenticatedMethod: - projectDetails && projectDetails.purpose === "funds" + projectDetails && projectDetails?.purpose === "funds" ? false : true, })} diff --git a/src/Donations/Micros/DonationTypes/FundingDonations.tsx b/src/Donations/Micros/DonationTypes/FundingDonations.tsx index 37897dcd..61525202 100644 --- a/src/Donations/Micros/DonationTypes/FundingDonations.tsx +++ b/src/Donations/Micros/DonationTypes/FundingDonations.tsx @@ -248,7 +248,7 @@ function FundingDonations({ setopenCurrencyModal }: Props): ReactElement { // if the purpose is planet-cash (i.e Top-up PlanetCash) then lock the currency and country for transaction. // since transaction needs to happen in the same currency. - projectDetails.purpose !== "planet-cash" && + projectDetails?.purpose !== "planet-cash" && !isPlanetCashActive && setopenCurrencyModal(true); }} @@ -258,7 +258,7 @@ function FundingDonations({ setopenCurrencyModal }: Props): ReactElement { ...(isPlanetCashActive && { cursor: "text" }), }} > - {projectDetails.purpose !== "planet-cash" ? ( + {projectDetails?.purpose !== "planet-cash" ? ( {t("selectCurrency")} @@ -269,7 +269,7 @@ function FundingDonations({ setopenCurrencyModal }: Props): ReactElement { )} {currency} - {projectDetails.purpose !== "planet-cash" && + {projectDetails?.purpose !== "planet-cash" && !isPlanetCashActive && ( )} diff --git a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx index 3e24a005..b7b810e3 100644 --- a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx +++ b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx @@ -53,7 +53,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { const ImageDonationText = () => { return (
- {projectDetails.purpose === "trees" && + {projectDetails?.purpose === "trees" && t("common:myTreesPlantedByOnLocation", { treeCount: getFormattedNumber( i18n.language, @@ -61,7 +61,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { ), location: t("country:" + donation.project.country.toLowerCase()), })} - {projectDetails.purpose === "conservation" && + {projectDetails?.purpose === "conservation" && t( `common:${ profile?.type && pluralProfileTypes.includes(profile?.type) @@ -77,13 +77,13 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { location: t("country:" + donation.project.country.toLowerCase()), } )} - {projectDetails.purpose === "funds" && + {projectDetails?.purpose === "funds" && t("common:contributedToTpo", { amount: currencyFormat(), organization: projectDetails.ownerName, })} - {projectDetails.purpose === "bouquet" && t("Message for Bouquet")} + {projectDetails?.purpose === "bouquet" && t("Message for Bouquet")}
); }; diff --git a/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx b/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx index 3c2f7cc0..1a69180e 100644 --- a/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx +++ b/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx @@ -43,7 +43,7 @@ function SuccessfulDonation({ donation, sendToReturn }: any) { projectDetails={projectDetails} donation={donation} /> - {projectDetails.purpose !== "planet-cash" && ( + {projectDetails?.purpose !== "planet-cash" && ( <> { return (
- {projectDetails.purpose === "trees" && ( + {projectDetails?.purpose === "trees" && ( <>
{donationSuccessfulMessage} @@ -75,7 +75,7 @@ function ThankyouMessage({ )} - {projectDetails.purpose === "funds" && ( + {projectDetails?.purpose === "funds" && ( <>
{donationSuccessfulMessage} @@ -88,7 +88,7 @@ function ThankyouMessage({ )} - {projectDetails.purpose === "planet-cash" && ( + {projectDetails?.purpose === "planet-cash" && (
{donationSuccessfulMessage}
@@ -97,7 +97,7 @@ function ThankyouMessage({
)} - {projectDetails.purpose === "bouquet" && ( + {projectDetails?.purpose === "bouquet" && ( <>
{donationSuccessfulMessage} @@ -110,7 +110,7 @@ function ThankyouMessage({ )} )} - {projectDetails.purpose === "conservation" && ( + {projectDetails?.purpose === "conservation" && ( <>
{donationSuccessfulMessage} diff --git a/src/Donations/Micros/TaxDeductionOption.tsx b/src/Donations/Micros/TaxDeductionOption.tsx index 1a9e984d..6f4c7c1a 100644 --- a/src/Donations/Micros/TaxDeductionOption.tsx +++ b/src/Donations/Micros/TaxDeductionOption.tsx @@ -46,14 +46,14 @@ function TaxDeductionOption({}: Props): ReactElement { // if the purpose is planet-cash (i.e Top-up PlanetCash) then lock the currency and country for transaction. // since transaction needs to happen in the same currency. - projectDetails.purpose !== "planet-cash" && + projectDetails?.purpose !== "planet-cash" && setopenTaxDeductionModal(true); }} className={"tax-country-selection text-primary text-bold"} data-test-id="taxCountrySelection" > {t(`country:${country?.toLowerCase()}`)} - {projectDetails.purpose !== "planet-cash" && ( + {projectDetails?.purpose !== "planet-cash" && ( )} diff --git a/src/Donations/PaymentMethods/PaymentFunctions.ts b/src/Donations/PaymentMethods/PaymentFunctions.ts index 532bf445..759b7f82 100644 --- a/src/Donations/PaymentMethods/PaymentFunctions.ts +++ b/src/Donations/PaymentMethods/PaymentFunctions.ts @@ -162,7 +162,7 @@ export function createDonationData({ callbackMethod, }: any) { let donationData = { - purpose: projectDetails.purpose, + purpose: projectDetails?.purpose, project: projectDetails.id, amount: paymentSetup.unitCost * quantity @@ -218,7 +218,7 @@ export function createDonationData({ } } - if (projectDetails.purpose === "planet-cash") { + if (projectDetails?.purpose === "planet-cash") { // For PlanetCash Top-up // No need to send quantity. diff --git a/src/Donations/PaymentMethods/PaymentMethodTabs.tsx b/src/Donations/PaymentMethods/PaymentMethodTabs.tsx index 91dacf97..89b12c24 100644 --- a/src/Donations/PaymentMethods/PaymentMethodTabs.tsx +++ b/src/Donations/PaymentMethods/PaymentMethodTabs.tsx @@ -75,7 +75,7 @@ export default function PaymentMethodTabs({ let paymentLabel; if (paymentSetup && currency) { - switch (projectDetails && projectDetails.purpose) { + switch (projectDetails && projectDetails?.purpose) { case "trees": paymentLabel = t("treesInCountry", { treeCount: quantity, diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index 39605aa5..d4f3a117 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -166,7 +166,7 @@ function DonationInfo() { {/* */} {donationStep > 0 && projectDetails.ownerName && - (projectDetails.purpose === "trees" ? ( + (projectDetails?.purpose === "trees" ? ( ))} {(donationStep === 2 || donationStep === 3) && - (projectDetails.purpose === "trees" || - projectDetails.purpose === "conservation") && ( + (projectDetails?.purpose === "trees" || + projectDetails?.purpose === "conservation") && (
{t("donating")}{" "} @@ -217,8 +217,8 @@ function DonationInfo() { )} {(donationStep === 2 || donationStep === 3) && - (projectDetails.purpose === "bouquet" || - projectDetails.purpose === "funds") && ( + (projectDetails?.purpose === "bouquet" || + projectDetails?.purpose === "funds") && (
{t("donating")}{" "} @@ -240,7 +240,7 @@ function DonationInfo() { {donationStep > 0 ? ( <> - {projectDetails.purpose === "trees" ? ( + {projectDetails?.purpose === "trees" ? ( )} - {projectDetails.purpose === "funds" || - projectDetails.purpose === "bouquet" ? ( + {projectDetails?.purpose === "funds" || + projectDetails?.purpose === "bouquet" ? (

{projectDetails.description}

) : ( [] )} - {(projectDetails.purpose === "trees" || - projectDetails.purpose === "conservation") && + {(projectDetails?.purpose === "trees" || + projectDetails?.purpose === "conservation") && projectDetails.ownerName && (
{t("byOrganization", { From a2fc69287c00aa9d7a7c21e6a61e32b6a22f9f62 Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Sat, 11 Jun 2022 12:43:41 +0200 Subject: [PATCH 02/41] change bouquet project, added more waiting time, click on field before typing --- cypress/integration/bouquetDonations.spec.js | 3 ++- cypress/integration/formError.spec.js | 14 +++++++------- cypress/support/commands.js | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cypress/integration/bouquetDonations.spec.js b/cypress/integration/bouquetDonations.spec.js index 62a7729a..fcffa04c 100644 --- a/cypress/integration/bouquetDonations.spec.js +++ b/cypress/integration/bouquetDonations.spec.js @@ -4,7 +4,8 @@ describe("Bouquet Donations", () => { it("Testing Restore bouquetDonation", () => { // cy.bouquetDonation("proj_bAwk5Agpfj1xcG61tFXMqKbu", "Germany{enter}", "de", "ten_1e5WejOp") - cy.bouquetDonation("proj_6x3GTD5cMRv0OeQAiIlJZ0Au", "United States of America{enter}", "us", "ten_1e5WejOp") + // cy.bouquetDonation("proj_6x3GTD5cMRv0OeQAiIlJZ0Au", "United States of America{enter}", "us", "ten_1e5WejOp") + cy.bouquetDonation("proj_lZIhXOL00Pw4cRUMIlnDGPaQ", "United States of America{enter}", "us", "ten_NxJq55pm") cy.cardPayment("4242424242424242", "424", "242") }); }) \ No newline at end of file diff --git a/cypress/integration/formError.spec.js b/cypress/integration/formError.spec.js index 503069b8..3db750d8 100644 --- a/cypress/integration/formError.spec.js +++ b/cypress/integration/formError.spec.js @@ -15,7 +15,7 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0,0) cy.get('[data-test-id="test-continueToPayment"]').click() cy.get('.form-errors').should("have.text", "First Name is required") - cy.get('[data-test-id="test-firstName"]').type("Peter") + cy.get('[data-test-id="test-firstName"]').click().type("Peter") cy.get('body').should("not.have.text", "First Name is required") }) @@ -31,7 +31,7 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0,0) cy.get('[data-test-id="test-continueToPayment"]').click() cy.get('.form-errors').should("have.text", "Last Name is required") - cy.get('[data-test-id="test-lastName"]').type("Payer") + cy.get('[data-test-id="test-lastName"]').click().type("Payer") cy.get('body').should("not.have.text", "Last Name is required") }) @@ -69,7 +69,7 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0, 0) cy.get('[data-test-id="test-continueToPayment"]').click() cy.get('.form-errors').should("have.text", "Address is required") - cy.get('[data-test-id="test-address"]').type("Unbekannt 1") + cy.get('[data-test-id="test-address"]').clear().type("Unbekannt 1") cy.get('body').should("not.have.text", "Address is required") }) @@ -84,9 +84,9 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-city"]').clear() cy.get('[data-test-id="test-zipCode"]').clear().type("82449") cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0, 0) - cy.get('[data-test-id="test-continueToPayment"]').click() + //cy.get('[data-test-id="test-continueToPayment"]').click() cy.get('.form-errors').should("have.text", "City is required") - cy.get('[data-test-id="test-city"]').type("Uffing am Staffelsee") + cy.get('[data-test-id="test-city"]').click().type("Uffing am Staffelsee") cy.get('body').should("not.have.text", "City is required") }) @@ -105,9 +105,9 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-city"]').clear().type("Uffing am Staffelsee") cy.get('[data-test-id="test-zipCode"]').clear() cy.get('[data-test-id="test-country"]').clear().type(`${selectedCountry}{enter}`).get('body').click(0, 0) - cy.get('[data-test-id="test-continueToPayment"]').click() + //cy.get('[data-test-id="test-continueToPayment"]').click() cy.get('.form-errors').should("have.text", "ZipCode is invalid") - cy.get('[data-test-id="test-zipCode"]').type(new RandExp(fiteredCountry[0].postal).gen()) + cy.get('[data-test-id="test-zipCode"]').click().type(new RandExp(fiteredCountry[0].postal).gen()) cy.get('body').should("not.have.text", "ZipCode is invalid") }) }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9f4d835e..4650845c 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -232,7 +232,7 @@ Cypress.Commands.add('bankTransfer', () => { cy.wait(5000) // cy.get('.frequency-selection-option').eq(0).should("have.text", "Once").click() cy.contactForm("Peter", "Payer", "peter.payer@gmail.com", "Unbekannt 1", "Uffing am Staffelsee", "Germany{enter}", "82449") - cy.wait(10000) + cy.wait(15000) cy.get('[data-test-id="bankTransfer"]').click() cy.get('[data-test-id="bankDonateContinue"]').click() cy.wait(10000) From d9e41a43322d5ac3e0bfa44a7f28150142c3c238 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 14 Jun 2022 11:17:50 +0530 Subject: [PATCH 03/41] set translated description from paymentDetails api --- src/Donations/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index 39605aa5..c7b2631c 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -261,7 +261,9 @@ function DonationInfo() { {projectDetails.purpose === "funds" || projectDetails.purpose === "bouquet" ? ( -

{projectDetails.description}

+

+ {paymentSetup.description ? paymentSetup.description : ""} +

) : ( [] )} From 20bdf0270bdd586965aa88e2b13c3f673d74d6b4 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 14 Jun 2022 12:23:14 +0530 Subject: [PATCH 04/41] load paymentDetails based on language --- src/Layout/Footer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/Footer.tsx b/src/Layout/Footer.tsx index 3a3903c2..c2f10c4b 100644 --- a/src/Layout/Footer.tsx +++ b/src/Layout/Footer.tsx @@ -252,7 +252,7 @@ function LanguageModal({ loadPaymentSetup({ projectGUID: router.query.to, paymentSetupCountry: country, - shouldSetPaymentDetails: false, + shouldSetPaymentDetails: true, }); } setlanguageModalOpen(false); From ba41fe638177a1a4e265c7a109ff9da0640221c2 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 14 Jun 2022 14:34:31 +0530 Subject: [PATCH 05/41] set name of the project from paymentOptions api --- src/Donations/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index c7b2631c..dd6903ca 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -255,7 +255,7 @@ function DonationInfo() { className="title-text text-white" style={{ marginTop: "10px" }} > - {projectDetails.name} + {paymentSetup.name && paymentSetup.name} )} From aa9e3dd1dbfb3bf490557ddef2d74d5b5c3f1fce Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 14 Jun 2022 15:39:09 +0530 Subject: [PATCH 06/41] Changed null check style --- src/Donations/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index dd6903ca..123b1f5d 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -255,7 +255,7 @@ function DonationInfo() { className="title-text text-white" style={{ marginTop: "10px" }} > - {paymentSetup.name && paymentSetup.name} + {paymentSetup.name ? paymentSetup.name : ""} )} From fd3e2be062dada77bf48b62a0a4b9ef8f0c33307 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Wed, 15 Jun 2022 09:57:08 +0530 Subject: [PATCH 07/41] fetch paymentOptions with provided locale --- pages/index.tsx | 1 + src/Donations/index.tsx | 4 ++-- src/Layout/Footer.tsx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 270241f9..399bd600 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -255,6 +255,7 @@ export async function getServerSideProps(context: any) { url: `/app/paymentOptions/${to}?country=${country}`, setshowErrorCard, tenant, + locale, }; const paymentOptionsResponse = await apiRequest(requestParams); if (paymentOptionsResponse.data) { diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index 123b1f5d..8b4a0e4f 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -255,14 +255,14 @@ function DonationInfo() { className="title-text text-white" style={{ marginTop: "10px" }} > - {paymentSetup.name ? paymentSetup.name : ""} + {projectDetails.name ? projectDetails.name : ""} )} {projectDetails.purpose === "funds" || projectDetails.purpose === "bouquet" ? (

- {paymentSetup.description ? paymentSetup.description : ""} + {projectDetails.description ? projectDetails.description : ""}

) : ( [] diff --git a/src/Layout/Footer.tsx b/src/Layout/Footer.tsx index c2f10c4b..3a3903c2 100644 --- a/src/Layout/Footer.tsx +++ b/src/Layout/Footer.tsx @@ -252,7 +252,7 @@ function LanguageModal({ loadPaymentSetup({ projectGUID: router.query.to, paymentSetupCountry: country, - shouldSetPaymentDetails: true, + shouldSetPaymentDetails: false, }); } setlanguageModalOpen(false); From b386a1fa7898a8ab63afa467e45cb6d523aa9b51 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Wed, 15 Jun 2022 12:27:15 +0530 Subject: [PATCH 08/41] persist locale in url --- src/Layout/Footer.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Layout/Footer.tsx b/src/Layout/Footer.tsx index 3a3903c2..2da76124 100644 --- a/src/Layout/Footer.tsx +++ b/src/Layout/Footer.tsx @@ -255,6 +255,8 @@ function LanguageModal({ shouldSetPaymentDetails: false, }); } + router.query.locale = event.target.value; + router.push(router); setlanguageModalOpen(false); }} > From 0961c7eec17a8663c498c31b2c28cd0c74ab2ca3 Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Wed, 15 Jun 2022 20:30:31 +0200 Subject: [PATCH 09/41] don't do the browser check for Safari on Android devices --- src/Utils/browsercheck.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Utils/browsercheck.ts b/src/Utils/browsercheck.ts index 5e79103c..a2fe26ab 100644 --- a/src/Utils/browsercheck.ts +++ b/src/Utils/browsercheck.ts @@ -20,10 +20,11 @@ function compareVersion(version: string, range: string) { return comparator[op] ? comparator[op](version, n) : (version == n || n !== n); } -// check for safari version +// check for safari version, but not if Android device function safari(range: string, userAgent: string) { const match = userAgent.match(/version\/(\d+).+?safari/); - return match !== null && compareVersion(match[1], range); + const matchAndroid = userAgent.match(/android/); + return match !== null && matchAndroid == null && compareVersion(match[1], range); } // check for samsung version From 9adf19d302826b6d1c303270cdad38c10b7c73f9 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Thu, 16 Jun 2022 10:03:34 +0530 Subject: [PATCH 10/41] fix translation auto switching --- pages/index.tsx | 7 ------- src/Layout/Footer.tsx | 2 -- 2 files changed, 9 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 399bd600..a37cf81b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -115,13 +115,6 @@ function index({ setCountryCode({ setcountry, setcurrency, country }); }, []); - // If project details are present set project details - React.useEffect(() => { - if (projectDetails) { - setprojectDetails(projectDetails); - } - }, [projectDetails]); - settenant(tenant); // If gift details are present set gift if (giftDetails && isGift) { diff --git a/src/Layout/Footer.tsx b/src/Layout/Footer.tsx index 2da76124..3a3903c2 100644 --- a/src/Layout/Footer.tsx +++ b/src/Layout/Footer.tsx @@ -255,8 +255,6 @@ function LanguageModal({ shouldSetPaymentDetails: false, }); } - router.query.locale = event.target.value; - router.push(router); setlanguageModalOpen(false); }} > From a80d6148151d462bc1a5b7886dfb33a077db1e0a Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Thu, 16 Jun 2022 15:52:12 +0530 Subject: [PATCH 11/41] load Profile --- src/Layout/QueryParamContext.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 442d727b..6edc72ef 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -8,6 +8,7 @@ import countriesData from "../Utils/countriesData.json"; import { setCountryCode } from "src/Utils/setCountryCode"; import { THANK_YOU } from "src/Utils/donationStepConstants"; import { PaymentSetupProps } from "src/Common/Types"; +import { useAuth0 } from "@auth0/auth0-react"; export const QueryParamContext = React.createContext({ isGift: false, @@ -105,6 +106,7 @@ export default function QueryParamProvider({ children }: any) { const router = useRouter(); const { i18n } = useTranslation(); + const { getAccessTokenSilently } = useAuth0(); const [paymentSetup, setpaymentSetup] = useState({}); @@ -282,8 +284,31 @@ export default function QueryParamProvider({ children }: any) { } } + const _loadProfile = async () => { + let _profile; + const loadProfile = async () => { + const token = await getAccessTokenSilently(); + try { + _profile = await apiRequest({ + url: "/app/profile", + token: token, + setshowErrorCard, + tenant, + }); + } catch (err) { + console.error(err); + } + }; + await loadProfile(); + if (_profile) { + console.log("===>", _profile); + } + } + React.useEffect(() => { - if (router.query.to && country !== undefined && country !== "") { + if (router.query.to === "planetCash") { + + } else if (router.query.to && country !== undefined && country !== "") { const to = String(router.query.to).replace(/\//g, ""); loadPaymentSetup({ projectGUID: to, From 96cb906a04310d3609119c5004f99da54ba8935e Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Fri, 17 Jun 2022 10:59:06 +0530 Subject: [PATCH 12/41] add and handle redirection to planetCash topup --- pages/index.tsx | 7 --- src/Donations/Micros/PlanetCashSelector.tsx | 2 +- src/Layout/QueryParamContext.tsx | 62 +++++++++++++-------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 270241f9..9f925a0c 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -115,13 +115,6 @@ function index({ setCountryCode({ setcountry, setcurrency, country }); }, []); - // If project details are present set project details - React.useEffect(() => { - if (projectDetails) { - setprojectDetails(projectDetails); - } - }, [projectDetails]); - settenant(tenant); // If gift details are present set gift if (giftDetails && isGift) { diff --git a/src/Donations/Micros/PlanetCashSelector.tsx b/src/Donations/Micros/PlanetCashSelector.tsx index d508f568..d77dc3e8 100644 --- a/src/Donations/Micros/PlanetCashSelector.tsx +++ b/src/Donations/Micros/PlanetCashSelector.tsx @@ -114,7 +114,7 @@ const PlanetCashSelector: FC = (props) => { const handleAddBalance = () => { router.replace({ - query: { ...router.query, to: profile!.planetCash.account }, + query: { ...router.query, to: "planetCash" }, }); }; diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 6edc72ef..05dbebd7 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -106,7 +106,7 @@ export default function QueryParamProvider({ children }: any) { const router = useRouter(); const { i18n } = useTranslation(); - const { getAccessTokenSilently } = useAuth0(); + const { getAccessTokenSilently, isLoading, isAuthenticated } = useAuth0(); const [paymentSetup, setpaymentSetup] = useState({}); @@ -284,30 +284,44 @@ export default function QueryParamProvider({ children }: any) { } } - const _loadProfile = async () => { - let _profile; - const loadProfile = async () => { - const token = await getAccessTokenSilently(); - try { - _profile = await apiRequest({ - url: "/app/profile", - token: token, - setshowErrorCard, - tenant, - }); - } catch (err) { - console.error(err); - } - }; - await loadProfile(); - if (_profile) { - console.log("===>", _profile); - } - } + const loadProfile = React.useCallback(async () => { + const token = await getAccessTokenSilently(); + try { + const profile: any = await apiRequest({ + url: "/app/profile", + token: token, + setshowErrorCard, + tenant, + }); + setprofile(profile.data); + } catch (err) { + console.error(err); + } + }, []); + + React.useEffect(() => { + if (!isLoading && isAuthenticated) { + loadProfile(); + } + }, [isLoading, isAuthenticated, loadProfile]); React.useEffect(() => { - if (router.query.to === "planetCash") { - + const regex = /^pcash_/; + if (regex.test(router.query.to)) { + router.push("/"); + } else if (router.query.to === "planetCash") { + if (profile && profile?.planetCash?.account) { + loadPaymentSetup({ + projectGUID: profile?.planetCash?.account, + paymentSetupCountry: country, + shouldSetPaymentDetails: true, + }); + setdonationStep(1); + } else if (!profile?.planetCash) { + setPaymentError("PlanetCash is not enabled"); + setdonationStep(1); + console.log("Here.."); + } } else if (router.query.to && country !== undefined && country !== "") { const to = String(router.query.to).replace(/\//g, ""); loadPaymentSetup({ @@ -316,7 +330,7 @@ export default function QueryParamProvider({ children }: any) { shouldSetPaymentDetails: true, }); } - }, [router.query.to, country]); + }, [router.query.to, country, profile]); async function loadConfig() { let userLang; From bb39cc19367318cc4dd10dafa52b668608542f1a Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Fri, 17 Jun 2022 07:13:00 +0000 Subject: [PATCH 13/41] =?UTF-8?q?Language=20update=20from=20LingoHub=20?= =?UTF-8?q?=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Project Name: Planet Donations Project Link: https://translate.lingohub.com/plant-for-the-planet/dashboard/planet-donations User: Norbert Schuler Easy language translations with LingoHub 🚀 --- public/locales/cs/common.json | 2 +- public/locales/de/common.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/locales/cs/common.json b/public/locales/cs/common.json index c44a5411..4773f41a 100644 --- a/public/locales/cs/common.json +++ b/public/locales/cs/common.json @@ -99,7 +99,7 @@ "contact": "Kontakt", "faqs": "FAQ", "selectLanguage": "Zvolit jazyk", - "trees": "stromy", + "trees": "stromy/ů", "logout": "Odhlásit se", "directGiftRecipient": "Tento dar podporuje Les od {{name}}", "saveGiftDetails": "Uloži darovací údaje", diff --git a/public/locales/de/common.json b/public/locales/de/common.json index b7dfc493..f8839c81 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -167,5 +167,6 @@ "fundsPurpose": "Spende", "bouquetPurpose": "Spende", "conservationPurpose": "Naturschutzspende", - "planet-cashPurpose": "PlanetCash-Spende" + "planet-cashPurpose": "PlanetCash-Spende", + "pfpSupportsUNEP": "Plant-for-the-Planet unterstützt das Umweltprogramm der Vereinten Nationen" } \ No newline at end of file From f9966542e8996a6b1de13f649e51bf1ce5844c55 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 20 Jun 2022 10:41:53 +0530 Subject: [PATCH 14/41] Restrict fetching paymentOptions in getSerserSideProps if to is planetCash --- pages/index.tsx | 46 +++++++++++++++++++++-------------------- src/Donations/index.tsx | 2 +- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 9f925a0c..1da66022 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -243,30 +243,32 @@ export async function getServerSideProps(context: any) { ) { const to = context.query?.to?.replace(/\//g, "") || ""; donationStep = 1; - try { - const requestParams = { - url: `/app/paymentOptions/${to}?country=${country}`, - setshowErrorCard, - tenant, - }; - const paymentOptionsResponse = await apiRequest(requestParams); - if (paymentOptionsResponse.data) { - projectDetails = { - id: paymentOptionsResponse.data.id, - name: paymentOptionsResponse.data.name, - description: paymentOptionsResponse.data.description, - purpose: paymentOptionsResponse.data.purpose, - ownerName: paymentOptionsResponse.data.ownerName, - taxDeductionCountries: - paymentOptionsResponse.data.taxDeductionCountries, - projectImage: paymentOptionsResponse.data.image, - ownerAvatar: paymentOptionsResponse.data.ownerAvatar, + if (to !== "planetCash") { + try { + const requestParams = { + url: `/app/paymentOptions/${to}?country=${country}`, + setshowErrorCard, + tenant, }; - donationStep = 1; + const paymentOptionsResponse = await apiRequest(requestParams); + if (paymentOptionsResponse.data) { + projectDetails = { + id: paymentOptionsResponse.data.id, + name: paymentOptionsResponse.data.name, + description: paymentOptionsResponse.data.description, + purpose: paymentOptionsResponse.data.purpose, + ownerName: paymentOptionsResponse.data.ownerName, + taxDeductionCountries: + paymentOptionsResponse.data.taxDeductionCountries, + projectImage: paymentOptionsResponse.data.image, + ownerAvatar: paymentOptionsResponse.data.ownerAvatar, + }; + donationStep = 1; + } + } catch (err) { + donationStep = 0; + console.log("err", err); } - } catch (err) { - donationStep = 0; - console.log("err", err); } } else { if (!context.query.context) { diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index 39605aa5..fca41551 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -47,7 +47,7 @@ function Donations({}: Props): ReactElement { step = router.query?.step; } - switch (step) { + switch (step) { case SELECT_PROJECT: setdonationStep(0); break; From 901f658ba3998280710c83ba4e45ae7c4a3ae278 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 20 Jun 2022 16:03:47 +0530 Subject: [PATCH 15/41] Handle No PlanetCash Account Case --- public/locales/en/common.json | 5 +++-- src/Donations/Components/PaymentStatus.tsx | 5 ++++- src/Donations/index.tsx | 2 +- src/Layout/QueryParamContext.tsx | 12 +++++++++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 2756a546..447ad77a 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -168,5 +168,6 @@ "bouquetPurpose": "donation", "conservationPurpose": "conservation donation", "planet-cashPurpose": "PlanetCash donation", - "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program" -} \ No newline at end of file + "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program", + "planetCashDisabled": "Your PlanetCash account is not activated. Please activate PlanetCash." +} diff --git a/src/Donations/Components/PaymentStatus.tsx b/src/Donations/Components/PaymentStatus.tsx index 2d31c535..eab0f0ec 100644 --- a/src/Donations/Components/PaymentStatus.tsx +++ b/src/Donations/Components/PaymentStatus.tsx @@ -94,7 +94,8 @@ function ThankYou() { getFormatedCurrency(i18n.language, donation.currency, donation.amount); } - const { callbackUrl, paymentError } = React.useContext(QueryParamContext); + const { callbackUrl, paymentError, projectDetails } = + React.useContext(QueryParamContext); const router = useRouter(); @@ -150,6 +151,8 @@ function ThankYou() { sendToReturn={sendToReturn} /> ) + ) : projectDetails?.purpose === "planet-cash" ? ( +
{t("common:planetCashDisabled")}
) : (
diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index fca41551..39605aa5 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -47,7 +47,7 @@ function Donations({}: Props): ReactElement { step = router.query?.step; } - switch (step) { + switch (step) { case SELECT_PROJECT: setdonationStep(0); break; diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 05dbebd7..f11e297c 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -318,9 +318,15 @@ export default function QueryParamProvider({ children }: any) { }); setdonationStep(1); } else if (!profile?.planetCash) { - setPaymentError("PlanetCash is not enabled"); - setdonationStep(1); - console.log("Here.."); + if (profile?.name) { + setprojectDetails({ + name: `PlanetCash - ${profile?.name}`, + ownerName: profile?.name, + ownerAvatar: profile?.image, + purpose: "planet-cash", + }); + } + setdonationStep(4); } } else if (router.query.to && country !== undefined && country !== "") { const to = String(router.query.to).replace(/\//g, ""); From 8f21b96f80fbbcc92c2b0552ae27df81901d31e2 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 21 Jun 2022 11:05:07 +0530 Subject: [PATCH 16/41] Fix CodeRefactor Issues --- pages/index.tsx | 10 +++------- src/Layout/QueryParamContext.tsx | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 1da66022..f8eaa1bc 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -13,11 +13,11 @@ import { setCountryCode } from "src/Utils/setCountryCode"; import { DONATE } from "src/Utils/donationStepConstants"; interface Props { - projectDetails: Object; + projectDetails?: Object; donationStep: any; giftDetails: Object; isGift: boolean; - resolvedUrl: any; + resolvedUrl?: any; isDirectDonation: boolean; hideTaxDeduction: boolean; isTaxDeductible: boolean; @@ -28,7 +28,7 @@ interface Props { allowTaxDeductionChange: boolean; currency: any; paymentSetup: any; - treecount: any; + treecount?: any; amount: any; meta: { title: string; description: string; image: string; url: string }; frequency: string; @@ -38,11 +38,9 @@ interface Props { } function index({ - projectDetails, donationStep, giftDetails, isGift, - resolvedUrl, isDirectDonation, hideTaxDeduction, isTaxDeductible, @@ -53,7 +51,6 @@ function index({ allowTaxDeductionChange, currency, paymentSetup, - treecount, amount, meta, frequency, @@ -62,7 +59,6 @@ function index({ callbackMethod, }: Props): ReactElement { const { - setprojectDetails, setdonationStep, loadselectedProjects, setgiftDetails, diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index f11e297c..f465e6ef 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -287,7 +287,7 @@ export default function QueryParamProvider({ children }: any) { const loadProfile = React.useCallback(async () => { const token = await getAccessTokenSilently(); try { - const profile: any = await apiRequest({ + const profile = await apiRequest({ url: "/app/profile", token: token, setshowErrorCard, From 7777ebaf8db2e7006948a087a8bd64394cedb7bd Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 21 Jun 2022 14:03:59 +0530 Subject: [PATCH 17/41] make planetCash in to case insensitive --- src/Layout/QueryParamContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index f465e6ef..a8e0c34e 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -309,7 +309,7 @@ export default function QueryParamProvider({ children }: any) { const regex = /^pcash_/; if (regex.test(router.query.to)) { router.push("/"); - } else if (router.query.to === "planetCash") { + } else if (router.query.to?.toString().toLowerCase() === "planetcash") { if (profile && profile?.planetCash?.account) { loadPaymentSetup({ projectGUID: profile?.planetCash?.account, From 0c38defdc30df5569082f407082de7306d1d21ce Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 21 Jun 2022 14:14:36 +0530 Subject: [PATCH 18/41] fix profile check condition --- src/Layout/QueryParamContext.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index a8e0c34e..95f791a1 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -318,10 +318,10 @@ export default function QueryParamProvider({ children }: any) { }); setdonationStep(1); } else if (!profile?.planetCash) { - if (profile?.name) { + if (profile?.displayName) { setprojectDetails({ - name: `PlanetCash - ${profile?.name}`, - ownerName: profile?.name, + name: `PlanetCash - ${profile?.displayName}`, + ownerName: profile?.displayName, ownerAvatar: profile?.image, purpose: "planet-cash", }); From e73b40566025bee489f2466593cc8b35765bc6da Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 21 Jun 2022 15:11:31 +0530 Subject: [PATCH 19/41] Static UI for Create PlanetCash Account --- public/locales/en/common.json | 6 ++++- src/Donations/Components/PaymentStatus.tsx | 3 ++- src/Donations/Micros/PlanetCashSignup.tsx | 28 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/Donations/Micros/PlanetCashSignup.tsx diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 447ad77a..5a3687a7 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -169,5 +169,9 @@ "conservationPurpose": "conservation donation", "planet-cashPurpose": "PlanetCash donation", "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program", - "planetCashDisabled": "Your PlanetCash account is not activated. Please activate PlanetCash." + "noPlanetCashAccount": "You do not have a PlanetCash account, however you can signup for one below", + "planetCashSignup": "SIGNUP for PLANETCASH", + "planetCashTC": "By clicking Continue, I agree to the Terms and Conditions of Plant-for-the-Planet Platform, and PlanetCash.", + "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects after six months.", + "createPlanetCashAccount": "Create PlanetCash Account" } diff --git a/src/Donations/Components/PaymentStatus.tsx b/src/Donations/Components/PaymentStatus.tsx index eab0f0ec..25a5e1b7 100644 --- a/src/Donations/Components/PaymentStatus.tsx +++ b/src/Donations/Components/PaymentStatus.tsx @@ -14,6 +14,7 @@ import SuccessfulDonationJane from "../Micros/PaymentStatus/Tenants/SuccessfulDo import TransferDetails from "../Micros/PaymentStatus/TransferDetails"; import CircularProgress from "@material-ui/core/CircularProgress"; import styles from "./PaymentStatus.module.scss"; +import PlanetCashSignup from "../Micros/PlanetCashSignup"; function ThankYou() { const { t, i18n, ready } = useTranslation(["common", "country", "donate"]); @@ -152,7 +153,7 @@ function ThankYou() { /> ) ) : projectDetails?.purpose === "planet-cash" ? ( -
{t("common:planetCashDisabled")}
+ ) : (
diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx new file mode 100644 index 00000000..244ccf8e --- /dev/null +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { useTranslation } from "next-i18next"; + +const PlanetCashSignup = () => { + const { t } = useTranslation(["common"]); + return ( +
+
+

{t("planetCashSignup")}

+

{t("noPlanetCashAccount")}

+

{t("planetCashTC")}

+

{t("planetCashIUnderstand")}

+
+ +
+ ); +}; + +export default PlanetCashSignup; From 348ab852783f71bdfb33992d5ec7411e6b0d8374 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 21 Jun 2022 20:37:07 +0530 Subject: [PATCH 20/41] Add Select country dropdown in planetCash create account --- src/Common/InputTypes/AutoCompleteCountry.tsx | 611 ++++++++++-------- src/Donations/Micros/PlanetCashSignup.tsx | 15 +- 2 files changed, 341 insertions(+), 285 deletions(-) diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index dc996c03..66b19264 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -1,34 +1,40 @@ /* eslint-disable no-use-before-define */ -import { makeStyles } from '@material-ui/core/styles'; -import Autocomplete from '@material-ui/lab/Autocomplete'; -import React from 'react'; -import MaterialTextField from './MaterialTextField'; +import { makeStyles } from "@material-ui/core/styles"; +import Autocomplete from "@material-ui/lab/Autocomplete"; +import React from "react"; +import MaterialTextField from "./MaterialTextField"; import { useTranslation } from "next-i18next"; -import themeProperties from './../../../styles/themeProperties'; -import { ThemeContext } from '../../../styles/themeContext'; +import themeProperties from "./../../../styles/themeProperties"; +import { ThemeContext } from "../../../styles/themeContext"; // ISO 3166-1 alpha-2 // ⚠️ No support for IE 11 function countryToFlag(isoCode: string) { - return typeof String.fromCodePoint !== 'undefined' + return typeof String.fromCodePoint !== "undefined" ? isoCode - .toUpperCase() - .replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397)) + .toUpperCase() + .replace(/./g, (char) => + String.fromCodePoint(char.charCodeAt(0) + 127397) + ) : isoCode; } export default function CountrySelect(props: { label: React.ReactNode; - inputRef: ((instance: any) => void) | React.RefObject | null | undefined; + allowedCountries?: string[]; + inputRef?: + | ((instance: any) => void) + | React.RefObject + | null + | undefined; name: string | undefined; defaultValue: String | undefined; - onChange: - | (( + onChange: ( event: React.ChangeEvent - ) => void); + ) => void; }) { - const { t, ready } = useTranslation('country'); - const {theme} = React.useContext(ThemeContext) + const { t, ready } = useTranslation("country"); + const { theme } = React.useContext(ThemeContext); const useStylesAutoComplete = makeStyles({ paper: { color: @@ -55,8 +61,8 @@ export default function CountrySelect(props: { ? themeProperties.light.backgroundColorDark : themeProperties.dark.backgroundColorDark, }, - fontSize: '14px', - '& > span': { + fontSize: "14px", + "& > span": { marginRight: 10, fontSize: 18, }, @@ -66,7 +72,7 @@ export default function CountrySelect(props: { const classes = useStylesAutoComplete(); // This value is in country code - eg. DE, IN, US - const { defaultValue, onChange } = props; + const { defaultValue, onChange, allowedCountries } = props; // This value is an object with keys - code, label and phone // This has to be passed to the component as default value @@ -75,7 +81,9 @@ export default function CountrySelect(props: { // use default country passed to create default object & set contact details React.useEffect(() => { // create default object - const defaultCountry = countries.filter((data) => data.code === defaultValue); + const defaultCountry = countries.filter( + (data) => data.code === defaultValue + ); if (defaultCountry && defaultCountry.length > 0) { // set initial value setValue(defaultCountry[0]); @@ -93,22 +101,39 @@ export default function CountrySelect(props: { if (ready) { countries.sort((a, b) => { - const nameA = t(`country:${a.code.toLowerCase()}`); - const nameB = t(`country:${b.code.toLowerCase()}`); - if (nameA > nameB) { - return 1; - } if (nameA < nameB) { - return -1; + const nameA = t(`country:${a.code.toLowerCase()}`); + const nameB = t(`country:${b.code.toLowerCase()}`); + if (nameA > nameB) { + return 1; + } + if (nameA < nameB) { + return -1; + } + return 0; + }); + } + + const getCountries = (): CountryType[] => { + if (allowedCountries) { + const allowedCountriesResult: CountryType[] = []; + countries.forEach((country) => { + for (let allowedCountry of allowedCountries) { + if (country.code === allowedCountry) { + allowedCountriesResult.push(country); + } } - return 0; }); - } + return allowedCountriesResult; + } else { + return countries; + } + }; return value && ready ? ( ( <> {countryToFlag(option.code)} - {(t(`country:${option.code.toLowerCase()}`))} + {t(`country:${option.code.toLowerCase()}`)} )} onChange={(event: any, newValue: CountryType | null) => { @@ -135,9 +160,9 @@ export default function CountrySelect(props: { variant="outlined" inputProps={{ ...params.inputProps, - autoComplete: 'new-password', // disable autocomplete and autofill + autoComplete: "new-password", // disable autocomplete and autofill }} - name={'countrydropdown'} + name={"countrydropdown"} data-test-id="test-country" /> )} @@ -154,272 +179,290 @@ interface CountryType { // From https://bitbucket.org/atlassian/atlaskit-mk-2/raw/4ad0e56649c3e6c973e226b7efaeb28cb240ccb0/packages/core/select/src/data/countries.js const countries = [ - { code: 'AD', label: 'Andorra', phone: '376' }, - { code: 'AE', label: 'United Arab Emirates', phone: '971' }, - { code: 'AF', label: 'Afghanistan', phone: '93' }, - { code: 'AG', label: 'Antigua and Barbuda', phone: '1-268' }, - { code: 'AI', label: 'Anguilla', phone: '1-264' }, - { code: 'AL', label: 'Albania', phone: '355' }, - { code: 'AM', label: 'Armenia', phone: '374' }, - { code: 'AO', label: 'Angola', phone: '244' }, - { code: 'AQ', label: 'Antarctica', phone: '672' }, - { code: 'AR', label: 'Argentina', phone: '54' }, - { code: 'AS', label: 'American Samoa', phone: '1-684' }, - { code: 'AT', label: 'Austria', phone: '43' }, + { code: "AD", label: "Andorra", phone: "376" }, + { code: "AE", label: "United Arab Emirates", phone: "971" }, + { code: "AF", label: "Afghanistan", phone: "93" }, + { code: "AG", label: "Antigua and Barbuda", phone: "1-268" }, + { code: "AI", label: "Anguilla", phone: "1-264" }, + { code: "AL", label: "Albania", phone: "355" }, + { code: "AM", label: "Armenia", phone: "374" }, + { code: "AO", label: "Angola", phone: "244" }, + { code: "AQ", label: "Antarctica", phone: "672" }, + { code: "AR", label: "Argentina", phone: "54" }, + { code: "AS", label: "American Samoa", phone: "1-684" }, + { code: "AT", label: "Austria", phone: "43" }, { - code: 'AU', label: 'Australia', phone: '61', suggested: true, + code: "AU", + label: "Australia", + phone: "61", + suggested: true, }, - { code: 'AW', label: 'Aruba', phone: '297' }, - { code: 'AX', label: 'Alland Islands', phone: '358' }, - { code: 'AZ', label: 'Azerbaijan', phone: '994' }, - { code: 'BA', label: 'Bosnia and Herzegovina', phone: '387' }, - { code: 'BB', label: 'Barbados', phone: '1-246' }, - { code: 'BD', label: 'Bangladesh', phone: '880' }, - { code: 'BE', label: 'Belgium', phone: '32' }, - { code: 'BF', label: 'Burkina Faso', phone: '226' }, - { code: 'BG', label: 'Bulgaria', phone: '359' }, - { code: 'BH', label: 'Bahrain', phone: '973' }, - { code: 'BI', label: 'Burundi', phone: '257' }, - { code: 'BJ', label: 'Benin', phone: '229' }, - { code: 'BL', label: 'Saint Barthelemy', phone: '590' }, - { code: 'BM', label: 'Bermuda', phone: '1-441' }, - { code: 'BN', label: 'Brunei Darussalam', phone: '673' }, - { code: 'BO', label: 'Bolivia', phone: '591' }, - { code: 'BR', label: 'Brazil', phone: '55' }, - { code: 'BS', label: 'Bahamas', phone: '1-242' }, - { code: 'BT', label: 'Bhutan', phone: '975' }, - { code: 'BV', label: 'Bouvet Island', phone: '47' }, - { code: 'BW', label: 'Botswana', phone: '267' }, - { code: 'BY', label: 'Belarus', phone: '375' }, - { code: 'BZ', label: 'Belize', phone: '501' }, + { code: "AW", label: "Aruba", phone: "297" }, + { code: "AX", label: "Alland Islands", phone: "358" }, + { code: "AZ", label: "Azerbaijan", phone: "994" }, + { code: "BA", label: "Bosnia and Herzegovina", phone: "387" }, + { code: "BB", label: "Barbados", phone: "1-246" }, + { code: "BD", label: "Bangladesh", phone: "880" }, + { code: "BE", label: "Belgium", phone: "32" }, + { code: "BF", label: "Burkina Faso", phone: "226" }, + { code: "BG", label: "Bulgaria", phone: "359" }, + { code: "BH", label: "Bahrain", phone: "973" }, + { code: "BI", label: "Burundi", phone: "257" }, + { code: "BJ", label: "Benin", phone: "229" }, + { code: "BL", label: "Saint Barthelemy", phone: "590" }, + { code: "BM", label: "Bermuda", phone: "1-441" }, + { code: "BN", label: "Brunei Darussalam", phone: "673" }, + { code: "BO", label: "Bolivia", phone: "591" }, + { code: "BR", label: "Brazil", phone: "55" }, + { code: "BS", label: "Bahamas", phone: "1-242" }, + { code: "BT", label: "Bhutan", phone: "975" }, + { code: "BV", label: "Bouvet Island", phone: "47" }, + { code: "BW", label: "Botswana", phone: "267" }, + { code: "BY", label: "Belarus", phone: "375" }, + { code: "BZ", label: "Belize", phone: "501" }, { - code: 'CA', label: 'Canada', phone: '1', suggested: true, + code: "CA", + label: "Canada", + phone: "1", + suggested: true, }, - { code: 'CC', label: 'Cocos (Keeling) Islands', phone: '61' }, - { code: 'CD', label: 'Congo, Democratic Republic of the', phone: '243' }, - { code: 'CF', label: 'Central African Republic', phone: '236' }, - { code: 'CG', label: 'Congo, Republic of the', phone: '242' }, - { code: 'CH', label: 'Switzerland', phone: '41' }, - { code: 'CI', label: "Cote d'Ivoire", phone: '225' }, - { code: 'CK', label: 'Cook Islands', phone: '682' }, - { code: 'CL', label: 'Chile', phone: '56' }, - { code: 'CM', label: 'Cameroon', phone: '237' }, - { code: 'CN', label: 'China', phone: '86' }, - { code: 'CO', label: 'Colombia', phone: '57' }, - { code: 'CR', label: 'Costa Rica', phone: '506' }, - { code: 'CU', label: 'Cuba', phone: '53' }, - { code: 'CV', label: 'Cape Verde', phone: '238' }, - { code: 'CW', label: 'Curacao', phone: '599' }, - { code: 'CX', label: 'Christmas Island', phone: '61' }, - { code: 'CY', label: 'Cyprus', phone: '357' }, - { code: 'CZ', label: 'Czech Republic', phone: '420' }, + { code: "CC", label: "Cocos (Keeling) Islands", phone: "61" }, + { code: "CD", label: "Congo, Democratic Republic of the", phone: "243" }, + { code: "CF", label: "Central African Republic", phone: "236" }, + { code: "CG", label: "Congo, Republic of the", phone: "242" }, + { code: "CH", label: "Switzerland", phone: "41" }, + { code: "CI", label: "Cote d'Ivoire", phone: "225" }, + { code: "CK", label: "Cook Islands", phone: "682" }, + { code: "CL", label: "Chile", phone: "56" }, + { code: "CM", label: "Cameroon", phone: "237" }, + { code: "CN", label: "China", phone: "86" }, + { code: "CO", label: "Colombia", phone: "57" }, + { code: "CR", label: "Costa Rica", phone: "506" }, + { code: "CU", label: "Cuba", phone: "53" }, + { code: "CV", label: "Cape Verde", phone: "238" }, + { code: "CW", label: "Curacao", phone: "599" }, + { code: "CX", label: "Christmas Island", phone: "61" }, + { code: "CY", label: "Cyprus", phone: "357" }, + { code: "CZ", label: "Czech Republic", phone: "420" }, { - code: 'DE', label: 'Germany', phone: '49', suggested: true, + code: "DE", + label: "Germany", + phone: "49", + suggested: true, }, - { code: 'DJ', label: 'Djibouti', phone: '253' }, - { code: 'DK', label: 'Denmark', phone: '45' }, - { code: 'DM', label: 'Dominica', phone: '1-767' }, - { code: 'DO', label: 'Dominican Republic', phone: '1-809' }, - { code: 'DZ', label: 'Algeria', phone: '213' }, - { code: 'EC', label: 'Ecuador', phone: '593' }, - { code: 'EE', label: 'Estonia', phone: '372' }, - { code: 'EG', label: 'Egypt', phone: '20' }, - { code: 'EH', label: 'Western Sahara', phone: '212' }, - { code: 'ER', label: 'Eritrea', phone: '291' }, - { code: 'ES', label: 'Spain', phone: '34' }, - { code: 'ET', label: 'Ethiopia', phone: '251' }, - { code: 'FI', label: 'Finland', phone: '358' }, - { code: 'FJ', label: 'Fiji', phone: '679' }, - { code: 'FK', label: 'Falkland Islands (Malvinas)', phone: '500' }, - { code: 'FM', label: 'Micronesia, Federated States of', phone: '691' }, - { code: 'FO', label: 'Faroe Islands', phone: '298' }, + { code: "DJ", label: "Djibouti", phone: "253" }, + { code: "DK", label: "Denmark", phone: "45" }, + { code: "DM", label: "Dominica", phone: "1-767" }, + { code: "DO", label: "Dominican Republic", phone: "1-809" }, + { code: "DZ", label: "Algeria", phone: "213" }, + { code: "EC", label: "Ecuador", phone: "593" }, + { code: "EE", label: "Estonia", phone: "372" }, + { code: "EG", label: "Egypt", phone: "20" }, + { code: "EH", label: "Western Sahara", phone: "212" }, + { code: "ER", label: "Eritrea", phone: "291" }, + { code: "ES", label: "Spain", phone: "34" }, + { code: "ET", label: "Ethiopia", phone: "251" }, + { code: "FI", label: "Finland", phone: "358" }, + { code: "FJ", label: "Fiji", phone: "679" }, + { code: "FK", label: "Falkland Islands (Malvinas)", phone: "500" }, + { code: "FM", label: "Micronesia, Federated States of", phone: "691" }, + { code: "FO", label: "Faroe Islands", phone: "298" }, { - code: 'FR', label: 'France', phone: '33', suggested: true, + code: "FR", + label: "France", + phone: "33", + suggested: true, }, - { code: 'GA', label: 'Gabon', phone: '241' }, - { code: 'GB', label: 'United Kingdom', phone: '44' }, - { code: 'GD', label: 'Grenada', phone: '1-473' }, - { code: 'GE', label: 'Georgia', phone: '995' }, - { code: 'GF', label: 'French Guiana', phone: '594' }, - { code: 'GG', label: 'Guernsey', phone: '44' }, - { code: 'GH', label: 'Ghana', phone: '233' }, - { code: 'GI', label: 'Gibraltar', phone: '350' }, - { code: 'GL', label: 'Greenland', phone: '299' }, - { code: 'GM', label: 'Gambia', phone: '220' }, - { code: 'GN', label: 'Guinea', phone: '224' }, - { code: 'GP', label: 'Guadeloupe', phone: '590' }, - { code: 'GQ', label: 'Equatorial Guinea', phone: '240' }, - { code: 'GR', label: 'Greece', phone: '30' }, + { code: "GA", label: "Gabon", phone: "241" }, + { code: "GB", label: "United Kingdom", phone: "44" }, + { code: "GD", label: "Grenada", phone: "1-473" }, + { code: "GE", label: "Georgia", phone: "995" }, + { code: "GF", label: "French Guiana", phone: "594" }, + { code: "GG", label: "Guernsey", phone: "44" }, + { code: "GH", label: "Ghana", phone: "233" }, + { code: "GI", label: "Gibraltar", phone: "350" }, + { code: "GL", label: "Greenland", phone: "299" }, + { code: "GM", label: "Gambia", phone: "220" }, + { code: "GN", label: "Guinea", phone: "224" }, + { code: "GP", label: "Guadeloupe", phone: "590" }, + { code: "GQ", label: "Equatorial Guinea", phone: "240" }, + { code: "GR", label: "Greece", phone: "30" }, { - code: 'GS', - label: 'South Georgia and the South Sandwich Islands', - phone: '500', + code: "GS", + label: "South Georgia and the South Sandwich Islands", + phone: "500", }, - { code: 'GT', label: 'Guatemala', phone: '502' }, - { code: 'GU', label: 'Guam', phone: '1-671' }, - { code: 'GW', label: 'Guinea-Bissau', phone: '245' }, - { code: 'GY', label: 'Guyana', phone: '592' }, - { code: 'HK', label: 'Hong Kong', phone: '852' }, - { code: 'HM', label: 'Heard Island and McDonald Islands', phone: '672' }, - { code: 'HN', label: 'Honduras', phone: '504' }, - { code: 'HR', label: 'Croatia', phone: '385' }, - { code: 'HT', label: 'Haiti', phone: '509' }, - { code: 'HU', label: 'Hungary', phone: '36' }, - { code: 'ID', label: 'Indonesia', phone: '62' }, - { code: 'IE', label: 'Ireland', phone: '353' }, - { code: 'IL', label: 'Israel', phone: '972' }, - { code: 'IM', label: 'Isle of Man', phone: '44' }, - { code: 'IN', label: 'India', phone: '91' }, - { code: 'IO', label: 'British Indian Ocean Territory', phone: '246' }, - { code: 'IQ', label: 'Iraq', phone: '964' }, - { code: 'IR', label: 'Iran, Islamic Republic of', phone: '98' }, - { code: 'IS', label: 'Iceland', phone: '354' }, - { code: 'IT', label: 'Italy', phone: '39' }, - { code: 'JE', label: 'Jersey', phone: '44' }, - { code: 'JM', label: 'Jamaica', phone: '1-876' }, - { code: 'JO', label: 'Jordan', phone: '962' }, + { code: "GT", label: "Guatemala", phone: "502" }, + { code: "GU", label: "Guam", phone: "1-671" }, + { code: "GW", label: "Guinea-Bissau", phone: "245" }, + { code: "GY", label: "Guyana", phone: "592" }, + { code: "HK", label: "Hong Kong", phone: "852" }, + { code: "HM", label: "Heard Island and McDonald Islands", phone: "672" }, + { code: "HN", label: "Honduras", phone: "504" }, + { code: "HR", label: "Croatia", phone: "385" }, + { code: "HT", label: "Haiti", phone: "509" }, + { code: "HU", label: "Hungary", phone: "36" }, + { code: "ID", label: "Indonesia", phone: "62" }, + { code: "IE", label: "Ireland", phone: "353" }, + { code: "IL", label: "Israel", phone: "972" }, + { code: "IM", label: "Isle of Man", phone: "44" }, + { code: "IN", label: "India", phone: "91" }, + { code: "IO", label: "British Indian Ocean Territory", phone: "246" }, + { code: "IQ", label: "Iraq", phone: "964" }, + { code: "IR", label: "Iran, Islamic Republic of", phone: "98" }, + { code: "IS", label: "Iceland", phone: "354" }, + { code: "IT", label: "Italy", phone: "39" }, + { code: "JE", label: "Jersey", phone: "44" }, + { code: "JM", label: "Jamaica", phone: "1-876" }, + { code: "JO", label: "Jordan", phone: "962" }, { - code: 'JP', label: 'Japan', phone: '81', suggested: true, + code: "JP", + label: "Japan", + phone: "81", + suggested: true, }, - { code: 'KE', label: 'Kenya', phone: '254' }, - { code: 'KG', label: 'Kyrgyzstan', phone: '996' }, - { code: 'KH', label: 'Cambodia', phone: '855' }, - { code: 'KI', label: 'Kiribati', phone: '686' }, - { code: 'KM', label: 'Comoros', phone: '269' }, - { code: 'KN', label: 'Saint Kitts and Nevis', phone: '1-869' }, - { code: 'KP', label: "Korea, Democratic People's Republic of", phone: '850' }, - { code: 'KR', label: 'Korea, Republic of', phone: '82' }, - { code: 'KW', label: 'Kuwait', phone: '965' }, - { code: 'KY', label: 'Cayman Islands', phone: '1-345' }, - { code: 'KZ', label: 'Kazakhstan', phone: '7' }, - { code: 'LA', label: "Lao People's Democratic Republic", phone: '856' }, - { code: 'LB', label: 'Lebanon', phone: '961' }, - { code: 'LC', label: 'Saint Lucia', phone: '1-758' }, - { code: 'LI', label: 'Liechtenstein', phone: '423' }, - { code: 'LK', label: 'Sri Lanka', phone: '94' }, - { code: 'LR', label: 'Liberia', phone: '231' }, - { code: 'LS', label: 'Lesotho', phone: '266' }, - { code: 'LT', label: 'Lithuania', phone: '370' }, - { code: 'LU', label: 'Luxembourg', phone: '352' }, - { code: 'LV', label: 'Latvia', phone: '371' }, - { code: 'LY', label: 'Libya', phone: '218' }, - { code: 'MA', label: 'Morocco', phone: '212' }, - { code: 'MC', label: 'Monaco', phone: '377' }, - { code: 'MD', label: 'Moldova, Republic of', phone: '373' }, - { code: 'ME', label: 'Montenegro', phone: '382' }, - { code: 'MF', label: 'Saint Martin (French part)', phone: '590' }, - { code: 'MG', label: 'Madagascar', phone: '261' }, - { code: 'MH', label: 'Marshall Islands', phone: '692' }, + { code: "KE", label: "Kenya", phone: "254" }, + { code: "KG", label: "Kyrgyzstan", phone: "996" }, + { code: "KH", label: "Cambodia", phone: "855" }, + { code: "KI", label: "Kiribati", phone: "686" }, + { code: "KM", label: "Comoros", phone: "269" }, + { code: "KN", label: "Saint Kitts and Nevis", phone: "1-869" }, + { code: "KP", label: "Korea, Democratic People's Republic of", phone: "850" }, + { code: "KR", label: "Korea, Republic of", phone: "82" }, + { code: "KW", label: "Kuwait", phone: "965" }, + { code: "KY", label: "Cayman Islands", phone: "1-345" }, + { code: "KZ", label: "Kazakhstan", phone: "7" }, + { code: "LA", label: "Lao People's Democratic Republic", phone: "856" }, + { code: "LB", label: "Lebanon", phone: "961" }, + { code: "LC", label: "Saint Lucia", phone: "1-758" }, + { code: "LI", label: "Liechtenstein", phone: "423" }, + { code: "LK", label: "Sri Lanka", phone: "94" }, + { code: "LR", label: "Liberia", phone: "231" }, + { code: "LS", label: "Lesotho", phone: "266" }, + { code: "LT", label: "Lithuania", phone: "370" }, + { code: "LU", label: "Luxembourg", phone: "352" }, + { code: "LV", label: "Latvia", phone: "371" }, + { code: "LY", label: "Libya", phone: "218" }, + { code: "MA", label: "Morocco", phone: "212" }, + { code: "MC", label: "Monaco", phone: "377" }, + { code: "MD", label: "Moldova, Republic of", phone: "373" }, + { code: "ME", label: "Montenegro", phone: "382" }, + { code: "MF", label: "Saint Martin (French part)", phone: "590" }, + { code: "MG", label: "Madagascar", phone: "261" }, + { code: "MH", label: "Marshall Islands", phone: "692" }, { - code: 'MK', - label: 'Macedonia, the Former Yugoslav Republic of', - phone: '389', + code: "MK", + label: "Macedonia, the Former Yugoslav Republic of", + phone: "389", }, - { code: 'ML', label: 'Mali', phone: '223' }, - { code: 'MM', label: 'Myanmar', phone: '95' }, - { code: 'MN', label: 'Mongolia', phone: '976' }, - { code: 'MO', label: 'Macao', phone: '853' }, - { code: 'MP', label: 'Northern Mariana Islands', phone: '1-670' }, - { code: 'MQ', label: 'Martinique', phone: '596' }, - { code: 'MR', label: 'Mauritania', phone: '222' }, - { code: 'MS', label: 'Montserrat', phone: '1-664' }, - { code: 'MT', label: 'Malta', phone: '356' }, - { code: 'MU', label: 'Mauritius', phone: '230' }, - { code: 'MV', label: 'Maldives', phone: '960' }, - { code: 'MW', label: 'Malawi', phone: '265' }, - { code: 'MX', label: 'Mexico', phone: '52' }, - { code: 'MY', label: 'Malaysia', phone: '60' }, - { code: 'MZ', label: 'Mozambique', phone: '258' }, - { code: 'NA', label: 'Namibia', phone: '264' }, - { code: 'NC', label: 'New Caledonia', phone: '687' }, - { code: 'NE', label: 'Niger', phone: '227' }, - { code: 'NF', label: 'Norfolk Island', phone: '672' }, - { code: 'NG', label: 'Nigeria', phone: '234' }, - { code: 'NI', label: 'Nicaragua', phone: '505' }, - { code: 'NL', label: 'Netherlands', phone: '31' }, - { code: 'NO', label: 'Norway', phone: '47' }, - { code: 'NP', label: 'Nepal', phone: '977' }, - { code: 'NR', label: 'Nauru', phone: '674' }, - { code: 'NU', label: 'Niue', phone: '683' }, - { code: 'NZ', label: 'New Zealand', phone: '64' }, - { code: 'OM', label: 'Oman', phone: '968' }, - { code: 'PA', label: 'Panama', phone: '507' }, - { code: 'PE', label: 'Peru', phone: '51' }, - { code: 'PF', label: 'French Polynesia', phone: '689' }, - { code: 'PG', label: 'Papua New Guinea', phone: '675' }, - { code: 'PH', label: 'Philippines', phone: '63' }, - { code: 'PK', label: 'Pakistan', phone: '92' }, - { code: 'PL', label: 'Poland', phone: '48' }, - { code: 'PM', label: 'Saint Pierre and Miquelon', phone: '508' }, - { code: 'PN', label: 'Pitcairn', phone: '870' }, - { code: 'PR', label: 'Puerto Rico', phone: '1' }, - { code: 'PS', label: 'Palestine, State of', phone: '970' }, - { code: 'PT', label: 'Portugal', phone: '351' }, - { code: 'PW', label: 'Palau', phone: '680' }, - { code: 'PY', label: 'Paraguay', phone: '595' }, - { code: 'QA', label: 'Qatar', phone: '974' }, - { code: 'RE', label: 'Reunion', phone: '262' }, - { code: 'RO', label: 'Romania', phone: '40' }, - { code: 'RS', label: 'Serbia', phone: '381' }, - { code: 'RU', label: 'Russian Federation', phone: '7' }, - { code: 'RW', label: 'Rwanda', phone: '250' }, - { code: 'SA', label: 'Saudi Arabia', phone: '966' }, - { code: 'SB', label: 'Solomon Islands', phone: '677' }, - { code: 'SC', label: 'Seychelles', phone: '248' }, - { code: 'SD', label: 'Sudan', phone: '249' }, - { code: 'SE', label: 'Sweden', phone: '46' }, - { code: 'SG', label: 'Singapore', phone: '65' }, - { code: 'SH', label: 'Saint Helena', phone: '290' }, - { code: 'SI', label: 'Slovenia', phone: '386' }, - { code: 'SJ', label: 'Svalbard and Jan Mayen', phone: '47' }, - { code: 'SK', label: 'Slovakia', phone: '421' }, - { code: 'SL', label: 'Sierra Leone', phone: '232' }, - { code: 'SM', label: 'San Marino', phone: '378' }, - { code: 'SN', label: 'Senegal', phone: '221' }, - { code: 'SO', label: 'Somalia', phone: '252' }, - { code: 'SR', label: 'Suriname', phone: '597' }, - { code: 'SS', label: 'South Sudan', phone: '211' }, - { code: 'ST', label: 'Sao Tome and Principe', phone: '239' }, - { code: 'SV', label: 'El Salvador', phone: '503' }, - { code: 'SX', label: 'Sint Maarten (Dutch part)', phone: '1-721' }, - { code: 'SY', label: 'Syrian Arab Republic', phone: '963' }, - { code: 'SZ', label: 'Swaziland', phone: '268' }, - { code: 'TC', label: 'Turks and Caicos Islands', phone: '1-649' }, - { code: 'TD', label: 'Chad', phone: '235' }, - { code: 'TF', label: 'French Southern Territories', phone: '262' }, - { code: 'TG', label: 'Togo', phone: '228' }, - { code: 'TH', label: 'Thailand', phone: '66' }, - { code: 'TJ', label: 'Tajikistan', phone: '992' }, - { code: 'TK', label: 'Tokelau', phone: '690' }, - { code: 'TL', label: 'Timor-Leste', phone: '670' }, - { code: 'TM', label: 'Turkmenistan', phone: '993' }, - { code: 'TN', label: 'Tunisia', phone: '216' }, - { code: 'TO', label: 'Tonga', phone: '676' }, - { code: 'TR', label: 'Turkey', phone: '90' }, - { code: 'TT', label: 'Trinidad and Tobago', phone: '1-868' }, - { code: 'TV', label: 'Tuvalu', phone: '688' }, - { code: 'TW', label: 'Taiwan', phone: '886' }, - { code: 'TZ', label: 'United Republic of Tanzania', phone: '255' }, - { code: 'UA', label: 'Ukraine', phone: '380' }, - { code: 'UG', label: 'Uganda', phone: '256' }, + { code: "ML", label: "Mali", phone: "223" }, + { code: "MM", label: "Myanmar", phone: "95" }, + { code: "MN", label: "Mongolia", phone: "976" }, + { code: "MO", label: "Macao", phone: "853" }, + { code: "MP", label: "Northern Mariana Islands", phone: "1-670" }, + { code: "MQ", label: "Martinique", phone: "596" }, + { code: "MR", label: "Mauritania", phone: "222" }, + { code: "MS", label: "Montserrat", phone: "1-664" }, + { code: "MT", label: "Malta", phone: "356" }, + { code: "MU", label: "Mauritius", phone: "230" }, + { code: "MV", label: "Maldives", phone: "960" }, + { code: "MW", label: "Malawi", phone: "265" }, + { code: "MX", label: "Mexico", phone: "52" }, + { code: "MY", label: "Malaysia", phone: "60" }, + { code: "MZ", label: "Mozambique", phone: "258" }, + { code: "NA", label: "Namibia", phone: "264" }, + { code: "NC", label: "New Caledonia", phone: "687" }, + { code: "NE", label: "Niger", phone: "227" }, + { code: "NF", label: "Norfolk Island", phone: "672" }, + { code: "NG", label: "Nigeria", phone: "234" }, + { code: "NI", label: "Nicaragua", phone: "505" }, + { code: "NL", label: "Netherlands", phone: "31" }, + { code: "NO", label: "Norway", phone: "47" }, + { code: "NP", label: "Nepal", phone: "977" }, + { code: "NR", label: "Nauru", phone: "674" }, + { code: "NU", label: "Niue", phone: "683" }, + { code: "NZ", label: "New Zealand", phone: "64" }, + { code: "OM", label: "Oman", phone: "968" }, + { code: "PA", label: "Panama", phone: "507" }, + { code: "PE", label: "Peru", phone: "51" }, + { code: "PF", label: "French Polynesia", phone: "689" }, + { code: "PG", label: "Papua New Guinea", phone: "675" }, + { code: "PH", label: "Philippines", phone: "63" }, + { code: "PK", label: "Pakistan", phone: "92" }, + { code: "PL", label: "Poland", phone: "48" }, + { code: "PM", label: "Saint Pierre and Miquelon", phone: "508" }, + { code: "PN", label: "Pitcairn", phone: "870" }, + { code: "PR", label: "Puerto Rico", phone: "1" }, + { code: "PS", label: "Palestine, State of", phone: "970" }, + { code: "PT", label: "Portugal", phone: "351" }, + { code: "PW", label: "Palau", phone: "680" }, + { code: "PY", label: "Paraguay", phone: "595" }, + { code: "QA", label: "Qatar", phone: "974" }, + { code: "RE", label: "Reunion", phone: "262" }, + { code: "RO", label: "Romania", phone: "40" }, + { code: "RS", label: "Serbia", phone: "381" }, + { code: "RU", label: "Russian Federation", phone: "7" }, + { code: "RW", label: "Rwanda", phone: "250" }, + { code: "SA", label: "Saudi Arabia", phone: "966" }, + { code: "SB", label: "Solomon Islands", phone: "677" }, + { code: "SC", label: "Seychelles", phone: "248" }, + { code: "SD", label: "Sudan", phone: "249" }, + { code: "SE", label: "Sweden", phone: "46" }, + { code: "SG", label: "Singapore", phone: "65" }, + { code: "SH", label: "Saint Helena", phone: "290" }, + { code: "SI", label: "Slovenia", phone: "386" }, + { code: "SJ", label: "Svalbard and Jan Mayen", phone: "47" }, + { code: "SK", label: "Slovakia", phone: "421" }, + { code: "SL", label: "Sierra Leone", phone: "232" }, + { code: "SM", label: "San Marino", phone: "378" }, + { code: "SN", label: "Senegal", phone: "221" }, + { code: "SO", label: "Somalia", phone: "252" }, + { code: "SR", label: "Suriname", phone: "597" }, + { code: "SS", label: "South Sudan", phone: "211" }, + { code: "ST", label: "Sao Tome and Principe", phone: "239" }, + { code: "SV", label: "El Salvador", phone: "503" }, + { code: "SX", label: "Sint Maarten (Dutch part)", phone: "1-721" }, + { code: "SY", label: "Syrian Arab Republic", phone: "963" }, + { code: "SZ", label: "Swaziland", phone: "268" }, + { code: "TC", label: "Turks and Caicos Islands", phone: "1-649" }, + { code: "TD", label: "Chad", phone: "235" }, + { code: "TF", label: "French Southern Territories", phone: "262" }, + { code: "TG", label: "Togo", phone: "228" }, + { code: "TH", label: "Thailand", phone: "66" }, + { code: "TJ", label: "Tajikistan", phone: "992" }, + { code: "TK", label: "Tokelau", phone: "690" }, + { code: "TL", label: "Timor-Leste", phone: "670" }, + { code: "TM", label: "Turkmenistan", phone: "993" }, + { code: "TN", label: "Tunisia", phone: "216" }, + { code: "TO", label: "Tonga", phone: "676" }, + { code: "TR", label: "Turkey", phone: "90" }, + { code: "TT", label: "Trinidad and Tobago", phone: "1-868" }, + { code: "TV", label: "Tuvalu", phone: "688" }, + { code: "TW", label: "Taiwan", phone: "886" }, + { code: "TZ", label: "United Republic of Tanzania", phone: "255" }, + { code: "UA", label: "Ukraine", phone: "380" }, + { code: "UG", label: "Uganda", phone: "256" }, { - code: 'US', label: 'United States', phone: '1', suggested: true, + code: "US", + label: "United States", + phone: "1", + suggested: true, }, - { code: 'UY', label: 'Uruguay', phone: '598' }, - { code: 'UZ', label: 'Uzbekistan', phone: '998' }, - { code: 'VA', label: 'Holy See (Vatican City State)', phone: '379' }, - { code: 'VC', label: 'Saint Vincent and the Grenadines', phone: '1-784' }, - { code: 'VE', label: 'Venezuela', phone: '58' }, - { code: 'VG', label: 'British Virgin Islands', phone: '1-284' }, - { code: 'VI', label: 'US Virgin Islands', phone: '1-340' }, - { code: 'VN', label: 'Vietnam', phone: '84' }, - { code: 'VU', label: 'Vanuatu', phone: '678' }, - { code: 'WF', label: 'Wallis and Futuna', phone: '681' }, - { code: 'WS', label: 'Samoa', phone: '685' }, - { code: 'XK', label: 'Kosovo', phone: '383' }, - { code: 'YE', label: 'Yemen', phone: '967' }, - { code: 'YT', label: 'Mayotte', phone: '262' }, - { code: 'ZA', label: 'South Africa', phone: '27' }, - { code: 'ZM', label: 'Zambia', phone: '260' }, - { code: 'ZW', label: 'Zimbabwe', phone: '263' }, + { code: "UY", label: "Uruguay", phone: "598" }, + { code: "UZ", label: "Uzbekistan", phone: "998" }, + { code: "VA", label: "Holy See (Vatican City State)", phone: "379" }, + { code: "VC", label: "Saint Vincent and the Grenadines", phone: "1-784" }, + { code: "VE", label: "Venezuela", phone: "58" }, + { code: "VG", label: "British Virgin Islands", phone: "1-284" }, + { code: "VI", label: "US Virgin Islands", phone: "1-340" }, + { code: "VN", label: "Vietnam", phone: "84" }, + { code: "VU", label: "Vanuatu", phone: "678" }, + { code: "WF", label: "Wallis and Futuna", phone: "681" }, + { code: "WS", label: "Samoa", phone: "685" }, + { code: "XK", label: "Kosovo", phone: "383" }, + { code: "YE", label: "Yemen", phone: "967" }, + { code: "YT", label: "Mayotte", phone: "262" }, + { code: "ZA", label: "South Africa", phone: "27" }, + { code: "ZM", label: "Zambia", phone: "260" }, + { code: "ZW", label: "Zimbabwe", phone: "263" }, ]; diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index 244ccf8e..6e4cbc4a 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -1,8 +1,12 @@ -import React from "react"; +import React, { useState } from "react"; import { useTranslation } from "next-i18next"; +import CountrySelect from "src/Common/InputTypes/AutoCompleteCountry"; const PlanetCashSignup = () => { const { t } = useTranslation(["common"]); + + const [country, setCountry] = useState("DE"); + return (
{

{t("planetCashSignup")}

{t("noPlanetCashAccount")}

+
+ setCountry(e.target?.value)} + defaultValue={country} + /> +

{t("planetCashTC")}

{t("planetCashIUnderstand")}

From 0fcae57ef0819e5d3929625579d623a919f873c8 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Thu, 23 Jun 2022 21:20:54 +0530 Subject: [PATCH 21/41] Integrate PlanetCash create and activate account API --- public/locales/en/common.json | 2 + src/Common/InputTypes/AutoCompleteCountry.tsx | 4 +- src/Donations/Micros/PlanetCashSignup.tsx | 172 ++++++++++++++++-- src/Layout/QueryParamContext.tsx | 36 ++-- 4 files changed, 179 insertions(+), 35 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 5a3687a7..bb8cb6a7 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -171,6 +171,8 @@ "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program", "noPlanetCashAccount": "You do not have a PlanetCash account, however you can signup for one below", "planetCashSignup": "SIGNUP for PLANETCASH", + "activatePlanetCash": "Activate PlanetCash", + "activatePlanetCashMsg": "Your PlanetCash account for currency {{currency}} is deactivated. To use PlanetCash account for currency {{currency}} please activate your account.", "planetCashTC": "By clicking Continue, I agree to the Terms and Conditions of Plant-for-the-Planet Platform, and PlanetCash.", "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects after six months.", "createPlanetCashAccount": "Create PlanetCash Account" diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index 66b19264..9f22b3fd 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -29,9 +29,7 @@ export default function CountrySelect(props: { | undefined; name: string | undefined; defaultValue: String | undefined; - onChange: ( - event: React.ChangeEvent - ) => void; + onChange: (event: string) => void; }) { const { t, ready } = useTranslation("country"); const { theme } = React.useContext(ThemeContext); diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index 6e4cbc4a..e69ab901 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -1,39 +1,179 @@ -import React, { useState } from "react"; +import React, { useState, useEffect, useCallback, useContext } from "react"; import { useTranslation } from "next-i18next"; +import { useAuth0 } from "@auth0/auth0-react"; import CountrySelect from "src/Common/InputTypes/AutoCompleteCountry"; +import { apiRequest } from "src/Utils/api"; +import { QueryParamContext } from "src/Layout/QueryParamContext"; +import { makeStyles } from "@material-ui/core"; +import { useRouter } from "next/router"; + +interface PlanetCashAccount { + id: string; + ownerName: string; + balance: number; + debit: number; + creditLimit: number; + currency: string; + country: string; + topUpThreshold: number; + topUpAmount: number; + isActive: boolean; + fee: number; +} + +const usePlanetCashSignupStyles = makeStyles({ + rootContainer: { + height: 500, + display: "flex", + flexDirection: "column", + justifyContent: "space-between", + }, +}); const PlanetCashSignup = () => { const { t } = useTranslation(["common"]); + const { getAccessTokenSilently } = useAuth0(); + const { setshowErrorCard } = useContext(QueryParamContext); + const router = useRouter(); + const [loading, setLoading] = useState(false); const [country, setCountry] = useState("DE"); + const [planetCashAccounts, setPlanetCashAccounts] = useState< + PlanetCashAccount[] + >([]); + const [currentPlanetCashAccount, setCurrentPlanetCashAccount] = + useState(null); + + const classes = usePlanetCashSignupStyles(); + + const fetchPlanetCashAccounts = useCallback(async () => { + const token = await getAccessTokenSilently(); + try { + setLoading(true); + const options = { + url: "/app/planetCash", + token, + setshowErrorCard, + }; + const { data } = await apiRequest(options); + setPlanetCashAccounts(data); + setLoading(false); + } catch (err) { + console.error(err); + } + }, [apiRequest, getAccessTokenSilently]); + + useEffect(() => { + fetchPlanetCashAccounts(); + }, [fetchPlanetCashAccounts]); + + useEffect(() => { + const _planetCashAccount = planetCashAccounts.find( + (planetCashAccount) => + planetCashAccount.country.toLowerCase() === country.toLowerCase() + ); + + if (_planetCashAccount) { + setCurrentPlanetCashAccount(_planetCashAccount); + } else { + setCurrentPlanetCashAccount(null); + } + }, [country, planetCashAccounts]); + + const onChangeCountry = (_country: string) => { + setCountry(_country); + const _currentPlanetCashAccount = planetCashAccounts.find((account) => { + return account.country === _country; + }); + if (_currentPlanetCashAccount) { + setCurrentPlanetCashAccount(_currentPlanetCashAccount); + } else setCurrentPlanetCashAccount(null); + }; + + const handleActivatePlanetCashAccount = useCallback(async () => { + if (currentPlanetCashAccount) { + const token = await getAccessTokenSilently(); + try { + const options = { + method: "POST", + url: `/app/planetCash/${currentPlanetCashAccount.id}/activate`, + token, + setshowErrorCard, + }; + await apiRequest(options); + router.reload(); + } catch (err) { + console.error(err); + } + } + }, [currentPlanetCashAccount]); + + const handleCreatePlanetCashAccount = async () => { + const token = await getAccessTokenSilently(); + try { + const options = { + method: "POST", + url: "/app/planetCash", + token, + data: { + country, + activate: true, + }, + setshowErrorCard, + }; + await apiRequest(options); + router.reload(); + } catch (err) { + console.error(err); + } + }; return ( -
+
-

{t("planetCashSignup")}

-

{t("noPlanetCashAccount")}

+ {!loading && currentPlanetCashAccount ? ( +

{t("activatePlanetCash")}

+ ) : ( +

{t("planetCashSignup")}

+ )} + + {!loading && currentPlanetCashAccount ? ( +

+ {t("activatePlanetCashMsg", { + currency: currentPlanetCashAccount.currency, + })} +

+ ) : ( +

{t("noPlanetCashAccount")}

+ )} +
setCountry(e.target?.value)} + onChange={onChangeCountry} defaultValue={country} />

{t("planetCashTC")}

{t("planetCashIUnderstand")}

- + {!loading && currentPlanetCashAccount ? ( + + ) : ( + + )}
); }; diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 95f791a1..e28415e1 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -310,23 +310,27 @@ export default function QueryParamProvider({ children }: any) { if (regex.test(router.query.to)) { router.push("/"); } else if (router.query.to?.toString().toLowerCase() === "planetcash") { - if (profile && profile?.planetCash?.account) { - loadPaymentSetup({ - projectGUID: profile?.planetCash?.account, - paymentSetupCountry: country, - shouldSetPaymentDetails: true, - }); - setdonationStep(1); - } else if (!profile?.planetCash) { - if (profile?.displayName) { - setprojectDetails({ - name: `PlanetCash - ${profile?.displayName}`, - ownerName: profile?.displayName, - ownerAvatar: profile?.image, - purpose: "planet-cash", + if (!isLoading && !isAuthenticated) { + router.push("/"); + } else { + if (profile && profile?.planetCash?.account) { + loadPaymentSetup({ + projectGUID: profile?.planetCash?.account, + paymentSetupCountry: country, + shouldSetPaymentDetails: true, }); + setdonationStep(1); + } else if (!profile?.planetCash) { + if (profile?.displayName) { + setprojectDetails({ + name: `PlanetCash - ${profile?.displayName}`, + ownerName: profile?.displayName, + ownerAvatar: profile?.image, + purpose: "planet-cash", + }); + } + setdonationStep(4); } - setdonationStep(4); } } else if (router.query.to && country !== undefined && country !== "") { const to = String(router.query.to).replace(/\//g, ""); @@ -336,7 +340,7 @@ export default function QueryParamProvider({ children }: any) { shouldSetPaymentDetails: true, }); } - }, [router.query.to, country, profile]); + }, [router.query.to, country, profile, isLoading, isAuthenticated]); async function loadConfig() { let userLang; From 28d207ca235d5f582ef29337283022c977ede749 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Thu, 23 Jun 2022 21:37:33 +0530 Subject: [PATCH 22/41] Remove CZ from allowedCountries --- src/Donations/Micros/PlanetCashSignup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index e69ab901..dab38ec3 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -149,7 +149,7 @@ const PlanetCashSignup = () => {
Date: Thu, 23 Jun 2022 23:06:30 +0530 Subject: [PATCH 23/41] fix flashing of PlanetCash signup screen after donation bug --- src/Donations/Components/PaymentStatus.tsx | 96 +++++++++++----------- src/Layout/QueryParamContext.tsx | 2 +- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/Donations/Components/PaymentStatus.tsx b/src/Donations/Components/PaymentStatus.tsx index 25a5e1b7..1cd4b4d6 100644 --- a/src/Donations/Components/PaymentStatus.tsx +++ b/src/Donations/Components/PaymentStatus.tsx @@ -124,54 +124,56 @@ function ThankYou() { return (
-
- {!ready && !donation ? ( - - ) : ( -
- {donation && donation.paymentStatus ? ( - status === "success" || - status === "paid" || - status === "succeeded" ? ( - - ) : status === "failed" || paymentError ? ( - - ) : transferDetails ? ( - + {projectDetails?.purpose === "planet-cash-signup" ? ( + + ) : ( +
+ {!ready && !donation ? ( + + ) : ( +
+ {donation && donation.paymentStatus ? ( + status === "success" || + status === "paid" || + status === "succeeded" ? ( + + ) : status === "failed" || paymentError ? ( + + ) : transferDetails ? ( + + ) : ( + + ) ) : ( - - ) - ) : projectDetails?.purpose === "planet-cash" ? ( - - ) : ( -
- -
- )} -
- )} - - - - {t("donate:copiedToClipboard")} - - -
+
+ +
+ )} +
+ )} + + + + {t("donate:copiedToClipboard")} + + +
+ )}
); } diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index e28415e1..a45190a0 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -326,7 +326,7 @@ export default function QueryParamProvider({ children }: any) { name: `PlanetCash - ${profile?.displayName}`, ownerName: profile?.displayName, ownerAvatar: profile?.image, - purpose: "planet-cash", + purpose: "planet-cash-signup", }); } setdonationStep(4); From d716653b95b9b0827bc90c9ab86cbba0ee4a3d21 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Fri, 24 Jun 2022 12:17:52 +0530 Subject: [PATCH 24/41] Integrate updated donation API --- pages/index.tsx | 2 +- src/Donations/Components/DonationsForm.tsx | 6 +++++- src/Donations/Components/PaymentsForm.tsx | 5 ++++- src/Donations/Micros/PaymentStatus/FailedDonation.tsx | 4 ++-- src/Donations/Micros/PaymentStatus/ImageComponent.tsx | 4 ++-- src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx | 6 +++--- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index 8de2ac9c..ac3be42f 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -321,7 +321,7 @@ export async function getServerSideProps(context: any) { // This will fetch the payment options try { const requestParams = { - url: `/app/paymentOptions/${donation.data.project.id}?country=${country}`, + url: `/app/paymentOptions/${donation.data.destination.id}?country=${country}`, setshowErrorCard, tenant, locale, diff --git a/src/Donations/Components/DonationsForm.tsx b/src/Donations/Components/DonationsForm.tsx index dc1447f0..57ae246d 100644 --- a/src/Donations/Components/DonationsForm.tsx +++ b/src/Donations/Components/DonationsForm.tsx @@ -116,7 +116,11 @@ function DonationsForm() { }; let token = null; - if ((!isLoading && isAuthenticated) || (queryToken && profile.address)) { + if ( + (!isLoading && isAuthenticated) || + (queryToken && profile.address) || + projectDetails.purpose === "planet-cash" + ) { token = queryToken ? queryToken : await getAccessTokenSilently(); } diff --git a/src/Donations/Components/PaymentsForm.tsx b/src/Donations/Components/PaymentsForm.tsx index 369dade2..84cb2c32 100644 --- a/src/Donations/Components/PaymentsForm.tsx +++ b/src/Donations/Components/PaymentsForm.tsx @@ -124,7 +124,10 @@ function PaymentsForm({}: Props): ReactElement { async function getDonation() { let token = null; - if (((!isLoading && isAuthenticated) || queryToken) && profile?.address) { + if ( + (((!isLoading && isAuthenticated) || queryToken) && profile?.address) || + projectDetails.purpose === "planet-cash" + ) { token = queryToken ? queryToken : await getAccessTokenSilently(); } setisDonationLoading(true); diff --git a/src/Donations/Micros/PaymentStatus/FailedDonation.tsx b/src/Donations/Micros/PaymentStatus/FailedDonation.tsx index ca3ccb17..0adc7292 100644 --- a/src/Donations/Micros/PaymentStatus/FailedDonation.tsx +++ b/src/Donations/Micros/PaymentStatus/FailedDonation.tsx @@ -37,7 +37,7 @@ function FailedDonation({ sendToReturn, donation }: any) { async function getDonation() { setIsTaxDeductible(donation.taxDeductionCountry); - setprojectDetails(donation.project); + setprojectDetails(donation.destination); setPaymentError(""); setquantity(donation?.quantity); setContactDetails(donation.donor); @@ -71,7 +71,7 @@ function FailedDonation({ sendToReturn, donation }: any) { // TODO - Test this again after backend is updated setfrequency(donation.isRecurrent ? donation.frequency : "once"); await loadPaymentSetup({ - projectGUID: donation.project.id, + projectGUID: donation.destination.id, paymentSetupCountry: country, shouldSetPaymentDetails: true, }); diff --git a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx index b7b810e3..cc75eba3 100644 --- a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx +++ b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx @@ -59,7 +59,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { i18n.language, Number(donation.treeCount) ), - location: t("country:" + donation.project.country.toLowerCase()), + location: t("country:" + donation.destination.country.toLowerCase()), })} {projectDetails?.purpose === "conservation" && t( @@ -74,7 +74,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { donation.currency, Number(donation.amount) ), - location: t("country:" + donation.project.country.toLowerCase()), + location: t("country:" + donation.destination.country.toLowerCase()), } )} {projectDetails?.purpose === "funds" && diff --git a/src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx b/src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx index 1ca3f704..a492f7b2 100644 --- a/src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx +++ b/src/Donations/Micros/PaymentStatus/ThankyouMessage.tsx @@ -47,15 +47,15 @@ function ThankyouMessage({ : null; // EXAMPLE: Your 50 trees will be planted by AMU EcoVillage Project, Ethiopia in Ethiopia. - const donationProjectMessage = donation.project + const donationProjectMessage = donation.destination ? " " + t("common:yourTreesPlantedByOnLocation", { treeCount: getFormattedNumber( i18n.language, Number(donation.treeCount) ), - projectName: donation.project.name, - location: t("country:" + donation.project.country.toLowerCase()), + projectName: donation.destination.name, + location: t("country:" + donation.destination.country.toLowerCase()), }) : null; From aa5a7d162202c1cf66512dfcde3ff2cfe8d810a1 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Fri, 24 Jun 2022 14:33:20 +0530 Subject: [PATCH 25/41] fix eslint issue --- src/Common/InputTypes/AutoCompleteCountry.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index 9f22b3fd..e6cbb542 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -115,7 +115,7 @@ export default function CountrySelect(props: { if (allowedCountries) { const allowedCountriesResult: CountryType[] = []; countries.forEach((country) => { - for (let allowedCountry of allowedCountries) { + for (const allowedCountry of allowedCountries) { if (country.code === allowedCountry) { allowedCountriesResult.push(country); } From 5122d74c1c955546fefbf976ba3a408e757dbdce Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Fri, 24 Jun 2022 17:43:48 +0530 Subject: [PATCH 26/41] Set project details from getServerSideProps --- pages/index.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pages/index.tsx b/pages/index.tsx index a37cf81b..0e9c2590 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -115,6 +115,15 @@ function index({ setCountryCode({ setcountry, setcurrency, country }); }, []); + // If project details are present set project details + // This will be set from getServerSideProps. + + React.useEffect(() => { + if (projectDetails) { + setprojectDetails(projectDetails); + } + }, [projectDetails]); + settenant(tenant); // If gift details are present set gift if (giftDetails && isGift) { From cc9710b1bc6af31bd78d74976e84dc17c59e0199 Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Sun, 26 Jun 2022 11:39:58 +0200 Subject: [PATCH 27/41] test using some then statements --- cypress/integration/formError.spec.js | 26 ++++++++++++++--------- cypress/support/commands.js | 15 +++++++------ src/Donations/Components/ContactsForm.tsx | 5 ++++- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/cypress/integration/formError.spec.js b/cypress/integration/formError.spec.js index 3db750d8..2716bbda 100644 --- a/cypress/integration/formError.spec.js +++ b/cypress/integration/formError.spec.js @@ -83,11 +83,14 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-address"]').type("Unbekannt 1"); cy.get('[data-test-id="test-city"]').clear() cy.get('[data-test-id="test-zipCode"]').clear().type("82449") - cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0, 0) - //cy.get('[data-test-id="test-continueToPayment"]').click() - cy.get('.form-errors').should("have.text", "City is required") - cy.get('[data-test-id="test-city"]').click().type("Uffing am Staffelsee") - cy.get('body').should("not.have.text", "City is required") + cy.get('[data-test-id="test-country"]').clear().type("Germany{enter}").get('body').click(0, 0).then(() => { + cy.get('[data-test-id="test-continueDisabled"]').click().then(() => { + cy.get('.form-errors').should("have.text", "City is required") + cy.get('[data-test-id="test-city"]').click().type("Uffing am Staffelsee").then(() => { + cy.get('body').should("not.have.text", "City is required") + }) + }) + }) }) it("ZipCode error", () => { @@ -104,10 +107,13 @@ describe("Form Error Tests", () => { cy.get('[data-test-id="test-address"]').type("Unbekannt 1"); cy.get('[data-test-id="test-city"]').clear().type("Uffing am Staffelsee") cy.get('[data-test-id="test-zipCode"]').clear() - cy.get('[data-test-id="test-country"]').clear().type(`${selectedCountry}{enter}`).get('body').click(0, 0) - //cy.get('[data-test-id="test-continueToPayment"]').click() - cy.get('.form-errors').should("have.text", "ZipCode is invalid") - cy.get('[data-test-id="test-zipCode"]').click().type(new RandExp(fiteredCountry[0].postal).gen()) - cy.get('body').should("not.have.text", "ZipCode is invalid") + cy.get('[data-test-id="test-country"]').clear().type(`${selectedCountry}{enter}`).get('body').click(0, 0).then (() => { + cy.get('[data-test-id="test-continueDisabled"]').click().then(() => { + cy.get('.form-errors').should("have.text", "ZipCode is invalid") + cy.get('[data-test-id="test-zipCode"]').click().type(new RandExp(fiteredCountry[0].postal).gen()).then(() => { + cy.get('body').should("not.have.text", "ZipCode is invalid") + }) + }) + }) }) }) \ No newline at end of file diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 4650845c..e7d06592 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -232,12 +232,15 @@ Cypress.Commands.add('bankTransfer', () => { cy.wait(5000) // cy.get('.frequency-selection-option').eq(0).should("have.text", "Once").click() cy.contactForm("Peter", "Payer", "peter.payer@gmail.com", "Unbekannt 1", "Uffing am Staffelsee", "Germany{enter}", "82449") - cy.wait(15000) - cy.get('[data-test-id="bankTransfer"]').click() - cy.get('[data-test-id="bankDonateContinue"]').click() - cy.wait(10000) - cy.get('[data-test-id="test-thankYou"]').should("exist") - + cy.wait(15000).then(() => { + cy.get('[data-test-id="bankTransfer"]').click().then(() => { + cy.get('[data-test-id="bankDonateContinue"]').click().then(() => { + cy.wait(15000).then(() => { + cy.get('[data-test-id="test-thankYou"]').should("exist") + }) + }) + }) + }) }) diff --git a/src/Donations/Components/ContactsForm.tsx b/src/Donations/Components/ContactsForm.tsx index f48e56a1..9ce95df9 100644 --- a/src/Donations/Components/ContactsForm.tsx +++ b/src/Donations/Components/ContactsForm.tsx @@ -434,7 +434,10 @@ function ContactsForm({}: Props): ReactElement { errors.city || errors.zipCode || errors.country ? ( - ) : ( From 13b24d635e0b26d99eb7fbeadfe879d0a8fbf29d Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 27 Jun 2022 13:06:45 +0530 Subject: [PATCH 28/41] remove unnecessary null checks --- pages/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index ac3be42f..f7e42ee4 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -424,17 +424,17 @@ export async function getServerSideProps(context: any) { if (projectDetails) { title = `${projectDetails.name} - Donate with Plant-for-the-Planet`; - if (projectDetails?.purpose === "trees") { + if (projectDetails.purpose === "trees") { description = `Plant trees with ${projectDetails.ownerName}. Your journey to a trillion trees starts here.`; } else if ( - projectDetails?.purpose === "conservation" && + projectDetails.purpose === "conservation" && !projectDetails.description ) { description = `Conserve forests with ${projectDetails.ownerName}. Your journey to a trillion trees starts here.`; } else if ( - (projectDetails?.purpose === "bouquet" || - projectDetails?.purpose === "funds" || - projectDetails?.purpose === "conservation") && + (projectDetails.purpose === "bouquet" || + projectDetails.purpose === "funds" || + projectDetails.purpose === "conservation") && projectDetails.description ) { description = projectDetails.description; From 532827fd06cac55aaa837e06d2839517252cc76f Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 27 Jun 2022 13:08:07 +0530 Subject: [PATCH 29/41] remove unnecessary null checks --- src/Donations/Components/ContactsForm.tsx | 2 +- src/Donations/Components/DonationsForm.tsx | 18 ++++++++--------- src/Donations/Components/PaymentsForm.tsx | 6 +++--- src/Donations/Micros/TaxDeductionOption.tsx | 14 ++++++------- .../PaymentMethods/PaymentMethodTabs.tsx | 2 +- src/Donations/index.tsx | 20 +++++++++---------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Donations/Components/ContactsForm.tsx b/src/Donations/Components/ContactsForm.tsx index f48e56a1..24cc0015 100644 --- a/src/Donations/Components/ContactsForm.tsx +++ b/src/Donations/Components/ContactsForm.tsx @@ -150,7 +150,7 @@ function ContactsForm({}: Props): ReactElement { if ( projectDetails && projectDetails.taxDeductionCountries && - projectDetails?.taxDeductionCountries?.includes("ES") && + projectDetails.taxDeductionCountries?.includes("ES") && country == "ES" ) { setTaxIdentificationAvail(true); diff --git a/src/Donations/Components/DonationsForm.tsx b/src/Donations/Components/DonationsForm.tsx index 57ae246d..faf30f25 100644 --- a/src/Donations/Components/DonationsForm.tsx +++ b/src/Donations/Components/DonationsForm.tsx @@ -79,7 +79,7 @@ function DonationsForm() { if (projectDetails && profile) { if (profile!.planetCash) { - if (projectDetails?.purpose === "planet-cash") { + if (projectDetails.purpose === "planet-cash") { setcountry(profile!.planetCash.country); setcurrency(profile!.planetCash.currency); } @@ -187,7 +187,7 @@ function DonationsForm() { let paymentLabel = ""; if (paymentSetup && currency && projectDetails) { - switch (projectDetails?.purpose) { + switch (projectDetails.purpose) { case "trees": paymentLabel = t("treesInCountry", { treeCount: quantity, @@ -216,7 +216,7 @@ function DonationsForm() { default: paymentLabel = t("treesInCountry", { treeCount: quantity, - country: t(`country:${projectDetails?.country?.toLowerCase()}`), + country: t(`country:${projectDetails.country?.toLowerCase()}`), }); break; } @@ -293,20 +293,20 @@ function DonationsForm() {
- {projectDetails?.purpose !== "funds" && ( + {projectDetails.purpose !== "funds" && (

{t("donate")}

)} {/* show PlanetCashSelector only if user is signed up and have a planetCash account */} - {projectDetails?.purpose !== "funds" && - projectDetails?.purpose !== "planet-cash" && + {projectDetails.purpose !== "funds" && + projectDetails.purpose !== "planet-cash" && !(isGift && giftDetails.recipientName === "") && !(onBehalf && onBehalfDonor.firstName === "") && isSignedUp && profile!.planetCash && } {!(onBehalf && onBehalfDonor.firstName === "") && - (projectDetails?.purpose === "trees" ? ( + (projectDetails.purpose === "trees" ? (
@@ -355,8 +355,8 @@ function DonationsForm() { >
- {(projectDetails?.purpose === "trees" || - projectDetails?.purpose === "conservation") && } + {(projectDetails.purpose === "trees" || + projectDetails.purpose === "conservation") && } {/* Hide NativePay if PlanetCash is active */} diff --git a/src/Donations/Components/PaymentsForm.tsx b/src/Donations/Components/PaymentsForm.tsx index 84cb2c32..27e08511 100644 --- a/src/Donations/Components/PaymentsForm.tsx +++ b/src/Donations/Components/PaymentsForm.tsx @@ -267,7 +267,7 @@ function PaymentsForm({}: Props): ReactElement { {/* TODO - When donations are coming from context, check for haspublicprofile */} - {projectDetails && projectDetails?.purpose !== "funds" ? ( + {projectDetails && projectDetails.purpose !== "funds" ? (
{!Object.keys(contactDetails).includes("companyName") ? ( askpublishName ? ( @@ -288,7 +288,7 @@ function PaymentsForm({}: Props): ReactElement {
) : (
- {projectDetails?.purpose !== "planet-cash" && ( + {projectDetails.purpose !== "planet-cash" && ( @@ -328,7 +328,7 @@ function PaymentsForm({}: Props): ReactElement { paymentMethod: "sepa_debit", currencies: ["EUR"], authenticatedMethod: - projectDetails && projectDetails?.purpose === "funds" + projectDetails && projectDetails.purpose === "funds" ? false : true, })} diff --git a/src/Donations/Micros/TaxDeductionOption.tsx b/src/Donations/Micros/TaxDeductionOption.tsx index 6f4c7c1a..5fc7dc83 100644 --- a/src/Donations/Micros/TaxDeductionOption.tsx +++ b/src/Donations/Micros/TaxDeductionOption.tsx @@ -24,7 +24,7 @@ function TaxDeductionOption({}: Props): ReactElement { if ( projectDetails && projectDetails.taxDeductionCountries && - projectDetails?.taxDeductionCountries?.includes(country) + projectDetails.taxDeductionCountries?.includes(country) ) { setIsTaxDeductible(true); } else { @@ -38,7 +38,7 @@ function TaxDeductionOption({}: Props): ReactElement { projectDetails.taxDeductionCountries.length > 0 ? ( allowTaxDeductionChange ? (
- {projectDetails?.taxDeductionCountries?.includes(country) + {projectDetails.taxDeductionCountries?.includes(country) ? t("youWillReceiveTaxDeduction") : t("taxDeductionNotYetAvailable")}   - {projectDetails?.taxDeductionCountries?.includes(country) + {projectDetails.taxDeductionCountries?.includes(country) ? t("inTimeOfTaxReturns") : null}
) : isTaxDeductible ? (
- {projectDetails?.taxDeductionCountries?.includes(country) + {projectDetails.taxDeductionCountries?.includes(country) ? t("youWillReceiveTaxDeduction") : t("taxDeductionNotYetAvailable")}
{t(`country:${country?.toLowerCase()}`)}
{" "} - {projectDetails?.taxDeductionCountries?.includes(country) + {projectDetails.taxDeductionCountries?.includes(country) ? t("inTimeOfTaxReturns") : null}
diff --git a/src/Donations/PaymentMethods/PaymentMethodTabs.tsx b/src/Donations/PaymentMethods/PaymentMethodTabs.tsx index 89b12c24..91dacf97 100644 --- a/src/Donations/PaymentMethods/PaymentMethodTabs.tsx +++ b/src/Donations/PaymentMethods/PaymentMethodTabs.tsx @@ -75,7 +75,7 @@ export default function PaymentMethodTabs({ let paymentLabel; if (paymentSetup && currency) { - switch (projectDetails && projectDetails?.purpose) { + switch (projectDetails && projectDetails.purpose) { case "trees": paymentLabel = t("treesInCountry", { treeCount: quantity, diff --git a/src/Donations/index.tsx b/src/Donations/index.tsx index d4f3a117..39605aa5 100644 --- a/src/Donations/index.tsx +++ b/src/Donations/index.tsx @@ -166,7 +166,7 @@ function DonationInfo() { {/* */} {donationStep > 0 && projectDetails.ownerName && - (projectDetails?.purpose === "trees" ? ( + (projectDetails.purpose === "trees" ? ( ))} {(donationStep === 2 || donationStep === 3) && - (projectDetails?.purpose === "trees" || - projectDetails?.purpose === "conservation") && ( + (projectDetails.purpose === "trees" || + projectDetails.purpose === "conservation") && (
{t("donating")}{" "} @@ -217,8 +217,8 @@ function DonationInfo() { )} {(donationStep === 2 || donationStep === 3) && - (projectDetails?.purpose === "bouquet" || - projectDetails?.purpose === "funds") && ( + (projectDetails.purpose === "bouquet" || + projectDetails.purpose === "funds") && (
{t("donating")}{" "} @@ -240,7 +240,7 @@ function DonationInfo() { {donationStep > 0 ? ( <> - {projectDetails?.purpose === "trees" ? ( + {projectDetails.purpose === "trees" ? ( )} - {projectDetails?.purpose === "funds" || - projectDetails?.purpose === "bouquet" ? ( + {projectDetails.purpose === "funds" || + projectDetails.purpose === "bouquet" ? (

{projectDetails.description}

) : ( [] )} - {(projectDetails?.purpose === "trees" || - projectDetails?.purpose === "conservation") && + {(projectDetails.purpose === "trees" || + projectDetails.purpose === "conservation") && projectDetails.ownerName && (
{t("byOrganization", { From 3fe03c91a134a2feccc017993f312f67cfee645a Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 27 Jun 2022 15:50:07 +0530 Subject: [PATCH 30/41] Replace router with window --- src/Layout/QueryParamContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index a45190a0..f618f780 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -311,7 +311,7 @@ export default function QueryParamProvider({ children }: any) { router.push("/"); } else if (router.query.to?.toString().toLowerCase() === "planetcash") { if (!isLoading && !isAuthenticated) { - router.push("/"); + window.location.replace("/"); } else { if (profile && profile?.planetCash?.account) { loadPaymentSetup({ From d772773381f80d9228a189f6e8d286781413b5be Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 27 Jun 2022 16:22:06 +0530 Subject: [PATCH 31/41] redirect user to login and add null checks --- .../Micros/PaymentStatus/ImageComponent.tsx | 8 ++++---- .../Micros/PaymentStatus/SuccessfulDonation.tsx | 2 +- .../Micros/PaymentStatus/ThankyouMessage.tsx | 12 ++++++------ src/Layout/QueryParamContext.tsx | 11 +++++++++-- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx index b962e90e..f3b6dd67 100644 --- a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx +++ b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx @@ -53,7 +53,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { const ImageDonationText = () => { return (
- {projectDetails.purpose === "trees" && + {projectDetails?.purpose === "trees" && t("common:myTreesPlantedByOnLocation", { treeCount: getFormattedNumber( i18n.language, @@ -61,7 +61,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { ), location: t("country:" + donation.project.country.toLowerCase()), })} - {projectDetails.purpose === "conservation" && + {projectDetails?.purpose === "conservation" && t( `common:${ profile?.type && pluralProfileTypes.includes(profile?.type) @@ -77,13 +77,13 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { location: t("country:" + donation.project.country.toLowerCase()), } )} - {projectDetails.purpose === "funds" && + {projectDetails?.purpose === "funds" && t("common:contributedToTpo", { amount: currencyFormat(), organization: projectDetails.ownerName, })} - {projectDetails.purpose === "bouquet" && + {projectDetails?.purpose === "bouquet" && t("common:myContributionIsPartOfThat")}
); diff --git a/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx b/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx index 3c2f7cc0..1a69180e 100644 --- a/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx +++ b/src/Donations/Micros/PaymentStatus/SuccessfulDonation.tsx @@ -43,7 +43,7 @@ function SuccessfulDonation({ donation, sendToReturn }: any) { projectDetails={projectDetails} donation={donation} /> - {projectDetails.purpose !== "planet-cash" && ( + {projectDetails?.purpose !== "planet-cash" && ( <> { return (
- {projectDetails.purpose === "trees" && ( + {projectDetails?.purpose === "trees" && ( <>
{donationSuccessfulMessage} @@ -75,7 +75,7 @@ function ThankyouMessage({ )} - {projectDetails.purpose === "funds" && ( + {projectDetails?.purpose === "funds" && ( <>
{donationSuccessfulMessage} @@ -88,7 +88,7 @@ function ThankyouMessage({ )} - {projectDetails.purpose === "planet-cash" && ( + {projectDetails?.purpose === "planet-cash" && (
{donationSuccessfulMessage}
@@ -97,7 +97,7 @@ function ThankyouMessage({
)} - {projectDetails.purpose === "bouquet" && ( + {projectDetails?.purpose === "bouquet" && ( <>
{donationSuccessfulMessage} @@ -110,7 +110,7 @@ function ThankyouMessage({ )} )} - {projectDetails.purpose === "conservation" && ( + {projectDetails?.purpose === "conservation" && ( <>
{donationSuccessfulMessage} diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index f618f780..a9d81904 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -106,7 +106,12 @@ export default function QueryParamProvider({ children }: any) { const router = useRouter(); const { i18n } = useTranslation(); - const { getAccessTokenSilently, isLoading, isAuthenticated } = useAuth0(); + const { + getAccessTokenSilently, + isLoading, + isAuthenticated, + loginWithRedirect, + } = useAuth0(); const [paymentSetup, setpaymentSetup] = useState({}); @@ -311,7 +316,9 @@ export default function QueryParamProvider({ children }: any) { router.push("/"); } else if (router.query.to?.toString().toLowerCase() === "planetcash") { if (!isLoading && !isAuthenticated) { - window.location.replace("/"); + loginWithRedirect({ + redirectUri: window?.location.href, + }); } else { if (profile && profile?.planetCash?.account) { loadPaymentSetup({ From 268335cafdd4d8a80f409cf71c66a1de18153768 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 27 Jun 2022 17:35:18 +0530 Subject: [PATCH 32/41] Update signup message and add link to t&c --- public/locales/en/common.json | 6 +-- src/Donations/Micros/PlanetCashSignup.tsx | 46 +++++++++++++++++------ 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index bb8cb6a7..39318695 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -170,10 +170,10 @@ "planet-cashPurpose": "PlanetCash donation", "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program", "noPlanetCashAccount": "You do not have a PlanetCash account, however you can signup for one below", - "planetCashSignup": "SIGNUP for PLANETCASH", + "planetCashSignup": "Sign Up for PlanetCash", "activatePlanetCash": "Activate PlanetCash", "activatePlanetCashMsg": "Your PlanetCash account for currency {{currency}} is deactivated. To use PlanetCash account for currency {{currency}} please activate your account.", - "planetCashTC": "By clicking Continue, I agree to the Terms and Conditions of Plant-for-the-Planet Platform, and PlanetCash.", - "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects after six months.", + "planetCashTC": "By clicking \"Create PlanetCash Account\", I agree to the <0>Terms and Conditions of Plant-for-the-Planet Platform, and PlanetCash.", + "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects on the Platform after six months of Payment.", "createPlanetCashAccount": "Create PlanetCash Account" } diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index dab38ec3..f3786b47 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -1,11 +1,13 @@ import React, { useState, useEffect, useCallback, useContext } from "react"; -import { useTranslation } from "next-i18next"; +import { useTranslation, Trans } from "next-i18next"; import { useAuth0 } from "@auth0/auth0-react"; import CountrySelect from "src/Common/InputTypes/AutoCompleteCountry"; import { apiRequest } from "src/Utils/api"; import { QueryParamContext } from "src/Layout/QueryParamContext"; import { makeStyles } from "@material-ui/core"; import { useRouter } from "next/router"; +import themeProperties from "styles/themeProperties"; +import { ThemeContext } from "styles/themeContext"; interface PlanetCashAccount { id: string; @@ -21,19 +23,11 @@ interface PlanetCashAccount { fee: number; } -const usePlanetCashSignupStyles = makeStyles({ - rootContainer: { - height: 500, - display: "flex", - flexDirection: "column", - justifyContent: "space-between", - }, -}); - const PlanetCashSignup = () => { - const { t } = useTranslation(["common"]); + const { t, i18n } = useTranslation(["common"]); const { getAccessTokenSilently } = useAuth0(); const { setshowErrorCard } = useContext(QueryParamContext); + const { theme } = React.useContext(ThemeContext); const router = useRouter(); const [loading, setLoading] = useState(false); @@ -44,6 +38,25 @@ const PlanetCashSignup = () => { const [currentPlanetCashAccount, setCurrentPlanetCashAccount] = useState(null); + const usePlanetCashSignupStyles = makeStyles({ + rootContainer: { + height: 500, + display: "flex", + flexDirection: "column", + justifyContent: "space-between", + }, + tcLink: { + display: "inline", + color: + theme === "theme-light" + ? themeProperties.light.primaryFontColor + : themeProperties.dark.primaryFontColor, + "&:hover": { + color: themeProperties.primaryColor, + }, + }, + }); + const classes = usePlanetCashSignupStyles(); const fetchPlanetCashAccounts = useCallback(async () => { @@ -156,7 +169,16 @@ const PlanetCashSignup = () => { defaultValue={country} />
-

{t("planetCashTC")}

+
+ + + +

{t("planetCashIUnderstand")}

{!loading && currentPlanetCashAccount ? ( From f97b5285c4a8285428335be7ab3e81ce1f300d57 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 28 Jun 2022 11:56:11 +0530 Subject: [PATCH 33/41] Remove Activate PlanetCash Screen --- public/locales/en/common.json | 2 - src/Donations/Micros/PlanetCashSignup.tsx | 51 ++++++++--------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 39318695..322b24cb 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -171,8 +171,6 @@ "pfpSupportsUNEP": "Plant-for-the-Planet Supports the United Nations Environment Program", "noPlanetCashAccount": "You do not have a PlanetCash account, however you can signup for one below", "planetCashSignup": "Sign Up for PlanetCash", - "activatePlanetCash": "Activate PlanetCash", - "activatePlanetCashMsg": "Your PlanetCash account for currency {{currency}} is deactivated. To use PlanetCash account for currency {{currency}} please activate your account.", "planetCashTC": "By clicking \"Create PlanetCash Account\", I agree to the <0>Terms and Conditions of Plant-for-the-Planet Platform, and PlanetCash.", "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects on the Platform after six months of Payment.", "createPlanetCashAccount": "Create PlanetCash Account" diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index f3786b47..e307451c 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -23,6 +23,8 @@ interface PlanetCashAccount { fee: number; } +const allowedCountries = ["DE", "ES", "US"]; + const PlanetCashSignup = () => { const { t, i18n } = useTranslation(["common"]); const { getAccessTokenSilently } = useAuth0(); @@ -61,8 +63,8 @@ const PlanetCashSignup = () => { const fetchPlanetCashAccounts = useCallback(async () => { const token = await getAccessTokenSilently(); + setLoading(true); try { - setLoading(true); const options = { url: "/app/planetCash", token, @@ -70,10 +72,10 @@ const PlanetCashSignup = () => { }; const { data } = await apiRequest(options); setPlanetCashAccounts(data); - setLoading(false); } catch (err) { console.error(err); } + setLoading(false); }, [apiRequest, getAccessTokenSilently]); useEffect(() => { @@ -144,25 +146,13 @@ const PlanetCashSignup = () => { return (
- {!loading && currentPlanetCashAccount ? ( -

{t("activatePlanetCash")}

- ) : ( -

{t("planetCashSignup")}

- )} - - {!loading && currentPlanetCashAccount ? ( -

- {t("activatePlanetCashMsg", { - currency: currentPlanetCashAccount.currency, - })} -

- ) : ( -

{t("noPlanetCashAccount")}

- )} +

{t("planetCashSignup")}

+ +

{t("noPlanetCashAccount")}

{

{t("planetCashIUnderstand")}

- {!loading && currentPlanetCashAccount ? ( - - ) : ( - - )} +
); }; From 68c8c0e82ea4bf507dced665c3b26386a99b7d92 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Wed, 29 Jun 2022 15:26:44 +0530 Subject: [PATCH 34/41] Remove redundant code --- src/Donations/Micros/PlanetCashSignup.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index e307451c..c4d6f644 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -97,12 +97,6 @@ const PlanetCashSignup = () => { const onChangeCountry = (_country: string) => { setCountry(_country); - const _currentPlanetCashAccount = planetCashAccounts.find((account) => { - return account.country === _country; - }); - if (_currentPlanetCashAccount) { - setCurrentPlanetCashAccount(_currentPlanetCashAccount); - } else setCurrentPlanetCashAccount(null); }; const handleActivatePlanetCashAccount = useCallback(async () => { From 9df8d406517293a78b0838cd657a78166d4270b8 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Wed, 29 Jun 2022 15:43:24 +0530 Subject: [PATCH 35/41] change variable name --- src/Common/InputTypes/AutoCompleteCountry.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index e6cbb542..688add35 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -29,7 +29,7 @@ export default function CountrySelect(props: { | undefined; name: string | undefined; defaultValue: String | undefined; - onChange: (event: string) => void; + onChange: (value: string) => void; }) { const { t, ready } = useTranslation("country"); const { theme } = React.useContext(ThemeContext); From bb868af182a6301e50e9398b10d4f5eecf82cf70 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Thu, 30 Jun 2022 12:06:58 +0530 Subject: [PATCH 36/41] Rename onChange to onValueChange --- src/Common/InputTypes/AutoCompleteCountry.tsx | 8 ++++---- src/Donations/Components/ContactsForm.tsx | 4 ++-- src/Donations/Micros/PlanetCashSignup.tsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index 688add35..2879b9cb 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -29,7 +29,7 @@ export default function CountrySelect(props: { | undefined; name: string | undefined; defaultValue: String | undefined; - onChange: (value: string) => void; + onValueChange: (value: string) => void; }) { const { t, ready } = useTranslation("country"); const { theme } = React.useContext(ThemeContext); @@ -70,7 +70,7 @@ export default function CountrySelect(props: { const classes = useStylesAutoComplete(); // This value is in country code - eg. DE, IN, US - const { defaultValue, onChange, allowedCountries } = props; + const { defaultValue, onValueChange, allowedCountries } = props; // This value is an object with keys - code, label and phone // This has to be passed to the component as default value @@ -86,14 +86,14 @@ export default function CountrySelect(props: { // set initial value setValue(defaultCountry[0]); // set contact details - onChange(defaultCountry[0].code); + onValueChange(defaultCountry[0].code); } }, [defaultValue]); // Set contact details everytime value changes React.useEffect(() => { if (value) { - onChange(value?.code); + onValueChange(value?.code); } }, [value]); diff --git a/src/Donations/Components/ContactsForm.tsx b/src/Donations/Components/ContactsForm.tsx index f48e56a1..7fe56870 100644 --- a/src/Donations/Components/ContactsForm.tsx +++ b/src/Donations/Components/ContactsForm.tsx @@ -101,7 +101,7 @@ function ContactsForm({}: Props): ReactElement { )[0]?.postal ); - const changeCountry = (country: any) => { + const changeCountry = (country: string) => { let data = getValues(); data = { ...data, @@ -352,7 +352,7 @@ function ContactsForm({}: Props): ReactElement { inputRef={ref} label={t("country")} name="country" - onChange={changeCountry} + onValueChange={changeCountry} defaultValue={value} /> )} diff --git a/src/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx index c4d6f644..8429f5ab 100644 --- a/src/Donations/Micros/PlanetCashSignup.tsx +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -149,7 +149,7 @@ const PlanetCashSignup = () => { allowedCountries={allowedCountries} label={t("country")} name="country" - onChange={onChangeCountry} + onValueChange={onChangeCountry} defaultValue={country} />
From 4f9bddcc397d83719fa25afcf641d0d244bdac73 Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Sat, 2 Jul 2022 09:19:17 +0000 Subject: [PATCH 37/41] =?UTF-8?q?Language=20update=20from=20LingoHub=20?= =?UTF-8?q?=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Project Name: Planet Donations Project Link: https://translate.lingohub.com/plant-for-the-planet/dashboard/planet-donations User: Norbert Schuler Easy language translations with LingoHub 🚀 --- public/locales/de/common.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/locales/de/common.json b/public/locales/de/common.json index f8839c81..5aac2027 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -47,7 +47,7 @@ "expDate": "Gültigkeitsdatum (MM/JJJJ)", "donate": "Spenden", "noPaymentMethodError": "Deine Zahlung konnte nicht verarbeitet werden, bitte versuche es erneut.", - "sofortDisclaimer": "SOFORT Zahlungen dauern in der Regel 1-3 Werktage. Sobald wir den Zahlungseingang verbucht haben, vervollständigen wir die Spende und schicken wir dir eine Bestätigungs-Mail.", + "sofortDisclaimer": "SOFORT Zahlungen dauern in der Regel 1-3 Werktage. Sobald wir den Zahlungseingang verbucht haben, vervollständigen wir die Spende und schicken dir eine Bestätigungs-Mail.", "payWithSofort": "Spende mit SOFORT", "payWithGiroPay": "Spende mit GiroPay", "sepaDisclaimer": "SEPA-Bankeinzüge dauern in der Regel 1-4 Werktage. Sobald der Zahlungseingang verarbeitet wurde, vervollständigen wir die Spende und schicken wir dir eine Bestätigungs-E-Mail.", @@ -168,5 +168,6 @@ "bouquetPurpose": "Spende", "conservationPurpose": "Naturschutzspende", "planet-cashPurpose": "PlanetCash-Spende", - "pfpSupportsUNEP": "Plant-for-the-Planet unterstützt das Umweltprogramm der Vereinten Nationen" + "pfpSupportsUNEP": "Plant-for-the-Planet unterstützt das Umweltprogramm der Vereinten Nationen", + "myContributionIsPartOfThat": "Und meine Spende ist Teil davon." } \ No newline at end of file From d89dc9e3b6d58f362cbb6caef14f71a53e905fd5 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 4 Jul 2022 13:07:59 +0530 Subject: [PATCH 38/41] Fix Continue button reload issue --- src/Layout/QueryParamContext.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index a9d81904..9abbda9f 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -339,7 +339,16 @@ export default function QueryParamProvider({ children }: any) { setdonationStep(4); } } - } else if (router.query.to && country !== undefined && country !== "") { + } + }, [router.query.to, country, profile, isLoading, isAuthenticated]); + + React.useEffect(() => { + if ( + router.query.to && + country !== undefined && + country !== "" && + router.query.to?.toString().toLowerCase() !== "planetcash" + ) { const to = String(router.query.to).replace(/\//g, ""); loadPaymentSetup({ projectGUID: to, @@ -347,7 +356,7 @@ export default function QueryParamProvider({ children }: any) { shouldSetPaymentDetails: true, }); } - }, [router.query.to, country, profile, isLoading, isAuthenticated]); + }, [router.query.to, country]); async function loadConfig() { let userLang; From 623bda7e99b09aff61816e08f541cd961864bf41 Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Mon, 4 Jul 2022 13:36:51 +0530 Subject: [PATCH 39/41] Restrict loading anything with pcash_* --- src/Layout/QueryParamContext.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 9abbda9f..c475c36d 100644 --- a/src/Layout/QueryParamContext.tsx +++ b/src/Layout/QueryParamContext.tsx @@ -343,8 +343,10 @@ export default function QueryParamProvider({ children }: any) { }, [router.query.to, country, profile, isLoading, isAuthenticated]); React.useEffect(() => { + const regex = /^pcash_/; if ( router.query.to && + !regex.test(router.query.to) && country !== undefined && country !== "" && router.query.to?.toString().toLowerCase() !== "planetcash" From 4d21f2a8ffd949f6cb90e89ebb908a739cb49d8f Mon Sep 17 00:00:00 2001 From: Shreyas Chorge Date: Tue, 5 Jul 2022 19:42:50 +0530 Subject: [PATCH 40/41] Fix showing blank screen after successful donation redirect --- pages/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.tsx b/pages/index.tsx index 29147f02..4fe8beec 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -57,6 +57,7 @@ function index({ tenant, callbackUrl, callbackMethod, + projectDetails, }: Props): ReactElement { const { setdonationStep, @@ -78,7 +79,6 @@ function index({ settenant, setcallbackUrl, setCallbackMethod, - projectDetails, setprojectDetails, } = React.useContext(QueryParamContext); From 7225e5a3b8f2edf3f54626c743117f9b2010a152 Mon Sep 17 00:00:00 2001 From: Norbert Schuler Date: Thu, 7 Jul 2022 12:36:33 +0000 Subject: [PATCH 41/41] =?UTF-8?q?Language=20update=20from=20LingoHub=20?= =?UTF-8?q?=F0=9F=A4=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Project Name: Planet Donations Project Link: https://translate.lingohub.com/plant-for-the-planet/dashboard/planet-donations User: Norbert Schuler Easy language translations with LingoHub 🚀 --- public/locales/de/common.json | 5 +++++ public/locales/en/common.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/public/locales/de/common.json b/public/locales/de/common.json index 5aac2027..66fe79a7 100644 --- a/public/locales/de/common.json +++ b/public/locales/de/common.json @@ -169,5 +169,10 @@ "conservationPurpose": "Naturschutzspende", "planet-cashPurpose": "PlanetCash-Spende", "pfpSupportsUNEP": "Plant-for-the-Planet unterstützt das Umweltprogramm der Vereinten Nationen", + "noPlanetCashAccount": "Du hast noch kein PlanetCash-Konto, kannst dich aber unten für eines anmelden", + "planetCashSignup": "Anmeldung für PlanetCash", + "planetCashTC": "Indem ich auf \"PlanetCash-Konto erstellen\" klicke, erkläre ich mich mit den <0>Allgemeinen Geschäftsbedingungen der Plant-for-the-Planet-Plattform und von PlanetCash einverstanden.", + "planetCashIUnderstand": "Ich verstehe, dass PlanetCash Spenden/Zahlungen nicht zurückerstattet werden können, und dass nicht zugewiesene Zahlungen nach sechs Monaten automatisch Projekten auf der Plattform zugewiesen werden.", + "createPlanetCashAccount": "PlanetCash Konto erstellen", "myContributionIsPartOfThat": "Und meine Spende ist Teil davon." } \ No newline at end of file diff --git a/public/locales/en/common.json b/public/locales/en/common.json index e2e57ff4..ead4190b 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -175,4 +175,4 @@ "planetCashIUnderstand": "I understand that PlanetCash donation/payments are non-refundable, and unallocated payments will be auto allocated to projects on the Platform after six months of Payment.", "createPlanetCashAccount": "Create PlanetCash Account", "myContributionIsPartOfThat": "And my contribution is a part of that." -} +} \ No newline at end of file