paymob-pixel-alpha 1.1.25 → 1.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/main.js +57 -39
  2. package/package.json +1 -1
  3. package/styles.css +71 -3267
package/main.js CHANGED
@@ -13582,57 +13582,54 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13582
13582
  formState: {
13583
13583
  errors,
13584
13584
  isDirty,
13585
- isValid,
13586
- dirtyFields
13585
+ isValid
13587
13586
  },
13588
13587
  setValue,
13589
13588
  trigger,
13590
13589
  clearErrors,
13591
- control
13590
+ control,
13591
+ getValues
13592
13592
  } = useForm({
13593
13593
  mode: 'onChange',
13594
13594
  shouldUnregister: true,
13595
13595
  defaultValues: flattenContactFormValues(defaultCountryISO, defaultValues)
13596
13596
  });
13597
+ const countriesSource = useMemo(() => {
13598
+ if (allowedCountries && allowedCountries.length > 0) {
13599
+ return restCountries.filter(c => allowedCountries.includes(c.iso));
13600
+ }
13601
+ return restCountries;
13602
+ }, [allowedCountries, restCountries]);
13597
13603
  const {
13598
13604
  defaultCountry,
13599
13605
  defaultShippingCountry,
13600
13606
  defaultBillingCountry
13601
13607
  } = useMemo(() => {
13602
- const result = {
13603
- defaultCountry: {},
13604
- defaultShippingCountry: {},
13605
- defaultBillingCountry: {}
13608
+ var _defaultValues$shippi, _defaultValues$billin;
13609
+ const fallback = countriesSource.find(c => c.iso === defaultCountryISO) || countriesSource[0] || null;
13610
+ const shipping = defaultValues != null && (_defaultValues$shippi = defaultValues.shipping) != null && _defaultValues$shippi.country ? countriesSource.find(c => {
13611
+ var _defaultValues$shippi2;
13612
+ return c.iso === ((_defaultValues$shippi2 = defaultValues.shipping) == null ? void 0 : _defaultValues$shippi2.country);
13613
+ }) || null : null;
13614
+ const billing = defaultValues != null && (_defaultValues$billin = defaultValues.billing) != null && _defaultValues$billin.country ? countriesSource.find(c => {
13615
+ var _defaultValues$billin2;
13616
+ return c.iso === ((_defaultValues$billin2 = defaultValues.billing) == null ? void 0 : _defaultValues$billin2.country);
13617
+ }) || null : null;
13618
+ return {
13619
+ defaultCountry: shipping || billing || fallback,
13620
+ defaultShippingCountry: shipping || fallback,
13621
+ defaultBillingCountry: billing || fallback
13606
13622
  };
13607
- for (const country of restCountries) {
13608
- var _defaultValues$shippi, _defaultValues$billin, _defaultValues$shippi2, _defaultValues$billin2;
13609
- if (country.iso === defaultCountryISO) {
13610
- result.defaultCountry = country;
13611
- }
13612
- if (defaultValues != null && (_defaultValues$shippi = defaultValues.shipping) != null && _defaultValues$shippi.country && country.iso === defaultValues.shipping.country) {
13613
- result.defaultShippingCountry = country;
13614
- }
13615
- if (defaultValues != null && (_defaultValues$billin = defaultValues.billing) != null && _defaultValues$billin.country && country.iso === defaultValues.billing.country) {
13616
- result.defaultBillingCountry = country;
13617
- }
13618
- if (!(defaultValues != null && defaultValues.shipping) && !(defaultValues != null && (_defaultValues$shippi2 = defaultValues.shipping) != null && _defaultValues$shippi2.country) && country.iso === defaultCountryISO) {
13619
- result.defaultShippingCountry = country;
13620
- }
13621
- if (!(defaultValues != null && defaultValues.billing) && !(defaultValues != null && (_defaultValues$billin2 = defaultValues.billing) != null && _defaultValues$billin2.country) && country.iso === defaultCountryISO) {
13622
- result.defaultBillingCountry = country;
13623
- }
13624
- }
13625
- return result;
13626
- }, [restCountries, defaultCountryISO, JSON.stringify(defaultValues)]);
13623
+ }, [countriesSource, defaultCountryISO, JSON.stringify(defaultValues)]);
13627
13624
  const {
13628
13625
  t
13629
13626
  } = useTranslation('kitComponents');
13630
13627
  const isMobile = useWidth();
13631
13628
  const [country, setCountry] = useState(defaultCountry);
13632
13629
  const [shippingCountry, setShippingCountry] = useState(defaultShippingCountry);
13633
- const [shippingPhoneCountry, setShippingPhoneCountry] = useState(defaultCountry);
13630
+ const [shippingPhoneCountry, setShippingPhoneCountry] = useState(defaultShippingCountry);
13634
13631
  const [billingCountry, setBillingCountry] = useState(defaultBillingCountry);
13635
- const [billingPhoneCountry, setBillingPhoneCountry] = useState(defaultCountry);
13632
+ const [billingPhoneCountry, setBillingPhoneCountry] = useState(defaultBillingCountry);
13636
13633
  const [regionData, setRegionData] = useState(null);
13637
13634
  const [isLoadingRegionData, setIsLoadingRegionData] = useState(false);
13638
13635
  const countriesOptions = useMemo(() => {
@@ -13707,6 +13704,27 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13707
13704
  getRegionData();
13708
13705
  }
13709
13706
  }, []);
