Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/src/components/dynamic-breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SEGMENT_LABELS = {
customers: "Clientes",
branches: "Sucursales",
contacts: "Contactos",
suppliers: "Proveedores",
} satisfies Record<string, string>;

type KnownSegment = keyof typeof SEGMENT_LABELS;
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/nav-items.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { LinkProps } from "@tanstack/react-router";
import type { LucideIcon } from "lucide-react";
import {
BriefcaseBusiness,
Building2,
Contact,
ContactRound,
DollarSign,
Home,
Truck,
Users,
} from "lucide-react";

Expand Down Expand Up @@ -42,6 +44,11 @@ export const NAV_ENTRIES: NavEntry[] = [
{ to: "/contacts", label: "Contactos", icon: Contact },
],
},
{
label: "Administración",
icon: BriefcaseBusiness,
items: [{ to: "/suppliers", label: "Proveedores", icon: Truck }],
},
];

export function isSection(entry: NavEntry): entry is NavSection {
Expand Down
154 changes: 154 additions & 0 deletions apps/web/src/components/suppliers/supplier-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import type { AppRouterOutputs } from "@suni/api/routers/index";
import { Button } from "@suni/ui/components/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuTrigger,
} from "@suni/ui/components/dropdown-menu";
import { cn } from "@suni/ui/lib/utils";
import { Link } from "@tanstack/react-router";
import {
ChevronRight,
MapPin,
MoreVertical,
Pencil,
Phone,
} from "lucide-react";

import { ArchiveMenuItem } from "@/components/customers/shared/archive-menu-item";
import { ArchivedFooter } from "@/components/customers/shared/archived-footer";

interface SupplierCardProps {
supplier: AppRouterOutputs["suppliers"]["list"][number];
onChangeStatus?: () => void;
}

export function SupplierCard({ supplier, onChangeStatus }: SupplierCardProps) {
const isArchived = !!supplier.archived;
const params = { supplierId: supplier.id };

return (
<div
className={cn(
"group bg-card relative flex h-full flex-col overflow-hidden rounded-xl border transition-colors duration-200",
isArchived
? "border-border bg-muted/30"
: "border-border hover:border-primary/30 hover:shadow-md"
)}
>
<div className="border-muted border-b p-4">
<div className="flex items-center justify-between gap-2">
<Link
className="min-w-0 flex-1"
params={params}
to="/suppliers/$supplierId"
>
<h2
className={cn(
"line-clamp-2 text-lg leading-tight font-semibold transition-colors hover:underline",
isArchived
? "text-muted-foreground decoration-muted-foreground/50 underline underline-offset-4"
: "text-primary"
)}
>
{supplier.name}
{isArchived ? <span className="sr-only">, Archivado</span> : null}
</h2>
</Link>

{onChangeStatus ? (
<span className="shrink-0 transition-opacity pointer-fine:opacity-0 pointer-fine:group-hover:opacity-100 pointer-fine:focus-within:opacity-100">
<DropdownMenu>
<DropdownMenuTrigger
render={<Button size="icon-sm" variant="ghost" />}
>
<span className="sr-only">Acciones de {supplier.name}</span>
<MoreVertical aria-hidden className="size-4" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuGroup>
<DropdownMenuLabel>Acciones</DropdownMenuLabel>
{isArchived ? null : (
<DropdownMenuItem
render={
<Link
params={params}
to="/suppliers/$supplierId/edit"
/>
}
>
<Pencil aria-hidden className="mr-2 size-4" />
Editar
</DropdownMenuItem>
)}
<ArchiveMenuItem
isOwnArchived={isArchived}
onClick={onChangeStatus}
/>
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
</span>
) : null}
</div>
</div>

<div className="flex grow flex-col p-5">
<div>
<span className="bg-muted text-muted-foreground inline-flex items-center rounded-md px-2.5 py-1 text-xs font-medium">
{supplier.rfc}
</span>
</div>

<div className="mt-4 flex items-start gap-2">
<MapPin
aria-hidden
className="text-muted-foreground/70 mt-0.5 size-4 shrink-0"
/>
<div className="text-muted-foreground flex flex-col text-sm leading-relaxed">
<span className="line-clamp-1">
{supplier.suburb}, {supplier.city}
</span>
<span className="text-muted-foreground/70 text-xs">
{supplier.state} · CP {supplier.postalCode}
</span>
</div>
</div>

<div className="text-muted-foreground mt-3 flex items-start gap-2 text-sm tabular-nums">
<Phone
aria-hidden
className="text-muted-foreground/70 mt-0.5 size-4 shrink-0"
/>
<span>
{supplier.phone}
{supplier.phoneExtension && ` ext. ${supplier.phoneExtension}`}
</span>
</div>
</div>

{isArchived ? (
<ArchivedFooter
label="Archivado"
name={supplier.name}
onUnarchive={onChangeStatus}
/>
) : (
<Link params={params} to="/suppliers/$supplierId">
<div className="border-border bg-card group-hover:bg-muted/30 flex items-center justify-between border-t px-4 py-3 transition-colors">
<span className="text-muted-foreground text-sm font-medium">
Ver detalles
</span>
<ChevronRight
aria-hidden
className="text-muted-foreground/70 group-hover:text-primary size-4 transition-colors"
/>
</div>
</Link>
)}
</div>
);
}
40 changes: 40 additions & 0 deletions apps/web/src/components/suppliers/supplier-data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { AppRouterOutputs } from "@suni/api/routers/index";

interface SupplierDataProps {
supplier: AppRouterOutputs["suppliers"]["get"];
}

export function SupplierData({ supplier }: SupplierDataProps) {
return (
<section
aria-label="Datos del proveedor"
className="bg-card rounded-xl border p-5"
>
<dl className="grid gap-5 sm:grid-cols-2">
<div className="space-y-1">
<dt className="text-muted-foreground text-xs font-medium">
Dirección fiscal
</dt>
<dd className="text-sm">
<address className="not-italic">
{supplier.street}, No. Ext. {supplier.extNumber}
{supplier.intNumber && `, No. Int. ${supplier.intNumber}`},
Colonia {supplier.suburb}
<br />
{supplier.city}, {supplier.state}, CP {supplier.postalCode}
</address>
</dd>
</div>
<div className="space-y-1">
<dt className="text-muted-foreground text-xs font-medium">
Teléfono
</dt>
<dd className="text-sm tabular-nums">
{supplier.phone}
{supplier.phoneExtension && ` ext. ${supplier.phoneExtension}`}
</dd>
</div>
</dl>
</section>
);
}
23 changes: 23 additions & 0 deletions apps/web/src/components/suppliers/supplier-filters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getRouteApi } from "@tanstack/react-router";

import { FilterBar } from "@/components/customers/shared/filter-bar";

const routeApi = getRouteApi("/_auth/suppliers/");

export function SupplierFilters() {
const { name } = routeApi.useSearch();
const navigate = routeApi.useNavigate();

return (
<FilterBar
onSearchChange={(next) =>
navigate({
search: (prev) => ({ ...prev, name: next }),
replace: true,
})
}
search={name}
searchLabel="Buscar por razón social"
/>
);
}
Loading
Loading