From b274a729ee8a312fb4645672da7ef69e4f4a3bcd Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 19 Mar 2026 10:23:07 +0100 Subject: [PATCH] feat: refactor DataTableProps type declaration and remove unused Facehash component files --- .../src/components/custom_ui/data-table.tsx | 2 +- .../src/components/facehash/facehash.tsx | 352 ------------------ .../src/components/facehash/faces.tsx | 195 ---------- .../src/components/servizio/servizio.tsx | 7 +- .../controllers/pagamenti.controller.ts | 2 +- .../src/server/services/ordini.service.ts | 17 +- 6 files changed, 11 insertions(+), 564 deletions(-) delete mode 100644 apps/infoalloggi/src/components/facehash/facehash.tsx delete mode 100644 apps/infoalloggi/src/components/facehash/faces.tsx diff --git a/apps/infoalloggi/src/components/custom_ui/data-table.tsx b/apps/infoalloggi/src/components/custom_ui/data-table.tsx index 19dd467..5f84223 100644 --- a/apps/infoalloggi/src/components/custom_ui/data-table.tsx +++ b/apps/infoalloggi/src/components/custom_ui/data-table.tsx @@ -34,7 +34,7 @@ import { cn } from "~/lib/utils"; import { DataTableProvider } from "~/providers/DataTableProvider"; import { ContextMenu, ContextMenuTrigger } from "../ui/context-menu"; -export type DataTableProps = { +type DataTableProps = { columns: ColumnDef[]; data: TData[]; pinnedFiltri?: PinnedFiltro[]; diff --git a/apps/infoalloggi/src/components/facehash/facehash.tsx b/apps/infoalloggi/src/components/facehash/facehash.tsx deleted file mode 100644 index baaba81..0000000 --- a/apps/infoalloggi/src/components/facehash/facehash.tsx +++ /dev/null @@ -1,352 +0,0 @@ -import * as React from "react"; -import { isColorDark } from "~/lib/color"; -import { FACES } from "./faces"; - -// from https://github.com/cossistantcom/cossistant/tree/main/packages/facehash - -type Intensity3D = "none" | "subtle" | "medium" | "dramatic"; -type Variant = "gradient" | "solid"; - -export interface FacehashProps - extends Omit, "children"> { - /** - * String to generate a deterministic face from. - * Same string always produces the same face. - */ - name: string; - - /** - * Size in pixels or CSS units. - * @default 40 - */ - size?: number | string; - - /** - * Background style. - * - "gradient": Adds gradient overlay (default) - * - "solid": Plain background color - * @default "gradient" - */ - variant?: Variant; - - /** - * 3D effect intensity. - * @default "dramatic" - */ - intensity3d?: Intensity3D; - - /** - * Enable hover interaction. - * When true, face "looks straight" on hover. - * @default true - */ - interactive?: boolean; - - /** - * Show first letter of name below the face. - * @default true - */ - showInitial?: boolean; - - initialsCount?: number; - - /** - * Hex color array for inline styles. - * Use this OR colorClasses, not both. - */ - colors?: string[]; - - /** - * Tailwind class array for background colors. - * Example: ["bg-pink-500 dark:bg-pink-600", "bg-blue-500 dark:bg-blue-600"] - * Use this OR colors, not both. - */ - colorClasses?: string[]; - - /** - * Custom gradient overlay class (Tailwind). - * When provided, replaces the default pure CSS gradient. - * Only used when variant="gradient". - */ - gradientOverlayClass?: string; -} - -// ============================================================================ -// Constants -// ============================================================================ - -const INTENSITY_PRESETS = { - none: { - rotateRange: 0, - translateZ: 0, - perspective: "none", - }, - subtle: { - rotateRange: 5, - translateZ: 4, - perspective: "800px", - }, - medium: { - rotateRange: 10, - translateZ: 8, - perspective: "500px", - }, - dramatic: { - rotateRange: 15, - translateZ: 12, - perspective: "300px", - }, -} as const; - -const SPHERE_POSITIONS = [ - { x: -1, y: 1 }, // down-right - { x: 1, y: 1 }, // up-right - { x: 1, y: 0 }, // up - { x: 0, y: 1 }, // right - { x: -1, y: 0 }, // down - { x: 0, y: 0 }, // center - { x: 0, y: -1 }, // left - { x: -1, y: -1 }, // down-left - { x: 1, y: -1 }, // up-left -] as const; - -// Default gradient as pure CSS (works without Tailwind) -// Matches: bg-[radial-gradient(ellipse_100%_100%_at_50%_50%,_COLOR_0%,_transparent_60%)] -// Light mode: white glow in center, Dark mode: dark overlay in center -const DEFAULT_GRADIENT_STYLE: React.CSSProperties = { - background: - "radial-gradient(ellipse 100% 100% at 50% 50%, rgba(255,255,255,0.15) 0%, transparent 60%)", -}; - -/** - * Facehash - Deterministic avatar faces from any string. - * - * @example - * ```tsx - * // With Tailwind classes - * - * - * // With hex colors - * - * - * // Plain color (no gradient) - * - * ``` - */ -export const Facehash = React.forwardRef( - ( - { - name, - size = 40, - variant = "gradient", - intensity3d = "dramatic", - interactive = true, - showInitial = true, - initialsCount = 1, - colors, - colorClasses, - gradientOverlayClass, - className, - style, - onMouseEnter, - onMouseLeave, - ...props - }, - ref, - ) => { - const [isHovered, setIsHovered] = React.useState(false); - - // Generate deterministic values from name - const { FaceComponent, colorIndex, rotation } = React.useMemo(() => { - const hash = stringHash(name); - const faceIndex = hash % FACES.length; - const colorsLength = colorClasses?.length ?? colors?.length ?? 1; - const _colorIndex = hash % colorsLength; - const positionIndex = hash % SPHERE_POSITIONS.length; - const position = SPHERE_POSITIONS[positionIndex] ?? { x: 0, y: 0 }; - - return { - FaceComponent: FACES[faceIndex] ?? FACES[0], - colorIndex: _colorIndex, - rotation: position, - }; - }, [name, colors?.length, colorClasses?.length]); - - // Get intensity preset - const preset = INTENSITY_PRESETS[intensity3d]; - - // Calculate 3D transform - const transform = React.useMemo(() => { - if (intensity3d === "none") { - return; - } - - const rotateX = - isHovered && interactive ? 0 : rotation.x * preset.rotateRange; - const rotateY = - isHovered && interactive ? 0 : rotation.y * preset.rotateRange; - - return `rotateX(${rotateX}deg) rotateY(${rotateY}deg) translateZ(${preset.translateZ}px)`; - }, [intensity3d, isHovered, interactive, rotation, preset]); - - // Size style - const sizeValue = typeof size === "number" ? `${size}px` : size; - - // Initial letter - const initial = name.trim().substring(0, initialsCount).toUpperCase(); - - // Background: either hex color (inline) or class - const bgColorClass = colorClasses?.[colorIndex]; - const bgColorHex = colors?.[colorIndex]; - - // Event handlers - const handleMouseEnter = React.useCallback( - (e: React.MouseEvent) => { - if (interactive) { - setIsHovered(true); - } - onMouseEnter?.(e); - }, - [interactive, onMouseEnter], - ); - - const handleMouseLeave = React.useCallback( - (e: React.MouseEvent) => { - if (interactive) { - setIsHovered(false); - } - onMouseLeave?.(e); - }, - [interactive, onMouseLeave], - ); - - return ( - // biome-ignore lint/a11y/noNoninteractiveElementInteractions: Hover effect is purely cosmetic - // biome-ignore lint/a11y/noStaticElementInteractions: This is a decorative avatar component -
- {/* Gradient overlay */} - {variant === "gradient" && ( -
- )} - - {/* Face container with 3D transform */} -
- {/* Face SVG */} - - - {/* Initial letter */} - {showInitial && ( - - {initial} - - )} -
-
- ); - }, -); - -Facehash.displayName = "Facehash"; - -/** - * Generates a consistent numeric hash from a string. - * Used to deterministically select faces and colors for avatars. - * - * @param str - The input string to hash - * @returns A positive 32-bit integer hash - */ -function stringHash(str: string): number { - let hash = 0; - for (let i = 0; i < str.length; i++) { - const char = str.charCodeAt(i); - hash = (hash << 5) - hash + char; - hash &= hash; // Convert to 32bit integer - } - return Math.abs(hash); -} diff --git a/apps/infoalloggi/src/components/facehash/faces.tsx b/apps/infoalloggi/src/components/facehash/faces.tsx deleted file mode 100644 index b17947b..0000000 --- a/apps/infoalloggi/src/components/facehash/faces.tsx +++ /dev/null @@ -1,195 +0,0 @@ -import type * as React from "react"; - -type FaceProps = { - className?: string; - style?: React.CSSProperties; -}; - -/** - * Round eyes face - simple circular eyes - */ -const RoundFace: React.FC = ({ className, style }) => ( - -); - -/** - * Cross eyes face - X-shaped eyes - */ -const CrossFace: React.FC = ({ className, style }) => ( - -); - -/** - * Line eyes face - horizontal line eyes - */ -const LineFace: React.FC = ({ className, style }) => ( - -); - -/** - * Curved eyes face - sleepy/happy curved eyes - */ -const CurvedFace: React.FC = ({ className, style }) => ( - -); - -/** - * Square eyes face - robot/neutral style - */ -const SquareFace: React.FC = ({ className, style }) => ( - -); - -/** - * Star eyes face - excited/dazzled - */ -const StarFace: React.FC = ({ className, style }) => ( - -); - -/** - * Wink face - one round eye, one closed - */ -const WinkFace: React.FC = ({ className, style }) => ( - -); - -/** - * All available face components - */ -export const FACES = [ - RoundFace, - CrossFace, - LineFace, - CurvedFace, - SquareFace, - StarFace, - WinkFace, -] as const; - -//export type FaceComponent = (typeof FACES)[number]; diff --git a/apps/infoalloggi/src/components/servizio/servizio.tsx b/apps/infoalloggi/src/components/servizio/servizio.tsx index 4a54b56..b9b70fb 100644 --- a/apps/infoalloggi/src/components/servizio/servizio.tsx +++ b/apps/infoalloggi/src/components/servizio/servizio.tsx @@ -188,7 +188,8 @@ const ServizioLinkCard = ({ {t.servizio.vai_al_servizio} diff --git a/apps/infoalloggi/src/server/controllers/pagamenti.controller.ts b/apps/infoalloggi/src/server/controllers/pagamenti.controller.ts index d4e9230..87b5c7a 100644 --- a/apps/infoalloggi/src/server/controllers/pagamenti.controller.ts +++ b/apps/infoalloggi/src/server/controllers/pagamenti.controller.ts @@ -26,7 +26,7 @@ export type PreparedPaymentData = { packDesc: string; condizioni: string; }; -export type preparePaymentInput = +type preparePaymentInput = | { servizioId: ServizioServizioId; type: Exclude; diff --git a/apps/infoalloggi/src/server/services/ordini.service.ts b/apps/infoalloggi/src/server/services/ordini.service.ts index 90b0f2e..b4d6652 100644 --- a/apps/infoalloggi/src/server/services/ordini.service.ts +++ b/apps/infoalloggi/src/server/services/ordini.service.ts @@ -1,5 +1,5 @@ import { TRPCError } from "@trpc/server"; -import type { Insertable, Selectable, Updateable } from "kysely"; +import type { Insertable } from "kysely"; import type OrdiniTable from "~/schemas/public/Ordini"; import type { Ordini, @@ -10,20 +10,13 @@ import type { Users, UsersId } from "~/schemas/public/Users"; import { db } from "~/server/db"; export type ServizioOrdiniTable = Omit; - -export type ServizioOrdini = Selectable; - +//export type ServizioOrdini = Selectable; export type NewServizioOrdini = Insertable; - -export type ServizioOrdiniUpdate = Updateable; - +//export type ServizioOrdiniUpdate = Updateable; export type RinnovoOrdiniTable = Omit; - -export type RinnovoOrdini = Selectable; - +//export type RinnovoOrdini = Selectable; export type NewRinnovoOrdini = Insertable; - -export type RinnovoOrdiniUpdate = Updateable; +//export type RinnovoOrdiniUpdate = Updateable; export type Ordini_w_Utente = Ordini & Pick; export const getOrdini = async (