13707
+ useEffect(() => {
13708
+ if (!defaultCountryISO || !(allowedCountries != null && allowedCountries.length)) return;
13709
+ if (allowedCountries.includes(defaultCountryISO)) {
13710
+ if (collectShippingAddress) {
13711
+ setValue("shipping_country", defaultCountryISO, {
13712
+ shouldValidate: true,
13713
+ shouldDirty: true
13714
+ });
13715
+ setShippingCountry(countriesSource.find(c => c.iso === defaultCountryISO) || null);
13716
+ setShippingPhoneCountry(countriesSource.find(c => c.iso === defaultCountryISO) || null);
13717
+ }
13718
+ if (collectBillingAddress) {
13719
+ setValue("billing_country", defaultCountryISO, {
13720
+ shouldValidate: true,
13721
+ shouldDirty: true
13722
+ });
13723
+ setBillingCountry(countriesSource.find(c => c.iso === defaultCountryISO) || null);
13724
+ setBillingPhoneCountry(countriesSource.find(c => c.iso === defaultCountryISO) || null);
13725
+ }
13726
+ }
13727
+ }, [defaultCountryISO, allowedCountries, collectShippingAddress, collectBillingAddress, countriesSource, setValue]);
13710
13728
  const createEmailRegister = useCallback(({
13711
13729
  field: _field = 'email'
13712
13730
  } = {}) => {
@@ -13860,14 +13878,14 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13860
13878
  name: `${prefix}_phone_number`,
13861
13879
  error: errors[`${prefix}_phone_number`],
13862
13880
  selectedCountry: {
13863
- name: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry.name : billingPhoneCountry.name,
13864
- code: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry.code : billingPhoneCountry.code
13881
+ name: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry == null ? void 0 : shippingPhoneCountry.name : billingPhoneCountry == null ? void 0 : billingPhoneCountry.name,
13882
+ code: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry == null ? void 0 : shippingPhoneCountry.code : billingPhoneCountry == null ? void 0 : billingPhoneCountry.code
13865
13883
  },
13866
13884
  className: getInputClasses(`${prefix}_phone_number`, 'middle'),
13867
13885
  setSelectedCountry: country => prefix === ADDRESS_TYPES.SHIPPING ? setShippingPhoneCountry(country) : setBillingPhoneCountry(country),
13868
13886
  phoneFormRegister: createPhoneRegister({
13869
13887
  field: `${prefix}_phone_number`,
13870
- countryCode: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry.code : billingPhoneCountry.code
13888
+ countryCode: prefix === ADDRESS_TYPES.SHIPPING ? shippingPhoneCountry == null ? void 0 : shippingPhoneCountry.code : billingPhoneCountry == null ? void 0 : billingPhoneCountry.code
13871
13889
  }),
13872
13890
  placeholder: "10 000 000 00",
13873
13891
  allowedCountries: allowedCountries,
@@ -13877,7 +13895,7 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13877
13895
  }), /*#__PURE__*/_jsx(Controller, {
13878
13896
  name: countryField,
13879
13897
  control: control,
13880
- defaultValue: country == null ? void 0 : country.iso,
13898
+ defaultValue: (defaultCountry == null ? void 0 : defaultCountry.iso) || '',
13881
13899
  rules: {
13882
13900
  required: t('COUNTRY_IS_REQUIRED')
13883
13901
  },
@@ -13888,9 +13906,9 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13888
13906
  }
13889
13907
  }) => /*#__PURE__*/_jsx(Dropdown, {
13890
13908
  label: t('COUNTRIES'),
13891
- onChange: country => {
13892
- if (country.value !== value) {
13893
- onChange(country.value);
13909
+ onChange: selected => {
13910
+ if (selected.value !== value) {
13911
+ onChange(selected.value);
13894
13912
  additionalFields == null || additionalFields.forEach(({
13895
13913
  field
13896
13914
  }) => {
@@ -13899,11 +13917,11 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
13899
13917
  shouldValidate: true
13900
13918
  });
13901
13919
  });
13902
- handleCountryChange(country, prefix);
13920
+ handleCountryChange(selected, prefix);
13903
13921
  }
13904
13922
  },
13905
13923
  options: countriesOptions,
13906
- defaultOption: (country == null ? void 0 : country.iso) || '',
13924
+ defaultOption: value || (defaultCountry == null ? void 0 : defaultCountry.iso) || '',
13907
13925
  className: `!shadow-none !border-b-0 ${getInputClasses(`${prefix}_country`, 'middle')}`,
13908
13926
  hideCircleIcon: true,
13909
13927
  hideRemoveOptionBtn: true
@@ -14002,7 +14020,7 @@ const ContactForm = /*#__PURE__*/(/* unused pure expression or super */ null &&
14002
14020
  hideCircleIcon: true,
14003
14021
  hideRemoveOptionBtn: true,
14004
14022
  defaultOption: value,
14005
- disableDropdown: !dirtyFields[countryField]
14023
+ disableDropdown: !getValues(countryField)
14006
14024
  })
14007
14025
  }, key);
14008
14026
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paymob-pixel-alpha",
3
- "version": "1.1.25",
3
+ "version": "1.1.26",
4
4
  "keywords": ["paymob","pixel","paymob-pixel"],
5
5
  "main": "./main.js",
6
6
  "license": "MIT",