@7365admin1/layer-common 4.97.1-staging.657 → 4.97.1-staging.658
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.
|
@@ -104,17 +104,10 @@
|
|
|
104
104
|
<v-text-field v-model="setup.name" :rules="[requiredRule]" density="comfortable" placeholder="e.g. Main Store" class="mb-2" />
|
|
105
105
|
<template v-if="supplySites.length > 1">
|
|
106
106
|
<InputLabel title="Properties this store supplies" required class="mb-1" />
|
|
107
|
-
<
|
|
107
|
+
<InventorySitePicker
|
|
108
108
|
v-model="setup.sites"
|
|
109
|
-
:items="
|
|
110
|
-
|
|
111
|
-
item-value="_id"
|
|
112
|
-
multiple
|
|
113
|
-
chips
|
|
114
|
-
density="comfortable"
|
|
115
|
-
:rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
|
|
116
|
-
hint="Choose more than one only if one store supplies them all (e.g. a company's central store). If a property keeps its own separate stock, leave it out and set up its own store there."
|
|
117
|
-
persistent-hint
|
|
109
|
+
:items="setupSiteItems"
|
|
110
|
+
hint="Most properties keep their own store. Choose more than one only if they share one store room."
|
|
118
111
|
class="mb-4"
|
|
119
112
|
/>
|
|
120
113
|
</template>
|
|
@@ -183,7 +176,7 @@
|
|
|
183
176
|
<InventorySuppliersTab :store="store" />
|
|
184
177
|
</v-window-item>
|
|
185
178
|
<v-window-item v-if="ctl.tabs.settings" value="settings">
|
|
186
|
-
<InventorySettingsTab :store="store" :org-sites="supplySites" @saved="loadStores" />
|
|
179
|
+
<InventorySettingsTab :store="store" :org-sites="supplySites" @saved="loadStores" @deleted="afterStoreDeleted" />
|
|
187
180
|
</v-window-item>
|
|
188
181
|
</v-window>
|
|
189
182
|
</template>
|
|
@@ -224,7 +217,7 @@ const linked = { storeId: String(linkQuery.storeId ?? ""), tab: String(linkQuery
|
|
|
224
217
|
// `?requestId=` (approved / confirm-received alerts): the Requests tab opens on that request.
|
|
225
218
|
const focusRequest = String(linkQuery.requestId ?? "");
|
|
226
219
|
|
|
227
|
-
const { getHandovers, getStores, getStore, createStore: apiCreateStore, getRequests, getReport } = useInventory();
|
|
220
|
+
const { getHandovers, getStores, getStore, createStore: apiCreateStore, getSiteOwners, getRequests, getReport } = useInventory();
|
|
228
221
|
const { getSites } = useSite();
|
|
229
222
|
const { requiredRule } = useUtils();
|
|
230
223
|
|
|
@@ -306,6 +299,13 @@ const tabs = computed(() => {
|
|
|
306
299
|
];
|
|
307
300
|
});
|
|
308
301
|
|
|
302
|
+
/** After a store is deleted: reload, and with none left show the set-up form for its freed properties. */
|
|
303
|
+
async function afterStoreDeleted() {
|
|
304
|
+
await Promise.all([loadStores(), loadSiteOwners()]);
|
|
305
|
+
Object.assign(setup, { name: "Main Store", sites: [props.siteId] });
|
|
306
|
+
showSetup.value = !store.value;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
309
|
async function loadStores() {
|
|
310
310
|
loading.value = true;
|
|
311
311
|
loadError.value = "";
|
|
@@ -396,6 +396,15 @@ const supplySites = computed(() => inventorySupplySites(orgSites.value, mySites.
|
|
|
396
396
|
const setupSiteOptions = computed(() =>
|
|
397
397
|
inventorySiteOptions(supplySites.value, { sites: setup.sites, siteNames: [...mySites.value, { _id: props.siteId, name: currentSiteName.value }] }),
|
|
398
398
|
);
|
|
399
|
+
const siteOwners = ref<{ site: string; store: string; name: string }[]>([]);
|
|
400
|
+
const setupSiteItems = computed(() => inventorySitePickerItems(setupSiteOptions.value, siteOwners.value));
|
|
401
|
+
async function loadSiteOwners() {
|
|
402
|
+
try {
|
|
403
|
+
siteOwners.value = await getSiteOwners(props.orgId);
|
|
404
|
+
} catch {
|
|
405
|
+
siteOwners.value = []; // the picker then shows no hints; saving still names the clash
|
|
406
|
+
}
|
|
407
|
+
}
|
|
399
408
|
const currentSiteName = computed(() => mySites.value.find((s) => s._id === props.siteId)?.name || storeSites.value.find((s) => s._id === props.siteId)?.name || "this property");
|
|
400
409
|
async function loadMySites() {
|
|
401
410
|
try {
|
|
@@ -446,6 +455,7 @@ async function createStore() {
|
|
|
446
455
|
try {
|
|
447
456
|
const created = await apiCreateStore({ org: props.orgId, sites: setup.sites, name: setup.name });
|
|
448
457
|
notify("Store created. Add your items next.");
|
|
458
|
+
loadSiteOwners();
|
|
449
459
|
showSetup.value = false;
|
|
450
460
|
storeId.value = (created as any)?._id ?? "";
|
|
451
461
|
await loadStores();
|
|
@@ -471,5 +481,6 @@ onMounted(() => {
|
|
|
471
481
|
loadStores();
|
|
472
482
|
loadOrgSites();
|
|
473
483
|
loadMySites();
|
|
484
|
+
loadSiteOwners();
|
|
474
485
|
});
|
|
475
486
|
</script>
|
|
@@ -6,17 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
<template v-if="orgSites.length > 1 || sites.length > 1">
|
|
8
8
|
<InputLabel title="Properties this store supplies" required class="mb-1" />
|
|
9
|
-
<
|
|
9
|
+
<InventorySitePicker
|
|
10
10
|
v-model="sites"
|
|
11
11
|
:items="siteItems"
|
|
12
|
-
|
|
13
|
-
item-value="_id"
|
|
14
|
-
multiple
|
|
15
|
-
chips
|
|
16
|
-
density="comfortable"
|
|
17
|
-
:rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
|
|
18
|
-
hint="Choose more than one only if this store supplies them all (e.g. a company's central store). A property that keeps its own separate stock needs its own store instead."
|
|
19
|
-
persistent-hint
|
|
12
|
+
hint="Keep one property per store unless they share one store room."
|
|
20
13
|
class="mb-4"
|
|
21
14
|
/>
|
|
22
15
|
</template>
|
|
@@ -59,23 +52,48 @@
|
|
|
59
52
|
<div class="d-flex mt-6">
|
|
60
53
|
<v-btn class="text-none screen-btn-primary" variant="flat" :loading="saving" @click="save">Save settings</v-btn>
|
|
61
54
|
</div>
|
|
55
|
+
|
|
56
|
+
<template v-if="store.access?.canManage">
|
|
57
|
+
<v-divider class="my-6" />
|
|
58
|
+
<div class="text-subtitle-1 mb-1">Delete store</div>
|
|
59
|
+
<p class="text-body-2 text-medium-emphasis mb-2">Stop using this store. Its items and history are kept for reports.</p>
|
|
60
|
+
<v-btn class="text-none" color="error" variant="outlined" @click="openDelete">Delete store</v-btn>
|
|
61
|
+
</template>
|
|
62
62
|
</v-form>
|
|
63
|
+
|
|
64
|
+
<v-dialog v-model="showDelete" max-width="520">
|
|
65
|
+
<AppCard class="pa-6">
|
|
66
|
+
<div class="text-h6 mb-2">Delete {{ store.name }}?</div>
|
|
67
|
+
<p class="text-body-2 mb-2">
|
|
68
|
+
It will no longer be used at: {{ siteNamesText }}. Its {{ itemCount }} items and their history are kept for reports.
|
|
69
|
+
People can no longer request from it. You can then set up a new store for these sites.
|
|
70
|
+
</p>
|
|
71
|
+
<InputLabel :title="`Type "${store.name}" to confirm`" class="mb-1" />
|
|
72
|
+
<v-text-field v-model="confirmName" density="comfortable" autocomplete="off" />
|
|
73
|
+
<div class="d-flex ga-2 mt-2">
|
|
74
|
+
<v-btn class="text-none screen-btn-ghost" variant="outlined" @click="showDelete = false">Cancel</v-btn>
|
|
75
|
+
<v-btn class="text-none" color="error" variant="flat" :disabled="confirmName.trim() !== store.name" :loading="deleting" @click="removeStore">
|
|
76
|
+
Delete store
|
|
77
|
+
</v-btn>
|
|
78
|
+
</div>
|
|
79
|
+
</AppCard>
|
|
80
|
+
</v-dialog>
|
|
63
81
|
</AppCard>
|
|
64
82
|
</template>
|
|
65
83
|
|
|
66
84
|
<script setup lang="ts">
|
|
67
85
|
import useInventory from "../composables/useInventory";
|
|
68
86
|
import useUtils from "../composables/useUtils";
|
|
69
|
-
import { inventorySiteOptions } from "../utils/inventory-store-label";
|
|
87
|
+
import { inventorySiteOptions, inventorySitePickerItems, type TSiteOwner } from "../utils/inventory-store-label";
|
|
70
88
|
import { inventoryStepsLive, reminderDaysText } from "../utils/inventory-ack";
|
|
71
89
|
|
|
72
90
|
const props = defineProps({
|
|
73
91
|
store: { type: Object as PropType<TInventoryStore>, required: true },
|
|
74
92
|
orgSites: { type: Array as PropType<{ _id: string; name: string }[]>, default: () => [] },
|
|
75
93
|
});
|
|
76
|
-
const emit = defineEmits(["saved"]);
|
|
94
|
+
const emit = defineEmits(["saved", "deleted"]);
|
|
77
95
|
|
|
78
|
-
const { updateStore } = useInventory();
|
|
96
|
+
const { updateStore, getSiteOwners, getItems, deleteStore } = useInventory();
|
|
79
97
|
const { requiredRule } = useUtils();
|
|
80
98
|
const notify = inject<(text: string, color?: string) => void>("inventoryNotify", () => {});
|
|
81
99
|
|
|
@@ -90,7 +108,44 @@ const reminderDays = ref<number>(1);
|
|
|
90
108
|
const workOrderMaterials = ref(false);
|
|
91
109
|
const stepsLive = computed(() => inventoryStepsLive(props.store));
|
|
92
110
|
|
|
93
|
-
const
|
|
111
|
+
const owners = ref<TSiteOwner[]>([]);
|
|
112
|
+
const siteItems = computed(() => inventorySitePickerItems(inventorySiteOptions(props.orgSites, props.store), owners.value, props.store._id));
|
|
113
|
+
async function loadOwners() {
|
|
114
|
+
try {
|
|
115
|
+
owners.value = await getSiteOwners(props.store.org);
|
|
116
|
+
} catch {
|
|
117
|
+
owners.value = []; // no hints; saving still names the clashing property
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
onMounted(loadOwners);
|
|
121
|
+
|
|
122
|
+
const showDelete = ref(false);
|
|
123
|
+
const deleting = ref(false);
|
|
124
|
+
const confirmName = ref("");
|
|
125
|
+
const itemCount = ref(0);
|
|
126
|
+
const siteNamesText = computed(() => siteItems.value.filter((i) => props.store.sites.includes(i._id)).map((i) => i.name).join(", ") || "its properties");
|
|
127
|
+
async function openDelete() {
|
|
128
|
+
confirmName.value = "";
|
|
129
|
+
showDelete.value = true;
|
|
130
|
+
try {
|
|
131
|
+
itemCount.value = (await getItems(props.store._id, { limit: 1 }))?.total ?? 0;
|
|
132
|
+
} catch {
|
|
133
|
+
itemCount.value = 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function removeStore() {
|
|
137
|
+
deleting.value = true;
|
|
138
|
+
try {
|
|
139
|
+
await deleteStore(props.store._id);
|
|
140
|
+
showDelete.value = false;
|
|
141
|
+
notify("Store deleted.");
|
|
142
|
+
emit("deleted");
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
notify(error?.data?.message || "Could not delete the store.", "error");
|
|
145
|
+
} finally {
|
|
146
|
+
deleting.value = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
94
149
|
|
|
95
150
|
function reset() {
|
|
96
151
|
name.value = props.store.name;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-select
|
|
3
|
+
v-model="model"
|
|
4
|
+
:items="items"
|
|
5
|
+
item-title="name"
|
|
6
|
+
item-value="_id"
|
|
7
|
+
multiple
|
|
8
|
+
chips
|
|
9
|
+
density="comfortable"
|
|
10
|
+
:rules="[(v: string[]) => v.length > 0 || 'Choose at least one property']"
|
|
11
|
+
:hint="hint"
|
|
12
|
+
persistent-hint
|
|
13
|
+
>
|
|
14
|
+
<template #prepend-item>
|
|
15
|
+
<div class="d-flex ga-2 px-4 py-2">
|
|
16
|
+
<v-btn size="small" variant="text" class="text-none" @click.stop="selectAll">Select all</v-btn>
|
|
17
|
+
<v-btn size="small" variant="text" class="text-none" @click.stop="model = []">Clear</v-btn>
|
|
18
|
+
</div>
|
|
19
|
+
<v-divider />
|
|
20
|
+
</template>
|
|
21
|
+
</v-select>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script setup lang="ts">
|
|
25
|
+
type TItem = { _id: string; name: string; props?: { disabled?: boolean } };
|
|
26
|
+
const props = defineProps({
|
|
27
|
+
modelValue: { type: Array as PropType<string[]>, default: () => [] },
|
|
28
|
+
items: { type: Array as PropType<TItem[]>, default: () => [] },
|
|
29
|
+
hint: { type: String, default: "" },
|
|
30
|
+
});
|
|
31
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
32
|
+
const model = computed({ get: () => props.modelValue, set: (v: string[]) => emit("update:modelValue", v) });
|
|
33
|
+
|
|
34
|
+
// Every property that is free to pick; ones another store supplies are skipped.
|
|
35
|
+
function selectAll() {
|
|
36
|
+
model.value = props.items.filter((i) => !i.props?.disabled).map((i) => i._id);
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
@@ -29,6 +29,9 @@ export default function useInventory() {
|
|
|
29
29
|
|
|
30
30
|
getStores: async (site: string) =>
|
|
31
31
|
((await api<TInventoryStore[]>("/stores", { query: { site } })) ?? []).map((s) => ({ ...s, access: inventoryCaps(s.access) })),
|
|
32
|
+
/** Which store of the organisation supplies each property (for the picker). */
|
|
33
|
+
getSiteOwners: async (org: string) => (await api<{ site: string; store: string; name: string }[]>("/stores/site-owners", { query: { org } })) ?? [],
|
|
34
|
+
deleteStore: (id: string) => api<{ deleted: boolean }>(`/stores/${id}`, { method: "DELETE" }),
|
|
32
35
|
createStore: (body: { org: string; sites: string[]; name: string }) =>
|
|
33
36
|
api<TInventoryStore>("/stores", { method: "POST", body }),
|
|
34
37
|
updateStore: (id: string, body: Partial<Pick<TInventoryStore, "name" | "sites" | "showInResidentApp" | "showCostInResidentApp" | "lowStockReminderDays" | "workOrderMaterials">>) =>
|
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.
|
|
5
|
+
"version": "4.97.1-staging.658",
|
|
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.",
|
|
@@ -104,3 +104,21 @@ export function inventoryTwoStoresText(stores: TStoreLike[]) {
|
|
|
104
104
|
if (!ours || !theirs) return "";
|
|
105
105
|
return "Two stores supply this property. Our store is your company's own stock. Main store is the property manager's stock: you can only request from it.";
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
export type TSiteOwner = { site: string; store: string; name: string };
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The picker rows: a property already supplied by ANOTHER store of the organisation is disabled with
|
|
112
|
+
* the reason as its subtitle; the current store's own properties stay selectable.
|
|
113
|
+
*/
|
|
114
|
+
export function inventorySitePickerItems(
|
|
115
|
+
options: { _id: string; name: string }[],
|
|
116
|
+
owners: TSiteOwner[],
|
|
117
|
+
currentStore?: string,
|
|
118
|
+
) {
|
|
119
|
+
const taken = new Map(owners.filter((o) => o.store !== currentStore).map((o) => [o.site, o.name]));
|
|
120
|
+
return options.map((o) => {
|
|
121
|
+
const by = taken.get(o._id);
|
|
122
|
+
return by ? { ...o, props: { disabled: true, subtitle: `Already supplied by ${by}` } } : { ...o };
|
|
123
|
+
});
|
|
124
|
+
}
|