@7365admin1/layer-common 4.35.1-staging.376 → 4.35.1-staging.378

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.
@@ -78,7 +78,17 @@
78
78
  </div>
79
79
 
80
80
  <div v-else-if="item.status === 'complete'" class="px-4 pb-4">
81
- <NuxtLink v-if="item.onThisOrg" :to="`/org/${org}/sites`">Open Sites</NuxtLink>
81
+ <v-btn
82
+ v-if="item.needsSiteLink"
83
+ variant="flat"
84
+ class="screen-btn-primary"
85
+ :loading="working[item._id] === 'link'"
86
+ :disabled="Boolean(working[item._id])"
87
+ @click="addToSites(item)"
88
+ >
89
+ Add {{ item.siteName }} to your Sites
90
+ </v-btn>
91
+ <NuxtLink v-else-if="item.onThisOrg" :to="`/org/${org}/sites`">Open Sites</NuxtLink>
82
92
  <NuxtLink
83
93
  v-else-if="item.providerOrgId && item.providerOrgId !== org"
84
94
  :to="`/org/${item.providerOrgId}/sites`"
@@ -124,8 +134,13 @@ const tabs: Array<{ value: Tab; label: string }> = [
124
134
  ];
125
135
 
126
136
  const route = useRoute();
127
- const { getReceivedInvitations, getInvitation, acceptInvitation, declineInvitation } =
128
- useServiceProviderInvitation();
137
+ const {
138
+ getReceivedInvitations,
139
+ getInvitation,
140
+ acceptInvitation,
141
+ declineInvitation,
142
+ linkInvitationSite,
143
+ } = useServiceProviderInvitation();
129
144
 
130
145
  const tab = ref<Tab>("pending");
131
146
  const items = ref<TReceivedServiceProviderInvitation[]>([]);
@@ -180,6 +195,9 @@ function stateLine(item: TReceivedServiceProviderInvitation) {
180
195
  if (item.onThisOrg) {
181
196
  return `Accepted${on(item.answeredAt)} — ${item.siteName} is on your Sites list as a site you serve for ${item.orgName}.`;
182
197
  }
198
+ if (item.needsSiteLink) {
199
+ return "This invitation was accepted, but the site wasn't added to your Sites. Add it now.";
200
+ }
183
201
  if (!item.providerOrgId || item.providerOrgId === props.org) {
184
202
  return `Accepted${on(item.answeredAt)}, but ${item.siteName} is not on this company's Sites list. Please contact Seven365 support so we can add it.`;
185
203
  }
@@ -228,6 +246,20 @@ async function answer(item: TReceivedServiceProviderInvitation, action: "accept"
228
246
  }
229
247
  }
230
248
 
249
+ /** Accepted but never added to the Sites list: add it now, then show it. */
250
+ async function addToSites(item: TReceivedServiceProviderInvitation) {
251
+ errors[item._id] = "";
252
+ working[item._id] = "link";
253
+ try {
254
+ await linkInvitationSite(item._id, props.org);
255
+ await load();
256
+ } catch (err: any) {
257
+ errors[item._id] = err?.data?.message || "Could not add this site to your Sites.";
258
+ } finally {
259
+ working[item._id] = "";
260
+ }
261
+ }
262
+
231
263
  // Opened from the bell: start on the tab the linked invitation is in.
232
264
  if (linked.value) {
233
265
  try {
@@ -1604,8 +1604,17 @@ const { org: orgId, site: siteId } = route.params as {
1604
1604
  site: string;
1605
1605
  };
1606
1606
 
1607
- const { enableUnregistered } = useANPRSettings(siteId);
1607
+ // The page reads its own site's switches rather than relying on the layout's
1608
+ // toast to have fetched them - that copy could belong to the previous site.
1609
+ const {
1610
+ enableUnregistered,
1611
+ loaded: anprSettingsLoaded,
1612
+ ensureANPRSettings,
1613
+ } = useANPRSettings(siteId);
1608
1614
  const enableUnregisteredTab = computed(() => enableUnregistered.value);
1615
+ ensureANPRSettings(true).catch(() => {
1616
+ // No settings = no Unregistered tab, same as before.
1617
+ });
1609
1618
 
1610
1619
  const {
1611
1620
  getVisitors,
@@ -3101,7 +3110,11 @@ watch([searchInput, dateFrom, dateTo, filterTypes, activeTab], () => {
3101
3110
  const syncVisitorFiltersFromRoute = () => {
3102
3111
  const requestedTab = (route.query.tab as string) || "registered";
3103
3112
  const nextTab =
3104
- (!enableUnregisteredTab.value && requestedTab === "unregistered") ||
3113
+ // Until the switches are read, keep a requested Unregistered tab (the plate
3114
+ // toast links here) instead of bouncing it to Registered.
3115
+ (anprSettingsLoaded.value &&
3116
+ !enableUnregisteredTab.value &&
3117
+ requestedTab === "unregistered") ||
3105
3118
  (!showResidentTransactionsTab.value && requestedTab === "resident-transactions")
3106
3119
  ? "registered"
3107
3120
  : requestedTab;
@@ -3160,9 +3173,9 @@ const { socketUnregisteredVisitorTrigger, visitorSocketData } =
3160
3173
  useVisitorSocket();
3161
3174
 
3162
3175
  watch(
3163
- enableUnregisteredTab,
3164
- (enabled) => {
3165
- if (!enabled && activeTab.value === "unregistered") {
3176
+ [enableUnregisteredTab, anprSettingsLoaded],
3177
+ ([enabled]) => {
3178
+ if (!enabled && anprSettingsLoaded.value && activeTab.value === "unregistered") {
3166
3179
  activeTab.value = "registered";
3167
3180
  }
3168
3181
  },
@@ -137,8 +137,9 @@ const config = useRuntimeConfig();
137
137
  const publicConfig = config.public as Record<string, string | undefined>;
138
138
  const route = useRoute();
139
139
  const { tab } = useVisitor();
140
+ // A getter, not the string: this component outlives site switches.
140
141
  const { enableUnregistered, ensureANPRSettings } = useANPRSettings(
141
- props.siteId
142
+ () => props.siteId
142
143
  );
143
144
  const enableUnregisteredSnackbar = computed(() => enableUnregistered.value);
144
145
  const { socketUnregisteredVisitorTrigger, visitorSocketData } =
@@ -1,19 +1,50 @@
1
- export default function (siteId?: string) {
2
- const stateKey = computed(() =>
3
- siteId ? `anpr-settings-${siteId}` : "anpr-settings"
4
- );
1
+ import { computed, toValue, type MaybeRefOrGetter } from "vue";
2
+
3
+ /*
4
+ * A site's ANPR switches (e.g. "Enable Unregistered Vehicles"), shared by every
5
+ * caller on the page: the Visitor Mgmt tabs, the plate toast in the layout, and
6
+ * Site Settings.
7
+ *
8
+ * `siteId` may be a ref or a getter. The layout's toast lives across site
9
+ * switches, so a plain string captured once kept answering for the FIRST site
10
+ * it saw - and the Visitor Mgmt page never fetched at all, so its
11
+ * "Unregistered" tab showed only when that stale copy happened to be for the
12
+ * right site (i.e. after a hard refresh on the page itself).
13
+ *
14
+ * One map keyed by site id: a key that is present means "fetched", even when
15
+ * the site has no settings yet (stored as `{}`).
16
+ */
17
+ export default function (siteId?: MaybeRefOrGetter<string | undefined>) {
18
+ const site = computed(() => toValue(siteId) || "");
5
19
 
6
- const anprSettings = useState<Record<string, any> | null>(
7
- stateKey.value,
8
- () => null
20
+ const bySite = useState<Record<string, Record<string, any>>>(
21
+ "anpr-settings-by-site",
22
+ () => ({})
9
23
  );
10
24
 
25
+ const anprSettings = computed<Record<string, any> | null>({
26
+ get: () => bySite.value[site.value] ?? null,
27
+ set: (value) => {
28
+ bySite.value = { ...bySite.value, [site.value]: value ?? {} };
29
+ },
30
+ });
31
+
32
+ /** True once this site's settings have been read (or saved) at least once. */
33
+ const loaded = computed(() => site.value in bySite.value);
34
+
11
35
  const enableUnregistered = computed(
12
36
  () => anprSettings.value?.ANPRSwitches?.enableUnregistered === true
13
37
  );
14
38
 
39
+ function store(forSite: unknown, response: Record<string, any> | null) {
40
+ const key = String(forSite ?? "");
41
+ if (!key) return;
42
+ bySite.value = { ...bySite.value, [key]: response ?? {} };
43
+ }
44
+
15
45
  async function fetchANPRSettings(data?: any) {
16
- const payload = data ?? (siteId ? { site: siteId, userType: "site" } : undefined);
46
+ const payload =
47
+ data ?? (site.value ? { site: site.value, userType: "site" } : undefined);
17
48
 
18
49
  if (!payload) {
19
50
  return anprSettings.value;
@@ -27,23 +58,21 @@ export default function (siteId?: string) {
27
58
  }
28
59
  );
29
60
 
30
- if (response) {
31
- anprSettings.value = response;
32
- }
61
+ store(payload.site, response);
33
62
 
34
63
  return response;
35
64
  }
36
65
 
37
66
  async function ensureANPRSettings(force = false) {
38
- if (!siteId) {
67
+ if (!site.value) {
39
68
  return anprSettings.value;
40
69
  }
41
70
 
42
- if (!force && anprSettings.value) {
71
+ if (!force && loaded.value) {
43
72
  return anprSettings.value;
44
73
  }
45
74
 
46
- return await fetchANPRSettings({ site: siteId, userType: "site" });
75
+ return await fetchANPRSettings({ site: site.value, userType: "site" });
47
76
  }
48
77
 
49
78
  async function getANPRSettingBySite(data: any) {
@@ -60,7 +89,7 @@ export default function (siteId?: string) {
60
89
  );
61
90
 
62
91
  if (response) {
63
- anprSettings.value = response;
92
+ store(data?.site, response);
64
93
  }
65
94
 
66
95
  return response;
@@ -68,6 +97,7 @@ export default function (siteId?: string) {
68
97
 
69
98
  return {
70
99
  anprSettings,
100
+ loaded,
71
101
  enableUnregistered,
72
102
  ensureANPRSettings,
73
103
  getANPRSettingBySite,
@@ -48,6 +48,8 @@ export type TReceivedServiceProviderInvitation = {
48
48
  providerOrgName?: string;
49
49
  /** Accepted AND on the Sites list of the company on screen. */
50
50
  onThisOrg?: boolean;
51
+ /** Accepted, but the site is on no company's Sites list: offer to add it. */
52
+ needsSiteLink?: boolean;
51
53
  };
52
54
 
53
55
  /** The words on screen. Kept beside the server's own list on purpose — a
@@ -171,6 +173,17 @@ export default function useServiceProviderInvitation() {
171
173
  });
172
174
  }
173
175
 
176
+ /**
177
+ * An accepted invitation whose site never reached this company's Sites
178
+ * list: add it now. Safe to repeat - the server adds it once.
179
+ */
180
+ function linkInvitationSite(id: string, org: string) {
181
+ return useNuxtApp().$api<{ message: string }>(`${base}/${id}/link-site`, {
182
+ method: "PUT",
183
+ body: { org },
184
+ });
185
+ }
186
+
174
187
  /**
175
188
  * "Client invitations": one tab of the invitations sent to the signed-in
176
189
  * account, plus the count in every tab. `org` is the company on screen.
@@ -200,6 +213,7 @@ export default function useServiceProviderInvitation() {
200
213
  getInvitation,
201
214
  declineInvitation,
202
215
  acceptInvitation,
216
+ linkInvitationSite,
203
217
  getReceivedInvitations,
204
218
  };
205
219
  }
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.35.1-staging.376",
5
+ "version": "4.35.1-staging.378",
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.",
@@ -36,7 +36,7 @@
36
36
  "build": "nuxt build .playground",
37
37
  "generate": "nuxt generate .playground",
38
38
  "preview": "nuxt preview .playground",
39
- "test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && esbuild utils/robot-fleet-core.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-fleet-core.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
39
+ "test": "esbuild composables/useANPRSettings.ts --format=esm --outfile=test/.build/useANPRSettings.mjs --log-level=error && esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && esbuild composables/usePlateToastWindow.ts --format=esm --outfile=test/.build/usePlateToastWindow.mjs --log-level=error && esbuild utils/client-invite-modules.ts --bundle --platform=node --format=esm --outfile=test/.build/client-invite-modules.mjs --log-level=error && esbuild utils/robot-display.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-display.mjs --log-level=error && esbuild utils/building-map.ts --bundle --platform=node --format=esm --outfile=test/.build/building-map.mjs --log-level=error && esbuild utils/robot-building.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-building.mjs --log-level=error && esbuild utils/robot-fleet-core.ts --bundle --platform=node --format=esm --outfile=test/.build/robot-fleet-core.mjs --log-level=error && node --experimental-strip-types --test \"test/*.test.mjs\" && yarn test:units",
40
40
  "test:units": "node --experimental-strip-types --test \"utils/*.test.ts\"",
41
41
  "release": "yarn run build && changeset publish"
42
42
  },