-
-
-
- {(column) => (
- {column.name}
- )}
-
- }
- >
- {(item) => (
-
- {(columnKey) => (
- {renderCell(item, columnKey)}
- )}
-
- )}
-
-
-
+ case "status":
+ return (
+
+
+ {cellValue}
+
+ );
- >
- );
+ case "actions":
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ Detail
+
+
+
+
+
+ Edit
+
+
+ handleDelete(role.id)}>
+
+ Delete
+
+
+
+
+ );
+
+ default:
+ return cellValue;
+ }
+ }, []);
+
+ return (
+ <>
+
+
+
+
+ {(column) => (
+ {column.name}
+ )}
+
+ }
+ >
+ {(item) => (
+
+ {(columnKey) => (
+ {renderCell(item, columnKey)}
+ )}
+
+ )}
+
+
+
+
+
+ >
+ );
}
diff --git a/components/table/master-user-table.tsx b/components/table/master-user-table.tsx
index 822b73b..443bd53 100644
--- a/components/table/master-user-table.tsx
+++ b/components/table/master-user-table.tsx
@@ -1,296 +1,228 @@
"use client";
import {
- CreateIconIon,
- DeleteIcon,
- DotsYIcon,
- EyeIconMdi
+ CreateIconIon,
+ DeleteIcon,
+ DotsYIcon,
+ EyeIconMdi,
} from "@/components/icons";
-import { error, success, } from "@/config/swal";
+import { error, success } from "@/config/swal";
import { deleteArticle, getListArticle } from "@/service/article";
import { deleteMasterUser, listMasterUsers } from "@/service/master-user";
import { Article, MasterUser } from "@/types/globals";
import { Button } from "@nextui-org/button";
import {
- Chip,
- ChipProps,
- Dropdown,
- DropdownItem,
- DropdownMenu,
- DropdownTrigger,
- Spinner,
- Table,
- TableBody,
- TableCell,
- TableColumn,
- TableHeader,
- TableRow
+ Chip,
+ ChipProps,
+ Dropdown,
+ DropdownItem,
+ DropdownMenu,
+ DropdownTrigger,
+ Pagination,
+ Spinner,
+ Table,
+ TableBody,
+ TableCell,
+ TableColumn,
+ TableHeader,
+ TableRow,
} from "@nextui-org/react";
import Link from "next/link";
import { Key, useCallback, useEffect, useState } from "react";
import Swal from "sweetalert2";
import withReactContent from "sweetalert2-react-content";
-type UserObject = {
- id: number;
- user: string;
- status: string;
- projectName: string;
- avatar: string;
-};
-
-const statusColorMap = {
- active: "success",
- paused: "danger",
- vacation: "warning",
-};
-
+const columns = [
+ { name: "No", uid: "no" },
+ { name: "Username", uid: "username" },
+ { name: "Fullname", uid: "fullname" },
+ { name: "Email", uid: "email" },
+ { name: "Identity Type", uid: "identityType" },
+ { name: "Identity Number", uid: "identityNumber" },
+ // { name: "Users", uid: "users" },
+ // { name: "Status", uid: "status" },
+ { name: "Aksi", uid: "actions" },
+];
export default function MasterUserTable() {
- const MySwal = withReactContent(Swal);
- const [user, setUser] = useState
([]);
+ const MySwal = withReactContent(Swal);
+ const [user, setUser] = useState([]);
+ const [page, setPage] = useState(1);
+ const [totalPage, setTotalPage] = useState(1);
+ useEffect(() => {
+ initState();
+ }, [page]);
+ async function initState() {
+ const res = await listMasterUsers({ page: page, limit: 10 });
+ getTableNumber(10, res?.data?.data);
+ setTotalPage(res?.data?.meta?.totalPage);
+ }
+ const getTableNumber = (limit: number, data?: any) => {
+ if (data) {
+ const startIndex = limit * (page - 1);
+ let iterate = 0;
+ const newData = data.map((value: any) => {
+ iterate++;
+ value.no = startIndex + iterate;
+ return value;
+ });
+ setUser(newData);
+ }
+ };
- useEffect(() => {
+ async function doDelete(id: any) {
+ // loading();
+ const resDelete = await deleteMasterUser(id);
+
+ if (resDelete?.error) {
+ error(resDelete.message);
+ return false;
+ }
+ close();
+ successSubmit();
+ }
+
+ const handleDelete = (id: any) => {
+ MySwal.fire({
+ title: "Hapus Data",
+ icon: "warning",
+ showCancelButton: true,
+ cancelButtonColor: "#3085d6",
+ confirmButtonColor: "#d33",
+ confirmButtonText: "Hapus",
+ }).then((result) => {
+ if (result.isConfirmed) {
+ doDelete(id);
+ }
+ });
+ };
+
+ function successSubmit() {
+ MySwal.fire({
+ title: "Sukses",
+ icon: "success",
+ confirmButtonColor: "#3085d6",
+ confirmButtonText: "OK",
+ }).then((result) => {
+ if (result.isConfirmed) {
initState();
- }, []);
+ }
+ });
+ }
- async function initState() {
- const res = await listMasterUsers();
- setUser(res.data?.data);
-
- console.log("List Users", res.data.data);
- }
-
- type TableRow = (typeof usersTable)[0];
-
- const columns = [
-
- { name: "No", uid: "id" },
- { name: "Username", uid: "username" },
- { name: "Fullname", uid: "fullname" },
- { name: "Email", uid: "email" },
- { name: "Gender", uid: "gender_type" },
- { name: "Identity Type", uid: "identity_type" },
- { name: "Identity Number", uid: "identity_number" },
- { name: "Phone Number", uid: "phone_number" },
- // { name: "Users", uid: "users" },
- // { name: "Status", uid: "status" },
- { name: "Aksi", uid: "actions" },
- ];
-
-
- async function doDelete(id: any) {
- // loading();
- const resDelete = await deleteMasterUser(id);
-
- if (resDelete?.error) {
- error(resDelete.message);
- return false;
- }
- close();
- successSubmit();
- }
-
- const handleDelete = (id: any) => {
- MySwal.fire({
- title: "Hapus Data",
- icon: "warning",
- showCancelButton: true,
- cancelButtonColor: "#3085d6",
- confirmButtonColor: "#d33",
- confirmButtonText: "Hapus",
- }).then((result) => {
- if (result.isConfirmed) {
- doDelete(id);
- }
- });
+ const renderCell = useCallback((user: MasterUser, columnKey: Key) => {
+ const cellValue = user[columnKey as keyof MasterUser];
+ const statusColorMap: Record = {
+ active: "primary",
+ cancel: "danger",
+ pending: "success",
};
- function successSubmit() {
- MySwal.fire({
- title: "Sukses",
- icon: "success",
- confirmButtonColor: "#3085d6",
- confirmButtonText: "OK",
- }).then((result) => {
- if (result.isConfirmed) {
- initState()
- }
- });
- }
+ switch (columnKey) {
+ case "id":
+ return {user.id}
;
- // const statusOptions = [
- // { name: "Active", uid: "active" },
- // { name: "Paused", uid: "paused" },
- // { name: "Vacation", uid: "vacation" },
- // ];
-
- const usersTable = [
- {
- id: 1,
- user: "Olivia Rhya",
- status: "active",
- projectName: "Xtreme admin",
- avatar: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSa8Luglga9J2R3Bxt_PsWZISUHQWODD6_ZTAJ5mIQgxYCAE-YbkY81faTqp-hSA_jVPTs&usqp=CAU",
- },
- {
- id: 2,
- user: "Barbara Steele",
- status: "cancel",
- projectName: "Adminpro admin",
- avatar: "https://cdn.icon-icons.com/icons2/2859/PNG/512/avatar_face_man_boy_male_profile_smiley_happy_people_icon_181661.png",
- },
- {
- id: 3,
- user: "Leonardo Gordon",
- status: "pending",
- projectName: "Monster admin",
- avatar: "https://cdn.icon-icons.com/icons2/2859/PNG/512/avatar_face_man_boy_male_profile_smiley_happy_people_icon_181657.png",
- },
- {
- id: 4,
- user: "Evelyn Pope",
- status: "cancel",
- projectName: "Materialpro admin",
- avatar: "https://cdn.icon-icons.com/icons2/3708/PNG/512/man_person_people_avatar_icon_230017.png",
- },
- {
- id: 5,
- user: "Tommy Garza",
- status: "cancel",
- projectName: "Elegant admin",
- avatar: "https://cdn.icon-icons.com/icons2/1736/PNG/512/4043275-avatar-man-person-punk_113271.png",
- },
-
-
- ];
-
- const renderCell = useCallback(
- (user: MasterUser, columnKey: Key) => {
- const cellValue = user[columnKey as keyof MasterUser];
- const statusColorMap: Record = {
- active: "primary",
- cancel: "danger",
- pending: "success",
- };
-
- switch (columnKey) {
- case "id":
- return (
- {user.id}
- )
-
- case "status":
- return (
-
-
- {cellValue}
-
-
- );
-
- case "actions":
- return (
-
-
-
-
-
-
-
-
-
-
-
-
- Detail
-
-
-
-
-
-
-
- Edit
-
-
-
- handleDelete(user.id)}
- >
-
-
- Delete
-
-
-
-
-
-
- );
-
- default:
- return cellValue;
- }
- }, []);
-
- return (
- <>
-
-
-
-
-
- {(column) => (
- {column.name}
- )}
-
- }
- >
- {(item) => (
-
- {(columnKey) => (
- {renderCell(item, columnKey)}
- )}
-
- )}
-
-
-
+ case "status":
+ return (
+
+
+ {cellValue}
+
+ );
- >
- );
+ case "actions":
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ Edit
+
+
+ handleDelete(user.id)}>
+
+ Delete
+
+
+
+
+ );
+
+ default:
+ return cellValue;
+ }
+ }, []);
+
+ return (
+ <>
+
+
+
+
+ {(column) => (
+ {column.name}
+ )}
+
+ }
+ >
+ {(item) => (
+
+ {(columnKey) => (
+ {renderCell(item, columnKey)}
+ )}
+
+ )}
+
+
+
+
+
+ >
+ );
}
diff --git a/service/master-user-role.ts b/service/master-user-role.ts
index c8c8789..5dd26b7 100644
--- a/service/master-user-role.ts
+++ b/service/master-user-role.ts
@@ -1,27 +1,34 @@
-import { httpDeleteInterceptor, httpGet, httpPost } from "./http-config/axios-base-service";
+import {
+ httpDeleteInterceptor,
+ httpGet,
+ httpPost,
+} from "./http-config/axios-base-service";
-export async function listUserRole() {
- const headers = {
- "content-type": "application/json",
- };
- return await httpGet(`/user-roles`, headers);
+export async function listUserRole(data: any) {
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpGet(
+ `/user-roles?limit=${data.limit}&page=${data.page}`,
+ headers
+ );
}
export async function createMasterUserRole(data: any) {
- const headers = {
- "content-type": "application/json",
- };
- const pathUrl = `/user-roles`;
- return await httpPost(pathUrl, headers, data);
+ const headers = {
+ "content-type": "application/json",
+ };
+ const pathUrl = `/user-roles`;
+ return await httpPost(pathUrl, headers, data);
}
export async function getMasterUserRoleById(id: any) {
- const headers = {
- "content-type": "application/json",
- };
- return await httpGet(`/user-roles/${id}`, headers);
+ const headers = {
+ "content-type": "application/json",
+ };
+ return await httpGet(`/user-roles/${id}`, headers);
}
export async function deleteMasterUserRole(id: string) {
- return await httpDeleteInterceptor(`/user-roles/${id}`);
-}
\ No newline at end of file
+ return await httpDeleteInterceptor(`/user-roles/${id}`);
+}
diff --git a/service/master-user.ts b/service/master-user.ts
index a85c8f8..629635a 100644
--- a/service/master-user.ts
+++ b/service/master-user.ts
@@ -4,11 +4,11 @@ import {
httpPost,
} from "./http-config/axios-base-service";
-export async function listMasterUsers() {
+export async function listMasterUsers(data: any) {
const headers = {
"content-type": "application/json",
};
- return await httpGet(`/users`, headers);
+ return await httpGet(`/users?page=${data.page}&limit=${data.limit}`, headers);
}
export async function createMasterUser(data: any) {