Add Kelola Data
This commit is contained in:
@@ -47,7 +47,7 @@ import {
|
||||
} from "lucide-react";
|
||||
import EditJenisPendaftaran from "@/components/datatable/edit-jenis-pendaftaran";
|
||||
import UploadExcelMahasiswa from "@/components/datatable/upload-excel-mahasiswa";
|
||||
|
||||
import { useToast } from "@/components/ui/toast-provider";
|
||||
// Define the Mahasiswa type based on API route structure
|
||||
interface Mahasiswa {
|
||||
nim: string;
|
||||
@@ -68,6 +68,7 @@ interface Mahasiswa {
|
||||
}
|
||||
|
||||
export default function DataTableMahasiswa() {
|
||||
const { showSuccess, showError } = useToast();
|
||||
// State for data
|
||||
const [mahasiswa, setMahasiswa] = useState<Mahasiswa[]>([]);
|
||||
const [filteredData, setFilteredData] = useState<Mahasiswa[]>([]);
|
||||
@@ -161,12 +162,14 @@ export default function DataTableMahasiswa() {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || "Failed to update semesters");
|
||||
}
|
||||
|
||||
|
||||
|
||||
showSuccess("Berhasil!", "Semester mahasiswa aktif berhasil diperbarui");
|
||||
|
||||
// Refresh data after successful update
|
||||
await fetchMahasiswa();
|
||||
} catch (err) {
|
||||
console.error("Error updating semesters:", err);
|
||||
showError("Gagal!", (err as Error).message);
|
||||
} finally {
|
||||
setIsUpdatingSemester(false);
|
||||
}
|
||||
@@ -337,7 +340,7 @@ export default function DataTableMahasiswa() {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || "Failed to add mahasiswa");
|
||||
}
|
||||
|
||||
showSuccess("Data mahasiswa berhasil ditambahkan!");
|
||||
} else {
|
||||
// Edit existing mahasiswa
|
||||
const response = await fetch(`/api/keloladata/data-mahasiswa?nim=${formData.nim}`, {
|
||||
@@ -352,8 +355,8 @@ export default function DataTableMahasiswa() {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || "Failed to update mahasiswa");
|
||||
}
|
||||
|
||||
}
|
||||
showSuccess("Data mahasiswa berhasil diperbarui!");
|
||||
}
|
||||
|
||||
// Refresh data after successful operation
|
||||
await fetchMahasiswa();
|
||||
@@ -361,6 +364,7 @@ export default function DataTableMahasiswa() {
|
||||
resetForm();
|
||||
} catch (err) {
|
||||
console.error("Error submitting form:", err);
|
||||
showError(`Gagal ${formMode === "add" ? "menambahkan" : "memperbarui"} data mahasiswa.`);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
@@ -387,8 +391,10 @@ export default function DataTableMahasiswa() {
|
||||
await fetchMahasiswa();
|
||||
setIsDeleteDialogOpen(false);
|
||||
setDeleteNim(null);
|
||||
showSuccess("Data mahasiswa berhasil dihapus!");
|
||||
} catch (err) {
|
||||
console.error("Error deleting mahasiswa:", err);
|
||||
showError("Gagal menghapus data mahasiswa.");
|
||||
} finally {
|
||||
setIsDeleting(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user