feat : update group

This commit is contained in:
lukman
2024-08-01 09:54:57 +08:00
parent 89281f286d
commit 86b0e93121
6 changed files with 77 additions and 72 deletions

View File

@@ -27,7 +27,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
const [selectId, setSelectId] = useState<string | null>(null); const [selectId, setSelectId] = useState<string | null>(null);
const [active, setActive] = useState<boolean | null>(null); const [active, setActive] = useState<boolean | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [isname, setName] = useState<string>("");
const getData = async () => { const getData = async () => {
try { try {
@@ -94,7 +93,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
setOpenDrawer(true); setOpenDrawer(true);
setSelectId(v.id); setSelectId(v.id);
setActive(v.isActive); setActive(v.isActive);
setName(v.name)
}} }}
> >
<Box> <Box>
@@ -128,7 +126,6 @@ export default function ListGroupActive({ status }: { status: boolean }) {
<EditDrawerGroup <EditDrawerGroup
id={selectId} id={selectId}
isActive={active} isActive={active}
isName={isname}
onUpdated={(val) => { onUpdated={(val) => {
if (val) { if (val) {
toast.success("Sukses! data tersimpan"); toast.success("Sukses! data tersimpan");

View File

@@ -12,7 +12,7 @@ import {
Text, Text,
TextInput, TextInput,
} from "@mantine/core"; } from "@mantine/core";
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { FaPencil, FaToggleOff } from "react-icons/fa6"; import { FaPencil, FaToggleOff } from "react-icons/fa6";
import { IoAddCircle, IoCloseCircleOutline } from "react-icons/io5"; import { IoAddCircle, IoCloseCircleOutline } from "react-icons/io5";
@@ -21,16 +21,30 @@ export default function EditDrawerGroup({
onUpdated, onUpdated,
id, id,
isActive, isActive,
isName,
}: { }: {
onUpdated: (val: boolean) => void; onUpdated: (val: boolean) => void;
id: string | null; id: string | null;
isActive: boolean | null; isActive: boolean | null;
isName: string;
}) { }) {
const [openDrawerGroup, setOpenDrawerGroup] = useState(false); const [openDrawerGroup, setOpenDrawerGroup] = useState(false);
const [isModal, setModal] = 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() { async function isUpdate() {
try { try {

View File

@@ -6,6 +6,7 @@ import { HiMagnifyingGlass } from "react-icons/hi2";
import DrawerDetailPosition from "./drawer_detail_position"; import DrawerDetailPosition from "./drawer_detail_position";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import _ from "lodash"; import _ from "lodash";
import { useShallowEffect } from "@mantine/hooks";
type dataPosition = { type dataPosition = {
name: string; name: string;
@@ -38,7 +39,7 @@ export default function ListPositionActive({ status }: { status: boolean }) {
} }
} }
useEffect(() => { useShallowEffect(() => {
getAllPosition(); getAllPosition();
}, [status]) }, [status])

View File

@@ -3,34 +3,39 @@ import { NextRequest } from "next/server";
export async function getAllUser(req: NextRequest) { export async function getAllUser(req: NextRequest) {
try { try {
const searchParams = req.nextUrl.searchParams; const searchParams = req.nextUrl.searchParams;
const idGroup = searchParams.get('groupID'); const idGroup = "2";
const idUserRole = searchParams.get('roleID'); const idVillage = "121212";
const idPosition = searchParams.get('positionID'); const active = searchParams.get("active");
const idVillage = searchParams.get('villageID');
const users = await prisma.user.findMany({ const users = await prisma.user.findMany({
where: { where: {
isActive: true, isActive: active == "true" ? true : false,
idUserRole: String(idUserRole),
idPosition: idPosition,
idVillage: idVillage, idVillage: idVillage,
idGroup: idGroup, idGroup: idGroup,
}, },
select: { select: {
id: true, id: true,
isActive: true,
nik: true, nik: true,
name: true, name: true,
phone: true, phone: true,
email: true, email: true,
gender: true, gender: true,
Group: {
select: {
name: true,
},
},
}, },
}); });
return Response.json(users); return Response.json(users);
} catch (error) { } catch (error) {
console.error(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 }
);
} }
} }

View File

@@ -42,11 +42,12 @@ export default function ListMember() {
/> />
<Tabs.Panel value="aktif"> <Tabs.Panel value="aktif">
<TabListMember /> <TabListMember status={true} />
</Tabs.Panel> </Tabs.Panel>
<Tabs.Panel value="tidak-aktif"> <Tabs.Panel value="tidak-aktif">
<TabListMember /> <TabListMember status={false} />
{/* <TabListMember /> */}
</Tabs.Panel> </Tabs.Panel>
</Tabs> </Tabs>
</Box> </Box>

View File

@@ -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 { Box, Group, ActionIcon, Text } from "@mantine/core"
import { useShallowEffect } from "@mantine/hooks"
import { useRouter } from "next/navigation" import { useRouter } from "next/navigation"
import { useEffect, useState } from "react"
import { HiMiniUser } from "react-icons/hi2" import { HiMiniUser } from "react-icons/hi2"
const dataMember = [ type dataMember = {
{ id: string,
id: 1, idUserRole: string,
name: 'Ali akbar', idVillage: string,
desc: 'Perbekel', idGroup: string,
grup: 'Dinas' idPosition: string,
}, nik: string,
{ name: string,
id: 2, phone: string,
name: 'Fibra Marcell', email: string,
desc: 'Kasi Kesejahteraan', gender: string,
grup: 'Dinas' isActive: boolean
},
{
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'
},
]
export default function TabListMember() { }
export default function TabListMember({ status }: { status: boolean }) {
const router = useRouter() 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 ( return (
<> <>
@@ -75,7 +62,7 @@ export default function TabListMember() {
</Box> </Box>
<Box> <Box>
<Text fw={'bold'} c={WARNA.biruTua}>{v.name}</Text> <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> </Box>
</Group> </Group>
</Box> </Box>