From 24d27df67eb74491928ad2ec7688cbbdae6d241a Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Mon, 2 Dec 2024 20:19:30 +0700 Subject: [PATCH] fix:landing footer link, admin create user form --- .env | 1 + app/(admin)/admin/master-user/create/page.tsx | 14 +- app/(admin)/admin/master-user/page.tsx | 35 +- app/kontak-kami/page.tsx | 7 +- components/form/form-master-user.tsx | 794 ++++++++++-------- components/landing/Footer.tsx | 209 +++-- components/landing/HeaderNews.tsx | 1 - components/landing/MedolUpdate.tsx | 2 +- components/main/detail/contact.tsx | 17 +- components/table/master-role-table.tsx | 518 ++++++------ components/table/master-user-table.tsx | 470 +++++------ service/master-user-role.ts | 41 +- service/master-user.ts | 4 +- 13 files changed, 1131 insertions(+), 982 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..f1988d2 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +NEXT_PUBLIC_MAPS_API_KEY=AIzaSyCOkxoeKykE60L_nM4VS1JYJqBmqy2GA0Q \ No newline at end of file diff --git a/app/(admin)/admin/master-user/create/page.tsx b/app/(admin)/admin/master-user/create/page.tsx index a345e3c..788304c 100644 --- a/app/(admin)/admin/master-user/create/page.tsx +++ b/app/(admin)/admin/master-user/create/page.tsx @@ -1,10 +1,10 @@ -import FormMasterUser from '@/components/form/form-master-user' -import { Card } from '@nextui-org/react' +import FormMasterUser from "@/components/form/form-master-user"; +import { Card } from "@nextui-org/react"; export default function CreateMasterUserPage() { - return ( - - - - ) + return ( + + + + ); } diff --git a/app/(admin)/admin/master-user/page.tsx b/app/(admin)/admin/master-user/page.tsx index 81372a0..5e3f452 100644 --- a/app/(admin)/admin/master-user/page.tsx +++ b/app/(admin)/admin/master-user/page.tsx @@ -1,24 +1,25 @@ -"use client" +"use client"; import { AddIcon } from "@/components/icons"; import MasterUserTable from "@/components/table/master-user-table"; import { Button, Card } from "@nextui-org/react"; import Link from "next/link"; export default function MasterUserPage() { - return ( -
-
- - - - - - - - -
-
- ); + return ( +
+
+ + + + + + + + +
+
+ ); } diff --git a/app/kontak-kami/page.tsx b/app/kontak-kami/page.tsx index c85da70..0e642c3 100644 --- a/app/kontak-kami/page.tsx +++ b/app/kontak-kami/page.tsx @@ -1,5 +1,10 @@ import Contact from "@/components/main/detail/contact"; +import { Suspense } from "react"; export default function VisiMisiPage() { - return ; + return ( + + + + ); } diff --git a/components/form/form-master-user.tsx b/components/form/form-master-user.tsx index 6460f1d..df8cbfc 100644 --- a/components/form/form-master-user.tsx +++ b/components/form/form-master-user.tsx @@ -1,348 +1,474 @@ -'use client' -import { error } from '@/config/swal'; -import { createMasterUser } 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 { useRouter } from 'next/navigation'; -import React, { useState } from 'react' -import { useForm } from 'react-hook-form'; -import Swal from 'sweetalert2'; -import withReactContent from 'sweetalert2-react-content'; -import { z } from 'zod'; +"use client"; +import { error } from "@/config/swal"; +import { createMasterUser } 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 { useRouter } from "next/navigation"; +import React, { 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"; 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" }), - identityType: z.string().min(1, { message: "Required" }), - lastEducation: z.string().min(1, { message: "Required" }), - phoneNumber: z.string().min(1, { message: "Required" }), - workingType: z.string().min(1, { message: "Required" }), + fullname: z.string().min(1, { message: "Required" }), + username: z.string().min(1, { message: "Required" }), + password: z.string().min(1, { message: "Required" }), + email: z.string().min(1, { message: "Required" }), + identityType: z.string().min(1, { message: "Required" }), + identityNumber: z.string().min(1, { message: "Required" }), + lastEducation: z.string().min(1, { message: "Required" }), + genderType: z.string().min(1, { message: "Required" }), + phoneNumber: z.string().min(1, { message: "Required" }), + workType: z.string().min(1, { message: "Required" }), + address: z.string().min(1, { message: "Required" }), + birthDate: z.object({ + startDate: z.string().min(1, { message: "Required" }), + endDate: z.string().min(1, { message: "Required" }), + }), }); +const typeIdentity = [ + { + id: 1, + value: "KTP", + }, + { + id: 2, + value: "SIM", + }, + { + id: 3, + value: "Passport", + }, +]; + +const workingBackground = [ + { + id: 1, + value: "Pegawai Negri Sipil", + }, + { + id: 2, + value: "Wiraswasta", + }, + { + id: 3, + value: "Guru", + }, + { + id: 4, + value: "Dokter", + }, +]; + +const educationGrade = [ + { + id: 1, + value: "SMA / Sederajat", + }, + { + id: 2, + value: "Diploma 1", + }, + { + id: 3, + value: "Diploma 2", + }, + { + id: 4, + value: "Diploma 3", + }, + { + id: 5, + value: "Diploma 4", + }, + { + id: 6, + value: "S1", + }, + { + id: 7, + value: "S2", + }, + { + id: 8, + value: "S3", + }, +]; + export default function FormMasterUser() { - const router = useRouter(); - const MySwal = withReactContent(Swal); - const [address, setAddress] = useState(); - const [dateOfBirt, setDateOfBirt] = useState("13-april-1995"); - const [email, setEmail] = useState(); - const [fullName, setFullname] = useState(); - const [genderType, setGenderType] = React.useState(""); - const [identityNumber, setIdentityNumber] = useState(); - const [lastEducation, setLastEducation] = useState([]); - const [phoneNumber, setPhoneNumber] = useState(); - const [userLevelsId, setUserLevelsId] = useState(1); - const [userRoleId, setUserRoleId] = useState(1); - const [username, setUsername] = useState(); - const [workType, setWorkType] = useState("Tets"); - const [identityType, setIdentityType] = useState([]) - const [showNumberInput, setShowNumberInput] = useState(false); + const router = useRouter(); + const MySwal = withReactContent(Swal); + const [isVisible, setIsVisible] = useState(false); + const toggleVisibility = () => setIsVisible(!isVisible); - const formOptions = { resolver: zodResolver(masterUserSchema) }; - type MicroIssueSchema = z.infer; - const { - register, - control, - handleSubmit, - setValue, - formState: { errors }, - } = useForm(formOptions); + const formOptions = { + resolver: zodResolver(masterUserSchema), + defaultValues: { + identityType: "KTP", + birthDate: { stardDate: "", endDate: "" }, + }, + }; + type MicroIssueSchema = z.infer; + const { + control, + handleSubmit, + formState: { errors }, + } = useForm(formOptions); - const typeIdentity = [ - { - id: 1, - value: "KTP", - }, - { - id: 2, - value: "SIM", - }, - { - id: 3, - value: "Passport", - }, - ] - - const workingBackground = [ - { - id: 1, - value: "Pegawai Negri Sipil", - }, - { - id: 2, - value: "Wiraswasta", - }, - { - id: 3, - value: "Guru", - }, - { - id: 4, - value: "Dokter", - }, - ] - - const educationGrade = [ - { - id: 1, - value: "SMA / Sederajat", - }, - { - id: 2, - value: "Diploma 1", - }, - { - id: 3, - value: "Diploma 2", - }, - { - id: 4, - value: "Diploma 3", - }, - { - id: 5, - value: "Diploma 4", - }, - { - id: 6, - value: "S1", - }, - { - id: 7, - value: "S2", - }, - { - id: 8, - value: "S3", - }, - ] - - - async function save(data: any) { - const formData = { - address: address, - dateOfBirt: dateOfBirt, - email: email, - fullName: fullName, - genderType: genderType, - identityNumber: identityNumber, - identityType: identityType.anchorKey, - lastEducation: Array.from(lastEducation)[0], - phoneNumber: phoneNumber, - userLevelsId: userLevelsId, - userRoleId: userRoleId, - username: username, - workType: workType, - }; - - console.log("Form MasterUser:", formData); - const response = await createMasterUser(formData); - - if (response?.error) { - error(response.message); - return false; - } - - successSubmit("/admin/article"); + async function save(data: z.infer) { + const formData = { + address: data.address, + dateOfBirt: data.birthDate, + password: data.password, + email: data.email, + fullname: data.fullname, + genderType: data.genderType, + identityNumber: data.identityNumber, + identityType: data.identityType, + lastEducation: data.lastEducation, + phoneNumber: data.phoneNumber, + userLevelId: 2, + userRoleId: 2, + username: data.username, + workType: data.workType, }; - function successSubmit(redirect: any) { - MySwal.fire({ - title: "Sukses", - icon: "success", - confirmButtonColor: "#3085d6", - confirmButtonText: "OK", - }).then((result) => { - if (result.isConfirmed) { - router.push(redirect); - } - }); + const response = await createMasterUser(formData); + + if (response?.error) { + error(response.message); + return false; } - async function onSubmit(data: any) { - MySwal.fire({ - title: "Simpan Data", - text: "", - icon: "warning", - showCancelButton: true, - cancelButtonColor: "#d33", - confirmButtonColor: "#3085d6", - confirmButtonText: "Simpan", - }).then((result) => { - if (result.isConfirmed) { - save(data); - } - }); - } + successSubmit("/admin/article"); + } - return ( -
-
- -
- setFullname(e.target.value)} - /> - {errors.fullname?.message} -
-
- setUsername(e.target.value)} + function successSubmit(redirect: any) { + MySwal.fire({ + title: "Sukses", + icon: "success", + confirmButtonColor: "#3085d6", + confirmButtonText: "OK", + }).then((result) => { + if (result.isConfirmed) { + router.push(redirect); + } + }); + } - /> - {errors.username?.message} -
-
- setEmail(e.target.value)} - /> - {errors.email?.message} -
-
- - {/*

selected : {identityType}

*/} - {errors.identityType?.message} - {/* {showNumberInput && ( */} - setIdentityNumber(e.target.value)} - /> - {/* )} */} -
-
- - Laki-laki - Perempuan - -

Selected: {genderType}

-
-
- -

Selected: {lastEducation}

- {errors.lastEducation?.message} -
-
- setPhoneNumber(e.target.value)} - /> - {errors.phoneNumber?.message} -
-
- - {errors.workingType?.message} -
-
-