@altinn/altinn-components 0.46.3 → 0.46.4
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/dist/hooks/useAccountSelector.js +99 -97
- package/package.json +1 -1
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useMemo as
|
|
1
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as K } from "react";
|
|
3
3
|
import "../index-L8X2o7IH.js";
|
|
4
|
-
import { IconButton as
|
|
4
|
+
import { IconButton as R } from "../components/Button/IconButton.js";
|
|
5
5
|
import "../components/RootProvider/RootProvider.js";
|
|
6
|
-
import { useIsDesktop as
|
|
6
|
+
import { useIsDesktop as U } from "./useIsDesktop.js";
|
|
7
7
|
import "../components/Snackbar/useSnackbar.js";
|
|
8
|
-
import { formatDisplayName as
|
|
9
|
-
import { formatDate as
|
|
10
|
-
import { S as
|
|
11
|
-
const
|
|
12
|
-
partyListDTO:
|
|
8
|
+
import { formatDisplayName as $ } from "../functions/name/name.js";
|
|
9
|
+
import { formatDate as W } from "../functions/date/date.js";
|
|
10
|
+
import { S as Y, a as q } from "../HeartFill-CYSrJ_xK.js";
|
|
11
|
+
const S = (t) => t === "Organization" ? "company" : "person", te = ({
|
|
12
|
+
partyListDTO: t = [],
|
|
13
13
|
favoriteAccountUuids: e,
|
|
14
14
|
currentAccountUuid: u,
|
|
15
|
-
selfAccountUuid:
|
|
16
|
-
isLoading:
|
|
17
|
-
onSelectAccount:
|
|
18
|
-
isVirtualized:
|
|
19
|
-
onToggleFavorite:
|
|
15
|
+
selfAccountUuid: m,
|
|
16
|
+
isLoading: f = !1,
|
|
17
|
+
onSelectAccount: _,
|
|
18
|
+
isVirtualized: h = !1,
|
|
19
|
+
onToggleFavorite: s,
|
|
20
20
|
languageCode: c
|
|
21
21
|
}) => {
|
|
22
|
-
const
|
|
23
|
-
var
|
|
24
|
-
if (
|
|
22
|
+
const r = U(), [i, b, a] = K(() => {
|
|
23
|
+
var A, N;
|
|
24
|
+
if (f || !t || !m)
|
|
25
25
|
return [[], {}, void 0];
|
|
26
|
-
const
|
|
26
|
+
const n = (o) => e == null ? void 0 : e.includes(o), l = D(c), I = t.find((o) => O(o.type) && o.partyUuid === m), z = t.filter((o) => O(o.type) && o.partyUuid !== m), B = t.filter((o) => J(o.type)), F = g(
|
|
27
27
|
c,
|
|
28
|
-
|
|
28
|
+
I,
|
|
29
29
|
"favorites",
|
|
30
30
|
u,
|
|
31
31
|
!1,
|
|
32
|
-
r,
|
|
33
32
|
s,
|
|
33
|
+
r,
|
|
34
34
|
void 0,
|
|
35
35
|
!0
|
|
36
|
-
),
|
|
37
|
-
(
|
|
36
|
+
), k = z == null ? void 0 : z.map(
|
|
37
|
+
(o) => g(
|
|
38
38
|
c,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
o,
|
|
40
|
+
o.partyUuid,
|
|
41
41
|
u,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
n(o.partyUuid),
|
|
43
|
+
s,
|
|
44
|
+
r
|
|
45
45
|
)
|
|
46
|
-
),
|
|
47
|
-
for (const
|
|
48
|
-
const
|
|
46
|
+
), v = [];
|
|
47
|
+
for (const o of B) {
|
|
48
|
+
const d = g(
|
|
49
49
|
c,
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
o,
|
|
51
|
+
o.partyUuid,
|
|
52
52
|
u,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
n(o.partyUuid),
|
|
54
|
+
s,
|
|
55
|
+
r
|
|
56
56
|
);
|
|
57
|
-
if (
|
|
58
|
-
for (const
|
|
59
|
-
const
|
|
57
|
+
if (v.push(d), o.subunits && o.subunits.length > 0)
|
|
58
|
+
for (const P of o.subunits) {
|
|
59
|
+
const G = g(
|
|
60
60
|
c,
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
P,
|
|
62
|
+
o.partyUuid,
|
|
63
63
|
u,
|
|
64
|
-
|
|
65
|
-
r,
|
|
64
|
+
n(P.partyUuid),
|
|
66
65
|
s,
|
|
67
|
-
|
|
66
|
+
r,
|
|
67
|
+
o
|
|
68
68
|
);
|
|
69
|
-
|
|
69
|
+
v.push(G);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
[((
|
|
74
|
-
title:
|
|
72
|
+
const j = k.reduce((o, d) => (n(d.id) && o.push({ ...d, groupId: "favorites" }), o), []), H = v.reduce((o, d) => (n(d.id) && o.push({ ...d, groupId: "favorites" }), o), []), M = [...j, ...H], x = [F, ...M, ...k, ...v], V = x.find((o) => (o == null ? void 0 : o.selected) === !0), w = {
|
|
73
|
+
[((A = v[0]) == null ? void 0 : A.groupId) || "company"]: {
|
|
74
|
+
title: l.account_orgs,
|
|
75
75
|
divider: !0
|
|
76
76
|
},
|
|
77
|
-
[((
|
|
78
|
-
title:
|
|
77
|
+
[((N = k[0]) == null ? void 0 : N.groupId) || "person"]: {
|
|
78
|
+
title: l.account_persons,
|
|
79
79
|
divider: !0
|
|
80
80
|
},
|
|
81
81
|
favorites: {
|
|
82
|
-
title:
|
|
82
|
+
title: l.account_favorites,
|
|
83
83
|
divider: !0
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
|
-
return [
|
|
86
|
+
return [x, w, V];
|
|
87
87
|
}, [
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
t,
|
|
89
|
+
m,
|
|
90
90
|
e,
|
|
91
91
|
u,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
f,
|
|
93
|
+
s,
|
|
94
94
|
c,
|
|
95
|
-
|
|
95
|
+
r
|
|
96
96
|
]);
|
|
97
|
-
return
|
|
97
|
+
return f || !t || !a ? {
|
|
98
98
|
accountMenu: {
|
|
99
99
|
items: [],
|
|
100
100
|
groups: {},
|
|
@@ -103,71 +103,73 @@ const P = (o) => o === "Organization" ? "company" : "person", ot = ({
|
|
|
103
103
|
},
|
|
104
104
|
currentAccount: void 0
|
|
105
105
|
},
|
|
106
|
-
loading:
|
|
106
|
+
loading: f
|
|
107
107
|
} : {
|
|
108
108
|
accountMenu: {
|
|
109
|
-
items:
|
|
110
|
-
groups:
|
|
111
|
-
isVirtualized:
|
|
112
|
-
onSelectAccount:
|
|
113
|
-
currentAccount:
|
|
109
|
+
items: i,
|
|
110
|
+
groups: b,
|
|
111
|
+
isVirtualized: h,
|
|
112
|
+
onSelectAccount: _,
|
|
113
|
+
currentAccount: a
|
|
114
114
|
},
|
|
115
115
|
loading: !1
|
|
116
116
|
};
|
|
117
|
-
},
|
|
118
|
-
const
|
|
119
|
-
fullName: e.name,
|
|
120
|
-
type:
|
|
121
|
-
}),
|
|
122
|
-
fullName:
|
|
123
|
-
type:
|
|
117
|
+
}, g = (t, e, u, m, f, _, h, s, c) => {
|
|
118
|
+
const r = S((e == null ? void 0 : e.type) ?? ""), i = D(t), b = $({
|
|
119
|
+
fullName: e == null ? void 0 : e.name,
|
|
120
|
+
type: r
|
|
121
|
+
}), a = s ? $({
|
|
122
|
+
fullName: s == null ? void 0 : s.name,
|
|
123
|
+
type: S((s == null ? void 0 : s.type) ?? ""),
|
|
124
124
|
reverseNameOrder: !1
|
|
125
125
|
}) : void 0;
|
|
126
|
-
let
|
|
127
|
-
const
|
|
128
|
-
switch (
|
|
126
|
+
let n = "";
|
|
127
|
+
const l = r === "company" && s ? "subunit" : r;
|
|
128
|
+
switch (l) {
|
|
129
129
|
case "company":
|
|
130
|
-
|
|
130
|
+
n = `${i.org_no}: ${e.organizationNumber}`;
|
|
131
131
|
break;
|
|
132
132
|
case "person":
|
|
133
|
-
|
|
133
|
+
n = e != null && e.dateOfBirth ? `${i.birthdate}: ${W(e == null ? void 0 : e.dateOfBirth)}` : "";
|
|
134
134
|
break;
|
|
135
135
|
case "subunit":
|
|
136
|
-
|
|
136
|
+
n = `↳ ${i.org_no}: ${e == null ? void 0 : e.organizationNumber}, ${i.subunit_of} ${a}`;
|
|
137
137
|
break;
|
|
138
|
+
default:
|
|
139
|
+
n = "";
|
|
138
140
|
}
|
|
139
141
|
return {
|
|
140
|
-
id: e.partyUuid,
|
|
142
|
+
id: e == null ? void 0 : e.partyUuid,
|
|
141
143
|
icon: {
|
|
142
|
-
name:
|
|
143
|
-
type:
|
|
144
|
-
isParent: !
|
|
145
|
-
isDeleted: e.isDeleted,
|
|
146
|
-
colorKey:
|
|
144
|
+
name: b,
|
|
145
|
+
type: r,
|
|
146
|
+
isParent: !s,
|
|
147
|
+
isDeleted: e == null ? void 0 : e.isDeleted,
|
|
148
|
+
colorKey: a ?? void 0
|
|
147
149
|
},
|
|
148
|
-
name:
|
|
149
|
-
description:
|
|
150
|
+
name: b,
|
|
151
|
+
description: n,
|
|
150
152
|
groupId: u,
|
|
151
|
-
type:
|
|
152
|
-
selected:
|
|
153
|
-
disabled: !!e.onlyHierarchyElementWithNoAccess,
|
|
154
|
-
badge: c ? { label:
|
|
155
|
-
controls: !c && /* @__PURE__ */
|
|
156
|
-
|
|
153
|
+
type: l,
|
|
154
|
+
selected: m === (e == null ? void 0 : e.partyUuid),
|
|
155
|
+
disabled: !!(e != null && e.onlyHierarchyElementWithNoAccess),
|
|
156
|
+
badge: c ? { label: i.you, color: "person" } : e.isDeleted && h ? { label: i.deleted, color: "neutral" } : void 0,
|
|
157
|
+
controls: !c && /* @__PURE__ */ E(
|
|
158
|
+
R,
|
|
157
159
|
{
|
|
158
160
|
rounded: !0,
|
|
159
161
|
variant: "text",
|
|
160
|
-
icon:
|
|
161
|
-
iconAltText:
|
|
162
|
-
onClick: (
|
|
163
|
-
|
|
162
|
+
icon: f ? Y : q,
|
|
163
|
+
iconAltText: f ? i.remove_from_favorites : i.add_to_favorites,
|
|
164
|
+
onClick: (I) => {
|
|
165
|
+
_ && (I.stopPropagation(), _(e == null ? void 0 : e.partyUuid));
|
|
164
166
|
},
|
|
165
167
|
size: "xs"
|
|
166
168
|
}
|
|
167
169
|
)
|
|
168
170
|
};
|
|
169
|
-
},
|
|
170
|
-
switch (
|
|
171
|
+
}, J = (t) => t === "Organization", O = (t) => t === "Person" || t === "SelfIdentified", D = (t) => {
|
|
172
|
+
switch (t) {
|
|
171
173
|
case "nn":
|
|
172
174
|
return {
|
|
173
175
|
account_orgs: "Virksemder",
|
|
@@ -210,5 +212,5 @@ const P = (o) => o === "Organization" ? "company" : "person", ot = ({
|
|
|
210
212
|
}
|
|
211
213
|
};
|
|
212
214
|
export {
|
|
213
|
-
|
|
215
|
+
te as useAccountSelector
|
|
214
216
|
};
|