feat: migrate showcase to Next.js and overhaul CRM UI
- rebuild the public site on the Next.js App Router with static export, per-section SEO pages, metadata, sitemap, robots and a generated OG image - add full-screen scroll-snap regions, staged scroll reveals, a hash-free tab navigation with a sliding indicator and region-by-region menu scrolling - replace the theme text toggle with animated sun/moon icons - restructure the CRM API into config, middleware, models, routes, services and utils layers - redesign the CRM shell with a single surface, tab rail, full-width blurred DataTable, record dialogs and mask-based icons - update Docker/Nginx publishing, Makefile targets, shared UI polish and docs
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 195 KiB |
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Spinner } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "./lib/api.js";
|
||||
import { FaultyTerminalBackdrop } from "./components/FaultyTerminalBackdrop.js";
|
||||
import { Login } from "./pages/Login.js";
|
||||
import { ChangePassword } from "./pages/ChangePassword.js";
|
||||
import { Crm } from "./pages/Crm.js";
|
||||
@@ -35,8 +36,11 @@ export const App = () => {
|
||||
|
||||
if (session.state === "loading") {
|
||||
return (
|
||||
<div className="flex min-h-dvh items-center justify-center bg-background">
|
||||
<Spinner size="md" />
|
||||
<div className="relative flex min-h-dvh items-center justify-center bg-background">
|
||||
<FaultyTerminalBackdrop />
|
||||
<div className="relative z-10">
|
||||
<Spinner size="md" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
import { useMemo, useState, type ReactNode } from "react";
|
||||
import { cn, Skeleton, Spinner } from "@cohaise/ui";
|
||||
import { SearchMaskIcon } from "./icons.js";
|
||||
|
||||
export interface DataTableColumn<T> {
|
||||
/** Identifiant stable de la colonne, utilisé pour le tri. */
|
||||
id: string;
|
||||
header: string;
|
||||
cell: (row: T) => ReactNode;
|
||||
sortable?: boolean;
|
||||
/** Valeur brute comparée lors du tri. Obligatoire si `sortable`. */
|
||||
sortValue?: (row: T) => string | number | null | undefined;
|
||||
className?: string;
|
||||
headerClassName?: string;
|
||||
/** Masque la colonne sur les cartes mobiles (utile pour un champ secondaire). */
|
||||
mobileHidden?: boolean;
|
||||
}
|
||||
|
||||
type SortDirection = "asc" | "desc";
|
||||
|
||||
interface SortState {
|
||||
column: string;
|
||||
direction: SortDirection;
|
||||
}
|
||||
|
||||
export interface DataTableProps<T> {
|
||||
data: T[];
|
||||
columns: DataTableColumn<T>[];
|
||||
keyExtractor: (row: T) => string | number;
|
||||
loading?: boolean;
|
||||
error?: string | null;
|
||||
emptyMessage?: string;
|
||||
emptyHint?: string;
|
||||
search?: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
placeholder?: string;
|
||||
};
|
||||
/** Contenu libre à gauche de la barre d'outils, quand il n'y a pas de recherche. */
|
||||
toolbarStart?: ReactNode;
|
||||
/** Bouton(s) à droite de la barre d'outils, par exemple « Nouveau ». */
|
||||
actions?: ReactNode;
|
||||
rowActions?: (row: T) => ReactNode;
|
||||
footer?: ReactNode;
|
||||
initialSort?: SortState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tableau de données du CRM.
|
||||
*
|
||||
* La page ne défile jamais : ce composant occupe la hauteur restante
|
||||
* (`min-h-0 flex-1`) et seul le bloc tableau (`overflow-auto`) défile. L'en-tête
|
||||
* reste collé en haut, les actions sont alignées à droite et chaque ligne
|
||||
* devient une carte sous `md`.
|
||||
*/
|
||||
export function DataTable<T>({
|
||||
data,
|
||||
columns,
|
||||
keyExtractor,
|
||||
loading = false,
|
||||
error = null,
|
||||
emptyMessage = "Aucun résultat",
|
||||
emptyHint,
|
||||
search,
|
||||
toolbarStart,
|
||||
actions,
|
||||
rowActions,
|
||||
footer,
|
||||
initialSort,
|
||||
}: DataTableProps<T>) {
|
||||
const [sort, setSort] = useState<SortState | null>(initialSort ?? null);
|
||||
|
||||
const sorted = useMemo(() => {
|
||||
if (!sort) return data;
|
||||
const column = columns.find((item) => item.id === sort.column);
|
||||
const read = column?.sortValue;
|
||||
if (!read) return data;
|
||||
|
||||
const direction = sort.direction === "asc" ? 1 : -1;
|
||||
return [...data].sort((left, right) => {
|
||||
const a = read(left);
|
||||
const b = read(right);
|
||||
const aEmpty = a === null || a === undefined || a === "";
|
||||
const bEmpty = b === null || b === undefined || b === "";
|
||||
// Les valeurs absentes restent en fin de liste, quel que soit le sens.
|
||||
if (aEmpty && bEmpty) return 0;
|
||||
if (aEmpty) return 1;
|
||||
if (bEmpty) return -1;
|
||||
if (typeof a === "number" && typeof b === "number") return (a - b) * direction;
|
||||
return (
|
||||
String(a).localeCompare(String(b), "fr", { sensitivity: "base", numeric: true }) *
|
||||
direction
|
||||
);
|
||||
});
|
||||
}, [columns, data, sort]);
|
||||
|
||||
const toggleSort = (column: DataTableColumn<T>) => {
|
||||
if (!column.sortable || !column.sortValue) return;
|
||||
setSort((current) =>
|
||||
current?.column === column.id
|
||||
? { column: column.id, direction: current.direction === "asc" ? "desc" : "asc" }
|
||||
: { column: column.id, direction: "asc" },
|
||||
);
|
||||
};
|
||||
|
||||
const showSkeleton = loading && data.length === 0;
|
||||
const hasActions = Boolean(rowActions);
|
||||
const columnCount = columns.length + (hasActions ? 1 : 0);
|
||||
const showToolbar = Boolean(search || toolbarStart || actions);
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-4">
|
||||
{showToolbar ? (
|
||||
<div className="flex shrink-0 flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex min-w-0 flex-1 flex-wrap items-center gap-3">
|
||||
{search ? (
|
||||
<div className="relative w-full sm:max-w-xs">
|
||||
<SearchMaskIcon className="pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-subtle-foreground" />
|
||||
<input
|
||||
type="search"
|
||||
value={search.value}
|
||||
onChange={(event) => search.onChange(event.target.value)}
|
||||
placeholder={search.placeholder ?? "Rechercher…"}
|
||||
className="h-9 w-full rounded-sm border border-border-control bg-surface pl-9 pr-3 text-sm text-foreground placeholder:text-subtle-foreground transition-[background-color,border-color,box-shadow] duration-fast ease-out-soft hover:border-accent/60 hover:bg-surface-raised focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{toolbarStart}
|
||||
</div>
|
||||
{actions ? <div className="flex shrink-0 items-center gap-2">{actions}</div> : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{error ? (
|
||||
<p className="shrink-0 text-sm text-destructive" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="relative flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border bg-surface/80 shadow-sm backdrop-blur-xl before:pointer-events-none before:absolute before:inset-x-0 before:top-0 before:z-20 before:h-px before:bg-accent-graphic">
|
||||
{/* Tableau : au-delà de md. Le conteneur porte seul le défilement. */}
|
||||
<div
|
||||
className="hidden min-h-0 flex-1 overflow-auto md:block"
|
||||
aria-busy={loading}
|
||||
data-table-scroll="desktop"
|
||||
>
|
||||
<table className="w-full min-w-[42rem] border-separate border-spacing-0 text-left text-sm">
|
||||
<thead className="sticky top-0 z-10">
|
||||
<tr>
|
||||
{columns.map((column) => {
|
||||
const active = sort?.column === column.id;
|
||||
return (
|
||||
<th
|
||||
key={column.id}
|
||||
scope="col"
|
||||
aria-sort={
|
||||
active
|
||||
? sort.direction === "asc"
|
||||
? "ascending"
|
||||
: "descending"
|
||||
: column.sortable
|
||||
? "none"
|
||||
: undefined
|
||||
}
|
||||
className={cn(
|
||||
"border-b border-border bg-surface/90 px-4 py-3 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground backdrop-blur-xl",
|
||||
column.headerClassName,
|
||||
)}
|
||||
>
|
||||
{column.sortable && column.sortValue ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggleSort(column)}
|
||||
className={cn(
|
||||
"group inline-flex items-center gap-1.5 transition-colors hover:text-foreground",
|
||||
active && "text-foreground",
|
||||
)}
|
||||
>
|
||||
{column.header}
|
||||
<SortGlyph direction={active ? sort.direction : null} />
|
||||
</button>
|
||||
) : (
|
||||
column.header
|
||||
)}
|
||||
</th>
|
||||
);
|
||||
})}
|
||||
{hasActions ? (
|
||||
<th
|
||||
scope="col"
|
||||
className="border-b border-border bg-surface/90 px-4 py-3 text-right font-display text-[0.6875rem] font-semibold uppercase tracking-label text-subtle-foreground backdrop-blur-xl"
|
||||
>
|
||||
Actions
|
||||
</th>
|
||||
) : null}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{showSkeleton ? (
|
||||
Array.from({ length: 7 }).map((_, rowIndex) => (
|
||||
<tr key={rowIndex}>
|
||||
{Array.from({ length: columnCount }).map((__, cellIndex) => (
|
||||
<td key={cellIndex} className="border-b border-border/60 px-4 py-3.5">
|
||||
<Skeleton
|
||||
className="h-4"
|
||||
width={cellIndex === 0 ? "70%" : cellIndex === columnCount - 1 ? "40%" : "55%"}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))
|
||||
) : sorted.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={columnCount} className="px-6 py-16">
|
||||
<div className="flex flex-col items-center gap-1 text-center">
|
||||
<p className="font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||
{emptyMessage}
|
||||
</p>
|
||||
{emptyHint ? (
|
||||
<p className="text-sm text-muted-foreground">{emptyHint}</p>
|
||||
) : null}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
sorted.map((row) => {
|
||||
const key = keyExtractor(row);
|
||||
return (
|
||||
<tr
|
||||
key={key}
|
||||
className="transition-colors hover:bg-surface-hover/60"
|
||||
>
|
||||
{columns.map((column) => (
|
||||
<td
|
||||
key={column.id}
|
||||
className={cn(
|
||||
"border-b border-border/60 px-4 py-3.5 align-middle",
|
||||
column.className,
|
||||
)}
|
||||
>
|
||||
{column.cell(row)}
|
||||
</td>
|
||||
))}
|
||||
{hasActions ? (
|
||||
<td className="border-b border-border/60 px-4 py-3.5 text-right">
|
||||
{rowActions?.(row)}
|
||||
</td>
|
||||
) : null}
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Cartes : en dessous de md. Même zone de défilement, aucun scroll de page. */}
|
||||
<div
|
||||
className="flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-3 md:hidden"
|
||||
aria-busy={loading}
|
||||
data-table-scroll="mobile"
|
||||
>
|
||||
{showSkeleton ? (
|
||||
Array.from({ length: 4 }).map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex flex-col gap-3 rounded-lg border border-border bg-surface-raised/75 p-4 backdrop-blur-sm"
|
||||
>
|
||||
<Skeleton className="h-3" width="35%" />
|
||||
<Skeleton className="h-4" width="75%" />
|
||||
<Skeleton className="h-3" width="45%" />
|
||||
<Skeleton className="h-4" width="60%" />
|
||||
</div>
|
||||
))
|
||||
) : sorted.length === 0 ? (
|
||||
<div className="flex flex-col items-center gap-1 px-6 py-12 text-center">
|
||||
<p className="font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||
{emptyMessage}
|
||||
</p>
|
||||
{emptyHint ? (
|
||||
<p className="text-sm text-muted-foreground">{emptyHint}</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
sorted.map((row) => {
|
||||
const key = keyExtractor(row);
|
||||
return (
|
||||
<article
|
||||
key={key}
|
||||
className="rounded-lg border border-border bg-surface-raised/75 p-4 shadow-sm backdrop-blur-sm"
|
||||
>
|
||||
<dl className="flex flex-col gap-3">
|
||||
{columns
|
||||
.filter((column) => !column.mobileHidden)
|
||||
.map((column) => (
|
||||
<div key={column.id} className="flex flex-col gap-0.5">
|
||||
<dt className="font-display text-[0.625rem] font-semibold uppercase tracking-label text-subtle-foreground">
|
||||
{column.header}
|
||||
</dt>
|
||||
<dd className="break-words text-sm">{column.cell(row)}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
{hasActions ? (
|
||||
<div className="mt-4 flex justify-end border-t border-border pt-3">
|
||||
{rowActions?.(row)}
|
||||
</div>
|
||||
) : null}
|
||||
</article>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
{footer ? (
|
||||
<div
|
||||
className="flex shrink-0 items-center justify-between gap-3 border-t border-border bg-surface/70 px-4 py-2 text-xs text-subtle-foreground backdrop-blur-xl"
|
||||
data-table-footer=""
|
||||
>
|
||||
<span>{footer}</span>
|
||||
{loading && !showSkeleton ? <Spinner size="xs" /> : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const SortGlyph = ({ direction }: { direction: SortDirection | null }) => (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
className="h-3.5 w-3.5 shrink-0"
|
||||
>
|
||||
<path d="m8 9 4-4 4 4" className={direction === "asc" ? "opacity-100" : "opacity-25"} />
|
||||
<path
|
||||
d="m16 15-4 4-4-4"
|
||||
className={direction === "desc" ? "opacity-100" : "opacity-25"}
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useEffect, type ReactNode } from "react";
|
||||
import { CloseMaskIcon } from "./icons.js";
|
||||
|
||||
interface RecordDialogProps {
|
||||
open: boolean;
|
||||
title: string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Panneau de saisie par-dessus la liste.
|
||||
*
|
||||
* Le CRM ne défile jamais au niveau de la page : sur grand écran le panneau est
|
||||
* borné à la hauteur du viewport, et seule sa zone de formulaire défile. Sur
|
||||
* téléphone il occupe l'écran entier, toujours sans faire grandir la page.
|
||||
*/
|
||||
export const RecordDialog = ({ open, title, onClose, children }: RecordDialogProps) => {
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") onClose();
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
return () => window.removeEventListener("keydown", onKeyDown);
|
||||
}, [open, onClose]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
role="presentation"
|
||||
onMouseDown={(event) => {
|
||||
if (event.target === event.currentTarget) onClose();
|
||||
}}
|
||||
className="fixed inset-0 z-40 flex items-center justify-center bg-black/60 backdrop-blur-sm sm:p-6"
|
||||
>
|
||||
<div
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={title}
|
||||
className="flex h-full w-full flex-col overflow-hidden border-border bg-surface shadow-lg sm:h-auto sm:max-h-full sm:max-w-2xl sm:rounded-xl sm:border"
|
||||
>
|
||||
<header className="flex shrink-0 items-center justify-between gap-4 border-b border-border px-5 py-4">
|
||||
<h2 className="font-display text-sm font-semibold uppercase tracking-label text-foreground">
|
||||
{title}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
aria-label="Fermer"
|
||||
title="Fermer"
|
||||
className="flex size-8 items-center justify-center rounded-sm text-muted-foreground transition-colors hover:bg-surface-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
>
|
||||
<CloseMaskIcon />
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-5 py-5">{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
interface RowActionButtonProps {
|
||||
label: string;
|
||||
onClick: () => void;
|
||||
tone?: "neutral" | "destructive";
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bouton d'action compact d'une ligne de tableau.
|
||||
*
|
||||
* Les icônes au trait héritent de `currentColor` : le survol teinte donc le
|
||||
* pictogramme en accent (modifier) ou en destructif (supprimer).
|
||||
*/
|
||||
export const RowActionButton = ({
|
||||
label,
|
||||
onClick,
|
||||
tone = "neutral",
|
||||
children,
|
||||
}: RowActionButtonProps) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className={
|
||||
tone === "destructive"
|
||||
? "flex size-8 items-center justify-center rounded-sm border border-border-strong bg-surface text-muted-foreground transition-colors hover:border-destructive hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
: "flex size-8 items-center justify-center rounded-sm border border-border-strong bg-surface text-muted-foreground transition-colors hover:border-accent hover:bg-accent/10 hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
import type { SVGProps } from "react";
|
||||
import { cn } from "@cohaise/ui";
|
||||
|
||||
/**
|
||||
* Petites icônes au trait, dessinées avec `currentColor`.
|
||||
*
|
||||
* Les pictogrammes d'action (recherche, modifier, supprimer, fermer,
|
||||
* déconnexion) viennent des WebP du dépôt et passent par `MaskIcon` dans
|
||||
* `icons.tsx`. On ne garde ici que les flèches, qui n'ont pas d'équivalent.
|
||||
*/
|
||||
type GlyphProps = SVGProps<SVGSVGElement>;
|
||||
|
||||
const Glyph = ({ className, children, ...props }: GlyphProps) => (
|
||||
<svg
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
aria-hidden="true"
|
||||
className={cn("h-4 w-4 shrink-0", className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const ChevronDownGlyph = (props: GlyphProps) => (
|
||||
<Glyph {...props}>
|
||||
<path d="m6 9 6 6 6-6" />
|
||||
</Glyph>
|
||||
);
|
||||
|
||||
export const ArrowUpGlyph = (props: GlyphProps) => (
|
||||
<Glyph {...props}>
|
||||
<path d="M12 19V5M5 12l7-7 7 7" />
|
||||
</Glyph>
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ImgHTMLAttributes } from "react";
|
||||
import type { HTMLAttributes, ImgHTMLAttributes } from "react";
|
||||
|
||||
type IconProps = Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "alt"> & {
|
||||
filled?: boolean;
|
||||
@@ -18,6 +18,39 @@ const ImgIcon = ({
|
||||
/>
|
||||
);
|
||||
|
||||
type MaskIconProps = Omit<HTMLAttributes<HTMLSpanElement>, "children">;
|
||||
|
||||
/**
|
||||
* Icône WebP du dépôt teintée par `currentColor`.
|
||||
*
|
||||
* Les fichiers sont blancs avec un canal alpha : un `<img>` serait invisible
|
||||
* sur fond clair. Le masque CSS garde la forme et laisse le bouton décider de
|
||||
* la couleur (accent au survol, destructif pour la poubelle).
|
||||
*/
|
||||
const MaskIcon = ({
|
||||
src,
|
||||
className = "",
|
||||
style,
|
||||
...props
|
||||
}: MaskIconProps & { src: string }) => (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`inline-block h-4 w-4 shrink-0 bg-current ${className}`}
|
||||
style={{
|
||||
maskImage: `url(${src})`,
|
||||
WebkitMaskImage: `url(${src})`,
|
||||
maskRepeat: "no-repeat",
|
||||
WebkitMaskRepeat: "no-repeat",
|
||||
maskPosition: "center",
|
||||
WebkitMaskPosition: "center",
|
||||
maskSize: "contain",
|
||||
WebkitMaskSize: "contain",
|
||||
...style,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
export const FolderIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/folder.webp" {...props} />
|
||||
);
|
||||
@@ -90,6 +123,39 @@ export const LogoutIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/sign-out.webp" {...props} />
|
||||
);
|
||||
|
||||
/* Variantes masquées : mêmes WebP, mais teintées par `currentColor`. */
|
||||
export const LogoutMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/sign-out.webp" {...props} />
|
||||
);
|
||||
|
||||
export const SearchMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/search.webp" {...props} />
|
||||
);
|
||||
|
||||
export const FolderMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/folder.webp" {...props} />
|
||||
);
|
||||
|
||||
export const UsersMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/accounts.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ActivityMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/activity.webp" {...props} />
|
||||
);
|
||||
|
||||
export const CloseMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/close.webp" {...props} />
|
||||
);
|
||||
|
||||
export const PenMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/edit-pencil.webp" {...props} />
|
||||
);
|
||||
|
||||
export const TrashMaskIcon = (props: MaskIconProps) => (
|
||||
<MaskIcon src="/icons/trash-can.webp" {...props} />
|
||||
);
|
||||
|
||||
export const ShieldIcon = (props: IconProps) => (
|
||||
<ImgIcon src="/icons/accounts.webp" {...props} />
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "../lib/api.js";
|
||||
import { FaultyTerminalBackdrop } from "../components/FaultyTerminalBackdrop.js";
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
@@ -40,8 +41,10 @@ export const ChangePassword = ({ user, onCompleted, onLogout }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<main className="relative flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<FaultyTerminalBackdrop />
|
||||
|
||||
<div className="relative z-10 w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
|
||||
+214
-189
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton } from "@cohaise/ui";
|
||||
import { Button, Input } from "@cohaise/ui";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
@@ -9,6 +9,10 @@ import {
|
||||
type Country,
|
||||
type Organization,
|
||||
} from "../lib/api.js";
|
||||
import { DataTable, type DataTableColumn } from "../components/DataTable.js";
|
||||
import { RecordDialog } from "../components/RecordDialog.js";
|
||||
import { RowActionButton } from "../components/RowActionButton.js";
|
||||
import { PenMaskIcon, TrashMaskIcon } from "../components/icons.js";
|
||||
|
||||
const EMPTY: ContactInput = {
|
||||
firstName: "",
|
||||
@@ -33,6 +37,7 @@ export const Contacts = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<Contact | null>(null);
|
||||
const [form, setForm] = useState<ContactInput>(EMPTY);
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -68,15 +73,21 @@ export const Contacts = () => {
|
||||
.catch(() => undefined);
|
||||
}, []);
|
||||
|
||||
const close = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setFormError(null);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const openEdit = (contact: Contact) => {
|
||||
setOpen(true);
|
||||
setEditing(contact);
|
||||
setForm({
|
||||
firstName: contact.first_name,
|
||||
@@ -89,14 +100,8 @@ export const Contacts = () => {
|
||||
countryId: contact.country_id,
|
||||
description: contact.description,
|
||||
});
|
||||
setError(null);
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
@@ -104,7 +109,7 @@ export const Contacts = () => {
|
||||
const firstName = text(form.firstName ?? "");
|
||||
const lastName = text(form.lastName ?? "");
|
||||
if (!firstName || !lastName) {
|
||||
setError("Le prénom et le nom sont obligatoires.");
|
||||
setFormError("Le prénom et le nom sont obligatoires.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,14 +126,14 @@ export const Contacts = () => {
|
||||
};
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
try {
|
||||
if (editing) await api.updateContact(editing.id, payload);
|
||||
else await api.createContact(payload);
|
||||
close();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
setFormError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -156,184 +161,204 @@ export const Contacts = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
const columns: DataTableColumn<Contact>[] = [
|
||||
{
|
||||
id: "name",
|
||||
header: "Nom",
|
||||
sortable: true,
|
||||
sortValue: (row) => `${row.last_name} ${row.first_name}`,
|
||||
cell: (row) => (
|
||||
<span className="font-medium text-foreground">
|
||||
{row.last_name} {row.first_name}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "job",
|
||||
header: "Fonction",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.job_title,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.job_title ?? "—",
|
||||
},
|
||||
{
|
||||
id: "organization",
|
||||
header: "Entreprise",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.organization_name,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.organization_name ?? "—",
|
||||
},
|
||||
{
|
||||
id: "contact",
|
||||
header: "Contact",
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => (
|
||||
<div className="flex flex-col">
|
||||
<span>{row.email ?? row.phone ?? row.mobile ?? "—"}</span>
|
||||
{row.email && (row.phone ?? row.mobile) ? (
|
||||
<span className="text-xs text-subtle-foreground">{row.phone ?? row.mobile}</span>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "country",
|
||||
header: "Pays",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.country_name ?? row.country_code,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.country_code ?? "—",
|
||||
},
|
||||
{
|
||||
id: "created",
|
||||
header: "Ajouté le",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.created_at,
|
||||
cell: (row) => (
|
||||
<span className="tabular-nums text-subtle-foreground">{formatDate(row.created_at)}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div className="w-full max-w-xs">
|
||||
<>
|
||||
<DataTable
|
||||
data={rows}
|
||||
columns={columns}
|
||||
keyExtractor={(contact) => contact.id}
|
||||
loading={loading}
|
||||
error={error}
|
||||
emptyMessage="Aucun prospect"
|
||||
emptyHint="Ajoutez le premier pour commencer."
|
||||
search={{
|
||||
value: search,
|
||||
onChange: setSearch,
|
||||
placeholder: "Prénom, nom, e-mail, entreprise…",
|
||||
}}
|
||||
actions={<Button onClick={openCreate}>Nouveau prospect</Button>}
|
||||
rowActions={(contact) => (
|
||||
<div className="flex items-center justify-end gap-1.5">
|
||||
<RowActionButton
|
||||
label={`Modifier ${contact.first_name} ${contact.last_name}`}
|
||||
onClick={() => openEdit(contact)}
|
||||
>
|
||||
<PenMaskIcon />
|
||||
</RowActionButton>
|
||||
<RowActionButton
|
||||
label={`Supprimer ${contact.first_name} ${contact.last_name}`}
|
||||
tone="destructive"
|
||||
onClick={() => void remove(contact)}
|
||||
>
|
||||
<TrashMaskIcon />
|
||||
</RowActionButton>
|
||||
</div>
|
||||
)}
|
||||
footer={
|
||||
<span>
|
||||
{rows.length === total
|
||||
? `${total} prospect${total > 1 ? "s" : ""}`
|
||||
: `${rows.length} sur ${total} prospects`}
|
||||
</span>
|
||||
}
|
||||
initialSort={{ column: "created", direction: "desc" }}
|
||||
/>
|
||||
|
||||
<RecordDialog
|
||||
open={open}
|
||||
title={editing ? "Modifier le prospect" : "Nouveau prospect"}
|
||||
onClose={close}
|
||||
>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Rechercher"
|
||||
type="search"
|
||||
placeholder="Prénom, nom, e-mail, entreprise…"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
label="Prénom *"
|
||||
required
|
||||
value={form.firstName ?? ""}
|
||||
onChange={(event) => set("firstName")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={openCreate}>Nouveau prospect</Button>
|
||||
</div>
|
||||
|
||||
{open ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier le prospect" : "Nouveau prospect"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Prénom *"
|
||||
required
|
||||
value={form.firstName ?? ""}
|
||||
onChange={(event) => set("firstName")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.lastName ?? ""}
|
||||
onChange={(event) => set("lastName")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fonction"
|
||||
value={form.jobTitle ?? ""}
|
||||
onChange={(event) => set("jobTitle")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mobile"
|
||||
value={form.mobile ?? ""}
|
||||
onChange={(event) => set("mobile")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Entreprise
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.organizationId ?? ""}
|
||||
onChange={(event) => set("organizationId")(event.target.value || null)}
|
||||
>
|
||||
<option value="">— Aucune —</option>
|
||||
{organizations.map((organization) => (
|
||||
<option key={organization.id} value={organization.id}>
|
||||
{organization.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3 sm:col-span-2">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" onClick={close}>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : rows.length === 0 ? (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Aucun prospect. Ajoutez le premier pour commencer.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Fonction</th>
|
||||
<th className="py-2 pr-4">Entreprise</th>
|
||||
<th className="py-2 pr-4">Contact</th>
|
||||
<th className="py-2 pr-4">Pays</th>
|
||||
<th className="py-2 pr-4">Ajouté le</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((contact) => (
|
||||
<tr key={contact.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">
|
||||
{contact.last_name} {contact.first_name}
|
||||
</td>
|
||||
<td className="py-3 pr-4">{contact.job_title ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.organization_name ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.email ?? contact.phone ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{contact.country_code ?? "—"}</td>
|
||||
<td className="py-3 pr-4 text-subtle-foreground">
|
||||
{formatDate(contact.created_at)}
|
||||
</td>
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button size="sm" variant="secondary" onClick={() => openEdit(contact)}>
|
||||
Modifier
|
||||
</Button>
|
||||
{
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(contact)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.lastName ?? ""}
|
||||
onChange={(event) => set("lastName")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Fonction"
|
||||
value={form.jobTitle ?? ""}
|
||||
onChange={(event) => set("jobTitle")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Mobile"
|
||||
value={form.mobile ?? ""}
|
||||
onChange={(event) => set("mobile")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Entreprise
|
||||
<select
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground transition-[background-color,border-color,box-shadow] duration-fast ease-out-soft hover:border-accent/60 hover:bg-surface-raised focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
value={form.organizationId ?? ""}
|
||||
onChange={(event) => set("organizationId")(event.target.value || null)}
|
||||
>
|
||||
<option value="">— Aucune —</option>
|
||||
{organizations.map((organization) => (
|
||||
<option key={organization.id} value={organization.id}>
|
||||
{organization.name}
|
||||
</option>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">
|
||||
{total} prospect{total > 1 ? "s" : ""}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</select>
|
||||
</label>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground transition-[background-color,border-color,box-shadow] duration-fast ease-out-soft hover:border-accent/60 hover:bg-surface-raised focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{formError ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{formError}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center justify-end gap-3 sm:col-span-2">
|
||||
<Button type="button" variant="secondary" onClick={close}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</RecordDialog>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton } from "@cohaise/ui";
|
||||
import { useCallback, useEffect, useMemo, useState, type FormEvent } from "react";
|
||||
import { Button, Input } from "@cohaise/ui";
|
||||
import { ApiError, api, type Country } from "../lib/api.js";
|
||||
import { DataTable, type DataTableColumn } from "../components/DataTable.js";
|
||||
import { RecordDialog } from "../components/RecordDialog.js";
|
||||
import { RowActionButton } from "../components/RowActionButton.js";
|
||||
import { PenMaskIcon, TrashMaskIcon } from "../components/icons.js";
|
||||
|
||||
interface Form {
|
||||
code: string;
|
||||
@@ -12,9 +16,11 @@ const EMPTY: Form = { code: "", name: "", phoneCode: "" };
|
||||
|
||||
export const Countries = () => {
|
||||
const [rows, setRows] = useState<Country[]>([]);
|
||||
const [search, setSearch] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [editing, setEditing] = useState<Country | null>(null);
|
||||
const [form, setForm] = useState<Form>(EMPTY);
|
||||
@@ -36,31 +42,66 @@ export const Countries = () => {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
// Le referentiel est court : le filtrage reste local, sans requete par frappe.
|
||||
const filtered = useMemo(() => {
|
||||
const query = search.trim().toLowerCase();
|
||||
if (!query) return rows;
|
||||
return rows.filter((country) =>
|
||||
[country.code, country.name, country.phone_code ?? ""]
|
||||
.join(" ")
|
||||
.toLowerCase()
|
||||
.includes(query),
|
||||
);
|
||||
}, [rows, search]);
|
||||
|
||||
const close = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setFormError(null);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const openEdit = (country: Country) => {
|
||||
setEditing(country);
|
||||
setForm({
|
||||
code: country.code,
|
||||
name: country.name,
|
||||
phoneCode: country.phone_code ?? "",
|
||||
});
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const code = form.code.trim().toUpperCase();
|
||||
const name = form.name.trim();
|
||||
if (!/^[A-Z]{2}$/.test(code)) {
|
||||
setError("Le code doit contenir exactement deux lettres.");
|
||||
setFormError("Le code doit contenir exactement deux lettres.");
|
||||
return;
|
||||
}
|
||||
if (!name) {
|
||||
setError("Le nom est obligatoire.");
|
||||
setFormError("Le nom est obligatoire.");
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
try {
|
||||
const payload = { code, name, phoneCode: form.phoneCode.trim() || null };
|
||||
if (editing) await api.updateCountry(editing.id, payload);
|
||||
else await api.createCountry(payload);
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setOpen(false);
|
||||
close();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
setFormError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -80,147 +121,135 @@ export const Countries = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const columns: DataTableColumn<Country>[] = [
|
||||
{
|
||||
id: "code",
|
||||
header: "Code",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.code,
|
||||
cell: (row) => (
|
||||
<span className="inline-flex rounded-sm border border-border bg-surface-muted px-1.5 py-0.5 font-mono text-xs font-semibold tracking-wide text-foreground">
|
||||
{row.code}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "name",
|
||||
header: "Nom",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.name,
|
||||
cell: (row) => <span className="font-medium text-foreground">{row.name}</span>,
|
||||
},
|
||||
{
|
||||
id: "phone",
|
||||
header: "Indicatif",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.phone_code,
|
||||
cell: (row) => (
|
||||
<span className="font-mono text-sm text-muted-foreground">{row.phone_code ?? "—"}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<p className="max-w-lg text-sm text-muted-foreground">
|
||||
Référentiel ISO 3166 utilisé par les entreprises et les prospects. Il ne contient
|
||||
que les pays déjà saisis dans la base.
|
||||
</p>
|
||||
{
|
||||
<Button
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
Nouveau pays
|
||||
</Button>
|
||||
<>
|
||||
<DataTable
|
||||
data={filtered}
|
||||
columns={columns}
|
||||
keyExtractor={(country) => country.id}
|
||||
loading={loading}
|
||||
error={error}
|
||||
emptyMessage={search ? "Aucun pays correspondant" : "Aucun pays"}
|
||||
emptyHint={
|
||||
search
|
||||
? "Essayez un autre code, un autre nom ou un indicatif."
|
||||
: "Ajoutez le premier pays du référentiel."
|
||||
}
|
||||
</div>
|
||||
|
||||
{open && (
|
||||
<Card className="shrink-0">
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier le pays" : "Nouveau pays"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form
|
||||
className="grid gap-4 sm:grid-cols-3"
|
||||
onSubmit={(event) => void submit(event)}
|
||||
search={{
|
||||
value: search,
|
||||
onChange: setSearch,
|
||||
placeholder: "Code, nom, indicatif…",
|
||||
}}
|
||||
toolbarStart={
|
||||
<p className="hidden max-w-lg text-sm text-muted-foreground lg:block">
|
||||
Référentiel ISO 3166 utilisé par les entreprises et les prospects.
|
||||
</p>
|
||||
}
|
||||
actions={<Button onClick={openCreate}>Nouveau pays</Button>}
|
||||
rowActions={(country) => (
|
||||
<div className="flex items-center justify-end gap-1.5">
|
||||
<RowActionButton
|
||||
label={`Modifier ${country.name}`}
|
||||
onClick={() => openEdit(country)}
|
||||
>
|
||||
<Input
|
||||
label="Code *"
|
||||
required
|
||||
maxLength={2}
|
||||
placeholder="FR"
|
||||
value={form.code}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, code: event.target.value.toUpperCase() }))
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name}
|
||||
onChange={(event) => setForm((current) => ({ ...current, name: event.target.value }))}
|
||||
/>
|
||||
<Input
|
||||
label="Indicatif"
|
||||
placeholder="+33"
|
||||
value={form.phoneCode}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, phoneCode: event.target.value }))
|
||||
}
|
||||
/>
|
||||
<PenMaskIcon />
|
||||
</RowActionButton>
|
||||
<RowActionButton
|
||||
label={`Supprimer ${country.name}`}
|
||||
tone="destructive"
|
||||
onClick={() => void remove(country)}
|
||||
>
|
||||
<TrashMaskIcon />
|
||||
</RowActionButton>
|
||||
</div>
|
||||
)}
|
||||
footer={
|
||||
<span>
|
||||
{filtered.length === rows.length
|
||||
? `${rows.length} pays`
|
||||
: `${filtered.length} sur ${rows.length} pays`}
|
||||
</span>
|
||||
}
|
||||
initialSort={{ column: "name", direction: "asc" }}
|
||||
/>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-3" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
<RecordDialog
|
||||
open={open}
|
||||
title={editing ? "Modifier le pays" : "Nouveau pays"}
|
||||
onClose={close}
|
||||
>
|
||||
<form className="grid gap-4 sm:grid-cols-3" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Code *"
|
||||
required
|
||||
maxLength={2}
|
||||
placeholder="FR"
|
||||
value={form.code}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, code: event.target.value.toUpperCase() }))
|
||||
}
|
||||
/>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name}
|
||||
onChange={(event) => setForm((current) => ({ ...current, name: event.target.value }))}
|
||||
/>
|
||||
<Input
|
||||
label="Indicatif"
|
||||
placeholder="+33"
|
||||
value={form.phoneCode}
|
||||
onChange={(event) =>
|
||||
setForm((current) => ({ ...current, phoneCode: event.target.value }))
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="flex gap-3 sm:col-span-3">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
{formError ? (
|
||||
<p className="text-sm text-destructive sm:col-span-3" role="alert">
|
||||
{formError}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Code</th>
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Indicatif</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((country) => (
|
||||
<tr key={country.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">{country.code}</td>
|
||||
<td className="py-3 pr-4">{country.name}</td>
|
||||
<td className="py-3 pr-4">{country.phone_code ?? "—"}</td>
|
||||
{
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(country);
|
||||
setForm({
|
||||
code: country.code,
|
||||
name: country.name,
|
||||
phoneCode: country.phone_code ?? "",
|
||||
});
|
||||
setError(null);
|
||||
setOpen(true);
|
||||
}}
|
||||
>
|
||||
Modifier
|
||||
</Button>
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(country)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">{rows.length} pays</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center justify-end gap-3 sm:col-span-3">
|
||||
<Button type="button" variant="secondary" onClick={close}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</RecordDialog>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
import { useState } from "react";
|
||||
import { Button, cn } from "@cohaise/ui";
|
||||
import { cn } from "@cohaise/ui";
|
||||
import type { User } from "../lib/api.js";
|
||||
import { Organizations } from "./Organizations.js";
|
||||
import { Contacts } from "./Contacts.js";
|
||||
import { Countries } from "./Countries.js";
|
||||
import { FaultyTerminalBackdrop } from "../components/FaultyTerminalBackdrop.js";
|
||||
import { ActivityIcon, FolderIcon, LogoutIcon, UsersIcon } from "../components/icons.js";
|
||||
import {
|
||||
ActivityMaskIcon,
|
||||
FolderMaskIcon,
|
||||
LogoutMaskIcon,
|
||||
UsersMaskIcon,
|
||||
} from "../components/icons.js";
|
||||
|
||||
type Tab = "organizations" | "contacts" | "countries";
|
||||
|
||||
const TABS: { id: Tab; label: string; icon: typeof FolderIcon }[] = [
|
||||
{ id: "organizations", label: "Entreprises", icon: FolderIcon },
|
||||
{ id: "contacts", label: "Prospects", icon: UsersIcon },
|
||||
{ id: "countries", label: "Pays", icon: ActivityIcon },
|
||||
const TABS: { id: Tab; label: string; icon: typeof FolderMaskIcon }[] = [
|
||||
{ id: "organizations", label: "Entreprises", icon: FolderMaskIcon },
|
||||
{ id: "contacts", label: "Prospects", icon: UsersMaskIcon },
|
||||
{ id: "countries", label: "Pays", icon: ActivityMaskIcon },
|
||||
];
|
||||
|
||||
export const Crm = ({ user, onLogout }: { user: User; onLogout: () => void }) => {
|
||||
@@ -23,7 +28,7 @@ export const Crm = ({ user, onLogout }: { user: User; onLogout: () => void }) =>
|
||||
<FaultyTerminalBackdrop />
|
||||
|
||||
<div className="relative z-10 flex h-full min-h-0 flex-col gap-3 p-3 sm:p-4">
|
||||
<header className="glass flex shrink-0 items-center justify-between gap-4 rounded-xl border border-border/50 px-4 py-3 shadow-sm">
|
||||
<header className="glass flex shrink-0 items-center justify-between gap-4 rounded-xl border border-border/50 px-4 py-2.5 shadow-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="font-logo text-sm font-bold tracking-logo text-accent">COHAISE</span>
|
||||
<span className="text-border" aria-hidden="true">
|
||||
@@ -32,52 +37,72 @@ export const Crm = ({ user, onLogout }: { user: User; onLogout: () => void }) =>
|
||||
<span className="font-display text-sm font-semibold uppercase tracking-label">CRM</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="hidden text-right sm:block">
|
||||
<p className="text-sm font-medium">
|
||||
<p className="font-display text-[0.8125rem] font-semibold uppercase tracking-label text-foreground">
|
||||
{user.first_name} {user.last_name}
|
||||
</p>
|
||||
<p className="text-[0.6875rem] text-muted-foreground">{user.email}</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
<span className="flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface/50 p-1">
|
||||
<img
|
||||
src="/images/cohaise.webp"
|
||||
alt=""
|
||||
width={28}
|
||||
height={28}
|
||||
aria-hidden="true"
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onLogout}
|
||||
iconLeading={<LogoutIcon />}
|
||||
aria-label="Se déconnecter"
|
||||
title="Se déconnecter"
|
||||
className="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border/60 bg-surface/40 text-muted-foreground transition-[color,background-color,border-color,box-shadow] duration-fast ease-out-soft hover:border-destructive/50 hover:bg-destructive/10 hover:text-destructive focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-none"
|
||||
>
|
||||
Se déconnecter
|
||||
</Button>
|
||||
<LogoutMaskIcon />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav className="glass flex shrink-0 items-center gap-1 rounded-xl border border-border/50 p-1.5">
|
||||
{TABS.map((item) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
type="button"
|
||||
onClick={() => setTab(item.id)}
|
||||
aria-current={tab === item.id ? "page" : undefined}
|
||||
className={cn(
|
||||
"flex items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
|
||||
tab === item.id
|
||||
? "bg-accent/10 text-accent"
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<Icon />
|
||||
{item.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
{/* Une seule grande surface : onglets à gauche, vue des données à droite. */}
|
||||
<main className="flex min-h-0 flex-1 overflow-hidden rounded-xl border border-border/50 bg-surface/40">
|
||||
<nav
|
||||
aria-label="Sections du CRM"
|
||||
className="flex w-14 shrink-0 flex-col gap-1 border-r border-border/50 p-1.5 sm:p-2 md:w-[15%]"
|
||||
>
|
||||
{TABS.map((item) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<button
|
||||
key={item.id}
|
||||
type="button"
|
||||
onClick={() => setTab(item.id)}
|
||||
aria-current={tab === item.id ? "page" : undefined}
|
||||
aria-label={item.label}
|
||||
title={item.label}
|
||||
className={cn(
|
||||
"flex items-center justify-center gap-2.5 rounded-lg px-2 py-2.5 text-sm font-medium transition-colors md:justify-start lg:px-3",
|
||||
tab === item.id
|
||||
? "bg-accent/10 text-accent"
|
||||
: "text-muted-foreground hover:bg-surface-hover hover:text-foreground",
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4 shrink-0" />
|
||||
<span className="hidden truncate lg:inline">{item.label}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
<main className="glass flex min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-border/50">
|
||||
<div className="mx-auto flex min-h-0 w-full max-w-6xl flex-1 flex-col px-4 py-6">
|
||||
{tab === "organizations" ? <Organizations /> : null}
|
||||
{tab === "contacts" ? <Contacts /> : null}
|
||||
{tab === "countries" ? <Countries /> : null}
|
||||
</div>
|
||||
<section className="flex min-h-0 min-w-0 flex-1 flex-col px-3 py-3 sm:px-4 sm:py-4">
|
||||
<div className="flex min-h-0 w-full flex-1 flex-col">
|
||||
{tab === "organizations" ? <Organizations /> : null}
|
||||
{tab === "contacts" ? <Contacts /> : null}
|
||||
{tab === "countries" ? <Countries /> : null}
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Input } from "@cohaise/ui";
|
||||
import { ApiError, api, type User } from "../lib/api.js";
|
||||
import { FaultyTerminalBackdrop } from "../components/FaultyTerminalBackdrop.js";
|
||||
|
||||
export const Login = ({ onAuthenticated }: { onAuthenticated: (user: User) => void }) => {
|
||||
const [email, setEmail] = useState("");
|
||||
@@ -23,8 +24,10 @@ export const Login = ({ onAuthenticated }: { onAuthenticated: (user: User) => vo
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<div className="w-full max-w-sm">
|
||||
<main className="relative flex min-h-dvh items-center justify-center bg-background px-4 py-10">
|
||||
<FaultyTerminalBackdrop />
|
||||
|
||||
<div className="relative z-10 w-full max-w-sm">
|
||||
<header className="mb-6 text-center">
|
||||
<p className="font-display text-xs font-semibold uppercase tracking-logo text-accent">
|
||||
CoHaiSe
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useState, type FormEvent } from "react";
|
||||
import { Button, Card, CardContent, CardHeader, CardTitle, Input, Skeleton, Spinner } from "@cohaise/ui";
|
||||
import { Button, Input } from "@cohaise/ui";
|
||||
import {
|
||||
ApiError,
|
||||
api,
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
type Organization,
|
||||
type OrganizationInput,
|
||||
} from "../lib/api.js";
|
||||
import { DataTable, type DataTableColumn } from "../components/DataTable.js";
|
||||
import { RecordDialog } from "../components/RecordDialog.js";
|
||||
import { RowActionButton } from "../components/RowActionButton.js";
|
||||
import { PenMaskIcon, TrashMaskIcon } from "../components/icons.js";
|
||||
|
||||
const EMPTY: OrganizationInput = {
|
||||
name: "",
|
||||
@@ -33,10 +37,11 @@ export const Organizations = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const [editing, setEditing] = useState<Organization | null>(null);
|
||||
const [form, setForm] = useState<OrganizationInput>(EMPTY);
|
||||
// Un etat explicite : comparer form a EMPTY ne fonctionnerait pas, car
|
||||
// saisir puis effacer recrée un objet different de la constante.
|
||||
// saisir puis effacer recree un objet different de la constante.
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
@@ -64,15 +69,21 @@ export const Organizations = () => {
|
||||
.catch(() => undefined);
|
||||
}, []);
|
||||
|
||||
const close = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setFormError(null);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const openCreate = () => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const openEdit = (organization: Organization) => {
|
||||
setOpen(true);
|
||||
setEditing(organization);
|
||||
setForm({
|
||||
name: organization.name,
|
||||
@@ -87,14 +98,15 @@ export const Organizations = () => {
|
||||
countryId: organization.country_id,
|
||||
description: organization.description,
|
||||
});
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const submit = async (event: FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const name = text(form.name ?? "");
|
||||
if (!name) {
|
||||
setError("Le nom de l'entreprise est obligatoire.");
|
||||
setFormError("Le nom de l'entreprise est obligatoire.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -113,16 +125,14 @@ export const Organizations = () => {
|
||||
};
|
||||
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
setFormError(null);
|
||||
try {
|
||||
if (editing) await api.updateOrganization(editing.id, payload);
|
||||
else await api.createOrganization(payload);
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setOpen(false);
|
||||
close();
|
||||
await load();
|
||||
} catch (caught) {
|
||||
setError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
setFormError(caught instanceof ApiError ? caught.message : "Enregistrement impossible.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
@@ -151,194 +161,207 @@ export const Organizations = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
const columns: DataTableColumn<Organization>[] = [
|
||||
{
|
||||
id: "name",
|
||||
header: "Nom",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.name,
|
||||
cell: (row) => (
|
||||
<div className="flex min-w-0 flex-col">
|
||||
<span className="truncate font-medium text-foreground">{row.name}</span>
|
||||
{row.website ? (
|
||||
<a
|
||||
href={/^https?:\/\//i.test(row.website) ? row.website : `https://${row.website}`}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
className="block max-w-[16rem] truncate text-xs text-subtle-foreground transition-colors hover:text-accent"
|
||||
>
|
||||
{row.website.replace(/^https?:\/\//i, "")}
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "city",
|
||||
header: "Ville",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.city,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.city ?? "—",
|
||||
},
|
||||
{
|
||||
id: "country",
|
||||
header: "Pays",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.country_name ?? row.country_code,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.country_code ?? "—",
|
||||
},
|
||||
{
|
||||
id: "industry",
|
||||
header: "Secteur",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.industry,
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.industry ?? "—",
|
||||
},
|
||||
{
|
||||
id: "contact",
|
||||
header: "Contact",
|
||||
className: "text-muted-foreground",
|
||||
cell: (row) => row.email ?? row.phone ?? "—",
|
||||
},
|
||||
{
|
||||
id: "created",
|
||||
header: "Créée le",
|
||||
sortable: true,
|
||||
sortValue: (row) => row.created_at,
|
||||
cell: (row) => (
|
||||
<span className="tabular-nums text-subtle-foreground">{formatDate(row.created_at)}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-6">
|
||||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div className="w-full max-w-xs">
|
||||
<>
|
||||
<DataTable
|
||||
data={rows}
|
||||
columns={columns}
|
||||
keyExtractor={(organization) => organization.id}
|
||||
loading={loading}
|
||||
error={error}
|
||||
emptyMessage="Aucune entreprise"
|
||||
emptyHint="Créez la première pour commencer."
|
||||
search={{
|
||||
value: search,
|
||||
onChange: setSearch,
|
||||
placeholder: "Nom, ville, secteur…",
|
||||
}}
|
||||
actions={<Button onClick={openCreate}>Nouvelle entreprise</Button>}
|
||||
rowActions={(organization) => (
|
||||
<div className="flex items-center justify-end gap-1.5">
|
||||
<RowActionButton
|
||||
label={`Modifier ${organization.name}`}
|
||||
onClick={() => openEdit(organization)}
|
||||
>
|
||||
<PenMaskIcon />
|
||||
</RowActionButton>
|
||||
<RowActionButton
|
||||
label={`Supprimer ${organization.name}`}
|
||||
tone="destructive"
|
||||
onClick={() => void remove(organization)}
|
||||
>
|
||||
<TrashMaskIcon />
|
||||
</RowActionButton>
|
||||
</div>
|
||||
)}
|
||||
footer={
|
||||
<span>
|
||||
{rows.length === total
|
||||
? `${total} entreprise${total > 1 ? "s" : ""}`
|
||||
: `${rows.length} sur ${total} entreprises`}
|
||||
</span>
|
||||
}
|
||||
initialSort={{ column: "created", direction: "desc" }}
|
||||
/>
|
||||
|
||||
<RecordDialog
|
||||
open={open}
|
||||
title={editing ? "Modifier l'entreprise" : "Nouvelle entreprise"}
|
||||
onClose={close}
|
||||
>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Rechercher"
|
||||
type="search"
|
||||
placeholder="Nom, ville, secteur…"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name ?? ""}
|
||||
onChange={(event) => set("name")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button onClick={openCreate}>Nouvelle entreprise</Button>
|
||||
</div>
|
||||
|
||||
{open ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{editing ? "Modifier l'entreprise" : "Nouvelle entreprise"}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form className="grid gap-4 sm:grid-cols-2" onSubmit={(event) => void submit(event)}>
|
||||
<Input
|
||||
label="Nom *"
|
||||
required
|
||||
value={form.name ?? ""}
|
||||
onChange={(event) => set("name")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Secteur"
|
||||
value={form.industry ?? ""}
|
||||
onChange={(event) => set("industry")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Site web"
|
||||
type="url"
|
||||
value={form.website ?? ""}
|
||||
onChange={(event) => set("website")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 rounded-md border border-border-control bg-background px-3 text-sm"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
label="Adresse"
|
||||
value={form.addressLine1 ?? ""}
|
||||
onChange={(event) => set("addressLine1")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Complément"
|
||||
value={form.addressLine2 ?? ""}
|
||||
onChange={(event) => set("addressLine2")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Code postal"
|
||||
value={form.postalCode ?? ""}
|
||||
onChange={(event) => set("postalCode")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Ville"
|
||||
value={form.city ?? ""}
|
||||
onChange={(event) => set("city")(event.target.value)}
|
||||
/>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3 sm:col-span-2">
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="secondary"
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setForm(EMPTY);
|
||||
setError(null);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
Annuler
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
<Skeleton className="h-10" />
|
||||
</div>
|
||||
) : error && rows.length === 0 ? (
|
||||
<p className="text-sm text-destructive">{error}</p>
|
||||
) : rows.length === 0 ? (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Aucune entreprise. Créez la première pour commencer.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-auto">
|
||||
<table className="w-full border-collapse text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border-control text-left text-xs uppercase tracking-label text-subtle-foreground">
|
||||
<th className="py-2 pr-4">Nom</th>
|
||||
<th className="py-2 pr-4">Ville</th>
|
||||
<th className="py-2 pr-4">Pays</th>
|
||||
<th className="py-2 pr-4">Secteur</th>
|
||||
<th className="py-2 pr-4">Contact</th>
|
||||
<th className="py-2 pr-4">Créée le</th>
|
||||
<th className="py-2 pr-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((organization) => (
|
||||
<tr key={organization.id} className="border-b border-border-control/60">
|
||||
<td className="py-3 pr-4 font-medium">{organization.name}</td>
|
||||
<td className="py-3 pr-4">{organization.city ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{organization.country_code ?? "—"}</td>
|
||||
<td className="py-3 pr-4">{organization.industry ?? "—"}</td>
|
||||
<td className="py-3 pr-4">
|
||||
{organization.email ?? organization.phone ?? "—"}
|
||||
</td>
|
||||
<td className="py-3 pr-4 text-subtle-foreground">
|
||||
{formatDate(organization.created_at)}
|
||||
</td>
|
||||
<td className="py-3 pr-4">
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button size="sm" variant="secondary" onClick={() => openEdit(organization)}>
|
||||
Modifier
|
||||
</Button>
|
||||
{
|
||||
<Button size="sm" variant="destructive" onClick={() => void remove(organization)}>
|
||||
Supprimer
|
||||
</Button>
|
||||
}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<Input
|
||||
label="Secteur"
|
||||
value={form.industry ?? ""}
|
||||
onChange={(event) => set("industry")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Site web"
|
||||
type="url"
|
||||
value={form.website ?? ""}
|
||||
onChange={(event) => set("website")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="E-mail"
|
||||
type="email"
|
||||
value={form.email ?? ""}
|
||||
onChange={(event) => set("email")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Téléphone"
|
||||
value={form.phone ?? ""}
|
||||
onChange={(event) => set("phone")(event.target.value)}
|
||||
/>
|
||||
<label className="flex flex-col gap-2 text-sm font-medium text-foreground">
|
||||
Pays
|
||||
<select
|
||||
className="h-10 w-full rounded-sm border border-border-control bg-surface px-3 text-sm text-foreground transition-[background-color,border-color,box-shadow] duration-fast ease-out-soft hover:border-accent/60 hover:bg-surface-raised focus-visible:border-border-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||||
value={form.countryId ?? ""}
|
||||
onChange={(event) =>
|
||||
set("countryId")(event.target.value ? Number(event.target.value) : null)
|
||||
}
|
||||
>
|
||||
<option value="">— Aucun —</option>
|
||||
{countries.map((country) => (
|
||||
<option key={country.id} value={country.id}>
|
||||
{country.name} ({country.code})
|
||||
</option>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
<p className="mt-3 text-xs text-subtle-foreground">
|
||||
{total} entreprise{total > 1 ? "s" : ""}
|
||||
{loading ? <Spinner size="xs" /> : null}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</select>
|
||||
</label>
|
||||
<Input
|
||||
label="Adresse"
|
||||
value={form.addressLine1 ?? ""}
|
||||
onChange={(event) => set("addressLine1")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Complément"
|
||||
value={form.addressLine2 ?? ""}
|
||||
onChange={(event) => set("addressLine2")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Code postal"
|
||||
value={form.postalCode ?? ""}
|
||||
onChange={(event) => set("postalCode")(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Ville"
|
||||
value={form.city ?? ""}
|
||||
onChange={(event) => set("city")(event.target.value)}
|
||||
/>
|
||||
<div className="sm:col-span-2">
|
||||
<Input
|
||||
label="Notes"
|
||||
value={form.description ?? ""}
|
||||
onChange={(event) => set("description")(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{formError ? (
|
||||
<p className="text-sm text-destructive sm:col-span-2" role="alert">
|
||||
{formError}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex items-center justify-end gap-3 sm:col-span-2">
|
||||
<Button type="button" variant="secondary" onClick={close}>
|
||||
Annuler
|
||||
</Button>
|
||||
<Button type="submit" isLoading={busy}>
|
||||
{editing ? "Enregistrer" : "Créer"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</RecordDialog>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,3 +2,11 @@
|
||||
@import "@cohaise/ui/styles";
|
||||
|
||||
@source "../../../../frontend/shared/src";
|
||||
|
||||
/* Hauteur explicite de la racine : le shell du CRM peut ainsi occuper
|
||||
exactement le viewport et ne jamais faire defiler la page elle-meme. */
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user