51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { Copy, Eye, Pencil, Plus, Trash2 } from "lucide-react";
|
|
import { clsx, type ClassValue } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
import { usePage } from "@inertiajs/react";
|
|
import { AuthProp } from "@/back/types/global";
|
|
|
|
/**
|
|
* Merge classes.
|
|
* @param inputs ClassValue[]
|
|
* @returns string
|
|
*/
|
|
export function cn(...inputs: ClassValue[]): string {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
/**
|
|
* Format a date.
|
|
* @param timestamp string
|
|
* @return string
|
|
*/
|
|
export function getFormatDate(timestamp: string): string {
|
|
return timestamp ? new Date(timestamp).toLocaleDateString('fr-FR', {
|
|
minute: '2-digit',
|
|
hour: '2-digit',
|
|
day: '2-digit',
|
|
month: 'long',
|
|
year: 'numeric'
|
|
}) : 'Date inconnue'
|
|
}
|
|
|
|
/**
|
|
* List all actions on back-end models.
|
|
* @return object
|
|
*/
|
|
export const Views = {
|
|
ALL: { label: "tous", value: "all", policy: 'viewAny', icon: Plus },
|
|
CREATION: { label: "creation", value: "create", policy: 'create', icon: Plus },
|
|
DUPLICATION: { label: "duplication", value: "duplicate", policy: 'duplicate', icon: Copy },
|
|
DELETION: { label: "suppression", value: "destroy", policy: 'delete', icon: Trash2 },
|
|
EDITION: { label: "edition", value: "edit", policy: 'update', icon: Pencil },
|
|
SHOW: { label: "details", value: "show", policy: 'view', icon: Eye },
|
|
};
|
|
|
|
/**
|
|
* Check if the authenticated user is conceptor.
|
|
* @returns boolean
|
|
*/
|
|
export function checkConceptor(): boolean {
|
|
const auth = usePage().props.auth as AuthProp;
|
|
return auth.user.role === 1
|
|
}
|