kontenhumas-fe/components/form/sign-up.tsx

886 lines
33 KiB
TypeScript
Raw Normal View History

2025-09-16 08:29:07 +00:00
"use client";
import React, { useState } from "react";
import Link from "next/link";
import Cookies from "js-cookie";
2025-10-07 01:42:07 +00:00
// import { close, error, loading } from "@/config/swal";
2025-09-16 08:29:07 +00:00
import { useRouter } from "next/navigation";
2025-10-07 01:42:07 +00:00
2025-09-16 08:29:07 +00:00
import withReactContent from "sweetalert2-react-content";
import { Input } from "../ui/input";
import { Button } from "../ui/button";
import { Label } from "../ui/label";
2025-10-07 01:42:07 +00:00
// import { saveActivity } from "@/service/activity-log";
import Swal from "sweetalert2";
import { error } from "console";
import { EyeFilledIcon, EyeSlashFilledIcon } from "../icons";
2025-09-16 08:29:07 +00:00
import { RadioGroup, RadioGroupItem } from "../ui/radio-group";
2025-10-07 04:13:12 +00:00
import { createUser, registerTenant } from "@/service/auth";
2025-10-02 02:08:08 +00:00
2025-09-16 08:29:07 +00:00
export default function SignUp() {
const router = useRouter();
2025-10-07 01:42:07 +00:00
const [isVisible, setIsVisible] = useState(false);
const [isVisibleSetup, setIsVisibleSetup] = useState([false, false]);
const [oldEmail, setOldEmail] = useState("");
const [newEmail, setNewEmail] = useState("");
const [passwordSetup, setPasswordSetup] = useState("");
const [confPasswordSetup, setConfPasswordSetup] = useState("");
const toggleVisibility = () => setIsVisible(!isVisible);
const [needOtp, setNeedOtp] = useState(false);
const [isFirstLogin, setFirstLogin] = useState(false);
const [otpValue, setOtpValue] = useState("");
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [accessData, setAccessData] = useState<any>();
const [profile, setProfile] = useState<any>();
const [isValidEmail, setIsValidEmail] = useState(false);
const [isResetPassword, setIsResetPassword] = useState(false);
const [checkUsernameValue, setCheckUsernameValue] = useState("");
2025-09-16 08:29:07 +00:00
const MySwal = withReactContent(Swal);
2025-10-07 04:13:12 +00:00
const [fullname, setFullname] = useState("");
const [userLevelId, setUserLevelId] = useState("");
const [userRoleId, setUserRoleId] = useState("");
2025-10-07 01:42:07 +00:00
const setValUsername = (e: any) => {
const uname = e.replaceAll(/[^\w.-]/g, "");
setUsername(uname.toLowerCase());
};
const onSubmit = () => {
// Simpan userId dummy ke cookie
Cookies.set("userId", "3");
// (Opsional) Simpan juga data lainnya jika dibutuhkan
// Cookies.set("username", username);
// Redirect ke halaman dashboard atau homepage
router.push("/"); // Ganti dengan path sesuai kebutuhan
};
const [step, setStep] = useState<"login" | "otp">("login");
2025-10-02 02:08:08 +00:00
const [email, setEmail] = useState("");
2025-10-07 01:42:07 +00:00
const [role, setRole] = useState("umum");
2025-10-02 02:08:08 +00:00
const [otp, setOtp] = useState(["", "", "", "", "", ""]);
2025-10-07 01:42:07 +00:00
const [membership, setMembership] = useState("");
2025-10-02 05:08:31 +00:00
const [certNumber, setCertNumber] = useState("");
2025-10-07 01:42:07 +00:00
const [membershipType, setMembershipType] = useState("");
const [nrp, setNrp] = useState("");
2025-10-02 05:08:31 +00:00
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
2025-10-07 01:42:07 +00:00
const [whatsapp, setWhatsapp] = useState("");
const [namaTenant, setNamaTenant] = useState("");
const [tenantPassword, setTenantPassword] = useState("");
const [confirmTenantPassword, setConfirmTenantPassword] = useState("");
const [firstNameKontributor, setFirstNameKontributor] = useState("");
const [lastNameKontributor, setLastNameKontributor] = useState("");
const [whatsappKontributor, setWhatsappKontributor] = useState("");
const [namaPerusahaan, setNamaPerusahaan] = useState("");
const [kategoriPerusahaan, setKategoriPerusahaan] = useState("");
const [kontributorPassword, setKontributorPassword] = useState("");
const [confirmKontributorPassword, setConfirmKontributorPassword] =
useState("");
const [isLoading, setIsLoading] = useState(false);
const [formErrors, setFormErrors] = useState<any>({});
2025-09-16 08:29:07 +00:00
2025-10-07 04:13:12 +00:00
const handleSendOtp = async (e: React.FormEvent) => {
2025-10-02 02:08:08 +00:00
e.preventDefault();
2025-09-16 08:29:07 +00:00
2025-10-07 04:13:12 +00:00
// Tenant → gunakan API registerTenant
2025-10-07 01:42:07 +00:00
if (role === "tenant") {
2025-10-07 04:13:12 +00:00
await handleTenantRegistration(e);
return;
}
// Umum dan Jurnalis → gunakan API createUser
if (role === "umum" || role === "jurnalis") {
await handleCreateUserUmum(e);
2025-10-02 02:08:08 +00:00
return;
}
2025-10-07 04:13:12 +00:00
// Kontributor (sementara ikut umum)
if (role === "kontributor") {
await handleCreateUserUmum(e);
return;
}
// Default (fallback ke OTP flow jika ada tambahan nanti)
2025-10-07 01:42:07 +00:00
setStep("otp");
2025-09-16 08:29:07 +00:00
};
2025-10-07 01:42:07 +00:00
const handleVerifyOtp = (e: React.FormEvent) => {
2025-09-16 08:29:07 +00:00
e.preventDefault();
2025-10-02 02:08:08 +00:00
const code = otp.join("");
2025-10-07 01:42:07 +00:00
// Verifikasi kode OTP
console.log("Kode OTP:", code);
};
const handleOtpChange = (index: number, value: string) => {
if (!/^[0-9]?$/.test(value)) return;
const newOtp = [...otp];
newOtp[index] = value;
setOtp(newOtp);
// Fokus otomatis ke input selanjutnya
const nextInput = document.getElementById(`otp-${index + 1}`);
if (value && nextInput) nextInput.focus();
};
// Form validation functions
const validateEmail = (email: string) => {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
};
const validatePhone = (phone: string) => {
const phoneRegex = /^[0-9+\-\s()]+$/;
return phoneRegex.test(phone) && phone.length >= 10;
};
const validatePassword = (password: string) => {
return password.length >= 8;
};
2025-10-07 04:13:12 +00:00
const handleCreateUserUmum = async (e: React.FormEvent) => {
e.preventDefault();
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 (!userLevelId || !userRoleId) {
MySwal.fire("Peringatan", "Level dan Role wajib diisi", "warning");
return;
}
// ✅ Generate username otomatis
const autoUsername =
fullname.trim().replace(/\s+/g, "-").toLowerCase() || email.split("@")[0];
const payload = {
address: "",
clientId: "78356d32-52fa-4dfc-b836-6cebf4e3eead",
dateOfBirth: "",
email,
fullName: fullname,
genderType: "",
identityGroup: "",
identityGroupNumber: "",
identityNumber: "",
identityType: "",
lastEducation: "",
password,
phoneNumber: "",
userLevelId: parseInt(userLevelId),
userRoleId: 3,
username: autoUsername,
workType: "",
};
console.log("📦 createUser payload:", 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 berhasil dibuat, Anda akan diarahkan ke halaman login.",
icon: "success",
showConfirmButton: false,
timer: 2000,
});
setTimeout(() => router.push("/auth"), 2000);
}
} catch (err) {
console.error("Error createUser:", err);
MySwal.fire("Error", "Terjadi kesalahan server.", "error");
} finally {
setIsLoading(false);
}
};
2025-10-07 01:42:07 +00:00
const validateTenantForm = () => {
const errors: any = {};
if (!firstName.trim()) {
errors.firstName = "First name is required";
}
if (!lastName.trim()) {
errors.lastName = "Last name is required";
}
if (!email.trim()) {
errors.email = "Email is required";
} else if (!validateEmail(email)) {
errors.email = "Please enter a valid email address";
}
if (!whatsapp.trim()) {
errors.whatsapp = "WhatsApp number is required";
} else if (!validatePhone(whatsapp)) {
errors.whatsapp = "Please enter a valid phone number";
}
if (!namaTenant.trim()) {
errors.namaTenant = "Tenant name is required";
}
if (!tenantPassword) {
errors.tenantPassword = "Password is required";
} else if (!validatePassword(tenantPassword)) {
errors.tenantPassword = "Password must be at least 8 characters";
}
if (!confirmTenantPassword) {
errors.confirmTenantPassword = "Please confirm your password";
} else if (tenantPassword !== confirmTenantPassword) {
errors.confirmTenantPassword = "Passwords do not match";
2025-10-02 02:08:08 +00:00
}
2025-10-07 01:42:07 +00:00
setFormErrors(errors);
return Object.keys(errors).length === 0;
2025-09-16 08:29:07 +00:00
};
2025-10-07 01:42:07 +00:00
const handleTenantRegistration = async (e: React.FormEvent) => {
2025-09-16 08:29:07 +00:00
e.preventDefault();
2025-10-02 02:08:08 +00:00
2025-10-07 01:42:07 +00:00
if (!validateTenantForm()) {
return;
}
setIsLoading(true);
setFormErrors({});
2025-10-02 02:08:08 +00:00
try {
2025-10-07 01:42:07 +00:00
const registrationData = {
adminUser: {
2025-10-07 04:13:12 +00:00
address: "Jakarta",
2025-10-07 01:42:07 +00:00
email: email,
fullname: `${firstName} ${lastName}`,
password: tenantPassword,
phoneNumber: whatsapp,
2025-10-07 04:13:12 +00:00
username: `${firstName}-${lastName}`,
2025-10-07 01:42:07 +00:00
},
client: {
2025-10-07 04:13:12 +00:00
clientType: "sub_client",
2025-10-07 01:42:07 +00:00
name: namaTenant,
2025-10-07 04:13:12 +00:00
parentClientId: "78356d32-52fa-4dfc-b836-6cebf4e3eead",
2025-10-07 01:42:07 +00:00
},
};
const response = await registerTenant(registrationData);
if (response.error) {
2025-10-06 14:17:48 +00:00
MySwal.fire({
2025-10-07 01:42:07 +00:00
title: "Registration Failed",
text: response.message || "An error occurred during registration",
icon: "error",
confirmButtonText: "OK",
2025-10-06 14:17:48 +00:00
});
2025-10-02 02:08:08 +00:00
} else {
2025-10-06 14:17:48 +00:00
MySwal.fire({
2025-10-07 01:42:07 +00:00
title: "Registration Successful",
text: "Your tenant account has been created successfully!",
icon: "success",
confirmButtonText: "OK",
}).then(() => {
// Redirect to login page or dashboard
router.push("/auth");
2025-10-06 14:17:48 +00:00
});
2025-10-02 02:08:08 +00:00
}
2025-10-07 01:42:07 +00:00
} catch (error) {
console.error("Registration error:", error);
2025-10-06 14:17:48 +00:00
MySwal.fire({
2025-10-07 01:42:07 +00:00
title: "Registration Failed",
text: "An unexpected error occurred. Please try again.",
2025-10-06 14:17:48 +00:00
icon: "error",
2025-10-07 01:42:07 +00:00
confirmButtonText: "OK",
2025-10-06 14:17:48 +00:00
});
2025-10-07 01:42:07 +00:00
} finally {
setIsLoading(false);
2025-10-02 02:08:08 +00:00
}
2025-09-16 08:29:07 +00:00
};
2025-10-07 04:13:12 +00:00
// Generate username otomatis dari nama lengkap
React.useEffect(() => {
if (fullname.trim()) {
const generated = fullname
.toLowerCase()
.replace(/\s+/g, "-")
.replace(/[^a-z0-9_]/g, "-");
setUsername(generated);
}
}, [fullname]);
2025-09-16 08:29:07 +00:00
return (
<div className="min-h-screen flex">
2025-10-07 01:42:07 +00:00
{/* Left Side - Logo Section */}
<div className="hidden lg:flex lg:w-1/2 bg-white relative overflow-hidden">
<div className="absolute inset-0 bg-white"></div>
<div className="relative z-10 flex items-center justify-center w-full p-12">
<div className="text-center">
<Link href={"/"}>
<div>
<img
src="/Group.png"
alt="Mikul News Logo"
className="max-w-2xl h-auto drop-shadow-lg"
/>
</div>
</Link>
<div className="mt-8 text-white/90">
<h2 className="text-2xl font-bold mb-2">Portal NetIdhub</h2>
<p className="text-sm opacity-80">Platform beyond classic</p>
</div>
</div>
2025-09-16 08:29:07 +00:00
</div>
2025-10-07 01:42:07 +00:00
{/* Decorative elements */}
<div className="absolute top-10 left-10 w-20 h-20 bg-white/10 rounded-full blur-xl"></div>
<div className="absolute bottom-20 right-20 w-32 h-32 bg-white/5 rounded-full blur-2xl"></div>
2025-09-16 08:29:07 +00:00
</div>
2025-10-07 01:42:07 +00:00
{/* Right Side - Login Form */}
2025-09-16 08:29:07 +00:00
<div className="w-full lg:w-1/2 flex items-center justify-center p-8">
<div className="w-full max-w-md">
2025-10-07 01:42:07 +00:00
<div className=" ">
<div className="text-center mb-8">
<div className=" w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-8">
<img
src="/logo-netidhub.png"
alt="netidhub Logo"
className="max-w-[150px] h-auto drop-shadow-lg"
/>
</div>
<h2 className="text-lg font-bold text-gray-900 mb-2 mt-5">
MENYATUKAN INDONESIA
</h2>
</div>
{step === "login" ? (
<form
onSubmit={handleSendOtp}
className="w-full max-w-lg p-6 ml-0 md:ml-5"
2025-10-02 05:08:31 +00:00
>
2025-10-07 01:42:07 +00:00
{/* Radio Buttons */}
<RadioGroup
defaultValue="umum"
className="grid grid-cols-2 sm:grid-cols-4 gap-2 mb-6"
onValueChange={(val) => setRole(val)}
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="umum" id="umum" />
<Label htmlFor="umum">Umum</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="jurnalis" id="jurnalis" />
<Label htmlFor="jurnalis">Jurnalis</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="kontributor" id="kontributor" />
<Label htmlFor="kontributor">Kontributor</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="tenant" id="tenant" />
<Label htmlFor="tenant">Tenant</Label>
</div>
</RadioGroup>
2025-10-07 04:13:12 +00:00
{role === "umum" && (
<div className="mb-4 space-y-4">
{/* Nama Lengkap */}
<Input
type="text"
required
placeholder="Nama Lengkap"
value={fullname}
onChange={(e) => setFullname(e.target.value)}
/>
{/* Username (auto generated) */}
<Input
type="text"
placeholder="Username (otomatis dari nama)"
value={username}
readOnly
className="bg-gray-100 text-gray-700 cursor-not-allowed"
/>
{/* Email */}
<Input
type="email"
required
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
{/* Password */}
<div className="relative">
<Input
type={isVisible ? "text" : "password"}
required
placeholder="Password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="pr-10"
/>
<button
type="button"
onClick={toggleVisibility}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700"
>
{isVisible ? (
<EyeSlashFilledIcon className="h-4 w-4" />
) : (
<EyeFilledIcon className="h-4 w-4" />
)}
</button>
</div>
{/* Level dan Role */}
<select
required
className="w-full border border-gray-300 rounded-md p-2 text-sm"
value={userLevelId}
onChange={(e) => setUserLevelId(e.target.value)}
>
<option value="">Pilih Level Pengguna</option>
<option value="1">Mabes</option>
<option value="2">Polda</option>
<option value="3">Satker</option>
<option value="4">Polres</option>
<option value="5">Polsek</option>
</select>
<select
required
className="w-full border border-gray-300 rounded-md p-2 text-sm"
value={userRoleId}
onChange={(e) => setUserRoleId(e.target.value)}
>
<option value="">Pilih Role</option>
<option value="1">Admin</option>
<option value="2">Editor</option>
<option value="3">User</option>
</select>
</div>
)}
2025-10-02 05:08:31 +00:00
2025-10-07 01:42:07 +00:00
{/* Jurnalis: Select Keanggotaan */}
{role === "jurnalis" && (
<div className="mb-4 space-y-4">
<select
required
className="w-full border border-gray-300 rounded-md p-2 text-sm"
value={membershipType}
onChange={(e) => setMembershipType(e.target.value)}
>
<option value="">Pilih jenis keanggotaan</option>
<option value="pwi">
PWI (Persatuan Wartawan Indonesia)
</option>
<option value="ijti">
IJTI (Ikatan Jurnalis Televisi Indonesia)
</option>
<option value="pfi">PFI (Pewarta Foto Indonesia)</option>
<option value="aji">
AJI (Asosiasi Jurnalis Indonesia)
</option>
<option value="lainnya">Identitas Lainnya</option>
</select>
2025-10-02 05:08:31 +00:00
2025-10-07 01:42:07 +00:00
{/* Nomor Sertifikasi */}
<Input
type="text"
required
placeholder="Nomor Sertifikasi Wartawan"
value={certNumber}
onChange={(e) => setCertNumber(e.target.value)}
/>
</div>
)}
{/* Kontributor: Form Fields */}
{role === "kontributor" && (
<div className="mb-4 space-y-4">
<div className="grid grid-cols-2 gap-4">
<Input
type="text"
required
placeholder="First Name"
value={firstNameKontributor}
onChange={(e) =>
setFirstNameKontributor(e.target.value)
}
/>
<Input
type="text"
required
placeholder="Last Name"
value={lastNameKontributor}
onChange={(e) => setLastNameKontributor(e.target.value)}
/>
</div>
<Input
type="email"
required
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<Input
type="tel"
required
placeholder="WhatsApp"
value={whatsappKontributor}
onChange={(e) => setWhatsappKontributor(e.target.value)}
/>
<Input
type="text"
required
placeholder="Nama Perusahaan"
value={namaPerusahaan}
onChange={(e) => setNamaPerusahaan(e.target.value)}
/>
<select
required
className="w-full border border-gray-300 rounded-md p-2 text-sm"
value={kategoriPerusahaan}
onChange={(e) => setKategoriPerusahaan(e.target.value)}
>
<option value="">Pilih Kategori Perusahaan</option>
<option value="kementerian">Kementerian</option>
<option value="lembaga">Lembaga</option>
<option value="pemerintah-daerah">
Pemerintah Daerah
</option>
<option value="bumn">BUMN</option>
<option value="lainnya">Lainnya</option>
</select>
<div className="relative">
<Input
type={isVisible ? "text" : "password"}
required
placeholder="Password"
value={kontributorPassword}
onChange={(e) => setKontributorPassword(e.target.value)}
className="pr-10"
/>
<button
type="button"
onClick={toggleVisibility}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700"
>
{isVisible ? (
<EyeSlashFilledIcon className="h-4 w-4" />
) : (
<EyeFilledIcon className="h-4 w-4" />
)}
</button>
</div>
<div className="relative">
<Input
type={isVisibleSetup[1] ? "text" : "password"}
required
placeholder="Konfirmasi Password"
value={confirmKontributorPassword}
onChange={(e) =>
setConfirmKontributorPassword(e.target.value)
}
className="pr-10"
/>
<button
type="button"
onClick={() => {
const newVisibility = [...isVisibleSetup];
newVisibility[1] = !newVisibility[1];
setIsVisibleSetup(newVisibility);
}}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700"
>
{isVisibleSetup[1] ? (
<EyeSlashFilledIcon className="h-4 w-4" />
) : (
<EyeFilledIcon className="h-4 w-4" />
)}
</button>
</div>
</div>
)}
{/* Tenant: Form Fields */}
{role === "tenant" && (
<div className="mb-4 space-y-4">
<div className="grid grid-cols-2 gap-4">
<div>
<Input
type="text"
required
placeholder="First Name"
value={firstName}
onChange={(e) => setFirstName(e.target.value)}
className={
formErrors.firstName ? "border-red-500" : ""
}
/>
{formErrors.firstName && (
<p className="text-red-500 text-xs mt-1">
{formErrors.firstName}
</p>
)}
</div>
<div>
<Input
type="text"
required
placeholder="Last Name"
value={lastName}
onChange={(e) => setLastName(e.target.value)}
className={
formErrors.lastName ? "border-red-500" : ""
}
/>
{formErrors.lastName && (
<p className="text-red-500 text-xs mt-1">
{formErrors.lastName}
</p>
)}
</div>
</div>
<div>
<Input
type="email"
required
placeholder="Email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className={formErrors.email ? "border-red-500" : ""}
/>
{formErrors.email && (
<p className="text-red-500 text-xs mt-1">
{formErrors.email}
</p>
)}
</div>
<div>
<Input
type="tel"
required
placeholder="WhatsApp"
value={whatsapp}
onChange={(e) => setWhatsapp(e.target.value)}
className={formErrors.whatsapp ? "border-red-500" : ""}
/>
{formErrors.whatsapp && (
<p className="text-red-500 text-xs mt-1">
{formErrors.whatsapp}
</p>
)}
</div>
<div>
<Input
type="text"
required
placeholder="Nama Tenant"
value={namaTenant}
onChange={(e) => setNamaTenant(e.target.value)}
className={
formErrors.namaTenant ? "border-red-500" : ""
}
/>
{formErrors.namaTenant && (
<p className="text-red-500 text-xs mt-1">
{formErrors.namaTenant}
</p>
)}
</div>
<div className="relative">
<Input
type={isVisible ? "text" : "password"}
required
placeholder="Password"
value={tenantPassword}
onChange={(e) => setTenantPassword(e.target.value)}
className={`pr-10 ${
formErrors.tenantPassword ? "border-red-500" : ""
}`}
/>
<button
type="button"
onClick={toggleVisibility}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700"
>
{isVisible ? (
<EyeSlashFilledIcon className="h-4 w-4" />
) : (
<EyeFilledIcon className="h-4 w-4" />
)}
</button>
{formErrors.tenantPassword && (
<p className="text-red-500 text-xs mt-1">
{formErrors.tenantPassword}
</p>
)}
</div>
<div className="relative">
<Input
type={isVisibleSetup[1] ? "text" : "password"}
required
placeholder="Konfirmasi Password"
value={confirmTenantPassword}
onChange={(e) =>
setConfirmTenantPassword(e.target.value)
}
className={`pr-10 ${
formErrors.confirmTenantPassword
? "border-red-500"
: ""
}`}
/>
<button
type="button"
onClick={() => {
const newVisibility = [...isVisibleSetup];
newVisibility[1] = !newVisibility[1];
setIsVisibleSetup(newVisibility);
}}
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700"
>
{isVisibleSetup[1] ? (
<EyeSlashFilledIcon className="h-4 w-4" />
) : (
<EyeFilledIcon className="h-4 w-4" />
)}
</button>
{formErrors.confirmTenantPassword && (
<p className="text-red-500 text-xs mt-1">
{formErrors.confirmTenantPassword}
</p>
)}
</div>
</div>
)}
{/* Email Field (Selalu Ada, tapi posisi bergantung role) */}
{role !== "tenant" && role !== "kontributor" && (
2025-10-02 05:08:31 +00:00
<Input
2025-10-07 01:42:07 +00:00
type="email"
required
placeholder="Email"
className="mb-4"
value={email}
onChange={(e) => setEmail(e.target.value)}
2025-09-30 06:09:12 +00:00
/>
2025-10-07 01:42:07 +00:00
)}
{/* Note */}
<p className="text-xs text-gray-500 mb-4">
Dengan mendaftar, saya telah menyetujui{" "}
<a href="#" className="text-blue-600 underline">
Syarat dan Ketentuan
</a>{" "}
serta{" "}
<a href="#" className="text-blue-600 underline">
Kebijakan Privasi
</a>
</p>
{/* Submit */}
<Button
type="submit"
className="w-full bg-[#B89445] hover:bg-[#a1813d] text-white py-2 rounded-md text-base font-semibold"
disabled={isLoading}
>
{isLoading ? (
<div className="flex items-center justify-center">
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
{role === "tenant" ? "Mendaftar..." : "Mengirim..."}
</div>
) : role === "tenant" ? (
"Daftar Tenant"
2025-10-07 04:13:12 +00:00
) : role === "umum" ? (
"Daftar Umum"
) : role === "jurnalis" ? (
"Daftar Jurnalis"
) : role === "kontributor" ? (
"Daftar Kontributor"
2025-10-07 01:42:07 +00:00
) : (
"Kirim OTP"
)}
</Button>
{/* Link Login */}
<p className="text-center text-sm mt-4">
Sudah punya akun?{" "}
<a href="/login" className="text-[#007AFF] hover:underline">
Login
</a>
</p>
</form>
) : (
<form
onSubmit={handleVerifyOtp}
className="w-full max-w-sm p-6 text-center ml-5 space-y-4"
2025-09-16 08:29:07 +00:00
>
2025-10-07 01:42:07 +00:00
<h3 className="text-base font-semibold text-gray-800">
Masukkan Kode OTP
</h3>
<p className="text-sm text-gray-500">
Silahkan cek inbox atau kotak spam pada email Anda.
</p>
<div className="flex justify-between mb-4">
{otp.map((value, index) => (
<input
key={index}
id={`otp-${index}`}
type="text"
inputMode="numeric"
maxLength={1}
value={value}
onChange={(e) => handleOtpChange(index, e.target.value)}
className="w-10 h-12 text-center border border-gray-300 rounded-md text-lg focus:outline-none focus:ring-2 focus:ring-[#B89445]"
/>
))}
</div>
<Button
type="submit"
className="w-full bg-[#B89445] hover:bg-[#a1813d] text-white py-2 rounded-md text-base font-semibold"
>
Lanjut
</Button>
<p className="text-sm text-black mt-4 cursor-pointer hover:underline">
Kirim Ulang OTP
</p>
</form>
)}
</div>
2025-09-16 08:29:07 +00:00
</div>
</div>
</div>
);
}