infoalloggi-monorepo/apps/infoalloggi/src/lib/utils.ts
Marco Pedone 1971251490 feat(chat): implement chat bubble, list, sidebar, topbar, and loading components
- Added ChatBubble component for displaying individual chat messages with read status and timestamps.
- Introduced ChatList component to manage and display a list of messages, including editing and deleting functionalities.
- Created ChatSidebar for navigating between active chats and managing user interactions.
- Developed ChatTopbar for displaying chat information and admin actions.
- Implemented loading animation for messages with MessageLoading component.
- Enhanced user experience with context menus for chat options and dialogs for editing and deleting messages.
2026-04-22 19:17:54 +02:00

71 lines
1.7 KiB
TypeScript

import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
export const Capitalize = (str: string | null | undefined) => {
if (!str) return "";
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
};
export const redirectTo500 = {
redirect: {
destination: "/500",
permanent: false,
},
} as const;
export function getInitials(name: string) {
name = name.trim();
if (name.includes(" ")) {
const [firstName, lastName] = name.split(" ");
if (firstName && lastName) {
return (firstName.charAt(0) + lastName.charAt(0)).toUpperCase();
}
}
return name.slice(0, 2).toUpperCase();
}
// export function getHexColorFromString(str: string): string {
// let hash = 0;
// if (str.length === 0) return "#000000"; // Return black for empty string
// for (let i = 0; i < str.length; i++) {
// hash = str.charCodeAt(i) + ((hash << 5) - hash);
// hash = hash & 0xffffffff; // Ensure hash is a 32-bit integer
// }
// let color = "#";
// for (let i = 0; i < 3; i++) {
// const value = (hash >> (i * 8)) & 255;
// color += value.toString(16).padStart(2, "0");
// }
// return color;
// }
export function formatCurrency(amount: number): string {
return new Intl.NumberFormat("it-IT", {
currency: "EUR",
maximumFractionDigits: 2,
minimumFractionDigits: 2,
style: "currency",
}).format(amount);
}
export const debounce = <T extends unknown[]>(
callback: (...args: T) => void,
delay: number,
) => {
let timeoutTimer: ReturnType<typeof setTimeout>;
return (...args: T) => {
clearTimeout(timeoutTimer);
timeoutTimer = setTimeout(() => {
callback(...args);
}, delay);
};
};