@7365admin1/layer-common 4.97.1-staging.743 → 4.97.1-staging.745

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.
@@ -9,15 +9,15 @@
9
9
  <v-card-title>Delete Card</v-card-title>
10
10
 
11
11
  <v-card-text class="screen-modal__body">
12
- <p class="text-center mb-4">
13
- Are you sure you want to delete this card? This action cannot be
14
- undone.
12
+ <!-- Names the card, so the operator can see which one goes (DV-2281). -->
13
+ <p class="text-center mb-4" data-test="delete-card-question">
14
+ {{ question }}
15
15
  </p>
16
16
 
17
- <v-form v-model="validForm" :disabled="loading">
17
+ <v-form ref="formRef" :disabled="loading">
18
18
  <InputLabel class="text-capitalize font-weight-bold" title="Remarks" required />
19
- <!-- Still a `v-textarea`, not an `AppField`: Delete Card is gated on
20
- `validForm`, which only exists because this `:rules` runs.
19
+ <!-- Still a `v-textarea`, not an `AppField`: Delete Card checks
20
+ this `:rules` on click, so an empty Remarks says so (DV-2280).
21
21
  `.filter-field` gives it the design's 10px corner and 13.5px
22
22
  type without taking the validation away. -->
23
23
  <v-textarea
@@ -28,7 +28,7 @@
28
28
  rows="3"
29
29
  auto-grow
30
30
  hide-details="auto"
31
- :rules="[requiredRule]"
31
+ :rules="[remarksRule]"
32
32
  />
33
33
  </v-form>
34
34
 
@@ -57,7 +57,7 @@
57
57
  variant="flat"
58
58
  class="screen-btn-primary"
59
59
  :loading="loading"
60
- :disabled="!validForm || loading"
60
+ :disabled="loading"
61
61
  @click="handleConfirm"
62
62
  >
63
63
  Delete Card
@@ -81,6 +81,11 @@ const props = defineProps({
81
81
  type: String,
82
82
  default: "",
83
83
  },
84
+ /** The number of the card being deleted, shown in the question. */
85
+ cardNo: {
86
+ type: String,
87
+ default: "",
88
+ },
84
89
  });
85
90
 
