"use client"; import { FormEvent, Fragment, useEffect, useRef, useState } from "react"; import { Controller, useForm } from "react-hook-form"; import * as z from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { Input, Textarea } from "@heroui/input"; import { Button } from "@heroui/button"; import { Radio, RadioGroup } from "@heroui/react"; import { updateProfile } from "@/services/master-user"; import { close, error, loading } from "@/config/swal"; const formSchema = z.object({ fullname: z.string().min(1, { message: "Harus diisi", }), username: z.string().min(1, { message: "Harus diisi", }), email: z .string() .email({ message: "Email tidak valid", }) .min(2, { message: "Harus diisi", }), nrp: z.string().optional(), address: z.string().optional(), gender: z.string().optional(), phoneNumber: z.string().optional(), }); export default function ProfileForm(props: { profile: any; doFetch: () => void; }) { const MySwal = withReactContent(Swal); const { profile } = props; const formOptions = { resolver: zodResolver(formSchema), }; type UserSettingSchema = z.infer; const { control, handleSubmit, formState: { errors }, setValue, } = useForm(formOptions); useEffect(() => { setValue("fullname", profile?.fullname); setValue("username", profile?.username); setValue("email", profile?.email); setValue("address", profile?.address); setValue("nrp", profile?.identityNumber); setValue("gender", profile?.genderType); setValue("phoneNumber", profile?.phoneNumber); }, [profile]); const onSubmit = async (values: z.infer) => { loading(); const req = { address: values.address, fullname: values.fullname, username: values.username, email: values.email, identityNumber: values.nrp, phoneNumber: values.phoneNumber, genderType: values.gender, userLevelId: profile.userLevelId, userRoleId: profile.userRoleId, }; const res = await updateProfile(req); close(); if (res?.error) { error(res.message); return false; } props.doFetch(); MySwal.fire({ title: "Sukses", icon: "success", confirmButtonColor: "#3085d6", confirmButtonText: "OK", }).then((result) => { if (result.isConfirmed) { } }); }; return (

Username

( )} /> {errors?.username && (

{errors.username?.message}

)}

Nama Lengkap

( )} /> {errors?.fullname && (

{errors.fullname?.message}

)}

Email

( )} /> {errors?.email && (

{errors.email?.message}

)}

NRP

( )} /> {errors?.nrp && (

{errors.nrp?.message}

)}

Alamat

(