Add org-scoped activity priority labels/colors and apply them across forms, boards, and routines.
Also fix activity leave-without-save confirm, kanban due-date labels with tone-colored peek chevron, and rename the types manager button. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import type { ActivityPriority, ActivityPrioritySetting } from '@mento/shared';
|
||||
import {
|
||||
DEFAULT_ACTIVITY_PRIORITY_SETTINGS,
|
||||
parseActivityPrioritySettings,
|
||||
} from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
|
||||
const items = ref<ActivityPrioritySetting[]>([...DEFAULT_ACTIVITY_PRIORITY_SETTINGS]);
|
||||
const loaded = ref(false);
|
||||
let pending: Promise<void> | null = null;
|
||||
|
||||
/** تنظیمات اولویت فعالیت/روتین (کش مشترک) */
|
||||
export function useActivityPriorities() {
|
||||
async function load(force = false): Promise<void> {
|
||||
if (loaded.value && !force) return;
|
||||
if (pending && !force) return pending;
|
||||
pending = api
|
||||
.get<ActivityPrioritySetting[]>('/activities/priorities')
|
||||
.then(({ data }) => {
|
||||
items.value = parseActivityPrioritySettings(data);
|
||||
loaded.value = true;
|
||||
})
|
||||
.catch(() => {
|
||||
if (!loaded.value) items.value = [...DEFAULT_ACTIVITY_PRIORITY_SETTINGS];
|
||||
})
|
||||
.finally(() => {
|
||||
pending = null;
|
||||
});
|
||||
return pending;
|
||||
}
|
||||
|
||||
const byKey = computed(() => {
|
||||
const map = new Map<ActivityPriority, ActivityPrioritySetting>();
|
||||
for (const row of items.value) map.set(row.key, row);
|
||||
return map;
|
||||
});
|
||||
|
||||
const labels = computed(() => {
|
||||
const out = {} as Record<ActivityPriority, string>;
|
||||
for (const row of items.value) out[row.key] = row.label;
|
||||
return out;
|
||||
});
|
||||
|
||||
const colors = computed(() => {
|
||||
const out = {} as Record<ActivityPriority, string>;
|
||||
for (const row of items.value) out[row.key] = row.color;
|
||||
return out;
|
||||
});
|
||||
|
||||
function labelOf(key: ActivityPriority | string | null | undefined): string {
|
||||
if (!key) return '—';
|
||||
return byKey.value.get(key as ActivityPriority)?.label ?? String(key);
|
||||
}
|
||||
|
||||
function colorOf(key: ActivityPriority | string | null | undefined): string {
|
||||
if (!key) return '#94a3b8';
|
||||
return byKey.value.get(key as ActivityPriority)?.color ?? '#94a3b8';
|
||||
}
|
||||
|
||||
function setLocal(next: ActivityPrioritySetting[]) {
|
||||
items.value = parseActivityPrioritySettings(next);
|
||||
loaded.value = true;
|
||||
}
|
||||
|
||||
return { items, byKey, labels, colors, loaded, load, labelOf, colorOf, setLocal };
|
||||
}
|
||||
@@ -29,6 +29,7 @@ export {
|
||||
|
||||
type BadgeVariant = 'neutral' | 'accent' | 'success' | 'warning' | 'danger' | 'info';
|
||||
|
||||
/** پیشفرض؛ برای نمایش زنده از useActivityPriorities استفاده کنید */
|
||||
export const PRIORITY_LABELS: Record<ActivityPriority, string> = {
|
||||
very_low: 'خیلی کم',
|
||||
low: 'کم',
|
||||
|
||||
Reference in New Issue
Block a user