dstpabuaran.com/resources/js/pages/admin/master/raw-material/variant/sub-row.tsx
Yoga Pangestu d91ec8869e refactor: replace tooltip buttons with row actions component in supplier and role columns
feat: implement delete confirmation dialog component for better UX

refactor: update supplier and role index pages to utilize new form dialog and delete confirm dialog components

feat: add reusable form dialog component for creating and editing entities

feat: introduce filter popover component for enhanced filtering options in data tables

feat: create image preview button component for displaying images with modal preview

feat: add page header component for consistent page layout

feat: implement row actions component for handling actions on table rows

feat: add status badge component for displaying entity statuses

feat: create toggle status component for easily toggling entity states

feat: implement draft save hook for auto-saving form data

feat: add server table hook for managing server-side pagination and filtering

feat: create utility functions for formatting dates and numbers

feat: add constants for month names and measurement units
2026-08-02 23:40:12 +07:00

153 lines
6.4 KiB
TypeScript

import { router } from '@inertiajs/react';
import { Pencil, Trash2 } from 'lucide-react';
import { useState } from 'react';
import { ConfirmDialog } from '@/components/confirm-dialog';
import { ImagePreviewButton } from '@/components/image-preview-button';
import { RowActions } from '@/components/row-actions';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@/components/ui/table';
import { formatNumber } from '@/lib/format';
import { formatCurrency } from '@/lib/utils';
import {
edit as variantEdit,
destroy as variantDestroy,
} from '@/routes/admin/master/raw-materials/variants';
import type { RawMaterial, RawMaterialVariant } from '../columns';
export function RawMaterialVariantSubRow({
rawMaterial,
}: {
rawMaterial: RawMaterial;
}) {
const variants = rawMaterial.raw_material_prices ?? [];
const [deletingVariant, setDeletingVariant] =
useState<RawMaterialVariant | null>(null);
function handleDeleteVariant() {
if (!deletingVariant) {
return;
}
router.delete(
variantDestroy.url({
rawMaterial: rawMaterial.id,
variant: deletingVariant.id,
}),
{
onSuccess: () => setDeletingVariant(null),
},
);
}
return (
<div className="overflow-x-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[50px] text-center">
No
</TableHead>
<TableHead className="w-[60px]">Foto</TableHead>
<TableHead>Nama Varian</TableHead>
<TableHead>Harga</TableHead>
<TableHead className="text-center">Stok</TableHead>
<TableHead className="w-[100px] text-center">
Aksi
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{variants.length === 0 ? (
<TableRow>
<TableCell
colSpan={6}
className="text-center text-muted-foreground"
>
Tidak ada varian.
</TableCell>
</TableRow>
) : (
variants.map((variant, index) => (
<TableRow key={variant.id}>
<TableCell className="text-center">
{index + 1}
</TableCell>
<TableCell>
{variant.photo_url ? (
<ImagePreviewButton
srcs={[variant.photo_url]}
title={variant.variant}
/>
) : (
<div className="flex h-10 w-10 items-center justify-center rounded-md bg-muted text-xs text-muted-foreground">
N/A
</div>
)}
</TableCell>
<TableCell className="font-medium">
{variant.variant}
</TableCell>
<TableCell>
{formatCurrency(variant.price)}
</TableCell>
<TableCell className="text-center">
{formatNumber(variant.stock)}
</TableCell>
<TableCell>
<RowActions
actions={[
{
label: 'Edit',
icon: (
<Pencil className="h-4 w-4" />
),
onClick: () => {
window.location.href =
variantEdit.url({
rawMaterial:
rawMaterial.id,
variant: variant.id,
});
},
},
{
label: 'Hapus',
icon: (
<Trash2 className="h-4 w-4 text-destructive" />
),
onClick: () =>
setDeletingVariant(variant),
},
]}
/>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
{deletingVariant && (
<ConfirmDialog
open={deletingVariant !== null}
onOpenChange={(open) => {
if (!open) {
setDeletingVariant(null);
}
}}
title="Hapus Varian"
description={`Apakah Anda yakin ingin menghapus varian "${deletingVariant.variant}" dari bahan baku "${rawMaterial.name}"? Tindakan ini tidak dapat dibatalkan.`}
confirmLabel="Hapus"
onConfirm={handleDeleteVariant}
/>
)}
</div>
);
}