dstpabuaran.com/resources/js/pages/admin/master/supplier/columns.tsx
Yoga Pangestu 8edeaf0db7 feat: implement supplier management with CRUD functionality
- Added SupplierController for handling supplier operations.
- Created SupplierRequest for validation of supplier data.
- Introduced SupplierService for business logic related to suppliers.
- Developed UI components for supplier management, including a data table and dialogs for creating and editing suppliers.
- Updated routes to include resourceful routes for suppliers.
- Added SupplierSeeder for populating initial supplier data.
- Implemented tests for supplier functionality, including creation, updating, and deletion.
2026-07-29 01:16:58 +07:00

161 lines
5.4 KiB
TypeScript

import type { ColumnDef } from '@tanstack/react-table';
import { ArrowUpDown, Pencil, Trash2 } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip';
export type Supplier = {
id: number;
name: string;
phone_number: string | null;
address: string | null;
};
type CreateColumnsParams = {
handleEdit: (supplier: Supplier) => void;
handleDeleteClick: (supplier: Supplier) => void;
};
export function createSupplierColumns(
params: CreateColumnsParams,
): ColumnDef<Supplier>[] {
const { handleEdit, handleDeleteClick } = params;
return [
{
id: 'no',
header: () => <span className="block text-center">No</span>,
cell: ({ row }) => (
<span className="block text-center">
{row.index + 1}
</span>
),
meta: {
className: 'w-[50px] text-center',
headerClassName: 'w-[50px] text-center',
},
},
{
accessorKey: 'name',
header: ({ column }) => (
<Button
variant="ghost"
className="-ml-3 h-8"
onClick={() =>
column.toggleSorting(
column.getIsSorted() === 'asc',
)
}
>
<span>Nama</span>
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
),
cell: ({ row }) => (
<span className="font-medium">
{row.getValue('name') as string}
</span>
),
},
{
accessorKey: 'phone_number',
header: ({ column }) => (
<Button
variant="ghost"
className="-ml-3 h-8"
onClick={() =>
column.toggleSorting(
column.getIsSorted() === 'asc',
)
}
>
<span>No. Telepon</span>
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
),
cell: ({ row }) => (
<span>
{row.getValue('phone_number') as string ?? '-'}
</span>
),
},
{
accessorKey: 'address',
header: ({ column }) => (
<Button
variant="ghost"
className="-ml-3 h-8"
onClick={() =>
column.toggleSorting(
column.getIsSorted() === 'asc',
)
}
>
<span>Alamat</span>
<ArrowUpDown className="ml-2 h-4 w-4" />
</Button>
),
cell: ({ row }) => (
<span className="max-w-[200px] truncate block">
{row.getValue('address') as string ?? '-'}
</span>
),
},
{
id: 'actions',
header: () => <span className="block text-center">Aksi</span>,
meta: {
className: 'w-[100px] text-center',
headerClassName: 'w-[100px] text-center',
},
cell: ({ row }) => {
const supplier = row.original;
return (
<TooltipProvider>
<div className="flex items-center justify-center gap-1">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={() =>
handleEdit(supplier)
}
>
<Pencil className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent side="top">
Edit
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon"
onClick={() =>
handleDeleteClick(supplier)
}
>
<Trash2 className="h-4 w-4 text-destructive" />
</Button>
</TooltipTrigger>
<TooltipContent side="top">
Hapus
</TooltipContent>
</Tooltip>
</div>
</TooltipProvider>
);
},
},
];
}