diff --git a/app/(admin)/admin/master-user/edit/[id]/page.tsx b/app/(admin)/admin/master-user/edit/[id]/page.tsx new file mode 100644 index 0000000..eb182b5 --- /dev/null +++ b/app/(admin)/admin/master-user/edit/[id]/page.tsx @@ -0,0 +1,11 @@ +import FormMasterUser from "@/components/form/form-master-user"; +import FormMasterUserEdit from "@/components/form/form-master-user-edit"; +import { Card } from "@nextui-org/react"; + +export default function CreateMasterUserPage() { + return ( + + + + ); +} diff --git a/components/form/form-master-user-edit.tsx b/components/form/form-master-user-edit.tsx new file mode 100644 index 0000000..e311887 --- /dev/null +++ b/components/form/form-master-user-edit.tsx @@ -0,0 +1,421 @@ +"use client"; +import { error } from "@/config/swal"; +import { + createMasterUser, + editMasterUsers, + getDetailMasterUsers, +} from "@/service/master-user"; +import { MasterUser } from "@/types/globals"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { + Button, + Card, + Input, + Radio, + RadioGroup, + Select, + SelectItem, + Selection, + Textarea, +} from "@nextui-org/react"; +import Link from "next/link"; +import { useParams, useRouter } from "next/navigation"; +import React, { useEffect, useState } from "react"; +import { Controller, useForm } from "react-hook-form"; +import Datepicker from "react-tailwindcss-datepicker"; +import Swal from "sweetalert2"; +import withReactContent from "sweetalert2-react-content"; +import { z } from "zod"; +import { EyeFilledIcon, EyeSlashFilledIcon } from "../icons"; +import ReactPasswordChecklist from "react-password-checklist"; + +const masterUserSchema = z.object({ + fullname: z.string().min(1, { message: "Required" }), + username: z.string().min(1, { message: "Required" }), + email: z.string().min(1, { message: "Required" }), + identityNumber: z.string().min(1, { message: "Required" }), + genderType: z.string().min(1, { message: "Required" }), + phoneNumber: z.string().min(1, { message: "Required" }), + address: z.string().min(1, { message: "Required" }), +}); + +export default function FormMasterUserEdit() { + const router = useRouter(); + const MySwal = withReactContent(Swal); + const [isVisible, setIsVisible] = useState([false, false]); + const [isValidPassword, setIsValidPassword] = useState(false); + const params = useParams(); + const id = params?.id; + + const toggleVisibility = (type: number) => { + setIsVisible( + type === 0 ? [!isVisible[0], isVisible[1]] : [isVisible[0], !isVisible[1]] + ); + }; + + const formOptions = { + resolver: zodResolver(masterUserSchema), + }; + type MicroIssueSchema = z.infer; + const { + control, + handleSubmit, + formState: { errors }, + setError, + watch, + setValue, + } = useForm(formOptions); + + async function save(data: z.infer) { + const formData = { + address: data.address, + email: data.email, + fullname: data.fullname, + genderType: data.genderType, + identityNumber: data.identityNumber, + phoneNumber: data.phoneNumber, + userLevelId: 2, + userRoleId: 2, + username: data.username, + }; + + const response = await editMasterUsers(formData); + + if (response?.error) { + error(response.message); + return false; + } + + successSubmit("/admin/master-user"); + } + + function successSubmit(redirect: any) { + MySwal.fire({ + title: "Sukses", + icon: "success", + confirmButtonColor: "#3085d6", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + router.push(redirect); + } + }); + } + + async function onSubmit(data: z.infer) { + MySwal.fire({ + title: "Simpan Data", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Simpan", + }).then((result) => { + if (result.isConfirmed) { + save(data); + } + }); + } + + useEffect(() => { + initFetch(); + }, [id]); + + const initFetch = async () => { + const res = await getDetailMasterUsers(String(id)); + const profile = res?.data?.data; + setValue("fullname", profile?.fullname); + setValue("username", profile?.username); + setValue("email", profile?.email); + setValue("address", profile?.address); + setValue("identityNumber", profile?.identityNumber); + setValue("genderType", profile?.genderType); + setValue("phoneNumber", profile?.phoneNumber); + }; + + return ( + + + + ( + + )} + /> + {errors.fullname?.message && ( + {errors.fullname?.message} + )} + ( + + )} + /> + {errors.username?.message && ( + {errors.username?.message} + )} + + ( + + )} + /> + {errors.email?.message && ( + {errors.email?.message} + )} + + {/* ( + + {typeIdentity.map((type) => ( + {type.value} + ))} + + )} + /> + {errors.identityType?.message && ( + + {errors.identityType?.message} + + )} */} + ( + + )} + /> + {errors.identityNumber?.message && ( + + {errors.identityNumber?.message} + + )} + + ( + + )} + /> + {errors.address?.message && ( + {errors.address?.message} + )} + + ( + + Laki-laki + Perempuan + + )} + /> + {errors.genderType?.message && ( + {errors.genderType?.message} + )} + {/* ( + + )} + /> + {errors.birthDate?.startDate?.message && ( + + {errors.birthDate?.startDate?.message} + + )} */} + {/* ( + + {educationGrade.map((grade) => ( + {grade.value} + ))} + + )} + /> + {errors.lastEducation?.message && ( + + {errors.lastEducation?.message} + + )} */} + ( + + )} + /> + {errors.phoneNumber?.message && ( + + {errors.phoneNumber?.message} + + )} + {/* ( + + {workingBackground.map((type) => ( + + {type.value} + + ))} + + )} + /> + {errors.workType?.message && ( + {errors.workType?.message} + )} */} + + + + + Cancel + + + + Save + + + + + + ); +} diff --git a/components/form/form-master-user.tsx b/components/form/form-master-user.tsx index 3c0e0b8..9051cc6 100644 --- a/components/form/form-master-user.tsx +++ b/components/form/form-master-user.tsx @@ -162,6 +162,7 @@ export default function FormMasterUser() { fullname: data.fullname, genderType: data.genderType, identityNumber: data.identityNumber, + identityType: "nrp", phoneNumber: data.phoneNumber, userLevelId: 2, userRoleId: 2, diff --git a/components/landing/BodyLayout.tsx b/components/landing/BodyLayout.tsx index 9e02798..bf198cd 100644 --- a/components/landing/BodyLayout.tsx +++ b/components/landing/BodyLayout.tsx @@ -19,7 +19,7 @@ export default function BodyLayout() { - + diff --git a/components/landing/SidebarNav.tsx b/components/landing/SidebarNav.tsx index ec56e96..f64cc05 100644 --- a/components/landing/SidebarNav.tsx +++ b/components/landing/SidebarNav.tsx @@ -24,7 +24,7 @@ export default function SidebarNav() { return ( <> - + = ({ updateSidebarData }) => { - {username} + + {textEllipsis(String(username), 23)} + onLogout()} diff --git a/service/master-user.ts b/service/master-user.ts index 9ef15ca..702cdcb 100644 --- a/service/master-user.ts +++ b/service/master-user.ts @@ -24,6 +24,20 @@ export async function createMasterUser(data: any) { return await httpPost(pathUrl, headers, data); } +export async function getDetailMasterUsers(id: string) { + const headers = { + "content-type": "application/json", + }; + return await httpGet(`/users/detail/${id}`, headers); +} + +export async function editMasterUsers(data: any) { + const headers = { + "content-type": "application/json", + }; + return await httpPut(`/users/${id}`, headers, data); +} + export async function deleteMasterUser(id: string) { return await httpDeleteInterceptor(`/users/${id}`); } diff --git a/service/third-party-service.ts b/service/third-party-service.ts index 3e44258..4cdaf63 100644 --- a/service/third-party-service.ts +++ b/service/third-party-service.ts @@ -7,7 +7,7 @@ const tbnInstance = axios.create({ }, }); const inpInstance = axios.create({ - baseURL: "https://inp.indoplusmedia.id/wp-json/wp/v2", + baseURL: "https://inp.demoaplikasi.web.id/api", headers: { "content-type": "application/json", }, @@ -71,7 +71,7 @@ export async function topNewsInp() { const headers = { "content-type": "application/json", }; - return await inpGetNews(`/posts`, headers); + return await inpGetNews(`/artikel/data?per_page=10&page=1`, headers); } export async function getImageInp(id: string) {
{errors.fullname?.message}
{errors.username?.message}
{errors.email?.message}
+ {errors.identityType?.message} +
+ {errors.identityNumber?.message} +
{errors.address?.message}
{errors.genderType?.message}
+ {errors.birthDate?.startDate?.message} +
+ {errors.lastEducation?.message} +
+ {errors.phoneNumber?.message} +
{errors.workType?.message}