copy dmenu-admin to dkala-admin

This commit is contained in:
hamid zarghami
2026-02-07 16:20:18 +03:30
commit 6b9e808bfd
292 changed files with 27167 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
export const formatDate = (dateString: string): string => {
const date = new Date(dateString);
return new Intl.DateTimeFormat("fa-IR", {
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(date);
};
export const formatDateShort = (dateString: string): string => {
const date = new Date(dateString);
return new Intl.DateTimeFormat("fa-IR", {
year: "numeric",
month: "short",
day: "numeric",
}).format(date);
};
export const formatOptionalDate = (
value?: string | null,
options?: Intl.DateTimeFormatOptions
): string => {
if (!value) {
return "-";
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return "-";
}
return new Intl.DateTimeFormat(
"fa-IR",
options ?? {
year: "numeric",
month: "2-digit",
day: "2-digit",
}
).format(date);
};
export const formatFaNumber = (value?: number | null): string => {
if (value === undefined || value === null || Number.isNaN(value)) {
return "0";
}
return value.toLocaleString("fa-IR");
};
export const formatPrice = (price: number): string => {
return (
new Intl.NumberFormat("fa-IR", {
minimumFractionDigits: 0,
}).format(price) + " تومان"
);
};
+59
View File
@@ -0,0 +1,59 @@
import type { PermissionType } from '@/pages/roles/types/Types';
/**
* Checks if user has a specific permission
* @param permissions - Array of user permissions
* @param permissionName - Name of the permission to check
* @returns boolean indicating if user has the permission
*/
export const hasPermission = (
permissions: PermissionType[] | undefined,
permissionName: string
): boolean => {
if (!permissions || permissions.length === 0) {
return false;
}
return permissions.some(
(permission) => permission.name === permissionName
);
};
/**
* Checks if user has any of the specified permissions
* @param permissions - Array of user permissions
* @param permissionNames - Array of permission names to check
* @returns boolean indicating if user has at least one of the permissions
*/
export const hasAnyPermission = (
permissions: PermissionType[] | undefined,
permissionNames: string[]
): boolean => {
if (!permissions || permissions.length === 0 || permissionNames.length === 0) {
return false;
}
return permissionNames.some((permissionName) =>
hasPermission(permissions, permissionName)
);
};
/**
* Checks if user has all of the specified permissions
* @param permissions - Array of user permissions
* @param permissionNames - Array of permission names to check
* @returns boolean indicating if user has all of the permissions
*/
export const hasAllPermissions = (
permissions: PermissionType[] | undefined,
permissionNames: string[]
): boolean => {
if (!permissions || permissions.length === 0 || permissionNames.length === 0) {
return false;
}
return permissionNames.every((permissionName) =>
hasPermission(permissions, permissionName)
);
};
+20
View File
@@ -0,0 +1,20 @@
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
export type XOR<T, U> = T | U extends object
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U;
export type ItemsSelectType = {
value: string;
label: string;
};
export type ErrorType = Error & {
response?: {
data?: {
error: {
message: string[];
};
};
};
};
+26
View File
@@ -0,0 +1,26 @@
import { twMerge } from "tailwind-merge";
/**
* Concatenates truthy classes into a space-separated string.
*
* @param classes - The classes to concatenate.
* @returns The concatenated classes.
*/
export const clx = (...classes: (string | boolean | undefined)[]): string => {
return twMerge(classes.filter(Boolean).join(" "));
};
/**
* Converts time string to HH:mm format
* @param time - Time string in various formats (HH:mm:ss, HH:mm, etc.)
* @returns Time string in HH:mm format
*/
export const formatTimeToHHmm = (time: string): string => {
if (!time) return '';
// اگر زمان به فرمت HH:mm:ss باشد، فقط HH:mm را برمی‌گرداند
if (time.includes(':') && time.split(':').length === 3) {
return time.substring(0, 5);
}
// اگر به فرمت HH:mm باشد، همان را برمی‌گرداند
return time;
};