diff --git a/app/(admin)/admin/(basic-form)/form-costum/page.tsx b/app/(admin)/admin/(basic-form)/form-costum/page.tsx deleted file mode 100644 index 224d54c..0000000 --- a/app/(admin)/admin/(basic-form)/form-costum/page.tsx +++ /dev/null @@ -1,30 +0,0 @@ -"use client" -import { Image } from "@nextui-org/react"; - -export default function CustumPage() { - return ( -
-
-
-
- -
-
-

Custum Form

-

custom designed elemnt

-
-
- NextUI hero Image -
-
-
-
- {/* */} -
-
- ); -} diff --git a/app/(admin)/admin/(basic-form)/form-horizontal/page.tsx b/app/(admin)/admin/(basic-form)/form-horizontal/page.tsx deleted file mode 100644 index 63b5dc8..0000000 --- a/app/(admin)/admin/(basic-form)/form-horizontal/page.tsx +++ /dev/null @@ -1,38 +0,0 @@ -"use client" -import CreateCustomForm from "@/components/form/form-costum/custom-form"; -import CreateHorizontalForm from "@/components/form/form-horizontal/custom-form"; -import CreateWizardForm from "@/components/form/form-wizard/wizard-form"; -import AuthtorsTable from "@/components/table/authors-table"; -import CustomerTable from "@/components/table/customers-table"; -import InvoiceTable from "@/components/table/invoice-table"; -import UserTable from "@/components/table/article-table"; -import UsersTable from "@/components/table/users-table"; -import { Card, Divider, Image } from "@nextui-org/react"; - -export default function HorizontalPage() { - return ( -
-
-
-
- -
-
-

Horizontal Form

-

Home{" > "} Horizontal Form

-
-
- NextUI hero Image -
-
-
-
- -
-
- ); -} diff --git a/app/(admin)/admin/(basic-form)/form-layout/page.tsx b/app/(admin)/admin/(basic-form)/form-layout/page.tsx deleted file mode 100644 index 74c70ca..0000000 --- a/app/(admin)/admin/(basic-form)/form-layout/page.tsx +++ /dev/null @@ -1,40 +0,0 @@ -"use client" - -import CreateLayoutForm from "@/components/form/form-layout/layout-form"; -import CreateValidationForm from "@/components/form/form-validation/validation-form"; -import CreateWizardForm from "@/components/form/form-wizard/wizard-form"; -import AuthtorsTable from "@/components/table/authors-table"; -import CustomerTable from "@/components/table/customers-table"; -import InvoiceTable from "@/components/table/invoice-table"; -import UserTable from "@/components/table/article-table"; -import UsersTable from "@/components/table/users-table"; -import { Card, Divider, Image } from "@nextui-org/react"; -import { useEffect, useState } from "react"; - -export default function FormLayoutPage() { - - return ( -
-
-
-
-
-
-

Form Layout

-

Home{" > "} Form Layout

-
-
- NextUI hero Image -
-
-
-
- -
-
- ); -} diff --git a/app/(admin)/admin/(basic-form)/form-validation/page.tsx b/app/(admin)/admin/(basic-form)/form-validation/page.tsx deleted file mode 100644 index 8480b7e..0000000 --- a/app/(admin)/admin/(basic-form)/form-validation/page.tsx +++ /dev/null @@ -1,37 +0,0 @@ -"use client" -import CreateValidationForm from "@/components/form/form-validation/validation-form"; -import CreateWizardForm from "@/components/form/form-wizard/wizard-form"; -import AuthtorsTable from "@/components/table/authors-table"; -import CustomerTable from "@/components/table/customers-table"; -import InvoiceTable from "@/components/table/invoice-table"; -import UserTable from "@/components/table/article-table"; -import UsersTable from "@/components/table/users-table"; -import { Card, Divider, Image } from "@nextui-org/react"; - -export default function ValidationPage() { - return ( -
-
-
-
- -
-
-

Form Validation

-

Home{" > "} Form Validation

-
-
- NextUI hero Image -
-
-
-
- -
-
- ); -} diff --git a/app/(admin)/admin/(basic-form)/form-vertical/page.tsx b/app/(admin)/admin/(basic-form)/form-vertical/page.tsx deleted file mode 100644 index 61ca9f4..0000000 --- a/app/(admin)/admin/(basic-form)/form-vertical/page.tsx +++ /dev/null @@ -1,30 +0,0 @@ -"use client" -import { Image } from "@nextui-org/react"; - -export default function VerticalPage() { - return ( -
-
-
-
- -
-
-

Vertical Form

-

Home{" > "} Verical Form

-
-
- NextUI hero Image -
-
-
-
- {/* */} -
-
- ); -} diff --git a/app/(admin)/admin/(basic-form)/form-wizard/page.tsx b/app/(admin)/admin/(basic-form)/form-wizard/page.tsx deleted file mode 100644 index b096f16..0000000 --- a/app/(admin)/admin/(basic-form)/form-wizard/page.tsx +++ /dev/null @@ -1,44 +0,0 @@ -"use client" -import CreateWizardForm from "@/components/form/form-wizard/wizard-form"; -import AuthtorsTable from "@/components/table/authors-table"; -import CustomerTable from "@/components/table/customers-table"; -import InvoiceTable from "@/components/table/invoice-table"; -import UserTable from "@/components/table/article-table"; -import UsersTable from "@/components/table/users-table"; -import { Card, Divider, Image } from "@nextui-org/react"; - -export default function WizardPage() { - return ( -
-
-
-
- -
-
-

Form Wizard

-

This is Form WizardPage

-
-
- NextUI hero Image -
-
-
-
- -

Form Wizard

- -
- -
- - -
-
-
- ); -} diff --git a/app/(admin)/admin/basic/page.tsx b/app/(admin)/admin/basic/page.tsx deleted file mode 100644 index f9d5058..0000000 --- a/app/(admin)/admin/basic/page.tsx +++ /dev/null @@ -1,39 +0,0 @@ -"use client" -import { Card, Divider, Image } from "@nextui-org/react"; - -export default function BasicPage() { - return ( -
-
-
-
-
-
-

Basic Table

-

Home{" > "} Basic Table

-
-
- NextUI hero Image -
-
-
-
- -

Basic Table

- -
- {/* - - - - */} -
-
-
-
- ); -} diff --git a/app/(admin)/admin/master-user/create/page.tsx b/app/(admin)/admin/master-user/create/page.tsx new file mode 100644 index 0000000..a345e3c --- /dev/null +++ b/app/(admin)/admin/master-user/create/page.tsx @@ -0,0 +1,10 @@ +import FormMasterUser from '@/components/form/form-master-user' +import { Card } from '@nextui-org/react' + +export default function CreateMasterUserPage() { + return ( + + + + ) +} diff --git a/app/(admin)/admin/master-user/page.tsx b/app/(admin)/admin/master-user/page.tsx new file mode 100644 index 0000000..81372a0 --- /dev/null +++ b/app/(admin)/admin/master-user/page.tsx @@ -0,0 +1,24 @@ +"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 ( +
+
+ + + + + + + + +
+
+ ); +} diff --git a/app/(admin)/admin/menu1/submenu1/page.tsx b/app/(admin)/admin/menu1/submenu1/page.tsx deleted file mode 100644 index e87ac7f..0000000 --- a/app/(admin)/admin/menu1/submenu1/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { ThemeSwitch } from "@/components/theme-switch"; - -export default function Submenu1Page() { - return ( -
Submenu1 -
- ) -} \ No newline at end of file diff --git a/app/(admin)/admin/menu1/submenu2/page.tsx b/app/(admin)/admin/menu1/submenu2/page.tsx deleted file mode 100644 index 648391b..0000000 --- a/app/(admin)/admin/menu1/submenu2/page.tsx +++ /dev/null @@ -1,8 +0,0 @@ -import { ThemeSwitch } from "@/components/theme-switch"; - -export default function Submenu2Page() { - return ( -
Submenu2 -
- ) -} \ No newline at end of file diff --git a/components/form/form-article.tsx b/components/form/form-article.tsx index d36f28b..b024a95 100644 --- a/components/form/form-article.tsx +++ b/components/form/form-article.tsx @@ -1,16 +1,16 @@ 'use client' -import { Button, Card, Chip, Input, Select, SelectItem, Selection } from '@nextui-org/react' +import { error } from '@/config/swal'; +import { createArticle } from '@/service/article'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { Button, Card, Chip, Input, Select, SelectItem, Selection } from '@nextui-org/react'; import JoditEditor from 'jodit-react'; -import React, { ChangeEvent, useRef, useState } from 'react' -import * as z from "zod"; +import Link from 'next/link'; +import { useRouter } from 'next/navigation'; +import React, { ChangeEvent, useRef, useState } from 'react'; +import { useForm } from 'react-hook-form'; import Swal from 'sweetalert2'; import withReactContent from 'sweetalert2-react-content'; -import { useForm } from 'react-hook-form'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { createArticle } from '@/service/article'; -import { error } from '@/config/swal'; -import { useRouter } from 'next/navigation'; -import Link from 'next/link'; +import * as z from "zod"; const articleSchema = z.object({ title: z.string().min(1, { message: "Required" }), @@ -23,7 +23,6 @@ const articleSchema = z.object({ export default function FormArticle() { const router = useRouter(); - const [id, setId] = useState(); const [title, setTitle] = useState(""); const [article, setArticle] = React.useState(new Set([])); const [slug, setSlug] = useState(""); diff --git a/components/form/form-master-user.tsx b/components/form/form-master-user.tsx new file mode 100644 index 0000000..6460f1d --- /dev/null +++ b/components/form/form-master-user.tsx @@ -0,0 +1,348 @@ +'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'; + +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" }), +}); + +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 formOptions = { resolver: zodResolver(masterUserSchema) }; + type MicroIssueSchema = z.infer; + const { + register, + control, + handleSubmit, + setValue, + 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"); + }; + + 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: any) { + MySwal.fire({ + title: "Simpan Data", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#d33", + confirmButtonColor: "#3085d6", + confirmButtonText: "Simpan", + }).then((result) => { + if (result.isConfirmed) { + save(data); + } + }); + } + + return ( +
+
+ +
+ setFullname(e.target.value)} + /> + {errors.fullname?.message} +
+
+ setUsername(e.target.value)} + + /> + {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} +
+
+