86
91
  const emit = defineEmits<{
@@ -88,15 +93,28 @@ const emit = defineEmits<{
88
93
  confirm: [remarks: string];
89
94
  }>();
90
95
 
91
- const { requiredRule } = useUtils();
92
-
93
- const validForm = ref(false);
96
+ // Delete Card stays clickable and checks Remarks itself: a button that only
97
+ // greyed out did nothing visible when clicked (DV-2280).
98
+ const formRef = ref<{
99
+ validate: () => Promise<{ valid: boolean }>;
100
+ resetValidation: () => void;
101
+ } | null>(null);
102
+ const remarksRule = (v: string) => !!(v && v.trim()) || "Remarks is required";
94
103
  const remarks = ref("");
95
104
 
105
+ const question = computed(() =>
106
+ props.cardNo
107
+ ? `Are you sure you want to delete card ${props.cardNo}? This action cannot be undone.`
108
+ : "Are you sure you want to delete this card? This action cannot be undone.",
109
+ );
110
+
96
111
  watch(
97
112
  () => props.modelValue,
98
113
  (val) => {
99
- if (val) remarks.value = "";
114
+ if (val) {
115
+ remarks.value = "";
116
+ formRef.value?.resetValidation();
117
+ }
100
118
  }
101
119
  );
102
120
 
@@ -104,8 +122,9 @@ function handleClose() {
104
122
  emit("update:modelValue", false);
105
123
  }
106
124
 
107
- function handleConfirm() {
108
- if (!validForm.value) return;
125
+ async function handleConfirm() {
126
+ const { valid } = (await formRef.value?.validate()) ?? { valid: false };
127
+ if (!valid || !remarks.value.trim()) return;
109
128
  emit("confirm", remarks.value.trim());
110
129
  }
111
130
  </script>
@@ -391,7 +391,7 @@
391
391
  @click="emit('delete')"
392
392
  class="text-error"
393
393
  :disabled="!isSelectedCardDeletable"
394
- v-if="canDeleteAccessCard"
394
+ v-if="canDeleteAccessCard && !isSelectedCardInactive"
395
395
  >
396
396
  <v-list-item-title class="text-subtitle-2">
397
397
  Delete Card
@@ -405,6 +405,7 @@
405
405
  </template>
406
406
 
407
407
  <script setup lang="ts">
408
+ import { cardStateInUnit, isInactiveCardState } from "../utils/access-card-state";
408
409
  const props = defineProps({
409
410
  modelValue: {
410
411
  type: Boolean,
@@ -593,6 +594,12 @@ const isSelectedCardAvailable = computed(() => {
593
594
  ].some((c) => c._id === id);
594
595
  });
595
596
 
597
+ // A deleted or replaced card is already deactivated: Delete Card is not shown
598
+ // for it at all (DV-2278), rather than shown greyed out.
599
+ const isSelectedCardInactive = computed(() =>
600
+ isInactiveCardState(cardStateInUnit(props.unit, props.selectedCardInUnit?._id))
601
+ );
602
+
596
603
  const isSelectedCardDeletable = computed(() => {
597
604
  if (!props.selectedCardInUnit?._id) return false;
598
605
  const id = props.selectedCardInUnit._id;
@@ -3,7 +3,7 @@
3
3
  <v-card-title>Replace Access Card</v-card-title>
4
4
 
5
5
  <v-card-text class="screen-modal__body pa-0">
6
- <v-form v-model="validForm" :disabled="loading">
6
+ <v-form ref="formRef" :disabled="loading">
7
7
  <v-row no-gutters class="px-6 pt-4 pb-6">
8
8
  <!-- Card being replaced -->
9
9
  <v-col cols="12" class="px-1 mb-4">
@@ -26,9 +26,10 @@
26
26
  title="Replacement Card"
27
27
  required
28
28
  />
29
- <!-- Both inputs keep their `:rules`: Replace is gated on
30
- `validForm`. `.filter-field` gives them the design's shape
31
- without touching the validation. -->
29
+ <!-- Both inputs keep their `:rules`, and Replace checks them on
30
+ click so an empty field says what is missing (DV-2280).
31
+ `.filter-field` gives them the design's shape without
32
+ touching the validation. -->
32
33
  <v-autocomplete
33
34
  v-model="form.replacementCardId"
34
35
  class="filter-field"
@@ -39,7 +40,7 @@
39
40
  item-value="_id"
40
41
  placeholder="Select replacement card..."
41
42
  persistent-placeholder
42
- :rules="[requiredRule]"
43
+ :rules="[replacementRule]"
43
44
  :no-data-text="noDataText"
44
45
  />
45
46
  </v-col>
@@ -60,7 +61,7 @@
60
61
  persistent-placeholder
61
62
  rows="3"
62
63
  auto-grow
63
- :rules="[requiredRule]"
64
+ :rules="[remarksRule]"
64
65
  />
65
66
  </v-col>
66
67
  </v-row>
@@ -88,7 +89,7 @@
88
89
  block
89
90
  variant="flat"
90
91
  class="text-none screen-btn-primary"
91
- :disabled="!validForm || loading"
92
+ :disabled="loading"
92
93
  :loading="loading"
93
94
  @click="submit"
94
95
  >
@@ -116,9 +117,12 @@ const props = defineProps({
116
117
  });
117
118
  const emit = defineEmits(["cancel", "success", "error"]);
118
119
 
119
- const { requiredRule } = useUtils();
120
-
121
- const validForm = ref(false);
120
+ // Replace stays clickable and checks the fields itself: a button that only
121
+ // greyed out showed no message, and an empty card once reached the API as
122
+ // `"issuedCardId" must be a string` (DV-2280).
123
+ const formRef = ref<{ validate: () => Promise<{ valid: boolean }> } | null>(null);
124
+ const replacementRule = (v: string | null) => !!v || "Select a replacement card";
125
+ const remarksRule = (v: string) => !!(v && v.trim()) || "Remarks is required";
122
126
  const loading = ref(false);
123
127
 
124
128
  const form = ref({
@@ -157,6 +161,8 @@ function cancel() {
157
161
  }
158
162
 
159
163
  async function submit() {
164
+ const { valid } = (await formRef.value?.validate()) ?? { valid: false };
165
+ if (!valid || !form.value.replacementCardId || !form.value.remarks.trim()) return;
160
166
  loading.value = true;
161
167
  try {
162
168
  const { replaceCard } = useCard();
@@ -164,9 +170,9 @@ async function submit() {
164
170
  // @TODO: userId should be the ID of the unit owner, not the current user
165
171
  await replaceCard({
166
172
  cardId: props.card._id,
167
- issuedCardId: form.value.replacementCardId!,
173
+ issuedCardId: form.value.replacementCardId,
168
174
  unitId: props.unit._id,
169
- remarks: form.value.remarks,
175
+ remarks: form.value.remarks.trim(),
170
176
  userId: currentUser.value?._id ?? "",
171
177
  });
172
178
  emit("success");
@@ -141,6 +141,7 @@
141
141
  v-model="confirmDialog"
142
142
  :loading="deleteLoading"
143
143
  :error="deleteError"
144
+ :card-no="selectedCardInUnit?.cardNo ?? ''"
144
145
  @confirm="handleDeleteCard"
145
146
  />
146
147
 
@@ -400,7 +401,7 @@ async function handleDeleteCard(remarks: string) {
400
401
  previewDialog.value = false;
401
402
  showMessage("Access card deleted successfully!", "success");
402
403
  } catch (error: any) {
403
- const msg = error?.response?._data?.message || "Failed to delete card";
404
+ const msg = error?.response?._data?.message || error?.data?.message || "Failed to delete card";
404
405
  deleteError.value = msg;
405
406
  showMessage(msg, "error");
406
407
  } finally {
@@ -111,6 +111,7 @@
111
111
  :items="filteredCardItems"
112
112
  :loading="cardsLoading"
113
113
  :hide-no-data="false"
114
+ :no-data-text="nfcNoDataText"
114
115
  item-title="cardNo"
115
116
  item-value="_id"
116
117
  density="comfortable"
@@ -415,6 +416,18 @@ const cardsLoadingMore = ref(false);
415
416
  // Typed text in the card picker. Reset after each pick so the next search
416
417
  // starts from the full list instead of staying narrowed to the last term.
417
418
  const cardSearch = ref("");
419
+
420
+ // What an empty card list means, said the way the QR Pass hint does: it was
421
+ // a bare "No data available" (DV-2282).
422
+ const nfcNoDataText = computed(() => {
423
+ if (cardsLoading.value) return "Loading cards...";
424
+ const term = (cardSearch.value ?? "").trim();
425
+ if (term) return `No cards match "${term}".`;
426
+ if (cardItems.value.length > 0) {
427
+ return "Every available NFC card is already picked for this visit.";
428
+ }
429
+ return "No NFC cards available. Add a physical card to this unit in Access Management.";
430
+ });
418
431
  const CARD_PAGE_SIZE = 100;
419
432
  const cardPage = ref(1);
420
433
  const cardHasMore = ref(false);
@@ -992,9 +992,13 @@ const saveResult = ref<{
992
992
  barrier?: TBarrierOutcome;
993
993
  /** The camera the barrier is at, "Entry Gate 1". */
994
994
  barrierCamera?: string;
995
+ /** Why the entry pass (QR or NFC) was not issued; unset when it was. */
996
+ passError?: string;
995
997
  }>({
996
998
  action: "add",
997
999
  });
1000
+ const ENTRY_PASS_NOT_ISSUED =
1001
+ "Visitor saved, but the entry pass was not issued and no card is assigned.";
998
1002
  const hidQrPreview = reactive({
999
1003
  imageUrl: "",
1000
1004
  issuedAt: "",
@@ -3120,8 +3124,10 @@ async function submit(options: { skipNonCheckedOutCheck?: boolean } = {}) {
3120
3124
  return;
3121
3125
  }
3122
3126
 
3123
- // The entry pass (isecure365 `onSubmit`), messages verbatim.
3124
- if (prop.type === "contractor" && showEntryPassInformation.value) {
3127
+ // The entry pass (isecure365 `onSubmit`), messages verbatim. Every visitor
3128
+ // type the section is shown to: a Guest or Walk-In can pick QR or NFC too
3129
+ // (DV-2279), and the checks only run for the pass type picked.
3130
+ if (showEntryPassInformation.value) {
3125
3131
  if (passType.value === "NFC" && passCards.value.length === 0) {
3126
3132
  errorMessage.value = "Please select at least one NFC card before proceeding.";
3127
3133
  return;
@@ -3222,10 +3228,11 @@ async function submit(options: { skipNonCheckedOutCheck?: boolean } = {}) {
3222
3228
  return;
3223
3229
  }
3224
3230
 
3225
- // The contractor's entry pass, issued once the visitor exists - for a
3226
- // register too, against the record being registered.
3231
+ // The entry pass, issued once the visitor exists - for a register too,
3232
+ // against the record being registered. Any visitor type the section was
3233
+ // shown to: a Guest or Walk-In whose NFC card was picked had it dropped
3234
+ // here before (DV-2279).
3227
3235
  if (
3228
- prop.type === "contractor" &&
3229
3236
  showEntryPassInformation.value &&
3230
3237
  (passType.value === "QR" || passType.value === "NFC")
3231
3238
  ) {
@@ -3248,9 +3255,17 @@ async function submit(options: { skipNonCheckedOutCheck?: boolean } = {}) {
3248
3255
  }
3249
3256
  }
3250
3257
 
3251
- /** Never fails the save: the visitor is already saved. */
3258
+ /**
3259
+ * Never fails the save: the visitor is already saved. A pass that is not
3260
+ * issued goes into `saveResult.passError`, which the list shows once this
3261
+ * dialog has closed. A snackbar here closed with the dialog, so nobody saw
3262
+ * why the card stayed unassigned (DV-2279).
3263
+ */
3252
3264
  async function issueEntryPass(visitorId: string, payload: Record<string, unknown>) {
3253
- if (!visitorId) return;
3265
+ if (!visitorId) {
3266
+ saveResult.value = { ...saveResult.value, passError: ENTRY_PASS_NOT_ISSUED };
3267
+ return;
3268
+ }
3254
3269
  try {
3255
3270
  const rawUrl = entryPassSettings.value?.data?.settings?.url;
3256
3271
  const { encrypted: acmUrl } = await $fetch<{ encrypted: string }>(
@@ -3314,10 +3329,11 @@ async function issueEntryPass(visitorId: string, payload: Record<string, unknown
3314
3329
  }
3315
3330
  }
3316
3331
  } catch (error: any) {
3317
- showSnackbar(
3318
- `Visitor saved, pass not issued. The visitor was registered, but the entry pass could not be issued. ${error?.data?.message ?? error?.message ?? ""}`.trim(),
3319
- "error"
3320
- );
3332
+ const reason = String(error?.data?.message ?? error?.message ?? "").trim();
3333
+ saveResult.value = {
3334
+ ...saveResult.value,
3335
+ passError: reason ? `${ENTRY_PASS_NOT_ISSUED} ${reason}` : ENTRY_PASS_NOT_ISSUED,
3336
+ };
3321
3337
  }
3322
3338
  }
3323
3339
 
@@ -3572,6 +3572,8 @@ type TVisitorFormResult = {
3572
3572
  barrier?: "opened" | "failed";
3573
3573
  /** The camera the barrier is at, "Entry Gate 1". */
3574
3574
  barrierCamera?: string;
3575
+ /** Why the entry pass was not issued (DV-2279); unset when it was. */
3576
+ passError?: string;
3575
3577
  };
3576
3578
 
3577
3579
  function visitorSavedMessage(result?: TVisitorFormResult) {
@@ -3580,15 +3582,29 @@ function visitorSavedMessage(result?: TVisitorFormResult) {
3580
3582
  return VISITOR_SAVED_MESSAGE;
3581
3583
  }
3582
3584
 
3583
- function handleVisitorFormDone(result?: TVisitorFormResult) {
3585
+ /**
3586
+ * The save message, then the entry pass failure in red under it. The form has
3587
+ * closed by now, so this toast is the only place the reason can be read.
3588
+ */
3589
+ function showVisitorSaved(result?: TVisitorFormResult) {
3584
3590
  showMessage(visitorSavedMessage(result), "success", result?.barrier, result?.barrierCamera);
3591
+ if (!result?.passError) return;
3592
+ const barrierText = messageDetail.value.text;
3593
+ messageDetail.value = {
3594
+ text: barrierText ? `${barrierText} ${result.passError}` : result.passError,
3595
+ tone: "error",
3596
+ };
3597
+ }
3598
+
3599
+ function handleVisitorFormDone(result?: TVisitorFormResult) {
3600
+ showVisitorSaved(result);
3585
3601
  getVisitorRefresh();
3586
3602
  dialog.showSelection = false;
3587
3603
  dialog.showForm = false;
3588
3604
  }
3589
3605
 
3590
3606
  function handleVisitorFormCreateMore(result?: TVisitorFormResult) {
3591
- showMessage(visitorSavedMessage(result), "success", result?.barrier, result?.barrierCamera);
3607
+ showVisitorSaved(result);
3592
3608
  getVisitorRefresh();
3593
3609
  dialog.showSelection = true;
3594
3610
  dialog.showForm = false;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@7365admin1/layer-common",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "4.97.1-staging.743",
5
+ "version": "4.97.1-staging.745",
6
6
  "author": "7365admin1",
7
7
  "main": "./nuxt.config.ts",
8
8
  "//files": "What a consumer extending this layer actually loads. Without this npm ships the whole working tree - the changesets, the CI workflows, the render harness in tools/ and any scratch directory that happened to exist at publish time. Nuxt resolves a layer by directory, so every runtime directory below has to stay listed; adding a new top-level runtime directory means adding it here too.",
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Which of a unit's card lists a card is in, as the Cards preview dialog shows
3
+ * them. A deleted or replaced card is already deactivated, so the dialog does
4
+ * not offer Delete Card for it (DV-2278).
5
+ */
6
+ export type CardState = "available" | "assigned" | "replaced" | "deleted";
7
+
8
+ const STATES: CardState[] = ["available", "assigned", "replaced", "deleted"];
9
+
10
+ export function cardStateInUnit(
11
+ unit: Record<string, any> | null | undefined,
12
+ cardId: string | null | undefined,
13
+ ): CardState | null {
14
+ if (!unit || !cardId) return null;
15
+ for (const state of STATES) {
16
+ const lists = unit[state];
17
+ const cards = [...(lists?.physical ?? []), ...(lists?.non_physical ?? [])];
18
+ if (cards.some((c: any) => c?._id === cardId)) return state;
19
+ }
20
+ return null;
21
+ }
22
+
23
+ export function isInactiveCardState(state: CardState | null): boolean {
24
+ return state === "deleted" || state === "replaced";
25
+ }