@7365admin1/layer-common 4.26.1-staging.355 → 4.28.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -4
  2. package/components/AccessCardAddForm.vue +4 -5
  3. package/components/AccessCardAssignToUnitForm.vue +2 -3
  4. package/components/AccessCardPreviewDialog.vue +3 -4
  5. package/components/Dialog/UpdateMoreAction.vue +1 -11
  6. package/components/DocumentForm.vue +112 -407
  7. package/components/DocumentManagement.vue +12 -213
  8. package/components/EntryPass/QrTemplatePreview.vue +25 -21
  9. package/components/EntryPassInformation.vue +24 -119
  10. package/components/Facility/BookingSetup.vue +0 -63
  11. package/components/HidAccessLogDashboard.vue +5 -29
  12. package/components/HidIntercomManagement.vue +14 -148
  13. package/components/HidReaderManagement.vue +0 -26
  14. package/components/HidReaderUserRoster.vue +2 -32
  15. package/components/HidUserEnrollment.vue +152 -833
  16. package/components/InvitationClientForm.vue +1 -19
  17. package/components/RolePermissionFormCreate.vue +19 -163
  18. package/components/RolePermissionFormPreviewUpdate.vue +19 -230
  19. package/components/RolePermissionMain.vue +0 -19
  20. package/components/VisitorManagement.vue +5 -267
  21. package/composables/useAccessManagement.ts +0 -5
  22. package/composables/useDocument.ts +0 -7
  23. package/composables/useFacility.ts +0 -11
  24. package/composables/useHidAmico.ts +0 -117
  25. package/composables/useHidNavigation.ts +1 -25
  26. package/composables/usePeople.ts +0 -19
  27. package/composables/useSiteEntryPassSettings.ts +0 -26
  28. package/composables/useWebUsb.ts +11 -14
  29. package/package.json +1 -1
  30. package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
  31. package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
  32. package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
  33. package/types/document.d.ts +0 -14
  34. package/types/facility.d.ts +0 -4
  35. package/types/people.d.ts +1 -28
  36. package/utils/permission-labels.ts +0 -30
  37. package/components/HidAccessPermissions.vue +0 -424
  38. package/components/HidProfileQrCode.vue +0 -323
  39. package/composables/useSiteCategory.ts +0 -45
  40. package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
  41. package/utils/hid-permission-assignments.ts +0 -190
  42. package/utils/occupancy-role.ts +0 -109
@@ -1,323 +0,0 @@
1
- <!--
2
- MY HID QR CODE.
3
-
4
- The signed-in member's own pass for one reader. Every other HID screen acts on
5
- somebody else - a resident being enrolled, a visitor being issued a pass. This
6
- one has no subject picker at all, because the server takes the caller from the
7
- session and there is no user id to send.
8
-
9
- Issuing a code does NOT grant access. A member's door permission comes from the
10
- HID permissions screen, and minting an access rule here would let anyone who
11
- can press Generate admit themselves. So the screen reports what the permissions
12
- screen says (`assigned`) and warns when a code would be refused at the door,
13
- rather than handing out something that silently fails.
14
- -->
15
- <template>
16
- <div class="hid-profile-qr">
17
- <div class="hid-profile-qr__header">
18
- <h2 class="hid-profile-qr__title">HID QR Code</h2>
19
- <AppSelect
20
- v-if="readerOptions.length"
21
- v-model="selectedReaderId"
22
- class="reader-select"
23
- :items="readerOptions"
24
- @update:model-value="loadProfile"
25
- />
26
- </div>
27
-
28
- <v-card class="screen-modal hid-profile-qr__card">
29
- <v-card-text class="screen-modal__body">
30
- <div v-if="loading" class="hid-profile-qr__state">Loading...</div>
31
-
32
- <div v-else-if="!readerOptions.length" class="hid-profile-qr__state">
33
- No HID reader is set up for this site yet.
34
- </div>
35
-
36
- <template v-else>
37
- <p class="hid-profile-qr__reader">
38
- {{ profile?.readerName || "HID reader" }}
39
- <span>{{ profile?.portalName || "Portal not configured" }}</span>
40
- </p>
41
-
42
- <!-- A code this reader cannot read is worse than no code, so the
43
- capability is checked before anything is offered. -->
44
- <v-alert
45
- v-if="profile && !profile.qrEnabled"
46
- type="warning"
47
- variant="tonal"
48
- density="compact"
49
- class="mb-4"
50
- >
51
- This reader is not set up to read QR codes.
52
- </v-alert>
53
-
54
- <!-- The honest part: a code opens the door only for a member the
55
- permissions screen already admits. `assigned` is null when the
56
- lookup failed, which is not the same as "no". -->
57
- <v-alert
58
- v-else-if="profile && profile.assigned === false"
59
- type="warning"
60
- variant="tonal"
61
- density="compact"
62
- class="mb-4"
63
- >
64
- You are not assigned to this reader, so this code will be refused at
65
- the door. Ask a property manager to add you on the HID permissions
66
- screen.
67
- </v-alert>
68
-
69
- <div v-if="qrImage" class="hid-profile-qr__code">
70
- <img :src="qrImage" alt="Your HID QR code" width="220" height="220" />
71
- <p class="hid-profile-qr__issued">
72
- Issued {{ formatIssuedAt(profile?.issuedAt) }}
73
- </p>
74
- </div>
75
- <p v-else class="hid-profile-qr__state">
76
- You have no QR code on this reader yet.
77
- </p>
78
-
79
- <div class="hid-profile-qr__actions">
80
- <AppButton
81
- :disabled="working || !profile?.qrEnabled"
82
- @click="generate"
83
- >
84
- {{ profile?.issued ? "Regenerate" : "Generate QR Code" }}
85
- </AppButton>
86
- <AppButton
87
- v-if="qrImage"
88
- variant="ghost"
89
- icon="mdi-download"
90
- @click="downloadQr"
91
- >
92
- Download
93
- </AppButton>
94
- <AppButton
95
- v-if="profile?.issued"
96
- variant="ghost"
97
- :disabled="working"
98
- @click="remove"
99
- >
100
- Remove
101
- </AppButton>
102
- </div>
103
-
104
- <p class="field-hint">
105
- Regenerating replaces the previous code. The old one stops working
106
- immediately.
107
- </p>
108
- </template>
109
- </v-card-text>
110
- </v-card>
111
-
112
- <v-snackbar v-model="snackbar.show" :color="snackbar.color" timeout="4000">
113
- {{ snackbar.message }}
114
- </v-snackbar>
115
- </div>
116
- </template>
117
-
118
- <script setup lang="ts">
119
- import QRCode from "qrcode";
120
- import type { HidProfileQr } from "../composables/useHidAmico";
121
-
122
- const props = defineProps<{ site: string }>();
123
-
124
- const { getReaders, getProfileQr, issueProfileQr, deleteProfileQr } = useHidAmico();
125
-
126
- type HidReaderOption = { _id: string; name?: string; portalName?: string };
127
-
128
- const readers = ref<HidReaderOption[]>([]);
129
- const selectedReaderId = ref("");
130
- const profile = ref<HidProfileQr | null>(null);
131
- const qrImage = ref("");
132
- const loading = ref(false);
133
- const working = ref(false);
134
- const snackbar = reactive({ show: false, color: "success", message: "" });
135
-
136
- const readerOptions = computed(() => readers.value.map((reader) => ({
137
- title: `${reader.name || reader._id} — ${reader.portalName || "Portal not configured"}`,
138
- value: reader._id,
139
- })));
140
-
141
- function showToast(message: string, color: "success" | "error" = "success") {
142
- snackbar.message = message;
143
- snackbar.color = color;
144
- snackbar.show = true;
145
- }
146
-
147
- function toRecord(value: unknown): Record<string, any> {
148
- return value && typeof value === "object" ? (value as Record<string, any>) : {};
149
- }
150
-
151
- function errorMessage(error: unknown) {
152
- const record = toRecord(error);
153
- return String(toRecord(record.data).message || record.message || "Something went wrong.");
154
- }
155
-
156
- function formatIssuedAt(value?: string) {
157
- if (!value) return "";
158
- const date = new Date(value);
159
- return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
160
- }
161
-
162
- /**
163
- * The image is drawn here, never fetched. The value is the credential itself,
164
- * so keeping it on this page and out of any URL is the point.
165
- */
166
- async function renderQr(value: string) {
167
- if (!value) {
168
- qrImage.value = "";
169
- return;
170
- }
171
- try {
172
- qrImage.value = await QRCode.toDataURL(value, { width: 440, margin: 1 });
173
- } catch (error) {
174
- console.error("Unable to render the HID QR code:", error);
175
- qrImage.value = "";
176
- }
177
- }
178
-
179
- /**
180
- * Saves the rendered code as a PNG.
181
- *
182
- * Straight off the data URL already in the page - no request, so the credential
183
- * never travels again to be downloaded. Same anchor-click approach `VisitorForm`
184
- * uses for a visitor pass, and the reader name is in the file name because a
185
- * member can hold one code per reader.
186
- */
187
- function downloadQr() {
188
- if (!qrImage.value) return;
189
- const slug = String(profile.value?.readerName || "reader")
190
- .trim()
191
- .replace(/[^a-z0-9]+/gi, "-")
192
- .replace(/^-|-$/g, "")
193
- .toLowerCase();
194
- const link = document.createElement("a");
195
- link.href = qrImage.value;
196
- link.download = `hid-qr-${slug || "reader"}.png`;
197
- link.click();
198
- }
199
-
200
- async function loadReaders() {
201
- if (!props.site) return;
202
- const response = toRecord(await getReaders({ site: props.site, page: 1, limit: 100 }));
203
- const data = toRecord(response.data);
204
- const items = response.items ?? data.items ?? data.readers ?? [];
205
- readers.value = (Array.isArray(items) ? items : []).filter((reader) => reader?._id);
206
- if (!selectedReaderId.value && readers.value.length) {
207
- selectedReaderId.value = String(readers.value[0]._id);
208
- }
209
- }
210
-
211
- async function loadProfile() {
212
- if (!selectedReaderId.value) return;
213
- loading.value = true;
214
- try {
215
- const response = await getProfileQr(selectedReaderId.value);
216
- profile.value = response?.data ?? null;
217
- await renderQr(profile.value?.qrValue || "");
218
- } catch (error: unknown) {
219
- profile.value = null;
220
- qrImage.value = "";
221
- showToast(errorMessage(error), "error");
222
- } finally {
223
- loading.value = false;
224
- }
225
- }
226
-
227
- async function generate() {
228
- if (!selectedReaderId.value) return;
229
- working.value = true;
230
- try {
231
- const response = await issueProfileQr(selectedReaderId.value);
232
- profile.value = response?.data ?? null;
233
- await renderQr(profile.value?.qrValue || "");
234
- showToast("QR code generated.");
235
- } catch (error: unknown) {
236
- showToast(errorMessage(error), "error");
237
- } finally {
238
- working.value = false;
239
- }
240
- }
241
-
242
- async function remove() {
243
- if (!selectedReaderId.value) return;
244
- if (!window.confirm("Remove your QR code from this reader?")) return;
245
- working.value = true;
246
- try {
247
- const response = await deleteProfileQr(selectedReaderId.value);
248
- profile.value = response?.data ?? null;
249
- await renderQr("");
250
- showToast("QR code removed.");
251
- } catch (error: unknown) {
252
- showToast(errorMessage(error), "error");
253
- } finally {
254
- working.value = false;
255
- }
256
- }
257
-
258
- watch(
259
- () => props.site,
260
- async () => {
261
- await loadReaders();
262
- await loadProfile();
263
- },
264
- { immediate: true },
265
- );
266
- </script>
267
-
268
- <style scoped>
269
- .hid-profile-qr__header {
270
- display: flex;
271
- align-items: center;
272
- gap: 12px;
273
- flex-wrap: wrap;
274
- }
275
-
276
- .hid-profile-qr__title {
277
- margin: 0;
278
- font-size: 18px;
279
- font-weight: 600;
280
- }
281
-
282
- .hid-profile-qr__card {
283
- margin-top: 16px;
284
- max-width: 460px;
285
- }
286
-
287
- .hid-profile-qr__reader {
288
- margin: 0 0 14px;
289
- font-size: 14px;
290
- font-weight: 600;
291
- }
292
-
293
- .hid-profile-qr__reader span {
294
- display: block;
295
- color: var(--muted);
296
- font-size: 12px;
297
- font-weight: 500;
298
- }
299
-
300
- .hid-profile-qr__code {
301
- display: grid;
302
- place-items: center;
303
- margin-bottom: 14px;
304
- }
305
-
306
- .hid-profile-qr__issued {
307
- margin: 8px 0 0;
308
- color: var(--muted);
309
- font-size: 12px;
310
- }
311
-
312
- .hid-profile-qr__state {
313
- color: var(--muted);
314
- font-size: 13.5px;
315
- padding: 8px 0 14px;
316
- }
317
-
318
- .hid-profile-qr__actions {
319
- display: flex;
320
- gap: 8px;
321
- flex-wrap: wrap;
322
- }
323
- </style>
@@ -1,45 +0,0 @@
1
- /**
2
- * THE CATEGORY OF THE SITE THE USER IS CURRENTLY IN.
3
- *
4
- * One shared answer, published once by the application's layout from the site
5
- * it already loaded for the switcher, and read by anything that has to behave
6
- * differently on a commercial or industrial site - the business Add Tenant
7
- * form, the tenant list. Publishing it rather than re-fetching it per
8
- * component means no two screens can disagree about which site this is.
9
- *
10
- * READ FROM THE CUSTOMER-SITE RECORD, NOT THE SITE RECORD. Both carry a
11
- * `category` and `customer-site.service` keeps them equal (it writes the site
12
- * on create and on update), but `siteSchema` DEFAULTS the site's own copy to
13
- * `commercial` - so a site created without an explicit category reads back as
14
- * commercial there even when it is a residential estate. The customer-site
15
- * copy has no default: it is either the category somebody chose or nothing.
16
- *
17
- * An empty category means "not published yet" or "never set", and every
18
- * caller must behave as it did before this existed - never assume commercial
19
- * from silence.
20
- */
21
- const BUSINESS_SITE_CATEGORIES: string[] = ["commercial", "industrial"];
22
-
23
- export default function useSiteCategory() {
24
- const siteCategory = useState<string>("current-site-category", () => "");
25
-
26
- function setSiteCategory(value?: string | null) {
27
- siteCategory.value = typeof value === "string" ? value : "";
28
- }
29
-
30
- /**
31
- * The categories whose units are LET TO A BUSINESS rather than lived in.
32
- *
33
- * These are the sites where a unit has an owner, an occupier and often a
34
- * person in charge who is neither, so they are the sites that ask for a
35
- * tenant's standing and print it back (see `OCCUPANCY_ROLE_OPTIONS`).
36
- *
37
- * The category never changes what the APPLICATION is called: the rail says
38
- * Property Management on every site it serves.
39
- */
40
- const isBusinessSite = computed(() =>
41
- BUSINESS_SITE_CATEGORIES.includes(siteCategory.value),
42
- );
43
-
44
- return { siteCategory, isBusinessSite, setSiteCategory };
45
- }
@@ -1,23 +0,0 @@
1
- <template>
2
- <v-container fluid>
3
- <HidEnabledGate
4
- :site="siteId"
5
- :org="orgId"
6
- message="Enable HID as a service for this site before generating a QR code."
7
- >
8
- <HidProfileQrCode :site="siteId" />
9
- </HidEnabledGate>
10
- </v-container>
11
- </template>
12
-
13
- <script setup lang="ts">
14
- definePageMeta({
15
- layout: "default",
16
- middleware: ["01-auth", "02-org"],
17
- memberOnly: true,
18
- });
19
-
20
- const route = useRoute();
21
- const siteId = computed(() => String(route.params.site ?? ""));
22
- const orgId = computed(() => String(route.params.org ?? ""));
23
- </script>
@@ -1,190 +0,0 @@
1
- /**
2
- * WHO IS ASSIGNED TO A HID READER — the editing model behind the permissions
3
- * dialog.
4
- *
5
- * This is the step that actually grants access. Enrolling a person gives the
6
- * reader a face, a card or a PIN it can RECOGNISE; it puts nobody in the group
7
- * the access rule is attached to, so a recognised person is still refused at
8
- * the door (access log event 6). `PUT /sites/:siteId/permissions` is the only
9
- * call in the system that writes that group membership.
10
- *
11
- * Two contracts make this file necessary rather than inlining the logic in the
12
- * component:
13
- *
14
- * 1. **The PUT REPLACES the whole assignment set for the reader.** The server
15
- * keeps other readers' rows and overwrites this reader's with exactly what
16
- * is sent. The candidate list, however, is fetched ONE CATEGORY AT A TIME.
17
- * Saving from the tab in front of you while sending only that tab's people
18
- * would silently revoke every resident if you were looking at the service
19
- * providers tab. So the edit state is held for the whole reader and the
20
- * payload is always built from all of it.
21
- *
22
- * 2. **The body schema accepts three keys and nothing else.**
23
- * `hidPermissionAssignmentSchema` is `{ subjectId, category, intercom }`,
24
- * and Joi rejects unknown keys rather than stripping them. The candidate
25
- * rows carry `name`, `subtitle`, `location` and friends for display, so the
26
- * payload has to be narrowed deliberately — passing a candidate straight
27
- * through is a 400.
28
- */
29
-
30
- /** The three real categories. `intercom` is a candidate FILTER, never a category. */
31
- export const HID_PERMISSION_CATEGORIES: THidPermissionCategory[] = [
32
- "resident",
33
- "property_management",
34
- "service_provider",
35
- ];
36
-
37
- export type HidAssignmentState = Map<string, { category: THidPermissionCategory; intercom: boolean }>;
38
-
39
- /** Body row for `updateSitePermissions` — exactly the keys Joi allows. */
40
- export type HidAssignmentPayload = {
41
- subjectId: string;
42
- category: THidPermissionCategory;
43
- intercom: boolean;
44
- };
45
-
46
- function isRealCategory(value: unknown): value is THidPermissionCategory {
47
- return HID_PERMISSION_CATEGORIES.includes(value as THidPermissionCategory);
48
- }
49
-
50
- /**
51
- * The reader's CURRENT assignments, as the edit state.
52
- *
53
- * Seeded from `getSitePermissions`, which returns every category at once —
54
- * that is what makes a whole-reader payload possible from a one-category view.
55
- * Rows with an unrecognised category are dropped rather than carried: sending
56
- * one back fails the enum check and takes the entire save with it.
57
- */
58
- export function seedAssignments(
59
- assignments: readonly THidPermissionAssignment[] | undefined | null,
60
- ): HidAssignmentState {
61
- const state: HidAssignmentState = new Map();
62
- if (!Array.isArray(assignments)) return state;
63
- for (const assignment of assignments) {
64
- const subjectId = String(assignment?.subjectId ?? "");
65
- if (!subjectId || !isRealCategory(assignment?.category)) continue;
66
- state.set(subjectId, {
67
- category: assignment.category,
68
- intercom: assignment.intercom === true,
69
- });
70
- }
71
- return state;
72
- }
73
-
74
- /**
75
- * Add or remove one person.
76
- *
77
- * `saved` is the state the dialog opened with, and it is consulted for one
78
- * reason: the `intercom` flag. Nothing here edits that flag, but
79
- * `userHasSiteIntercomPermission` reads it off these same rows, so it must
80
- * survive a round trip through the checkbox.
81
- *
82
- * - **Untick then save** drops it, which is right — an unassigned person
83
- * holding a dangling intercom right would keep answering the door panel
84
- * after losing the door.
85
- * - **Untick then re-tick, without saving** must restore it. Removing from the
86
- * draft forgets the flag, so re-adding recovers it from `saved`; otherwise a
87
- * misclick corrected a second later would silently revoke intercom on the
88
- * next save, with nothing on screen to show it had happened.
89
- */
90
- export function setAssignment(
91
- state: HidAssignmentState,
92
- saved: HidAssignmentState,
93
- subjectId: string,
94
- category: THidPermissionCategory,
95
- selected: boolean,
96
- ): HidAssignmentState {
97
- const next: HidAssignmentState = new Map(state);
98
- const id = String(subjectId ?? "");
99
- if (!id || !isRealCategory(category)) return next;
100
- if (!selected) {
101
- next.delete(id);
102
- return next;
103
- }
104
- const intercom = next.get(id)?.intercom ?? saved.get(id)?.intercom ?? false;
105
- next.set(id, { category, intercom: intercom === true });
106
- return next;
107
- }
108
-
109
- /** The whole reader's assignments, narrowed to the three keys the API accepts. */
110
- export function toAssignmentPayload(state: HidAssignmentState): HidAssignmentPayload[] {
111
- return [...state.entries()].map(([subjectId, value]) => ({
112
- subjectId,
113
- category: value.category,
114
- intercom: value.intercom === true,
115
- }));
116
- }
117
-
118
- /**
119
- * The server sends `selected` with each candidate, describing what is SAVED.
120
- * Once the dialog is open the local edit state is the truth, so the flag is
121
- * recomputed rather than trusted — otherwise paging or searching would redraw
122
- * a row with the saved value and quietly discard an unsaved tick.
123
- */
124
- export function applySelection(
125
- candidates: readonly THidPermissionCandidate[] | undefined | null,
126
- state: HidAssignmentState,
127
- ): THidPermissionCandidate[] {
128
- if (!Array.isArray(candidates)) return [];
129
- return candidates.map((candidate) => ({
130
- ...candidate,
131
- selected: state.has(String(candidate?.subjectId ?? "")),
132
- }));
133
- }
134
-
135
- /** Per-category totals for the dialog header, counted over the whole reader. */
136
- export function countByCategory(state: HidAssignmentState): Record<THidPermissionCategory, number> {
137
- const counts = { resident: 0, property_management: 0, service_provider: 0 } as Record<
138
- THidPermissionCategory,
139
- number
140
- >;
141
- for (const value of state.values()) counts[value.category] += 1;
142
- return counts;
143
- }
144
-
145
- /** Has anything changed since the dialog opened? Drives the Save button. */
146
- export function hasChanges(saved: HidAssignmentState, draft: HidAssignmentState): boolean {
147
- if (saved.size !== draft.size) return true;
148
- for (const [subjectId, value] of draft) {
149
- const before = saved.get(subjectId);
150
- if (!before) return true;
151
- if (before.category !== value.category) return true;
152
- if (before.intercom !== value.intercom) return true;
153
- }
154
- return false;
155
- }
156
-
157
- /**
158
- * What a listing response tells us: the rows, and how many pages exist.
159
- *
160
- * It deliberately does NOT return the current page, and the caller must keep
161
- * owning that. `paginate` in `@7365admin1/node-server-utils` returns only
162
- * `{ items, pages, pageRange }` — it never echoes the page it was asked for. A
163
- * caller that read one back therefore got a default on every fetch and pinned
164
- * itself to page one, so the pager moved and the rows never did.
165
- *
166
- * `items` sits at the root on some of these endpoints and under `data` on
167
- * others, so both are read.
168
- */
169
- export function readCandidatePage(response: unknown): {
170
- items: THidPermissionCandidate[];
171
- pages: number;
172
- pageRange: string;
173
- } {
174
- const source = (response && typeof response === "object" ? response : {}) as Record<string, unknown>;
175
- const nested = (source.data && typeof source.data === "object" ? source.data : {}) as Record<string, unknown>;
176
- const items = Array.isArray(source.items)
177
- ? source.items
178
- : Array.isArray(nested.items)
179
- ? nested.items
180
- : [];
181
- const pages = Number(source.pages ?? nested.pages ?? 1);
182
- // `paginate` builds this ("1-10 of 37") and the table renders it verbatim.
183
- // Without it the pager draws its placeholder, "-- - -- of --".
184
- const pageRange = String(source.pageRange ?? nested.pageRange ?? "");
185
- return {
186
- items: items as THidPermissionCandidate[],
187
- pages: Number.isFinite(pages) && pages > 0 ? pages : 1,
188
- pageRange,
189
- };
190
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * OWNER / OCCUPANT / PERSON IN CHARGE - the three standings a business
3
- * tenancy has, and everything the product says about them.
4
- *
5
- * One list, because three screens read it: the form that asks the question
6
- * (`PeopleFormMgmt`), the list and preview that print the answer back, and
7
- * the row menu that reassigns it (`people-mgmt`). The values are the ones the
8
- * server stores and validates - `OccupancyRoles` in core's `person.model.ts`
9
- * - so a value added on one side has to be added on the other.
10
- */
11
- export const OCCUPANCY_ROLE_OPTIONS: TOccupancyRoleOption[] = [
12
- {
13
- value: "owner",
14
- title: "Owner",
15
- action: "Assign Owner",
16
- prompt: "Assign Owner",
17
- description:
18
- "The legal titleholder or primary deed owner of the property.",
19
- },
20
- {
21
- value: "occupant",
22
- title: "Occupant",
23
- action: "Assign Occupant",
24
- prompt: "Assign Occupant",
25
- description:
26
- "The person currently living in, renting, or utilizing the physical unit.",
27
- },
28
- {
29
- value: "person-in-charge",
30
- title: "Person in Charge",
31
- action: "Assign Person in Charge",
32
- prompt: "Assign Person in Charge (PIC)",
33
- description:
34
- "The designated manager responsible for maintenance, emergencies, and daily operations.",
35
- },
36
- ];
37
-
38
- /**
39
- * The same three, in the order the ROW MENU draws them, which is not the
40
- * order the form's radio does. Derived rather than re-typed so the wording
41
- * cannot drift between the two.
42
- */
43
- export const OCCUPANCY_ROLE_ACTIONS: TOccupancyRoleOption[] = (
44
- ["person-in-charge", "owner", "occupant"] as TOccupancyRole[]
45
- ).map(
46
- (value) =>
47
- OCCUPANCY_ROLE_OPTIONS.find(
48
- (option) => option.value === value,
49
- ) as TOccupancyRoleOption,
50
- );
51
-
52
- /**
53
- * The label for a stored role, or "" for a person who was never asked - which
54
- * is everyone on a residential site and everyone saved before the question
55
- * existed. Callers decide what to print instead; nobody should print a raw
56
- * `person-in-charge` at a user.
57
- */
58
- export function occupancyRoleLabel(role?: string | null): string {
59
- return (
60
- OCCUPANCY_ROLE_OPTIONS.find((option) => option.value === role)?.title ?? ""
61
- );
62
- }
63
-
64
- /**
65
- * Does this person hold OWNER at their unit?
66
- *
67
- * The role when there is one, `isOwner` when there is not - the same test the
68
- * server applies (`holdsUnitOwner` in core's `unit-owner.util.ts`). A person
69
- * recorded before the role existed carries only the flag, and the people list
70
- * already prints them as "Owner".
71
- */
72
- export function holdsUnitOwner(person?: {
73
- occupancyRole?: string | null;
74
- isOwner?: boolean;
75
- }): boolean {
76
- if (!person) return false;
77
-
78
- if (person.occupancyRole) return person.occupancyRole === "owner";
79
-
80
- return person.isOwner === true;
81
- }
82
-
83
- /**
84
- * MUST THIS PERSON HAND THE UNIT OVER BEFORE THEY CAN BE DEACTIVATED?
85
- *
86
- * The owner of a unit does not leave while they still own it - the standing
87
- * moves to another tenant at the same block, level and unit first.
88
- *
89
- * Keyed to the ROLE and never to `isOwner`, exactly as the server keys it
90
- * (`mustHandOverBeforeDeactivating` in core): the flag is on every resident in
91
- * the estate, and no residential screen can change it, so a rule keyed to it
92
- * would trap records that can never satisfy it.
93
- */
94
- export function mustHandOverBeforeDeactivating(person?: {
95
- occupancyRole?: string | null;
96
- }): boolean {
97
- return person?.occupancyRole === "owner";
98
- }
99
-
100
- /**
101
- * Why a deactivation was held back. The SERVER carries the enforcing copy of
102
- * this rule and of these words (core `unit-owner.util.ts`); this one exists so
103
- * the console can say it before the round trip rather than after.
104
- */
105
- export function ownerHandoverRequiredMessage(name?: string): string {
106
- const who = name?.trim() ? `"${name.trim()}"` : "This person";
107
-
108
- return `${who} is the owner of this unit. Assign the owner role to another tenant at the same block, level and unit before deactivating them.`;
109
- }