add business_owner
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="app-shell-root min-h-[100dvh] w-full bg-surface-2">
|
||||
<div
|
||||
class="app-shell-frame mx-auto flex w-full min-w-0 max-w-full flex-col bg-surface shadow-xl shadow-black/5 dark:shadow-black/30 max-w-app max-lg:h-[100dvh] max-lg:max-h-[100dvh] max-lg:overflow-hidden lg:min-h-dvh"
|
||||
class="app-shell-frame mx-auto flex h-[100dvh] max-h-[100dvh] w-full min-w-0 max-w-full flex-col overflow-hidden bg-surface shadow-xl shadow-black/5 dark:shadow-black/30 max-w-app"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
+15
-17
@@ -34,25 +34,23 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 1023px) {
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@supports (-webkit-touch-callout: none) {
|
||||
.app-shell-root {
|
||||
min-height: 100%;
|
||||
min-height: -webkit-fill-available;
|
||||
}
|
||||
|
||||
@supports (-webkit-touch-callout: none) {
|
||||
.app-shell-root {
|
||||
min-height: 100%;
|
||||
min-height: -webkit-fill-available;
|
||||
}
|
||||
|
||||
.app-shell-frame {
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
min-height: -webkit-fill-available;
|
||||
}
|
||||
.app-shell-frame {
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
min-height: -webkit-fill-available;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,13 @@
|
||||
<AppSelect id="filterActive" v-model="filterActive" :options="activeFilterOptions" />
|
||||
</div>
|
||||
|
||||
<p
|
||||
v-if="infoMessage"
|
||||
class="mt-4 rounded-xl border border-emerald-500/30 bg-emerald-500/10 px-4 py-3 text-sm text-emerald-700 dark:text-emerald-400"
|
||||
>
|
||||
{{ infoMessage }}
|
||||
</p>
|
||||
|
||||
<p
|
||||
v-if="error"
|
||||
class="mt-4 rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600"
|
||||
@@ -249,6 +256,7 @@ const filterCategoryId = ref('');
|
||||
const filterActive = ref('all');
|
||||
const loading = ref(true);
|
||||
const error = ref('');
|
||||
const infoMessage = ref('');
|
||||
const saving = ref(false);
|
||||
|
||||
const formOpen = ref(false);
|
||||
@@ -322,6 +330,33 @@ function parseCoord(value: string): number | undefined {
|
||||
return Number.isFinite(num) ? num : undefined;
|
||||
}
|
||||
|
||||
async function backfillMissingOwners(
|
||||
bizList: Business[],
|
||||
users: User[],
|
||||
): Promise<number> {
|
||||
const usersByMobile = new Map(
|
||||
users.map((user) => [normalizeIranMobile(user.mobile), user]),
|
||||
);
|
||||
|
||||
let filled = 0;
|
||||
for (const biz of bizList) {
|
||||
if (biz.ownerId) continue;
|
||||
const mobile = normalizeIranMobile(biz.contactPhone ?? '');
|
||||
if (!isValidIranMobile(mobile)) continue;
|
||||
|
||||
const existing = usersByMobile.get(mobile);
|
||||
const fullName = existing?.fullName?.trim() || `مدیر ${biz.title}`;
|
||||
|
||||
try {
|
||||
await assignBusinessOwner(biz.id, { mobile, fullName });
|
||||
filled += 1;
|
||||
} catch {
|
||||
/* continue with remaining businesses */
|
||||
}
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
@@ -330,12 +365,21 @@ async function load() {
|
||||
if (filterCategoryId.value) params.categoryId = filterCategoryId.value;
|
||||
if (filterActive.value !== 'all') params.isActive = filterActive.value === 'true';
|
||||
|
||||
const [bizList, cats, users] = await Promise.all([
|
||||
let [bizList, cats, users] = await Promise.all([
|
||||
fetchBusinesses(params),
|
||||
fetchCategories(),
|
||||
fetchUsers().catch(() => []),
|
||||
fetchUsers().catch(() => [] as User[]),
|
||||
]);
|
||||
|
||||
const filled = await backfillMissingOwners(bizList, users);
|
||||
if (filled > 0) {
|
||||
infoMessage.value = `${filled} مدیر برای کسبوکارهای بدون مالک با نام «مدیر + عنوان» اضافه شد.`;
|
||||
[bizList, users] = await Promise.all([
|
||||
fetchBusinesses(params),
|
||||
fetchUsers().catch(() => [] as User[]),
|
||||
]);
|
||||
}
|
||||
|
||||
businesses.value = bizList;
|
||||
categories.value = cats;
|
||||
usersById.value = Object.fromEntries(users.map((u) => [u.id, u]));
|
||||
@@ -507,8 +551,8 @@ async function openAssign(biz: Business) {
|
||||
}
|
||||
assignUser.value = owner;
|
||||
assignForm.value = {
|
||||
mobile: owner?.mobile ?? '',
|
||||
fullName: owner?.fullName ?? '',
|
||||
mobile: owner?.mobile ?? biz.contactPhone ?? '',
|
||||
fullName: owner?.fullName ?? (biz.title ? `مدیر ${biz.title}` : ''),
|
||||
};
|
||||
} finally {
|
||||
assignLoading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user