feat : update group
This commit is contained in:
@@ -27,7 +27,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
|
||||
const [selectId, setSelectId] = useState<string | null>(null);
|
||||
const [active, setActive] = useState<boolean | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [isname, setName] = useState<string>("");
|
||||
|
||||
const getData = async () => {
|
||||
try {
|
||||
@@ -94,7 +93,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
|
||||
setOpenDrawer(true);
|
||||
setSelectId(v.id);
|
||||
setActive(v.isActive);
|
||||
setName(v.name)
|
||||
}}
|
||||
>
|
||||
<Box>
|
||||
@@ -128,7 +126,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
|
||||
<EditDrawerGroup
|
||||
id={selectId}
|
||||
isActive={active}
|
||||
isName={isname}
|
||||
onUpdated={(val) => {
|
||||
if (val) {
|
||||
toast.success("Sukses! data tersimpan");
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
Text,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import React, { useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaPencil, FaToggleOff } from "react-icons/fa6";
|
||||
import { IoAddCircle, IoCloseCircleOutline } from "react-icons/io5";
|
||||
@@ -21,16 +21,30 @@ export default function EditDrawerGroup({
|
||||
onUpdated,
|
||||
id,
|
||||
isActive,
|
||||
isName,
|
||||
}: {
|
||||
onUpdated: (val: boolean) => void;
|
||||
id: string | null;
|
||||
isActive: boolean | null;
|
||||
isName: string;
|
||||
}) {
|
||||
const [openDrawerGroup, setOpenDrawerGroup] = useState(false);
|
||||
const [isModal, setModal] = useState(false);
|
||||
const [name, setName] = useState(isName);
|
||||
const [name, setName] = useState("");
|
||||
|
||||
async function getOneGroup() {
|
||||
try {
|
||||
const res = await fetch(`${API_ADDRESS.apiGetOneGroup}&groupId=${id}`);
|
||||
const data = await res.json();
|
||||
setName(data.name);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getOneGroup();
|
||||
}, []);
|
||||
|
||||
async function isUpdate() {
|
||||
try {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { HiMagnifyingGlass } from "react-icons/hi2";
|
||||
import DrawerDetailPosition from "./drawer_detail_position";
|
||||
import toast from "react-hot-toast";
|
||||
import _ from "lodash";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
|
||||
type dataPosition = {
|
||||
name: string;
|
||||
@@ -38,7 +39,7 @@ export default function ListPositionActive({ status }: { status: boolean }) {
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
useShallowEffect(() => {
|
||||
getAllPosition();
|
||||
}, [status])
|
||||
|
||||
|
||||
@@ -3,34 +3,39 @@ import { NextRequest } from "next/server";
|
||||
|
||||
export async function getAllUser(req: NextRequest) {
|
||||
try {
|
||||
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const idGroup = searchParams.get('groupID');
|
||||
const idUserRole = searchParams.get('roleID');
|
||||
const idPosition = searchParams.get('positionID');
|
||||
const idVillage = searchParams.get('villageID');
|
||||
const idGroup = "2";
|
||||
const idVillage = "121212";
|
||||
const active = searchParams.get("active");
|
||||
|
||||
const users = await prisma.user.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: String(idUserRole),
|
||||
idPosition: idPosition,
|
||||
isActive: active == "true" ? true : false,
|
||||
idVillage: idVillage,
|
||||
idGroup: idGroup,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
isActive: true,
|
||||
nik: true,
|
||||
name: true,
|
||||
phone: true,
|
||||
email: true,
|
||||
gender: true,
|
||||
Group: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return Response.json(users);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return Response.json({ success: false, message: "Internal Server Error" }, { status: 500 });
|
||||
return Response.json(
|
||||
{ success: false, message: "Internal Server Error" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,12 @@ export default function ListMember() {
|
||||
/>
|
||||
|
||||
<Tabs.Panel value="aktif">
|
||||
<TabListMember />
|
||||
<TabListMember status={true} />
|
||||
</Tabs.Panel>
|
||||
|
||||
<Tabs.Panel value="tidak-aktif">
|
||||
<TabListMember />
|
||||
<TabListMember status={false} />
|
||||
{/* <TabListMember /> */}
|
||||
</Tabs.Panel>
|
||||
</Tabs>
|
||||
</Box>
|
||||
|
||||
@@ -1,61 +1,48 @@
|
||||
import { WARNA } from "@/module/_global"
|
||||
|
||||
import { API_ADDRESS, WARNA } from "@/module/_global"
|
||||
import { Box, Group, ActionIcon, Text } from "@mantine/core"
|
||||
import { useShallowEffect } from "@mantine/hooks"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { useEffect, useState } from "react"
|
||||
import { HiMiniUser } from "react-icons/hi2"
|
||||
|
||||
const dataMember = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Ali akbar',
|
||||
desc: 'Perbekel',
|
||||
grup: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Fibra Marcell',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Burhan',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
name: 'Chandra',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
name: 'Ayu',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'PKK'
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
name: 'Heriawan',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'Karang Taruna'
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'Jinan',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'Dinas'
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
name: 'Rizal',
|
||||
desc: 'Kasi Kesejahteraan',
|
||||
grup: 'LPD'
|
||||
},
|
||||
]
|
||||
type dataMember = {
|
||||
id: string,
|
||||
idUserRole: string,
|
||||
idVillage: string,
|
||||
idGroup: string,
|
||||
idPosition: string,
|
||||
nik: string,
|
||||
name: string,
|
||||
phone: string,
|
||||
email: string,
|
||||
gender: string,
|
||||
isActive: boolean
|
||||
|
||||
export default function TabListMember() {
|
||||
}
|
||||
|
||||
export default function TabListMember({ status }: { status: boolean }) {
|
||||
const router = useRouter()
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [dataMember, setDataMember] = useState<dataMember[]>([])
|
||||
|
||||
|
||||
async function getAllUser() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const res = await fetch(`${API_ADDRESS.apiGetAllUser}&active` + status)
|
||||
const data = await res.json()
|
||||
setDataMember(data)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getAllUser()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -75,7 +62,7 @@ export default function TabListMember() {
|
||||
</Box>
|
||||
<Box>
|
||||
<Text fw={'bold'} c={WARNA.biruTua}>{v.name}</Text>
|
||||
<Text fw={'lighter'} fz={12}>{v.grup + ' - ' + v.desc}</Text>
|
||||
{/* <Text fw={'lighter'} fz={12}>{v.grup + ' - ' + v.desc}</Text> */}
|
||||
</Box>
|
||||
</Group>
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user