Creating import&export excel
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import type { RolePermissionKey, UserRole } from '@mento/shared';
|
||||
import { ROLE_PERMISSION_ITEMS } from '@mento/shared';
|
||||
|
||||
export const ALL_ROLE_PERMISSIONS: RolePermissionKey[] = ROLE_PERMISSION_ITEMS.map(
|
||||
(item) => item.key,
|
||||
);
|
||||
|
||||
export const ROLE_COLORS = ['teal', 'violet', 'rose', 'sky', 'amber', 'slate', 'pink'] as const;
|
||||
export type RoleColor = (typeof ROLE_COLORS)[number];
|
||||
|
||||
export function defaultColorForSystemKey(key: UserRole): RoleColor {
|
||||
if (key === 'owner') return 'violet';
|
||||
if (key === 'admin') return 'rose';
|
||||
if (key === 'support') return 'sky';
|
||||
return 'teal';
|
||||
}
|
||||
|
||||
export const SYSTEM_ROLE_SEEDS: Array<{
|
||||
systemKey: UserRole;
|
||||
name: string;
|
||||
description: string;
|
||||
color: RoleColor;
|
||||
permissions: RolePermissionKey[];
|
||||
}> = [
|
||||
{
|
||||
systemKey: 'owner',
|
||||
name: 'مدیر سیستم',
|
||||
description: 'دسترسی کامل به تمام بخشهای سامانه.',
|
||||
color: 'violet',
|
||||
permissions: [...ALL_ROLE_PERMISSIONS],
|
||||
},
|
||||
{
|
||||
systemKey: 'admin',
|
||||
name: 'مدیر',
|
||||
description: 'مدیریت کاربران، تنظیمات و همه بخشهای سازمان.',
|
||||
color: 'rose',
|
||||
permissions: [...ALL_ROLE_PERMISSIONS],
|
||||
},
|
||||
{
|
||||
systemKey: 'sales',
|
||||
name: 'کارشناس فروش',
|
||||
description: 'امکان دسترسی به بخشهای فروش و مشتریان برای انجام فعالیتهای روزمره.',
|
||||
color: 'teal',
|
||||
permissions: [...ALL_ROLE_PERMISSIONS],
|
||||
},
|
||||
{
|
||||
systemKey: 'support',
|
||||
name: 'کارشناس پشتیبانی',
|
||||
description: 'پاسخگویی به مشتریان و پیگیری تیکتها و فعالیتها.',
|
||||
color: 'sky',
|
||||
permissions: ['customers', 'activities', 'notes', 'reports'],
|
||||
},
|
||||
];
|
||||
|
||||
export function isRolePermissionKey(value: string): value is RolePermissionKey {
|
||||
return ALL_ROLE_PERMISSIONS.includes(value as RolePermissionKey);
|
||||
}
|
||||
|
||||
export function sanitizePermissions(input: unknown): RolePermissionKey[] {
|
||||
if (!Array.isArray(input)) return [];
|
||||
return [...new Set(input.filter((item): item is RolePermissionKey => isRolePermissionKey(String(item))))];
|
||||
}
|
||||
|
||||
export function systemKeyToUserRole(key: string | null | undefined): UserRole {
|
||||
if (key === 'owner' || key === 'admin' || key === 'sales' || key === 'support') {
|
||||
return key;
|
||||
}
|
||||
return 'sales';
|
||||
}
|
||||
Reference in New Issue
Block a user