fix: register form in jouyrnalis
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c7eecd40c0
commit
6e3d01cdc0
|
|
@ -88,12 +88,16 @@ export default function SignUp() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Umum dan Jurnalis → gunakan API createUser
|
if (role === "umum") {
|
||||||
if (role === "umum" || role === "jurnalis") {
|
|
||||||
await handleCreateUserUmum(e);
|
await handleCreateUserUmum(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role === "jurnalis") {
|
||||||
|
await handleCreateUserJurnalis(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Kontributor (sementara ikut umum)
|
// Kontributor (sementara ikut umum)
|
||||||
if (role === "kontributor") {
|
if (role === "kontributor") {
|
||||||
await handleCreateUserKontributor(e);
|
await handleCreateUserKontributor(e);
|
||||||
|
|
@ -280,6 +284,98 @@ export default function SignUp() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCreateUserJurnalis = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
// ✅ VALIDASI
|
||||||
|
if (!fullname.trim()) {
|
||||||
|
MySwal.fire("Peringatan", "Nama lengkap wajib diisi", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validateEmail(email)) {
|
||||||
|
MySwal.fire("Peringatan", "Email tidak valid", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validatePassword(password)) {
|
||||||
|
MySwal.fire("Peringatan", "Password minimal 8 karakter", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!membershipType) {
|
||||||
|
MySwal.fire("Peringatan", "Jenis keanggotaan wajib diisi", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!certNumber.trim()) {
|
||||||
|
MySwal.fire("Peringatan", "Nomor sertifikasi wajib diisi", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ GENERATE USERNAME
|
||||||
|
const autoUsername =
|
||||||
|
fullname.trim().replace(/\s+/g, "-").toLowerCase() || email.split("@")[0];
|
||||||
|
|
||||||
|
if (!validateUsername(autoUsername)) {
|
||||||
|
MySwal.fire("Peringatan", "Username tidak valid", "warning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ PAYLOAD (SUDAH DISESUAIKAN BACKEND)
|
||||||
|
const payload = {
|
||||||
|
address: "",
|
||||||
|
clientId: "78356d32-52fa-4dfc-b836-6cebf4e3eead",
|
||||||
|
dateOfBirth: "",
|
||||||
|
email,
|
||||||
|
fullName: fullname,
|
||||||
|
genderType: "",
|
||||||
|
identityGroup: "",
|
||||||
|
identityGroupNumber: "",
|
||||||
|
identityNumber: certNumber, // 🔥 penting
|
||||||
|
identityType: "KTP",
|
||||||
|
lastEducation: "",
|
||||||
|
password,
|
||||||
|
phoneNumber: "08123456789", // 🔥 jangan kosong dulu
|
||||||
|
userLevelId: 1,
|
||||||
|
userRoleId: 3, // 🔥 pastikan ini role jurnalis
|
||||||
|
username: autoUsername + "-" + Date.now(),
|
||||||
|
workType: membershipType.toUpperCase(),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("📦 PAYLOAD JURNALIS:", payload);
|
||||||
|
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
const res = await createUser(payload);
|
||||||
|
|
||||||
|
if (res?.error) {
|
||||||
|
MySwal.fire("Gagal", res?.message || "Gagal mendaftar", "error");
|
||||||
|
} else {
|
||||||
|
MySwal.fire({
|
||||||
|
title: "Berhasil!",
|
||||||
|
text: "Akun jurnalis berhasil dibuat",
|
||||||
|
icon: "success",
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 2000,
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => router.push("/auth"), 2000);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("❌ ERROR JURNALIS:", err);
|
||||||
|
|
||||||
|
MySwal.fire(
|
||||||
|
"Error",
|
||||||
|
"Terjadi kesalahan server saat registrasi jurnalis",
|
||||||
|
"error",
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const validateTenantForm = () => {
|
const validateTenantForm = () => {
|
||||||
const errors: any = {};
|
const errors: any = {};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue