@lysaab/lysa-pep 5.0.0 → 5.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,10 +1,10 @@
1
- import { FunctionComponent } from "react";
2
- import { Language } from "@lysaab/ui-2";
3
- interface Props {
4
- countryName: string;
5
- countryCode: string;
6
- language: Language;
7
- next: () => void;
8
- }
9
- export declare const StatusPage: FunctionComponent<Props>;
10
- export {};
1
+ import { FunctionComponent } from "react";
2
+ import { Language } from "@lysaab/ui-2";
3
+ interface Props {
4
+ countryName: string;
5
+ countryCode: string;
6
+ language: Language;
7
+ next: () => void;
8
+ }
9
+ export declare const StatusPage: FunctionComponent<Props>;
10
+ export {};
@@ -1,104 +1,104 @@
1
- import React, { useRef, useCallback, useContext, } from "react";
2
- import { Form, RadioGroup, RequiredValidator, PrimaryButton, Datepicker, Card, CountrySelect, } from "@lysaab/ui-2";
3
- import { PepContext, PepStatus, EntityType, PepType } from "../PepContext";
4
- import { useIntl, FormattedMessage } from "react-intl";
5
- import { isOngoingMessages, endedMessages, isLocalCountryMessages, countrySelectionMessages, localCountryAltMessages, stateAltMessages, } from "./StatusMessages";
6
- import { formatPossessive } from "../../utils/Possession";
7
- export const StatusPage = ({ countryName, countryCode, language, next, }) => {
8
- const pepContext = useContext(PepContext);
9
- const formRef = useRef();
10
- const intl = useIntl();
11
- const stateAlternatives = getStateAlternatives(intl);
12
- const isLocalCountryAlternatives = getIsLocalCountryAlternatives(intl, countryName);
13
- const entityType = pepContext.state.legalEntityType || EntityType.PERSON;
14
- const nextPage = useCallback(() => {
15
- if (formRef.current && formRef.current.isValid) {
16
- next();
17
- }
18
- }, [formRef, next]);
19
- const updateIsLocalCountry = useCallback((alternative) => {
20
- pepContext.setState({ isLocalCountry: alternative.value });
21
- if (alternative.value === "other") {
22
- pepContext.setState({ country: undefined });
23
- }
24
- else {
25
- pepContext.setState({ country: countryCode });
26
- }
27
- }, [pepContext, countryCode]);
28
- const updateIsOngoing = useCallback((alternative) => {
29
- pepContext.setState({ isOngoing: alternative.value });
30
- if (alternative.value === PepStatus.ONGOING) {
31
- pepContext.setState({ ended: undefined });
32
- }
33
- }, [pepContext]);
34
- return (React.createElement("div", null,
35
- React.createElement(Form, { lysaFormRef: formRef, onSubmit: () => {
36
- nextPage();
37
- } },
38
- React.createElement(Card, null,
39
- React.createElement(RadioGroup, { alternatives: stateAlternatives, header: intl.formatMessage(isOngoingMessages.header, {
40
- entityType,
41
- name: pepContext.state.ownerName,
42
- possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
43
- relation: pepContext.state.type === PepType.COLLEAGUE
44
- ? pepContext.state.businessRelation
45
- : pepContext.state.relationToPEP,
46
- pepType: pepContext.state.type,
47
- }), onChange: updateIsOngoing, value: stateAlternatives.find((alt) => alt.value === pepContext.state.isOngoing), validators: [
48
- new RequiredValidator(intl.formatMessage(isOngoingMessages.required)),
49
- ] }),
50
- pepContext.state.isOngoing &&
51
- pepContext.state.isOngoing === PepStatus.ENDED ? (React.createElement(Datepicker, { label: intl.formatMessage(endedMessages.header), selected: pepContext.state.ended, onChange: (event) => {
52
- pepContext.setState({ ended: event || undefined });
53
- }, validators: [
54
- new RequiredValidator(intl.formatMessage(endedMessages.required)),
55
- ], showMonthYearPicker: true, dateFormat: "yyyy-MM", maxDate: new Date() })) : null),
56
- React.createElement(Card, null,
57
- React.createElement(RadioGroup, { alternatives: isLocalCountryAlternatives, header: intl.formatMessage(isLocalCountryMessages.header, {
58
- possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
59
- }), onChange: updateIsLocalCountry, value: isLocalCountryAlternatives.find((alt) => alt.value === pepContext.state.isLocalCountry), validators: [
60
- new RequiredValidator(intl.formatMessage(isLocalCountryMessages.required)),
61
- ] }),
62
- pepContext.state.isLocalCountry &&
63
- pepContext.state.isLocalCountry === "other" ? (React.createElement(CountrySelect, { label: intl.formatMessage(countrySelectionMessages.header, {
64
- entityType,
65
- name: pepContext.state.ownerName,
66
- possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
67
- relation: pepContext.state.type === PepType.COLLEAGUE
68
- ? pepContext.state.businessRelation
69
- : pepContext.state.relationToPEP,
70
- pepType: pepContext.state.type,
71
- }), onChange: (event) => pepContext.setState({
72
- country: event.value ? event.value.toString() : undefined,
73
- }), validators: [
74
- new RequiredValidator(intl.formatMessage(countrySelectionMessages.required)),
75
- ], value: pepContext.state.country, omitList: [countryCode], language: language, placeholder: intl.formatMessage(countrySelectionMessages.placeholder) })) : null),
76
- React.createElement(PrimaryButton, { block: true, type: "submit" },
77
- React.createElement(FormattedMessage, { id: "pep.status.next" })))));
78
- };
79
- function getIsLocalCountryAlternatives(intl, countryName) {
80
- return [
81
- {
82
- text: intl.formatMessage(localCountryAltMessages.localCountry, {
83
- countryName,
84
- }),
85
- value: "local",
86
- },
87
- {
88
- text: intl.formatMessage(localCountryAltMessages.otherCountry),
89
- value: "other",
90
- },
91
- ];
92
- }
93
- function getStateAlternatives(intl) {
94
- return [
95
- {
96
- text: intl.formatMessage(stateAltMessages[PepStatus.ONGOING]),
97
- value: PepStatus.ONGOING,
98
- },
99
- {
100
- text: intl.formatMessage(stateAltMessages[PepStatus.ENDED]),
101
- value: PepStatus.ENDED,
102
- },
103
- ];
104
- }
1
+ import React, { useRef, useCallback, useContext, } from "react";
2
+ import { Form, RadioGroup, RequiredValidator, PrimaryButton, Datepicker, Card, CountrySelect, } from "@lysaab/ui-2";
3
+ import { PepContext, PepStatus, EntityType, PepType } from "../PepContext";
4
+ import { useIntl, FormattedMessage } from "react-intl";
5
+ import { isOngoingMessages, endedMessages, isLocalCountryMessages, countrySelectionMessages, localCountryAltMessages, stateAltMessages, } from "./StatusMessages";
6
+ import { formatPossessive } from "../../utils/Possession";
7
+ export const StatusPage = ({ countryName, countryCode, language, next, }) => {
8
+ const pepContext = useContext(PepContext);
9
+ const formRef = useRef();
10
+ const intl = useIntl();
11
+ const stateAlternatives = getStateAlternatives(intl);
12
+ const isLocalCountryAlternatives = getIsLocalCountryAlternatives(intl, countryName);
13
+ const entityType = pepContext.state.legalEntityType || EntityType.PERSON;
14
+ const nextPage = useCallback(() => {
15
+ if (formRef.current && formRef.current.isValid) {
16
+ next();
17
+ }
18
+ }, [formRef, next]);
19
+ const updateIsLocalCountry = useCallback((alternative) => {
20
+ pepContext.setState({ isLocalCountry: alternative.value });
21
+ if (alternative.value === "other") {
22
+ pepContext.setState({ country: undefined });
23
+ }
24
+ else {
25
+ pepContext.setState({ country: countryCode });
26
+ }
27
+ }, [pepContext, countryCode]);
28
+ const updateIsOngoing = useCallback((alternative) => {
29
+ pepContext.setState({ isOngoing: alternative.value });
30
+ if (alternative.value === PepStatus.ONGOING) {
31
+ pepContext.setState({ ended: undefined });
32
+ }
33
+ }, [pepContext]);
34
+ return (React.createElement("div", null,
35
+ React.createElement(Form, { lysaFormRef: formRef, onSubmit: () => {
36
+ nextPage();
37
+ } },
38
+ React.createElement(Card, null,
39
+ React.createElement(RadioGroup, { alternatives: stateAlternatives, header: intl.formatMessage(isOngoingMessages.header, {
40
+ entityType,
41
+ name: pepContext.state.ownerName,
42
+ possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
43
+ relation: pepContext.state.type === PepType.COLLEAGUE
44
+ ? pepContext.state.businessRelation
45
+ : pepContext.state.relationToPEP,
46
+ pepType: pepContext.state.type,
47
+ }), onChange: updateIsOngoing, value: stateAlternatives.find((alt) => alt.value === pepContext.state.isOngoing), validators: [
48
+ new RequiredValidator(intl.formatMessage(isOngoingMessages.required)),
49
+ ] }),
50
+ pepContext.state.isOngoing &&
51
+ pepContext.state.isOngoing === PepStatus.ENDED ? (React.createElement(Datepicker, { label: intl.formatMessage(endedMessages.header), selected: pepContext.state.ended, onChange: (event) => {
52
+ pepContext.setState({ ended: event || undefined });
53
+ }, validators: [
54
+ new RequiredValidator(intl.formatMessage(endedMessages.required)),
55
+ ], showMonthYearPicker: true, dateFormat: "yyyy-MM", maxDate: new Date() })) : null),
56
+ React.createElement(Card, null,
57
+ React.createElement(RadioGroup, { alternatives: isLocalCountryAlternatives, header: intl.formatMessage(isLocalCountryMessages.header, {
58
+ possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
59
+ }), onChange: updateIsLocalCountry, value: isLocalCountryAlternatives.find((alt) => alt.value === pepContext.state.isLocalCountry), validators: [
60
+ new RequiredValidator(intl.formatMessage(isLocalCountryMessages.required)),
61
+ ] }),
62
+ pepContext.state.isLocalCountry &&
63
+ pepContext.state.isLocalCountry === "other" ? (React.createElement(CountrySelect, { label: intl.formatMessage(countrySelectionMessages.header, {
64
+ entityType,
65
+ name: pepContext.state.ownerName,
66
+ possessiveName: formatPossessive(pepContext.state.ownerName, intl.locale),
67
+ relation: pepContext.state.type === PepType.COLLEAGUE
68
+ ? pepContext.state.businessRelation
69
+ : pepContext.state.relationToPEP,
70
+ pepType: pepContext.state.type,
71
+ }), onChange: (event) => pepContext.setState({
72
+ country: event.value ? event.value.toString() : undefined,
73
+ }), validators: [
74
+ new RequiredValidator(intl.formatMessage(countrySelectionMessages.required)),
75
+ ], value: pepContext.state.country, omitList: [countryCode], language: language, placeholder: intl.formatMessage(countrySelectionMessages.placeholder) })) : null),
76
+ React.createElement(PrimaryButton, { block: true, type: "submit" },
77
+ React.createElement(FormattedMessage, { id: "pep.status.next" })))));
78
+ };
79
+ function getIsLocalCountryAlternatives(intl, countryName) {
80
+ return [
81
+ {
82
+ text: intl.formatMessage(localCountryAltMessages.localCountry, {
83
+ countryName,
84
+ }),
85
+ value: "local",
86
+ },
87
+ {
88
+ text: intl.formatMessage(localCountryAltMessages.otherCountry),
89
+ value: "other",
90
+ },
91
+ ];
92
+ }
93
+ function getStateAlternatives(intl) {
94
+ return [
95
+ {
96
+ text: intl.formatMessage(stateAltMessages[PepStatus.ONGOING]),
97
+ value: PepStatus.ONGOING,
98
+ },
99
+ {
100
+ text: intl.formatMessage(stateAltMessages[PepStatus.ENDED]),
101
+ value: PepStatus.ENDED,
102
+ },
103
+ ];
104
+ }
@@ -1 +1 @@
1
- export declare function formatPossessive(text: string | undefined, locale: string): string | undefined;
1
+ export declare function formatPossessive(text: string | undefined, locale: string): string | undefined;
@@ -1,27 +1,27 @@
1
- export function formatPossessive(text, locale) {
2
- if (!text) {
3
- return;
4
- }
5
- const language = locale.substr(0, 2);
6
- if (language === "sv") {
7
- return formatSwedish(text);
8
- }
9
- else if (language === "en") {
10
- return formatEnglish(text);
11
- }
12
- return text;
13
- }
14
- function formatSwedish(text) {
15
- if (text[text.length - 1] !== "s" &&
16
- text[text.length - 1] !== "z" &&
17
- text[text.length - 1] !== "x") {
18
- text += "s";
19
- }
20
- return text;
21
- }
22
- function formatEnglish(text) {
23
- if (text[text.length - 1] === "s") {
24
- return text + "'";
25
- }
26
- return text + "'s";
27
- }
1
+ export function formatPossessive(text, locale) {
2
+ if (!text) {
3
+ return;
4
+ }
5
+ const language = locale.substr(0, 2);
6
+ if (language === "sv") {
7
+ return formatSwedish(text);
8
+ }
9
+ else if (language === "en") {
10
+ return formatEnglish(text);
11
+ }
12
+ return text;
13
+ }
14
+ function formatSwedish(text) {
15
+ if (text[text.length - 1] !== "s" &&
16
+ text[text.length - 1] !== "z" &&
17
+ text[text.length - 1] !== "x") {
18
+ text += "s";
19
+ }
20
+ return text;
21
+ }
22
+ function formatEnglish(text) {
23
+ if (text[text.length - 1] === "s") {
24
+ return text + "'";
25
+ }
26
+ return text + "'s";
27
+ }