Merge pull request #86 from bipproduction/lukman/1-agustus-2024

feat : update group
This commit is contained in:
Amalia
2024-08-01 10:09:55 +08:00
committed by GitHub
6 changed files with 77 additions and 70 deletions

View File

@@ -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");

View File

@@ -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 {

View File

@@ -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])

View File

@@ -3,16 +3,14 @@ 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,
isActive: active == "true" ? true : false,
idUserRole: String(idUserRole),
idPosition: String(idPosition),
idVillage: String(idVillage),
@@ -20,17 +18,26 @@ export async function getAllUser(req: NextRequest) {
},
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 }
);
}
}

View File

@@ -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>

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 { 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>