diff --git a/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx b/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx
index 30cdb79..7d676fd 100644
--- a/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx
+++ b/apps/frontend/src/modules/aspectManagement/modals/AspectFormModal.tsx
@@ -93,8 +93,14 @@ export default function AspectFormModal() {
const handleSubmit = async (values: typeof form.values) => {
try {
+ // Name field validation
+ if (values.name.trim() === "") {
+ form.setErrors({ name: "Nama aspek harus diisi" });
+ return;
+ }
+
let payload: CreateAspectPayload | EditAspectPayload;
-
+
if (formType === "create") {
payload = {
name: values.name,
@@ -108,6 +114,7 @@ export default function AspectFormModal() {
};
await createAspect(payload);
} else if (formType === "edit") {
+ // Add validation for aspect name here
payload = {
id: values.id,
name: values.name,
@@ -125,18 +132,30 @@ export default function AspectFormModal() {
};
await updateAspect(payload);
}
-
+
queryClient.invalidateQueries({ queryKey: ["management-aspect"] });
-
+
notifications.show({
message: `Aspek ${formType === "create" ? "berhasil dibuat" : "berhasil diedit"}`,
});
-
+
navigate({ search: {} });
} catch (error) {
console.error("Error during submit:", error);
+
+ if (error instanceof Error && error.message === "Aspect name already exists") {
+ notifications.show({
+ message: "Nama aspek sudah ada. Silakan gunakan nama lain.",
+ color: "red",
+ });
+ } else {
+ notifications.show({
+ message: "Terjadi kesalahan saat menyimpan aspek.",
+ color: "red",
+ });
+ }
}
- };
+ };
return (
-
+
{form.values.subAspects.map((field, index) => (
- {
- const newSubAspects = [...form.values.subAspects];
- newSubAspects[index] = { ...newSubAspects[index], name: event.target.value };
+ {
+ const newSubAspects = [...form.values.subAspects];
+ newSubAspects[index] = { ...newSubAspects[index], name: event.target.value };
+ form.setValues({ subAspects: newSubAspects });
+ }}
+ disabled={formType === "detail"}
+ style={{ flex: 1 }}
+ />
+ {formType === "detail" && (
+ Jumlah Soal: {field.questionCount}
+ )}
+ {formType !== "detail" && (
+
+ >
+ Hapus
+
+ )}
+
))}
{formType !== "detail" && (
@@ -199,7 +221,7 @@ export default function AspectFormModal() {
Tambah Sub Aspek
)}
-
+
{/* Buttons */}
- );
+ );
}
\ No newline at end of file