@lysaab/lysa-pep 0.6.0 → 0.8.0

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.
package/lib/Exports.d.ts CHANGED
@@ -3,5 +3,5 @@ export * from './model/PepModel';
3
3
  export * from './model/PepTexts';
4
4
  export { PepIsPepPage } from './pages/PepIsPepPage';
5
5
  export { PepRelationPage } from './pages/PepRelationPage';
6
- export { PepRolePage } from './pages/PepRolePage';
6
+ export { PepRolePage, militaryAlternatives, roleAlternatives } from './pages/PepRolePage';
7
7
  export { PepStatusPage } from './pages/PepStatusPage';
package/lib/Exports.js CHANGED
@@ -3,5 +3,5 @@ export * from './model/PepModel';
3
3
  export * from './model/PepTexts';
4
4
  export { PepIsPepPage } from './pages/PepIsPepPage';
5
5
  export { PepRelationPage } from './pages/PepRelationPage';
6
- export { PepRolePage } from './pages/PepRolePage';
6
+ export { PepRolePage, militaryAlternatives, roleAlternatives } from './pages/PepRolePage';
7
7
  export { PepStatusPage } from './pages/PepStatusPage';
@@ -3,4 +3,5 @@ export interface PepRequest extends Omit<PepState, "isSweden" | "isOngoing" | "e
3
3
  ended?: string;
4
4
  birthdayOfPEP?: string;
5
5
  }
6
- export declare function formatServerRequest(pepData: PepState): PepRequest;
6
+ export declare function stateToRequest(pepData: PepState): PepRequest;
7
+ export declare function requestToState({ ended, birthdayOfPEP, ...serverData }: PepRequest): PepState;
@@ -1,6 +1,17 @@
1
- import { PepType, EntityType } from "../pages/PepContext";
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { PepType, EntityType, PepStatus } from "../pages/PepContext";
2
13
  import { DateTime } from "luxon";
3
- export function formatServerRequest(pepData) {
14
+ export function stateToRequest(pepData) {
4
15
  const data = Object.assign({}, pepData);
5
16
  delete data.isSweden;
6
17
  delete data.isOngoing;
@@ -14,3 +25,16 @@ export function formatServerRequest(pepData) {
14
25
  ? DateTime.fromJSDate(data.birthdayOfPEP).toFormat("yyyy-MM-dd")
15
26
  : undefined });
16
27
  }
28
+ export function requestToState(_a) {
29
+ var { ended, birthdayOfPEP } = _a, serverData = __rest(_a, ["ended", "birthdayOfPEP"]);
30
+ const state = Object.assign({}, serverData);
31
+ if (ended) {
32
+ state.ended = DateTime.fromFormat(ended, "yyyy-MM").toJSDate();
33
+ }
34
+ if (birthdayOfPEP) {
35
+ state.birthdayOfPEP = DateTime.fromFormat(birthdayOfPEP, "yyyy-MM").toJSDate();
36
+ }
37
+ state.isSweden = state.country === "SE" ? "sweden" : "other";
38
+ state.isOngoing = state.ended ? PepStatus.ENDED : PepStatus.ONGOING;
39
+ return state;
40
+ }
@@ -1,7 +1,7 @@
1
1
  import { PepType, EntityType, BusinessRelation, Relation } from "../pages/PepContext";
2
2
  export const LABELS = (name) => {
3
3
  let possessiveName = name;
4
- if (possessiveName && possessiveName[possessiveName.length - 1] !== "s") {
4
+ if (possessiveName && possessiveName[possessiveName.length - 1] !== "s" && possessiveName[possessiveName.length - 1] !== "z" && possessiveName[possessiveName.length - 1] !== "x") {
5
5
  possessiveName += "s";
6
6
  }
7
7
  return {
@@ -1,6 +1,9 @@
1
1
  import { FunctionComponent } from "react";
2
+ import { Alternative } from "@lysaab/ui-2/components/input/InputAPI";
2
3
  interface Props {
3
4
  next: () => void;
4
5
  }
6
+ export declare const roleAlternatives: Alternative[];
7
+ export declare const militaryAlternatives: Alternative[];
5
8
  export declare const PepRolePage: FunctionComponent<Props>;
6
9
  export {};
@@ -3,7 +3,7 @@ import { Form, PrimaryButton, RequiredValidator, TextInput, Select } from "@lysa
3
3
  import { PepContext, Role, MilitaryRank, EntityType, PepType, } from "./PepContext";
4
4
  import { CountrySelect } from "../components/CountrySelect";
5
5
  import { getGovernmentCompanyNameLabel, getGovernmentCompanyRoleLabel, getHighRankingPositionIntCorpNameLabel, getHighRankingPositionIntCorpRoleLabel, getMilitaryRankLabel, getRoleLabel, getAmbassadorLabel } from "../model/PepTexts";
6
- const roleAlternatives = [
6
+ export const roleAlternatives = [
7
7
  { text: "Stats eller regeringschef", value: Role.HEAD_OF_GOVERNMENT },
8
8
  { text: "Minister eller Vice/Biträdande minister", value: Role.MINISTER },
9
9
  { text: "Ledamot i parlament eller riksdag", value: Role.PARLIMENT_MEMBER },
@@ -39,7 +39,7 @@ const roleAlternatives = [
39
39
  value: Role.HIGH_RANKING_POSITION_INTERNALTIONAL_CORP
40
40
  }
41
41
  ];
42
- const militaryAlternatives = [
42
+ export const militaryAlternatives = [
43
43
  {
44
44
  text: "General",
45
45
  value: MilitaryRank.GENERAL
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lysaab/lysa-pep",
3
3
  "author": "Lysa AB",
4
- "version": "0.6.0",
4
+ "version": "0.8.0",
5
5
  "main": "./lib/Exports.js",
6
6
  "dependencies": {
7
7
  "@lysaab/ui-2": "^8.7.0",
package/src/Exports.ts CHANGED
@@ -4,5 +4,5 @@ export * from './model/PepTexts';
4
4
 
5
5
  export { PepIsPepPage } from './pages/PepIsPepPage';
6
6
  export { PepRelationPage } from './pages/PepRelationPage';
7
- export { PepRolePage } from './pages/PepRolePage';
7
+ export { PepRolePage, militaryAlternatives, roleAlternatives } from './pages/PepRolePage';
8
8
  export { PepStatusPage } from './pages/PepStatusPage';
package/src/demo/Done.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useContext } from "react";
2
2
  import { PepContext } from "../pages/PepContext";
3
- import { formatServerRequest } from "../model/PepModel";
3
+ import { stateToRequest } from "../model/PepModel";
4
4
 
5
5
  export function Done() {
6
6
  const pepContext = useContext(PepContext);
@@ -8,7 +8,7 @@ export function Done() {
8
8
  <div>
9
9
  <h2>Taco hej!</h2>
10
10
  <p>Leverpastej!</p>
11
- <pre>{JSON.stringify(formatServerRequest(pepContext.state), null, 2)}</pre>
11
+ <pre>{JSON.stringify(stateToRequest(pepContext.state), null, 2)}</pre>
12
12
  </div>
13
13
  );
14
14
  }
@@ -1,4 +1,4 @@
1
- import { PepState, PepType, EntityType } from "../pages/PepContext";
1
+ import { PepState, PepType, EntityType, PepStatus } from "../pages/PepContext";
2
2
  import { DateTime } from "luxon";
3
3
 
4
4
  export interface PepRequest
@@ -11,12 +11,12 @@ export interface PepRequest
11
11
  *
12
12
  * Do some minor preprocessing before we are ready to sen everything to the server
13
13
  */
14
- export function formatServerRequest(pepData: PepState): PepRequest {
14
+ export function stateToRequest(pepData: PepState): PepRequest {
15
15
  const data = { ...pepData };
16
16
  delete data.isSweden;
17
17
  delete data.isOngoing;
18
18
  delete data.ownerName;
19
- if(data.legalEntityType === EntityType.PERSON) {
19
+ if (data.legalEntityType === EntityType.PERSON) {
20
20
  delete data.tin;
21
21
  }
22
22
  return {
@@ -30,3 +30,23 @@ export function formatServerRequest(pepData: PepState): PepRequest {
30
30
  : undefined
31
31
  };
32
32
  }
33
+
34
+ export function requestToState({
35
+ ended,
36
+ birthdayOfPEP,
37
+ ...serverData
38
+ }: PepRequest): PepState {
39
+ const state: PepState = { ...serverData };
40
+ if (ended) {
41
+ state.ended = DateTime.fromFormat(ended, "yyyy-MM").toJSDate();
42
+ }
43
+ if (birthdayOfPEP) {
44
+ state.birthdayOfPEP = DateTime.fromFormat(
45
+ birthdayOfPEP,
46
+ "yyyy-MM"
47
+ ).toJSDate();
48
+ }
49
+ state.isSweden = state.country === "SE" ? "sweden" : "other";
50
+ state.isOngoing = state.ended ? PepStatus.ENDED : PepStatus.ONGOING;
51
+ return state;
52
+ }
@@ -7,7 +7,7 @@ import {
7
7
 
8
8
  export const LABELS = (name?: string) => {
9
9
  let possessiveName = name;
10
- if (possessiveName && possessiveName[possessiveName.length - 1] !== "s") {
10
+ if (possessiveName && possessiveName[possessiveName.length - 1] !== "s" && possessiveName[possessiveName.length - 1] !== "z" && possessiveName[possessiveName.length - 1] !== "x") {
11
11
  possessiveName += "s";
12
12
  }
13
13
 
@@ -27,7 +27,7 @@ interface Props {
27
27
  next: () => void;
28
28
  }
29
29
 
30
- const roleAlternatives: Alternative[] = [
30
+ export const roleAlternatives: Alternative[] = [
31
31
  { text: "Stats eller regeringschef", value: Role.HEAD_OF_GOVERNMENT },
32
32
  { text: "Minister eller Vice/Biträdande minister", value: Role.MINISTER },
33
33
  { text: "Ledamot i parlament eller riksdag", value: Role.PARLIMENT_MEMBER },
@@ -66,7 +66,7 @@ const roleAlternatives: Alternative[] = [
66
66
  }
67
67
  ];
68
68
 
69
- const militaryAlternatives: Alternative[] = [
69
+ export const militaryAlternatives: Alternative[] = [
70
70
  {
71
71
  text: "General",
72
72
  value: MilitaryRank.GENERAL
@@ -1,142 +1,142 @@
1
- import React, {
2
- FunctionComponent,
3
- useRef,
4
- useCallback,
5
- useContext
6
- } from "react";
7
- import {
8
- Form,
9
- RadioGroup,
10
- RequiredValidator,
11
- PrimaryButton,
12
- LysaFormRef,
13
- Datepicker
14
- } from "@lysaab/ui-2";
15
- import {
16
- Alternative,
17
- InputEvent
18
- } from "@lysaab/ui-2/components/input/InputAPI";
19
- import { PepContext, PepStatus } from "./PepContext";
20
- import { CountrySelect } from "../components/CountrySelect";
21
-
22
- const stateAlternatives: Alternative[] = [
23
- {
24
- text: "Pågående",
25
- value: PepStatus.ONGOING
26
- },
27
- {
28
- text: "Avslutad",
29
- value: PepStatus.ENDED
30
- }
31
- ];
32
-
33
- const isSwedenAlternatives: Alternative[] = [
34
- { text: "Sverige", value: "sweden" },
35
- { text: "Annat", value: "other" }
36
- ];
37
-
38
- interface Props {
39
- next: () => void;
40
- }
41
-
42
- export const PepStatusPage: FunctionComponent<Props> = ({ next }) => {
43
- const pepContext = useContext(PepContext);
44
- const formRef = useRef<LysaFormRef>();
45
-
46
- const nextPage = useCallback(() => {
47
- if (formRef.current && formRef.current.isValid) {
48
- next();
49
- }
50
- }, [formRef, next]);
51
-
52
- const updateIsSweden = useCallback(
53
- (event: InputEvent<Alternative>) => {
54
- pepContext.setState({
55
- isSweden:
56
- event.value && event.value.value
57
- ? event.value.value.toString()
58
- : undefined
59
- });
60
- if (event.value && event.value.value === "other") {
61
- pepContext.setState({ country: undefined });
62
- }
63
- },
64
- [pepContext]
65
- );
66
-
67
- const updateIsOngoing = useCallback(
68
- (event: InputEvent<Alternative>) => {
69
- pepContext.setState({
70
- isOngoing:
71
- event.value && event.value.value
72
- ? (event.value.value as PepStatus)
73
- : undefined
74
- });
75
- if (event.value && event.value.value === PepStatus.ONGOING) {
76
- pepContext.setState({ ended: undefined });
77
- }
78
- },
79
- [pepContext]
80
- );
81
-
82
- return (
83
- <div>
84
- <Form
85
- lysaFormRef={formRef}
86
- onSubmit={() => {
87
- nextPage();
88
- }}
89
- >
90
- <RadioGroup
91
- alternatives={stateAlternatives}
92
- header="Är befattningen pågående eller avslutad?"
93
- onChange={updateIsOngoing}
94
- value={
95
- stateAlternatives.find(
96
- alt => alt.value === pepContext.state.isOngoing
97
- )
98
- }
99
- validators={[RequiredValidator("Du måste välja ett alternativ")]}
100
- />
101
-
102
- {pepContext.state.isOngoing &&
103
- pepContext.state.isOngoing === PepStatus.ENDED ? (
104
- <Datepicker
105
- label="När avslutades uppdraget?"
106
- selected={pepContext.state.ended}
107
- onChange={event =>
108
- pepContext.setState({ ended: event || undefined })
109
- }
110
- validators={[RequiredValidator("Du måste ange fördelsedag")]}
111
- showMonthYearPicker
112
- dateFormat="yyyy-MM"
113
- maxDate={new Date()}
114
- />
115
- ) : null}
116
-
117
- <RadioGroup
118
- alternatives={isSwedenAlternatives}
119
- header="I vilket land är befattningen"
120
- onChange={updateIsSweden}
121
- value={
122
- isSwedenAlternatives.find(
123
- alt => alt.value === pepContext.state.isSweden
124
- )
125
- }
126
- validators={[RequiredValidator("Du måste välja ett alternativ")]}
127
- />
128
-
129
- {pepContext.state.isSweden && pepContext.state.isSweden === "other" ? (
130
- <CountrySelect
131
- label="Välj i vilket land befattningen är"
132
- onChange={event => pepContext.setState({ country: event.value ? event.value.toString() : undefined })}
133
- validators={[RequiredValidator("Du måste välja land")]}
134
- value={pepContext.state.country}
135
- />
136
- ) : null}
137
-
138
- <PrimaryButton type="submit">Nästa</PrimaryButton>
139
- </Form>
140
- </div>
141
- );
142
- };
1
+ import React, {
2
+ FunctionComponent,
3
+ useRef,
4
+ useCallback,
5
+ useContext
6
+ } from "react";
7
+ import {
8
+ Form,
9
+ RadioGroup,
10
+ RequiredValidator,
11
+ PrimaryButton,
12
+ LysaFormRef,
13
+ Datepicker
14
+ } from "@lysaab/ui-2";
15
+ import {
16
+ Alternative,
17
+ InputEvent
18
+ } from "@lysaab/ui-2/components/input/InputAPI";
19
+ import { PepContext, PepStatus } from "./PepContext";
20
+ import { CountrySelect } from "../components/CountrySelect";
21
+
22
+ const stateAlternatives: Alternative[] = [
23
+ {
24
+ text: "Pågående",
25
+ value: PepStatus.ONGOING
26
+ },
27
+ {
28
+ text: "Avslutad",
29
+ value: PepStatus.ENDED
30
+ }
31
+ ];
32
+
33
+ const isSwedenAlternatives: Alternative[] = [
34
+ { text: "Sverige", value: "sweden" },
35
+ { text: "Annat", value: "other" }
36
+ ];
37
+
38
+ interface Props {
39
+ next: () => void;
40
+ }
41
+
42
+ export const PepStatusPage: FunctionComponent<Props> = ({ next }) => {
43
+ const pepContext = useContext(PepContext);
44
+ const formRef = useRef<LysaFormRef>();
45
+
46
+ const nextPage = useCallback(() => {
47
+ if (formRef.current && formRef.current.isValid) {
48
+ next();
49
+ }
50
+ }, [formRef, next]);
51
+
52
+ const updateIsSweden = useCallback(
53
+ (event: InputEvent<Alternative>) => {
54
+ pepContext.setState({
55
+ isSweden:
56
+ event.value && event.value.value
57
+ ? event.value.value.toString()
58
+ : undefined
59
+ });
60
+ if (event.value && event.value.value === "other") {
61
+ pepContext.setState({ country: undefined });
62
+ }
63
+ },
64
+ [pepContext]
65
+ );
66
+
67
+ const updateIsOngoing = useCallback(
68
+ (event: InputEvent<Alternative>) => {
69
+ pepContext.setState({
70
+ isOngoing:
71
+ event.value && event.value.value
72
+ ? (event.value.value as PepStatus)
73
+ : undefined
74
+ });
75
+ if (event.value && event.value.value === PepStatus.ONGOING) {
76
+ pepContext.setState({ ended: undefined });
77
+ }
78
+ },
79
+ [pepContext]
80
+ );
81
+
82
+ return (
83
+ <div>
84
+ <Form
85
+ lysaFormRef={formRef}
86
+ onSubmit={() => {
87
+ nextPage();
88
+ }}
89
+ >
90
+ <RadioGroup
91
+ alternatives={stateAlternatives}
92
+ header="Är befattningen pågående eller avslutad?"
93
+ onChange={updateIsOngoing}
94
+ value={
95
+ stateAlternatives.find(
96
+ alt => alt.value === pepContext.state.isOngoing
97
+ )
98
+ }
99
+ validators={[RequiredValidator("Du måste välja ett alternativ")]}
100
+ />
101
+
102
+ {pepContext.state.isOngoing &&
103
+ pepContext.state.isOngoing === PepStatus.ENDED ? (
104
+ <Datepicker
105
+ label="När avslutades uppdraget?"
106
+ selected={pepContext.state.ended}
107
+ onChange={event =>
108
+ pepContext.setState({ ended: event || undefined })
109
+ }
110
+ validators={[RequiredValidator("Du måste ange fördelsedag")]}
111
+ showMonthYearPicker
112
+ dateFormat="yyyy-MM"
113
+ maxDate={new Date()}
114
+ />
115
+ ) : null}
116
+
117
+ <RadioGroup
118
+ alternatives={isSwedenAlternatives}
119
+ header="I vilket land är befattningen"
120
+ onChange={updateIsSweden}
121
+ value={
122
+ isSwedenAlternatives.find(
123
+ alt => alt.value === pepContext.state.isSweden
124
+ )
125
+ }
126
+ validators={[RequiredValidator("Du måste välja ett alternativ")]}
127
+ />
128
+
129
+ {pepContext.state.isSweden && pepContext.state.isSweden === "other" ? (
130
+ <CountrySelect
131
+ label="Välj i vilket land befattningen är"
132
+ onChange={event => pepContext.setState({ country: event.value ? event.value.toString() : undefined })}
133
+ validators={[RequiredValidator("Du måste välja land")]}
134
+ value={pepContext.state.country}
135
+ />
136
+ ) : null}
137
+
138
+ <PrimaryButton type="submit">Nästa</PrimaryButton>
139
+ </Form>
140
+ </div>
141
+ );
142
+ };