@lysaab/lysa-pep 3.0.0 → 3.0.1

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.
@@ -1,4 +1,4 @@
1
- import { FunctionComponent } from "react";
1
+ /// <reference types="react" />
2
2
  import { Alternative } from "@lysaab/ui-2";
3
3
  import { ValidationProps } from "@lysaab/ui-2/hooks/useValidation";
4
4
  interface Props extends ValidationProps {
@@ -7,5 +7,5 @@ interface Props extends ValidationProps {
7
7
  label: string;
8
8
  omitCountries?: string[];
9
9
  }
10
- export declare const CountrySelect: FunctionComponent<Props>;
10
+ export declare const CountrySelect: ({ value, omitCountries, ...props }: Props) => JSX.Element;
11
11
  export {};
@@ -9,7 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import React, { useState } from "react";
12
+ import React, { useState, useEffect } from "react";
13
13
  import { Select } from "@lysaab/ui-2";
14
14
  import countries from "@lysaab/countries";
15
15
  import { defineMessages, useIntl } from "react-intl";
@@ -20,15 +20,22 @@ const messages = defineMessages({
20
20
  defaultMessage: "Select a country",
21
21
  },
22
22
  });
23
- export const CountrySelect = (_a) => {
24
- var { value, omitCountries = [] } = _a, props = __rest(_a, ["value", "omitCountries"]);
25
- const intl = useIntl();
26
- const lang = intl.locale.slice(0, 2);
27
- const [countryAlternatives] = useState((countries[lang] || countries["en"])
23
+ function getCountries(lang, omitCountries) {
24
+ return (countries[lang] || countries["en"])
28
25
  .filter((country) => !omitCountries.includes(country.value))
29
26
  .map((country) => ({
30
27
  text: country.label,
31
28
  value: country.value,
32
- })));
29
+ }));
30
+ }
31
+ const EMPTY_OMIT_COUNTRIES = [];
32
+ export const CountrySelect = (_a) => {
33
+ var { value, omitCountries = EMPTY_OMIT_COUNTRIES } = _a, props = __rest(_a, ["value", "omitCountries"]);
34
+ const intl = useIntl();
35
+ const lang = intl.locale.slice(0, 2);
36
+ const [countryAlternatives, setCountryAlternatives] = useState(getCountries(lang, omitCountries));
37
+ useEffect(() => {
38
+ setCountryAlternatives(getCountries(lang, omitCountries));
39
+ }, [lang, omitCountries]);
33
40
  return (React.createElement(Select, Object.assign({ alternatives: countryAlternatives, placeholder: intl.formatMessage(messages.placeholder), value: countryAlternatives.find((country) => country.value === value) }, props)));
34
41
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lysaab/lysa-pep",
3
3
  "author": "Lysa AB",
4
- "version": "3.0.0",
4
+ "version": "3.0.1",
5
5
  "main": "./Exports.js",
6
6
  "dependencies": {
7
7
  "@lysaab/countries": "^3.1.1",
@@ -63,12 +63,7 @@ export const RelationPage = ({ next }) => {
63
63
  : pepContext.state.relationToPEP,
64
64
  possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
65
65
  }), selected: pepContext.state.birthdayOfPEP, onChange: (event) => {
66
- if (Array.isArray(event)) {
67
- pepContext.setState({ birthdayOfPEP: event[0] || undefined });
68
- }
69
- else {
70
- pepContext.setState({ birthdayOfPEP: event || undefined });
71
- }
66
+ pepContext.setState({ birthdayOfPEP: event || undefined });
72
67
  }, validators: [
73
68
  new RequiredValidator(intl.formatMessage(birthdayMessages.required)),
74
69
  ], maxDate: new Date(), openToDate: pepContext.state.birthdayOfPEP || DATEPICKER_START_DATE }))) : null,
@@ -50,12 +50,7 @@ export const StatusPage = ({ countryName, countryCode, next, }) => {
50
50
  ] }),
51
51
  pepContext.state.isOngoing &&
52
52
  pepContext.state.isOngoing === PepStatus.ENDED ? (React.createElement(Datepicker, { label: intl.formatMessage(endedMessages.header), selected: pepContext.state.ended, onChange: (event) => {
53
- if (Array.isArray(event)) {
54
- pepContext.setState({ ended: event[0] || undefined });
55
- }
56
- else {
57
- pepContext.setState({ ended: event || undefined });
58
- }
53
+ pepContext.setState({ ended: event || undefined });
59
54
  }, validators: [
60
55
  new RequiredValidator(intl.formatMessage(endedMessages.required)),
61
56
  ], showMonthYearPicker: true, dateFormat: "yyyy-MM", maxDate: new Date() })) : null),