feat: Menambahkan fitur untuk menyimpan, memperbarui, dan menghapus data Hukum
parent
a2343db925
commit
db45e28350
|
@ -2,8 +2,15 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests\HukumRequest;
|
||||||
|
use App\Models\Hukum;
|
||||||
|
use App\Models\JenisSanksi;
|
||||||
|
use App\Models\Penaatan;
|
||||||
|
use App\Models\Perusahaan;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
|
|
||||||
class HukumController extends Controller
|
class HukumController extends Controller
|
||||||
|
@ -11,10 +18,116 @@ class HukumController extends Controller
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return Inertia::render('admin/hukum/index_hukum');
|
$hukumData = Hukum::with(['perusahaan', 'jenisSanksi', 'penaatan'])->orderBy('created_at', 'desc')->get();
|
||||||
|
return Inertia::render('admin/hukum/index_hukum', [
|
||||||
|
'hukumData' => $hukumData,
|
||||||
|
'perusahaan' => Perusahaan::all(),
|
||||||
|
'jenisSanksi' => JenisSanksi::all(),
|
||||||
|
'penaatan' => Penaatan::all(),
|
||||||
|
]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error('Error rendering view: ' . $e->getMessage());
|
Log::error('Error fetching data: ' . $e->getMessage());
|
||||||
return back()->with('error', 'Something went wrong.');
|
return back()->with('error', 'Terjadi kesalahan saat memuat data.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function store(HukumRequest $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
if ($request->hasFile('SanksiFile')) {
|
||||||
|
$fileName = time() . '_' . $request->file('SanksiFile')->getClientOriginalName();
|
||||||
|
$path = $request->file('SanksiFile')->storeAs('files/hukum/sanksi', $fileName, 'public');
|
||||||
|
$data['SanksiFile'] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->hasFile('PenaatanFile')) {
|
||||||
|
$fileName = time() . '_' . $request->file('PenaatanFile')->getClientOriginalName();
|
||||||
|
$path = $request->file('PenaatanFile')->storeAs('files/hukum/penaatan', $fileName, 'public');
|
||||||
|
$data['PenaatanFile'] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
Hukum::create($data);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return redirect()->route('admin.hukum.index')->with('success', 'Status Hukum berhasil ditambahkan');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log::error('Error creating hukum: ' . $e->getMessage());
|
||||||
|
return response()->json(['message' => 'Error: ' . $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(HukumRequest $request, Hukum $hukum)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$data = $request->validated();
|
||||||
|
|
||||||
|
if ($request->hasFile('SanksiFile')) {
|
||||||
|
// Delete old file if exists
|
||||||
|
if ($hukum->SanksiFile && Storage::disk('public')->exists($hukum->SanksiFile)) {
|
||||||
|
Storage::disk('public')->delete($hukum->SanksiFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = time() . '_' . $request->file('SanksiFile')->getClientOriginalName();
|
||||||
|
$path = $request->file('SanksiFile')->storeAs('files/hukum/sanksi', $fileName, 'public');
|
||||||
|
$data['SanksiFile'] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->hasFile('PenaatanFile')) {
|
||||||
|
// Delete old file if exists
|
||||||
|
if ($hukum->PenaatanFile && Storage::disk('public')->exists($hukum->PenaatanFile)) {
|
||||||
|
Storage::disk('public')->delete($hukum->PenaatanFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileName = time() . '_' . $request->file('PenaatanFile')->getClientOriginalName();
|
||||||
|
$path = $request->file('PenaatanFile')->storeAs('files/hukum/penaatan', $fileName, 'public');
|
||||||
|
$data['PenaatanFile'] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
$hukum->update($data);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return redirect()->route('admin.hukum.index')->with('success', 'Status Hukum berhasil diperbarui');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log::error('Error updating hukum: ' . $e->getMessage());
|
||||||
|
return response()->json(['message' => 'Error: ' . $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Hukum $hukum)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
// Delete file if exists
|
||||||
|
if ($hukum->SanksiFile && Storage::disk('public')->exists($hukum->SanksiFile)) {
|
||||||
|
Storage::disk('public')->delete($hukum->SanksiFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hukum->PenaatanFile && Storage::disk('public')->exists($hukum->PenaatanFile)) {
|
||||||
|
Storage::disk('public')->delete($hukum->PenaatanFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
$hukum->delete();
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return redirect()->route('admin.hukum.index')->with('success', 'Status Hukum berhasil dihapus');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log::error('Error deleting hukum: ' . $e->getMessage());
|
||||||
|
return response()->json(['message' => 'Error: ' . $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,12 @@ class HukumRequest extends FormRequest
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'PerusahaanId' => 'nullable|integer|exists:RefPerusahaan,id',
|
'PerusahaanId' => 'nullable|integer',
|
||||||
'JenisSanksiId' => 'nullable|integer|exists:RefJenisSanksi,id',
|
'JenisSanksiId' => 'nullable|integer',
|
||||||
'SanksiNumber' => 'nullable|string|max:100',
|
'SanksiNumber' => 'nullable|string|max:100',
|
||||||
'SanksiDate' => 'nullable|date',
|
'SanksiDate' => 'nullable|date',
|
||||||
'SanksiFile' => 'nullable|file|mimes:pdf|max:2048',
|
'SanksiFile' => 'nullable|file|mimes:pdf|max:2048',
|
||||||
'StatusPenaatan' => 'required|integer|in:1,2,3',
|
'PenaatanId' => 'required|integer|in:1,2,3',
|
||||||
'PenaatanNumber' => 'nullable|string|max:100',
|
'PenaatanNumber' => 'nullable|string|max:100',
|
||||||
'PenaatanDate' => 'nullable|date',
|
'PenaatanDate' => 'nullable|date',
|
||||||
'PenaatanFile' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
'PenaatanFile' => 'nullable|file|mimes:pdf,jpg,png|max:2048',
|
||||||
|
@ -46,8 +46,8 @@ class HukumRequest extends FormRequest
|
||||||
'SanksiDate.date' => 'Tanggal SK Sanksi harus berupa format tanggal.',
|
'SanksiDate.date' => 'Tanggal SK Sanksi harus berupa format tanggal.',
|
||||||
'SanksiFile.mimes' => 'File Sanksi harus berupa PDF',
|
'SanksiFile.mimes' => 'File Sanksi harus berupa PDF',
|
||||||
'SanksiFile.max' => 'Ukuran file maksimal 2MB.',
|
'SanksiFile.max' => 'Ukuran file maksimal 2MB.',
|
||||||
'StatusPenaatan.required'=> 'Status Penaatan wajib diisi.',
|
'PenaatanId.required'=> 'Status Penaatan wajib diisi.',
|
||||||
'StatusPenaatan.in' => 'Status Penaatan hanya boleh 1, 2, atau 3.',
|
'PenaatanId.in' => 'Status Penaatan hanya boleh 1, 2, atau 3.',
|
||||||
'PenaatanNumber.max' => 'Nomor SK Penaatan maksimal 100 karakter.',
|
'PenaatanNumber.max' => 'Nomor SK Penaatan maksimal 100 karakter.',
|
||||||
'PenaatanDate.date' => 'Tanggal SK Penaatan harus berupa format tanggal.',
|
'PenaatanDate.date' => 'Tanggal SK Penaatan harus berupa format tanggal.',
|
||||||
'PenaatanFile.mimes' => 'File Penaatan harus berupa PDF',
|
'PenaatanFile.mimes' => 'File Penaatan harus berupa PDF',
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Hukum extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $table = 'Hukum';
|
protected $table = 'Hukum';
|
||||||
|
protected $primaryKey = 'HukumId';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'PerusahaanId',
|
'PerusahaanId',
|
||||||
|
@ -17,23 +18,26 @@ class Hukum extends Model
|
||||||
'SanksiNumber',
|
'SanksiNumber',
|
||||||
'SanksiDate',
|
'SanksiDate',
|
||||||
'SanksiFile',
|
'SanksiFile',
|
||||||
'StatusPenaatan',
|
'PenaatanId',
|
||||||
'PenaatanNumber',
|
'PenaatanNumber',
|
||||||
'PenaatanDate',
|
'PenaatanDate',
|
||||||
'PenaatanFile',
|
'PenaatanFile',
|
||||||
'IsDeleted',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
public function perusahaan()
|
public function perusahaan()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Perusahaan::class, 'PerusahaanId');
|
return $this->belongsTo(Perusahaan::class, 'PerusahaanId');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Relasi ke tabel jenis sanksi.
|
|
||||||
*/
|
|
||||||
public function jenisSanksi()
|
public function jenisSanksi()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(JenisSanksi::class, 'JenisSanksiId');
|
return $this->belongsTo(JenisSanksi::class, 'JenisSanksiId');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function penaatan()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Penaatan::class, 'PenaatanId');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('Hukum', function (Blueprint $table) {
|
||||||
|
// Remove the StatusPenaatan column
|
||||||
|
$table->dropColumn('StatusPenaatan');
|
||||||
|
|
||||||
|
// Add PenaatanId column as foreign key
|
||||||
|
$table->unsignedInteger('PenaatanId')->nullable()->comment('id dari tabel Penaatan untuk mengambil NamaPenaatan');
|
||||||
|
$table->foreign('PenaatanId')->references('PenaatanId')->on('Penaatan')->onDelete('set null');
|
||||||
|
|
||||||
|
// Add index for the new column
|
||||||
|
$table->index('PenaatanId');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('Hukum', function (Blueprint $table) {
|
||||||
|
// Remove the foreign key constraint and the PenaatanId column
|
||||||
|
$table->dropForeign(['PenaatanId']);
|
||||||
|
$table->dropIndex(['PenaatanId']);
|
||||||
|
$table->dropColumn('PenaatanId');
|
||||||
|
|
||||||
|
// Add back the StatusPenaatan column with its original properties
|
||||||
|
$table->unsignedTinyInteger('StatusPenaatan')->default(1)->comment('1=pengawasan, 2=peningkatan sanksi, 3=taat');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,277 @@
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogFooter,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import Select from "react-select";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useForm } from "@inertiajs/react";
|
||||||
|
import { useToast } from "@/hooks/use-toast";
|
||||||
|
|
||||||
|
import { HukumType } from "@/types/perusahaan";
|
||||||
|
|
||||||
|
interface AddHukumModalProps {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: () => void;
|
||||||
|
hukumtype: HukumType[];
|
||||||
|
perusahaan: { PerusahaanId: number; NamaPerusahaan: string }[];
|
||||||
|
jenisSanksi: { JenisSanksiId: number; NamaJenisSanksi: string }[];
|
||||||
|
penaatan: { PenaatanId: number; NamaPenaatan: string }[];
|
||||||
|
editingData?: HukumType | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddHukumModal({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
onSuccess,
|
||||||
|
hukumtype,
|
||||||
|
perusahaan,
|
||||||
|
jenisSanksi,
|
||||||
|
penaatan,
|
||||||
|
editingData,
|
||||||
|
}: AddHukumModalProps) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const { data, setData, post, reset } = useForm<{
|
||||||
|
PerusahaanId: string;
|
||||||
|
JenisSanksiId: string;
|
||||||
|
SanksiNumber: string;
|
||||||
|
SanksiDate: string;
|
||||||
|
SanksiFile: File | null;
|
||||||
|
PenaatanId: string;
|
||||||
|
PenaatanNumber: string;
|
||||||
|
PenaatanDate: string;
|
||||||
|
PenaatanFile: File | null;
|
||||||
|
currentSanksiFile?: string;
|
||||||
|
currentPenaatanFile?: string;
|
||||||
|
}>({
|
||||||
|
PerusahaanId: editingData?.PerusahaanId?.toString() || "",
|
||||||
|
JenisSanksiId: editingData?.JenisSanksiId?.toString() || "",
|
||||||
|
SanksiNumber: editingData?.SanksiNumber || "",
|
||||||
|
SanksiDate: editingData?.SanksiDate || "",
|
||||||
|
SanksiFile: null,
|
||||||
|
currentSanksiFile: editingData?.SanksiFile,
|
||||||
|
PenaatanId: editingData?.PenaatanId?.toString() || "",
|
||||||
|
PenaatanNumber: editingData?.PenaatanNumber || "",
|
||||||
|
PenaatanDate: editingData?.PenaatanDate || "",
|
||||||
|
PenaatanFile: null,
|
||||||
|
currentPenaatanFile: editingData?.PenaatanFile,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (editingData) {
|
||||||
|
setData({
|
||||||
|
PerusahaanId: editingData.PerusahaanId?.toString() || "",
|
||||||
|
JenisSanksiId: editingData.JenisSanksiId?.toString() || "",
|
||||||
|
SanksiNumber: editingData.SanksiNumber,
|
||||||
|
SanksiDate: editingData.SanksiDate,
|
||||||
|
SanksiFile: null,
|
||||||
|
currentSanksiFile: editingData.SanksiFile,
|
||||||
|
PenaatanId: editingData.PenaatanId?.toString() || "",
|
||||||
|
PenaatanNumber: "",
|
||||||
|
PenaatanDate: "",
|
||||||
|
PenaatanFile: null,
|
||||||
|
currentPenaatanFile: "",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}, [editingData, open]);
|
||||||
|
|
||||||
|
const perusahaanOptions = perusahaan.map((p) => ({
|
||||||
|
value: p.PerusahaanId.toString(),
|
||||||
|
label: p.NamaPerusahaan,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const jenisSanksiOptions = jenisSanksi.map((j) => ({
|
||||||
|
value: j.JenisSanksiId.toString(),
|
||||||
|
label: j.NamaJenisSanksi,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const penaatanOptions = penaatan.map((j) => ({
|
||||||
|
value: j.PenaatanId.toString(),
|
||||||
|
label: j.NamaPenaatan,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const handleSubmit = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("PerusahaanId", data.PerusahaanId);
|
||||||
|
formData.append("JenisSanksiId", data.JenisSanksiId);
|
||||||
|
formData.append("SanksiNumber", data.SanksiNumber);
|
||||||
|
formData.append("SanksiDate", data.SanksiDate);
|
||||||
|
if (data.SanksiFile) formData.append("SanksiFile", data.SanksiFile);
|
||||||
|
|
||||||
|
// Use the selected PenaatanId (no default fallback)
|
||||||
|
formData.append("PenaatanId", data.PenaatanId);
|
||||||
|
|
||||||
|
// Only include these fields if they have values
|
||||||
|
if (data.PenaatanNumber)
|
||||||
|
formData.append("PenaatanNumber", data.PenaatanNumber);
|
||||||
|
if (data.PenaatanDate)
|
||||||
|
formData.append("PenaatanDate", data.PenaatanDate);
|
||||||
|
if (data.PenaatanFile)
|
||||||
|
formData.append("PenaatanFile", data.PenaatanFile);
|
||||||
|
|
||||||
|
const url = editingData
|
||||||
|
? `/admin/hukum/${editingData.HukumId}`
|
||||||
|
: "/admin/hukum";
|
||||||
|
const method = editingData ? post : post;
|
||||||
|
|
||||||
|
method(url, {
|
||||||
|
data: formData,
|
||||||
|
forceFormData: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
toast({
|
||||||
|
title: "Berhasil",
|
||||||
|
description: editingData
|
||||||
|
? "Data berhasil diperbarui"
|
||||||
|
: "Data berhasil ditambahkan",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
reset();
|
||||||
|
setLoading(false);
|
||||||
|
onSuccess();
|
||||||
|
onClose();
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast({
|
||||||
|
title: "Gagal",
|
||||||
|
description: "Terjadi kesalahan saat menyimpan data",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onClose}>
|
||||||
|
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>
|
||||||
|
{editingData ? "Edit" : "Tambah"} Sanksi Administratif
|
||||||
|
</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<form onSubmit={handleSubmit} className="space-y-6">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Label>Nama Perusahaan</Label>
|
||||||
|
<Select
|
||||||
|
id="PerusahaanId"
|
||||||
|
options={perusahaanOptions}
|
||||||
|
placeholder="Pilih Perusahaan"
|
||||||
|
value={perusahaanOptions.find(
|
||||||
|
(p) => p.value === data.PerusahaanId
|
||||||
|
)}
|
||||||
|
onChange={(option) =>
|
||||||
|
setData("PerusahaanId", option?.value || "")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label>Jenis Sanksi</Label>
|
||||||
|
<Select
|
||||||
|
id="JenisSanksiId"
|
||||||
|
options={jenisSanksiOptions}
|
||||||
|
placeholder="Pilih Jenis Sanksi"
|
||||||
|
value={jenisSanksiOptions.find(
|
||||||
|
(j) => j.value === data.JenisSanksiId
|
||||||
|
)}
|
||||||
|
onChange={(option) =>
|
||||||
|
setData("JenisSanksiId", option?.value || "")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label>Nomor SK Sanksi</Label>
|
||||||
|
<Input
|
||||||
|
value={data.SanksiNumber}
|
||||||
|
onChange={(e) =>
|
||||||
|
setData("SanksiNumber", e.target.value)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label>Tanggal SK Sanksi</Label>
|
||||||
|
<Input
|
||||||
|
type="date"
|
||||||
|
value={data.SanksiDate}
|
||||||
|
onChange={(e) =>
|
||||||
|
setData("SanksiDate", e.target.value)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Label>Dokumen SK Sanksi</Label>
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<Input
|
||||||
|
type="file"
|
||||||
|
onChange={(e) =>
|
||||||
|
setData(
|
||||||
|
"SanksiFile",
|
||||||
|
e.target.files
|
||||||
|
? e.target.files[0]
|
||||||
|
: null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{editingData?.SanksiFile && (
|
||||||
|
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<span>
|
||||||
|
File saat ini: {editingData.SanksiFile}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
window.open(
|
||||||
|
`/storage/${editingData.SanksiFile}`,
|
||||||
|
"_blank"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Lihat File
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Label>Status Penaatan</Label>
|
||||||
|
<Select
|
||||||
|
id="PenaatanId"
|
||||||
|
options={penaatanOptions}
|
||||||
|
placeholder="Pilih Status Penaatan"
|
||||||
|
value={penaatanOptions.find(
|
||||||
|
(p) => p.value === data.PenaatanId
|
||||||
|
)}
|
||||||
|
onChange={(option) => {
|
||||||
|
setData("PenaatanId", option?.value || "");
|
||||||
|
}}
|
||||||
|
isDisabled={false} // Enable for all users
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={onClose}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
Batal
|
||||||
|
</Button>
|
||||||
|
<Button type="submit" disabled={loading}>
|
||||||
|
{loading ? "Menyimpan..." : "Simpan"}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useForm } from "@inertiajs/react";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import {
|
import {
|
||||||
|
@ -12,14 +11,6 @@ import {
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogTrigger,
|
|
||||||
DialogContent,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
DialogFooter,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import {
|
import {
|
||||||
Search,
|
Search,
|
||||||
Plus,
|
Plus,
|
||||||
|
@ -27,195 +18,176 @@ import {
|
||||||
Trash2,
|
Trash2,
|
||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
|
AlertTriangle,
|
||||||
|
Edit,
|
||||||
|
FileText,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import AuthenticatedLayout from "@/layouts/authenticated-layout";
|
import AuthenticatedLayout from "@/layouts/authenticated-layout";
|
||||||
import { Head } from "@inertiajs/react";
|
import { Head, router } from "@inertiajs/react";
|
||||||
import { Toaster } from "@/components/ui/toaster";
|
import { Toaster } from "@/components/ui/toaster";
|
||||||
import axios from "axios";
|
import { HukumType } from "@/types/perusahaan";
|
||||||
|
import { AddHukumModal } from "@/components/modals/add-sanksi-hukum";
|
||||||
|
import { AddPenaatanModal } from "@/components/modals/add-penaatan-modal";
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from "@/components/ui/alert-dialog";
|
||||||
|
|
||||||
interface Hukum {
|
interface HukumIndexProps {
|
||||||
HukumId: number;
|
hukumData: HukumType[];
|
||||||
PerusahaanId: number | null;
|
perusahaan: { PerusahaanId: number; NamaPerusahaan: string }[];
|
||||||
JenisSanksiId: number | null;
|
jenisSanksi: { JenisSanksiId: number; NamaJenisSanksi: string }[];
|
||||||
SanksiNumber: string;
|
penaatan: { PenaatanId: number; NamaPenaatan: string }[];
|
||||||
SanksiDate: string;
|
|
||||||
SanksiFile: string;
|
|
||||||
StatusPenaatan: number;
|
|
||||||
PenaatanNumber: string;
|
|
||||||
PenaatanDate: string;
|
|
||||||
PenaatanFile: string;
|
|
||||||
IsDeleted: number;
|
|
||||||
perusahaan: { nama: string } | null;
|
|
||||||
jenisSanksi: { nama: string } | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ITEMS_PER_PAGE = 5;
|
const ITEMS_PER_PAGE = 5;
|
||||||
|
|
||||||
export default function HukumIndex() {
|
export default function HukumIndex({
|
||||||
|
hukumData = [],
|
||||||
|
perusahaan = [],
|
||||||
|
jenisSanksi = [],
|
||||||
|
penaatan = [],
|
||||||
|
}: HukumIndexProps) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const [dataHukum, setDataHukum] = useState<Hukum[]>([]);
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [filteredHukum, setFilteredHukum] = useState<Hukum[]>([]);
|
const [filteredHukum, setFilteredHukum] = useState<HukumType[]>(
|
||||||
|
hukumData || []
|
||||||
|
);
|
||||||
|
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [deletingData, setDeletingData] = useState<HukumType | null>(null);
|
||||||
|
const [isDeleting, setIsDeleting] = useState(false);
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [editing, setEditing] = useState(false);
|
const [isPenaatanModalOpen, setIsPenaatanModalOpen] = useState(false);
|
||||||
const [deleteConfirm, setDeleteConfirm] = useState<Hukum | null>(null);
|
const [editingData, setEditingData] = useState<HukumType | null>(null);
|
||||||
|
const [selectedHukum, setSelectedHukum] = useState<HukumType | null>(null);
|
||||||
const {
|
|
||||||
data,
|
|
||||||
setData,
|
|
||||||
post,
|
|
||||||
put,
|
|
||||||
delete: destroy,
|
|
||||||
reset,
|
|
||||||
} = useForm<Hukum>({
|
|
||||||
HukumId: 0,
|
|
||||||
PerusahaanId: null,
|
|
||||||
JenisSanksiId: null,
|
|
||||||
SanksiNumber: "",
|
|
||||||
SanksiDate: "",
|
|
||||||
SanksiFile: "",
|
|
||||||
StatusPenaatan: 1,
|
|
||||||
PenaatanNumber: "",
|
|
||||||
PenaatanDate: "",
|
|
||||||
PenaatanFile: "",
|
|
||||||
IsDeleted: 0,
|
|
||||||
perusahaan: null,
|
|
||||||
jenisSanksi: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
axios
|
|
||||||
.get("/admin/hukum")
|
|
||||||
.then((response) => {
|
|
||||||
if (response.data && response.data.data) {
|
|
||||||
setDataHukum(response.data.data);
|
|
||||||
setFilteredHukum(response.data.data);
|
|
||||||
} else {
|
|
||||||
setDataHukum([]);
|
|
||||||
setFilteredHukum([]);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error fetching data:", error);
|
|
||||||
setDataHukum([]);
|
|
||||||
setFilteredHukum([]);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Filter Data
|
|
||||||
useEffect(() => {
|
|
||||||
let filtered = dataHukum;
|
|
||||||
if (search) {
|
|
||||||
filtered = filtered.filter((hukum) =>
|
|
||||||
hukum.SanksiNumber.toLowerCase().includes(search.toLowerCase())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setFilteredHukum(filtered);
|
|
||||||
setCurrentPage(1);
|
|
||||||
}, [dataHukum, search]);
|
|
||||||
|
|
||||||
// Pagination
|
|
||||||
const totalPages = filteredHukum?.length
|
|
||||||
? Math.ceil(filteredHukum.length / ITEMS_PER_PAGE)
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
|
// Pagination setup
|
||||||
|
const totalPages = Math.ceil((filteredHukum?.length || 0) / ITEMS_PER_PAGE);
|
||||||
const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
|
const startIndex = (currentPage - 1) * ITEMS_PER_PAGE;
|
||||||
const endIndex = startIndex + ITEMS_PER_PAGE;
|
const endIndex = startIndex + ITEMS_PER_PAGE;
|
||||||
const currentItems = filteredHukum.slice(startIndex, endIndex);
|
const currentItems = filteredHukum.slice(startIndex, endIndex);
|
||||||
|
|
||||||
// Handle Search
|
// Handle Search
|
||||||
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setSearch(e.target.value);
|
const keyword = e.target.value.toLowerCase();
|
||||||
|
setSearch(keyword);
|
||||||
|
setFilteredHukum(
|
||||||
|
hukumData.filter((hukum) =>
|
||||||
|
hukum.SanksiNumber.toLowerCase().includes(keyword)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
setCurrentPage(1);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Page Change
|
// Handle Open Modal (Add/Edit)
|
||||||
const handlePageChange = (page: number) => {
|
const handleOpenModal = (data?: HukumType) => {
|
||||||
setCurrentPage(page);
|
setEditingData(data || null);
|
||||||
|
setIsModalOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Form Submission
|
// Handle Delete Modal
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleDeleteModal = (data: HukumType) => {
|
||||||
e.preventDefault();
|
setDeletingData(data);
|
||||||
const url = editing ? `/admin/hukum/${data.HukumId}` : "/admin/hukum";
|
setIsDeleteModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
const requestMethod = editing ? put : post;
|
// Handle Open Modal for Penaatan
|
||||||
requestMethod(url, {
|
const handleOpenPenaatanModal = (hukum: HukumType) => {
|
||||||
|
setSelectedHukum(hukum);
|
||||||
|
setIsPenaatanModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteConfirm = () => {
|
||||||
|
if (!deletingData) return;
|
||||||
|
|
||||||
|
setIsDeleting(true);
|
||||||
|
|
||||||
|
router.delete(`/admin/hukum/${deletingData.HukumId}`, {
|
||||||
|
preserveScroll: true,
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
// Update the local state by filtering out the deleted item
|
||||||
|
setFilteredHukum((prev) =>
|
||||||
|
prev.filter((item) => item.HukumId !== deletingData.HukumId)
|
||||||
|
);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Berhasil",
|
title: "Berhasil",
|
||||||
description: editing
|
description: "Data berhasil dihapus",
|
||||||
? "Data berhasil diperbarui"
|
|
||||||
: "Data berhasil ditambahkan",
|
|
||||||
variant: "default",
|
variant: "default",
|
||||||
});
|
});
|
||||||
setIsModalOpen(false);
|
|
||||||
reset();
|
// Adjust page if necessary (if we're on the last page and it's now empty)
|
||||||
setEditing(false);
|
const newTotalItems = filteredHukum.length - 1;
|
||||||
|
const newTotalPages = Math.ceil(newTotalItems / ITEMS_PER_PAGE);
|
||||||
|
|
||||||
|
if (currentPage > newTotalPages && newTotalPages > 0) {
|
||||||
|
setCurrentPage(newTotalPages);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
setDeletingData(null);
|
||||||
|
setIsDeleting(false);
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: (errors) => {
|
||||||
|
console.error("Error deleting record:", errors);
|
||||||
toast({
|
toast({
|
||||||
title: "Gagal",
|
title: "Gagal",
|
||||||
description: "Terjadi kesalahan saat menyimpan data",
|
description: "Terjadi kesalahan saat menghapus data",
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
setIsDeleting(false);
|
||||||
|
},
|
||||||
|
onFinish: () => {
|
||||||
|
// This will run regardless of success or error
|
||||||
|
setIsDeleting(false);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Edit
|
// Handle Success Callback
|
||||||
const handleEdit = (hukum: Hukum) => {
|
const handleSuccess = () => {
|
||||||
setData({ ...hukum });
|
toast({
|
||||||
setEditing(true);
|
title: "Berhasil",
|
||||||
setIsModalOpen(true);
|
description: editingData
|
||||||
|
? "Data berhasil diperbarui"
|
||||||
|
: "Data berhasil ditambahkan",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
setIsModalOpen(false);
|
||||||
|
setEditingData(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Delete
|
console.log("hukumData", hukumData);
|
||||||
const handleDelete = () => {
|
|
||||||
if (deleteConfirm) {
|
|
||||||
destroy(`/admin/hukum/${deleteConfirm.HukumId}`, {
|
|
||||||
onSuccess: () => {
|
|
||||||
toast({
|
|
||||||
title: "Berhasil",
|
|
||||||
description: "Data berhasil dihapus",
|
|
||||||
variant: "default",
|
|
||||||
});
|
|
||||||
setDeleteConfirm(null);
|
|
||||||
},
|
|
||||||
onError: () => {
|
|
||||||
toast({
|
|
||||||
title: "Gagal",
|
|
||||||
description: "Terjadi kesalahan saat menghapus data",
|
|
||||||
variant: "destructive",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthenticatedLayout header="Penegakan Hukum">
|
<AuthenticatedLayout header="Riwayat Pengenaan dan Penaatan Sanksi Administratif">
|
||||||
<Head title="Penegakan Hukum" />
|
<Head title="Penegakan Hukum" />
|
||||||
<div className="container mx-auto p-4">
|
<div className="container mx-auto p-4">
|
||||||
<Card className="shadow-lg">
|
<Card className="shadow-lg">
|
||||||
<CardHeader>
|
<CardHeader className="flex md:flex-row flex-col justify-between items-center">
|
||||||
<div className="flex justify-between">
|
<Input
|
||||||
<Input
|
type="text"
|
||||||
type="text"
|
placeholder="Cari Sanksi Administratif..."
|
||||||
placeholder="Cari Sanksi..."
|
value={search}
|
||||||
value={search}
|
onChange={handleSearch}
|
||||||
onChange={handleSearch}
|
className="w-96 border-gray-300 focus:border-blue-500 focus:ring-blue-200 rounded-lg"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => handleOpenModal()}
|
||||||
setEditing(false);
|
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||||
setIsModalOpen(true);
|
>
|
||||||
}}
|
<Plus className="h-4 w-4 mr-2" />
|
||||||
>
|
Buat Sanksi Administratif
|
||||||
<Plus className="h-4 w-4" />
|
</Button>
|
||||||
Tambah
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Table>
|
<Table>
|
||||||
|
@ -226,70 +198,226 @@ export default function HukumIndex() {
|
||||||
<TableHead>Jenis Sanksi</TableHead>
|
<TableHead>Jenis Sanksi</TableHead>
|
||||||
<TableHead>Nomor SK Sanksi</TableHead>
|
<TableHead>Nomor SK Sanksi</TableHead>
|
||||||
<TableHead>Tanggal Sanksi</TableHead>
|
<TableHead>Tanggal Sanksi</TableHead>
|
||||||
<TableHead>SK Sanksi</TableHead>
|
<TableHead className="border-r">
|
||||||
|
SK Sanksi
|
||||||
|
</TableHead>
|
||||||
<TableHead>Status Penaatan</TableHead>
|
<TableHead>Status Penaatan</TableHead>
|
||||||
<TableHead>Nomor Penaatan</TableHead>
|
<TableHead>Nomor SK Penaatan</TableHead>
|
||||||
<TableHead>Tanggal Penaatan</TableHead>
|
<TableHead>Tanggal SK Penaatan</TableHead>
|
||||||
<TableHead>SK Penaatan</TableHead>
|
<TableHead>SK Penaatan</TableHead>
|
||||||
<TableHead>Aksi</TableHead>
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{currentItems.map((hukum, index) => (
|
{currentItems?.length > 0 ? (
|
||||||
<TableRow key={hukum.HukumId}>
|
currentItems.map((hukum, index) => (
|
||||||
<TableCell>
|
<TableRow key={hukum.HukumId}>
|
||||||
{startIndex + index + 1}
|
<TableCell>
|
||||||
</TableCell>
|
{startIndex + index + 1}
|
||||||
<TableCell>
|
</TableCell>
|
||||||
{hukum.perusahaan?.nama}
|
<TableCell className="flex flex-col gap-2">
|
||||||
</TableCell>
|
<Button
|
||||||
<TableCell>
|
variant="link"
|
||||||
{hukum.jenisSanksi?.nama}
|
className="px-2 py-1 bg-green-100 h-auto font-normal text-left flex items-center gap-1"
|
||||||
</TableCell>
|
onClick={() =>
|
||||||
<TableCell>
|
handleOpenModal(hukum)
|
||||||
{hukum.SanksiNumber}
|
}
|
||||||
</TableCell>
|
>
|
||||||
<TableCell>
|
<Edit className="h-3 w-3 text-green-500" />
|
||||||
{hukum.SanksiDate}
|
{hukum.perusahaan
|
||||||
</TableCell>
|
?.NamaPerusahaan || "-"}
|
||||||
<TableCell>
|
</Button>
|
||||||
{hukum.SanksiFile}
|
<Button
|
||||||
</TableCell>
|
variant="link"
|
||||||
<TableCell>
|
className="px-2 py-1 bg-red-100 h-auto font-normal text-left flex items-center gap-1"
|
||||||
{hukum.StatusPenaatan}
|
onClick={() =>
|
||||||
</TableCell>
|
handleDeleteModal(hukum)
|
||||||
<TableCell>
|
}
|
||||||
{hukum.PenaatanNumber}
|
>
|
||||||
</TableCell>
|
<Trash2 className="h-3 w-3 text-red-500" />
|
||||||
<TableCell>
|
Hapus
|
||||||
{hukum.PenaatanDate}
|
</Button>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{hukum.PenaatanFile}
|
{hukum.jenis_sanksi
|
||||||
</TableCell>
|
?.NamaJenisSanksi || "-"}
|
||||||
<TableCell>
|
</TableCell>
|
||||||
<Button
|
<TableCell>
|
||||||
onClick={() =>
|
{hukum.SanksiNumber || "-"}
|
||||||
handleEdit(hukum)
|
</TableCell>
|
||||||
}
|
<TableCell>
|
||||||
>
|
{hukum.SanksiDate
|
||||||
<Pencil className="h-4 w-4" />
|
? new Date(
|
||||||
</Button>
|
hukum.SanksiDate
|
||||||
<Button
|
).toLocaleDateString(
|
||||||
onClick={() =>
|
"id-ID",
|
||||||
setDeleteConfirm(hukum)
|
{
|
||||||
}
|
day: "2-digit",
|
||||||
>
|
month: "long",
|
||||||
<Trash2 className="h-4 w-4" />
|
year: "numeric",
|
||||||
</Button>
|
}
|
||||||
|
)
|
||||||
|
: "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="border-r">
|
||||||
|
{hukum.SanksiFile ? (
|
||||||
|
<a
|
||||||
|
href={`/storage/${hukum.SanksiFile}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center justify-center"
|
||||||
|
>
|
||||||
|
<FileText className="w-4 h-4 text-green-600 hover:text-green-800" />
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
"-"
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Button
|
||||||
|
variant="link"
|
||||||
|
className="px-2 py-1 bg-blue-100 h-auto font-normal text-left flex items-center gap-1"
|
||||||
|
onClick={() =>
|
||||||
|
handleOpenPenaatanModal(
|
||||||
|
hukum
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Edit className="h-3 w-3 text-blue-500" />
|
||||||
|
{hukum.penaatan
|
||||||
|
?.NamaPenaatan || "-"}
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{hukum.PenaatanNumber || "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{hukum.PenaatanDate
|
||||||
|
? new Date(
|
||||||
|
hukum.PenaatanDate
|
||||||
|
).toLocaleDateString(
|
||||||
|
"id-ID",
|
||||||
|
{
|
||||||
|
day: "2-digit",
|
||||||
|
month: "long",
|
||||||
|
year: "numeric",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
: "-"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{hukum.PenaatanFile ? (
|
||||||
|
<a
|
||||||
|
href={`/storage/${hukum.PenaatanFile}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center justify-center"
|
||||||
|
>
|
||||||
|
<FileText className="w-4 h-4 text-green-600 hover:text-green-800" />
|
||||||
|
</a>
|
||||||
|
) : (
|
||||||
|
"-"
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<TableRow>
|
||||||
|
<TableCell
|
||||||
|
colSpan={10}
|
||||||
|
className="text-center py-4 text-gray-500"
|
||||||
|
>
|
||||||
|
Tidak ada data
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
{/* Pagination */}
|
||||||
|
<div className="mt-4 flex justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setCurrentPage(currentPage - 1)}
|
||||||
|
disabled={currentPage === 1}
|
||||||
|
>
|
||||||
|
<ChevronLeft className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setCurrentPage(currentPage + 1)}
|
||||||
|
disabled={currentPage === totalPages}
|
||||||
|
>
|
||||||
|
<ChevronRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Modal for Adding/Editing Hukum */}
|
||||||
|
<AddHukumModal
|
||||||
|
open={isModalOpen}
|
||||||
|
onClose={() => setIsModalOpen(false)}
|
||||||
|
onSuccess={handleSuccess}
|
||||||
|
hukumtype={hukumData}
|
||||||
|
perusahaan={perusahaan}
|
||||||
|
penaatan={penaatan}
|
||||||
|
jenisSanksi={jenisSanksi}
|
||||||
|
editingData={editingData}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Modal for Updating Penaatan */}
|
||||||
|
<AddPenaatanModal
|
||||||
|
open={isPenaatanModalOpen}
|
||||||
|
onClose={() => setIsPenaatanModalOpen(false)}
|
||||||
|
onSuccess={() => {
|
||||||
|
toast({
|
||||||
|
title: "Berhasil",
|
||||||
|
description: "Penaatan diperbarui",
|
||||||
|
variant: "default",
|
||||||
|
});
|
||||||
|
setIsPenaatanModalOpen(false);
|
||||||
|
}}
|
||||||
|
editingData={selectedHukum}
|
||||||
|
penaatan={penaatan}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Delete Confirmation Dialog */}
|
||||||
|
<AlertDialog
|
||||||
|
open={isDeleteModalOpen}
|
||||||
|
onOpenChange={setIsDeleteModalOpen}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Konfirmasi Hapus</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
Apakah anda yakin ingin menghapus data sanksi untuk
|
||||||
|
perusahaan{" "}
|
||||||
|
<strong>
|
||||||
|
{deletingData?.perusahaan?.NamaPerusahaan}
|
||||||
|
</strong>
|
||||||
|
?
|
||||||
|
<br />
|
||||||
|
Tindakan ini tidak dapat dibatalkan.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={isDeleting}>
|
||||||
|
Batal
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleDeleteConfirm();
|
||||||
|
}}
|
||||||
|
disabled={isDeleting}
|
||||||
|
className="bg-red-600 hover:bg-red-700 text-white"
|
||||||
|
>
|
||||||
|
{isDeleting ? "Menghapus..." : "Hapus"}
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
</AuthenticatedLayout>
|
</AuthenticatedLayout>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue