@7365admin1/layer-common 4.9.1-staging.306 → 4.9.1-staging.308

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.
@@ -254,7 +254,7 @@
254
254
 
255
255
  <v-card-text class="screen-modal__body pa-4">
256
256
  <v-row>
257
- <v-col cols="12">
257
+ <v-col v-if="canAddRemarks" cols="12">
258
258
  <InputLabel title="Remarks" :required="false" class="mb-2" />
259
259
  <!-- `.filter-field` is the design's field on a `v-textarea`: the
260
260
  10px corner and 13.5px type, without taking the binding away. -->
@@ -458,6 +458,7 @@
458
458
 
459
459
  <script setup lang="ts">
460
460
  import { readListPage } from "../utils/list-page";
461
+ import { isPhotoRefusal, isSetFinished } from "../utils/checklist-set";
461
462
  import useCleaningSchedules from "../composables/useCleaningSchedules";
462
463
  import useCustomerSite from "../composables/useCustomerSite";
463
464
  import useFile from "../composables/useFile";
@@ -526,12 +527,13 @@ function getKey(item: any, set?: number): string {
526
527
  }
527
528
 
528
529
  function isGroupComplete(group: { set: number; items: any[] }): boolean {
529
- return (
530
- group.items.length > 0 &&
531
- group.items.every(
532
- (item: any) =>
533
- item.approve === true ||
534
- activeActions[getKey(item, group.set)] === "approve"
530
+ return isSetFinished(
531
+ group.items.map((item: any) =>
532
+ item.approve === true
533
+ ? "approve"
534
+ : item.reject === true
535
+ ? "reject"
536
+ : activeActions[getKey(item, group.set)]
535
537
  )
536
538
  );
537
539
  }
@@ -555,11 +557,12 @@ function getGroupCompletedByName(group: {
555
557
  );
556
558
  }
557
559
 
558
- function isSetFullyApproved(setNumber: number): boolean {
560
+ /** Every unit approved or rejected, counting this screen's pending ticks. */
561
+ function isSetFinishedLocally(setNumber: number): boolean {
559
562
  const group = items.value.find((g: any) => g.set === setNumber);
560
563
  if (!group) return false;
561
- return (group.units || []).every(
562
- (unit: any) => activeActions[getKey(unit, setNumber)] === "approve"
564
+ return isSetFinished(
565
+ (group.units || []).map((unit: any) => activeActions[getKey(unit, setNumber)])
563
566
  );
564
567
  }
565
568
 
@@ -671,7 +674,8 @@ const modalData = reactive({
671
674
  */
672
675
  const isModalValid = computed(() => {
673
676
  return (
674
- modalData.remark?.trim().length > 0 && modalData.photoIds.length > 0
677
+ (!canAddRemarks.value || modalData.remark?.trim().length > 0) &&
678
+ modalData.photoIds.length > 0
675
679
  );
676
680
  });
677
681
 
@@ -851,23 +855,9 @@ function openCompletionDialog({
851
855
  return;
852
856
  }
853
857
 
854
- // If user does not need to add remarks, perform approvals immediately
855
- if (!canAddRemarks.value) {
856
- // call update directly without opening modal
857
- _updateUnitChecklist({
858
- remark: "",
859
- photos: [],
860
- photoIds: [],
861
- approvedItems,
862
- lastApprovedKey,
863
- setNumber,
864
- }).catch((err) => {
865
- console.error("Error auto-approving set:", err);
866
- showMessage(err?.message || "Failed to approve set", "error");
867
- });
868
- return;
869
- }
870
-
858
+ // Every role gets the dialog: finishing a set needs a photo. A role without
859
+ // add-remarks used to skip it and auto-approve with no photo, which the
860
+ // server refuses. That role sees no remarks field (see `isModalValid`).
871
861
  modalData.currentSet = setNumber;
872
862
  modalData.approvedItems = approvedItems;
873
863
  modalData.lastApprovedKey = lastApprovedKey;
@@ -961,7 +951,7 @@ async function handleItemActionClick(
961
951
  // Approve: check if this completes the entire set
962
952
  lastApprovedKey.value = key;
963
953
 
964
- if (isSetFullyApproved(set) && !completedSets.value.has(set)) {
954
+ if (isSetFinishedLocally(set) && !completedSets.value.has(set)) {
965
955
  const newApprovedItems = getNewApprovedItemsForSet(set);
966
956
  if (newApprovedItems.length > 0) {
967
957
  completedSets.value.add(set);
@@ -1012,11 +1002,22 @@ async function _callUpdateUnitChecklist(
1012
1002
  );
1013
1003
  await getUnitCleanerChecklistRefresh();
1014
1004
  } catch (error: any) {
1005
+ const reason = error?.data?.message || error?.message;
1006
+ if (action === "approve" && isPhotoRefusal(reason)) {
1007
+ // This screen's view was out of date (someone else ticked the rest of
1008
+ // the set), so this tick finishes it. Ask for the photo, don't fail.
1009
+ const key = getKey(item, set);
1010
+ activeActions[key] = "approve";
1011
+ completedSets.value.add(set);
1012
+ openCompletionDialog({
1013
+ setNumber: set,
1014
+ approvedItems: [{ key, item: { ...item, set }, action: "approve" }],
1015
+ lastApprovedKey: key,
1016
+ });
1017
+ return;
1018
+ }
1015
1019
  console.error("Error updating unit checklist:", error);
1016
- showMessage(
1017
- error?.data?.message || error?.message || "Failed to update checklist",
1018
- "error"
1019
- );
1020
+ showMessage(reason || "Failed to update checklist", "error");
1020
1021
  } finally {
1021
1022
  submitting.value = false;
1022
1023
  if (action === "approve") {
@@ -1045,7 +1046,7 @@ async function _updateUnitChecklist({
1045
1046
  throw new Error("No items to approve");
1046
1047
  }
1047
1048
 
1048
- if (!remark?.trim()) {
1049
+ if (canAddRemarks.value && !remark?.trim()) {
1049
1050
  throw new Error("Remark is required");
1050
1051
  }
1051
1052
 
@@ -203,7 +203,11 @@
203
203
  // Relative import: this layer's `utils/` is not auto-imported into consumers.
204
204
  import { showSiteField } from "../utils/role";
205
205
  import { holdsPermission } from "../utils/permission-spellings";
206
- import { catalogueForOrg, effectiveModules } from "../utils/org-modules";
206
+ import {
207
+ catalogueForOrg,
208
+ effectiveModules,
209
+ siteModulesForOrg,
210
+ } from "../utils/org-modules";
207
211
 
208
212
  const props = defineProps({
209
213
  orgId: {
@@ -362,7 +366,8 @@ const offeredPermissions = computed(() =>
362
366
  props.permissions ?? {},
363
367
  effectiveModules(
364
368
  (orgForModules.value as any)?.modules,
365
- (siteForModules.value as any)?.metadata?.modules
369
+ // Only the site's OWN organisation is narrowed by it (owner Q1).
370
+ siteModulesForOrg(siteForModules.value as any, props.orgId)
366
371
  )
367
372
  )
368
373
  );
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.9.1-staging.306",
5
+ "version": "4.9.1-staging.308",
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,28 @@
1
+ /**
2
+ * WHICH TICK FINISHES A CHECKLIST SET — the one rule shared with the server and
3
+ * the five field apps.
4
+ *
5
+ * A task is a SET of units. A unit is done once it is approved OR rejected, and
6
+ * the set is finished when every unit is done. The server decides the same way
7
+ * (module-hygiene `readCompletion`, and the units list's `isFullyActioned`), and
8
+ * it requires a photo on the approve that finishes the set.
9
+ *
10
+ * This screen used to count approvals only. In a set holding a rejected unit it
11
+ * never saw the set as finished, so it sent the last approve without the photo
12
+ * dialog, and the server refused it.
13
+ */
14
+ export type UnitAction = "approve" | "reject" | undefined;
15
+
16
+ export function isSetFinished(actions: UnitAction[]): boolean {
17
+ return (
18
+ actions.length > 0 &&
19
+ actions.every((action) => action === "approve" || action === "reject")
20
+ );
21
+ }
22
+
23
+ /** The server's refusal for want of a photo (module-hygiene `COMPLETION_PHOTO_MESSAGE`). */
24
+ const PHOTO_REFUSAL = /photo is required to complete/i;
25
+
26
+ export function isPhotoRefusal(message: unknown): boolean {
27
+ return typeof message === "string" && PHOTO_REFUSAL.test(message);
28
+ }
@@ -187,6 +187,32 @@ export function effectiveModules(
187
187
  return allowed.length ? allowed : org;
188
188
  }
189
189
 
190
+ /**
191
+ * The site tier, but only for the organisation that OWNS the site.
192
+ *
193
+ * Owner Q1, 2026-09-11: a service provider's role editor follows the
194
+ * PROVIDER's own company modules, never the client's. A provider editing
195
+ * roles while working on a client's site passes that site's id, and the site
196
+ * list there is what the CLIENT chose for its own staff - so it must not
197
+ * narrow the provider. Only when the site belongs to the organisation whose
198
+ * roles are being edited does the site tier apply.
199
+ *
200
+ * Fails open: no site, no `orgId` on it, or no org to compare with all mean
201
+ * "no site tier", which leaves the organisation's own list in charge.
202
+ */
203
+ export function siteModulesForOrg(
204
+ site: { orgId?: unknown; org?: unknown; metadata?: { modules?: unknown } } | null | undefined,
205
+ orgId: unknown,
206
+ ): readonly string[] | undefined {
207
+ // `org` is the legacy field name; core reads `orgId ?? org` the same way.
208
+ const siteOrg = String(site?.orgId ?? site?.org ?? "");
209
+ const org = String(orgId ?? "");
210
+ if (!siteOrg || !org || siteOrg !== org) return undefined;
211
+
212
+ const modules = site?.metadata?.modules;
213
+ return Array.isArray(modules) ? modules : undefined;
214
+ }
215
+
190
216
  function isKey(value: unknown): value is string {
191
217
  return typeof value === "string" && value.trim().length > 0;
192
218
  }