diff --git a/pages/index.tsx b/pages/index.tsx index 8ea6fd4b..29147f02 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, @@ -82,6 +78,8 @@ function index({ settenant, setcallbackUrl, setCallbackMethod, + projectDetails, + setprojectDetails, } = React.useContext(QueryParamContext); const router = useRouter(); @@ -252,31 +250,33 @@ 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, - locale, - }; - 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, + locale, }; - 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/public/locales/en/common.json b/public/locales/en/common.json index f65ec408..e2e57ff4 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -169,5 +169,10 @@ "conservationPurpose": "conservation donation", "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": "Sign Up for PlanetCash", + "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", "myContributionIsPartOfThat": "And my contribution is a part of that." -} \ No newline at end of file +} diff --git a/src/Common/InputTypes/AutoCompleteCountry.tsx b/src/Common/InputTypes/AutoCompleteCountry.tsx index dc996c03..2879b9cb 100644 --- a/src/Common/InputTypes/AutoCompleteCountry.tsx +++ b/src/Common/InputTypes/AutoCompleteCountry.tsx @@ -1,34 +1,38 @@ /* 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: - | (( - event: React.ChangeEvent - ) => void); + onValueChange: (value: string) => 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 +59,8 @@ export default function CountrySelect(props: { ? themeProperties.light.backgroundColorDark : themeProperties.dark.backgroundColorDark, }, - fontSize: '14px', - '& > span': { + fontSize: "14px", + "& > span": { marginRight: 10, fontSize: 18, }, @@ -66,7 +70,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, 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 @@ -75,40 +79,59 @@ 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]); // 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]); 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 (const 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 +158,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 +177,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/Components/ContactsForm.tsx b/src/Donations/Components/ContactsForm.tsx index 8c7def77..4d82a41d 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/Components/PaymentStatus.tsx b/src/Donations/Components/PaymentStatus.tsx index 2d31c535..1cd4b4d6 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"]); @@ -94,7 +95,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(); @@ -122,52 +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 ? ( + + ) : ( + + ) ) : ( - - ) - ) : ( -
- -
- )} -
- )} - - - - {t("donate:copiedToClipboard")} - - -
+
+ +
+ )} +
+ )} + + + + {t("donate:copiedToClipboard")} + + +
+ )}
); } diff --git a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx index a443a358..e0dec5eb 100644 --- a/src/Donations/Micros/PaymentStatus/ImageComponent.tsx +++ b/src/Donations/Micros/PaymentStatus/ImageComponent.tsx @@ -83,7 +83,7 @@ const ImageComponent = ({ projectDetails, donation, imageRef }: Props) => { organization: projectDetails.ownerName, })} - {projectDetails.purpose === "bouquet" && + {projectDetails?.purpose === "bouquet" && t("common:myContributionIsPartOfThat")} ); 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/Donations/Micros/PlanetCashSignup.tsx b/src/Donations/Micros/PlanetCashSignup.tsx new file mode 100644 index 00000000..8429f5ab --- /dev/null +++ b/src/Donations/Micros/PlanetCashSignup.tsx @@ -0,0 +1,182 @@ +import React, { useState, useEffect, useCallback, useContext } from "react"; +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; + ownerName: string; + balance: number; + debit: number; + creditLimit: number; + currency: string; + country: string; + topUpThreshold: number; + topUpAmount: number; + isActive: boolean; + fee: number; +} + +const allowedCountries = ["DE", "ES", "US"]; + +const PlanetCashSignup = () => { + 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); + const [country, setCountry] = useState("DE"); + const [planetCashAccounts, setPlanetCashAccounts] = useState< + PlanetCashAccount[] + >([]); + 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 () => { + const token = await getAccessTokenSilently(); + setLoading(true); + try { + const options = { + url: "/app/planetCash", + token, + setshowErrorCard, + }; + const { data } = await apiRequest(options); + setPlanetCashAccounts(data); + } catch (err) { + console.error(err); + } + setLoading(false); + }, [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 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")}

+ +
+ +
+
+ + + +
+

{t("planetCashIUnderstand")}

+
+ +
+ ); +}; + +export default PlanetCashSignup; diff --git a/src/Layout/QueryParamContext.tsx b/src/Layout/QueryParamContext.tsx index 442d727b..c475c36d 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,12 @@ export default function QueryParamProvider({ children }: any) { const router = useRouter(); const { i18n } = useTranslation(); + const { + getAccessTokenSilently, + isLoading, + isAuthenticated, + loginWithRedirect, + } = useAuth0(); const [paymentSetup, setpaymentSetup] = useState({}); @@ -282,8 +289,68 @@ export default function QueryParamProvider({ children }: any) { } } + const loadProfile = React.useCallback(async () => { + const token = await getAccessTokenSilently(); + try { + const profile = 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 && country !== undefined && country !== "") { + const regex = /^pcash_/; + if (regex.test(router.query.to)) { + router.push("/"); + } else if (router.query.to?.toString().toLowerCase() === "planetcash") { + if (!isLoading && !isAuthenticated) { + loginWithRedirect({ + redirectUri: window?.location.href, + }); + } 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-signup", + }); + } + setdonationStep(4); + } + } + } + }, [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" + ) { const to = String(router.query.to).replace(/\//g, ""); loadPaymentSetup({ projectGUID: to,