upd: member
Deskripsi: - mulai pembatasan sesuai user role - nb : blm selesai No Issues
This commit is contained in:
@@ -22,6 +22,16 @@ export async function GET(request: Request) {
|
|||||||
fixGroup = idGroup
|
fixGroup = idGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filter = await prisma.group.findUnique({
|
||||||
|
where: {
|
||||||
|
id: fixGroup
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
const users = await prisma.user.findMany({
|
const users = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
@@ -60,7 +70,7 @@ export async function GET(request: Request) {
|
|||||||
position: v.Position.name
|
position: v.Position.name
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil member", data: allData, }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil member", data: allData, filter }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan member, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan member, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
@@ -77,7 +87,13 @@ export async function POST(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
}
|
}
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const village = "desa1"
|
const village = String(user.idVillage)
|
||||||
|
|
||||||
|
let groupFix = data.idGroup
|
||||||
|
|
||||||
|
if (groupFix == null || groupFix == undefined || groupFix == "") {
|
||||||
|
groupFix = user.idGroup
|
||||||
|
}
|
||||||
|
|
||||||
const cek = await prisma.user.count({
|
const cek = await prisma.user.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -95,18 +111,13 @@ export async function POST(request: Request) {
|
|||||||
phone: data.phone,
|
phone: data.phone,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
gender: data.gender,
|
gender: data.gender,
|
||||||
idGroup: data.idGroup,
|
idGroup: groupFix,
|
||||||
idVillage: village,
|
idVillage: village,
|
||||||
idPosition: data.idPosition,
|
idPosition: data.idPosition,
|
||||||
idUserRole: data.idUserRole,
|
idUserRole: data.idUserRole,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true
|
||||||
nik: true,
|
|
||||||
name: true,
|
|
||||||
phone: true,
|
|
||||||
email: true,
|
|
||||||
gender: true,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { WARNA } from "@/module/_global";
|
import { globalRole, WARNA } from "@/module/_global";
|
||||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
||||||
import { Box, Button, rem, Select, Stack, Text, TextInput } from "@mantine/core";
|
import { Box, Button, rem, Select, Stack, Text, TextInput } from "@mantine/core";
|
||||||
@@ -11,6 +11,9 @@ import { IDataPositionMember, IDataROleMember } from "../lib/type_member";
|
|||||||
import { funGetAllPosition } from "@/module/position/lib/api_position";
|
import { funGetAllPosition } from "@/module/position/lib/api_position";
|
||||||
import { funCreateMember, funGetRoleUser } from "../lib/api_member";
|
import { funCreateMember, funGetRoleUser } from "../lib/api_member";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
|
|
||||||
export default function CreateMember() {
|
export default function CreateMember() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -18,6 +21,8 @@ export default function CreateMember() {
|
|||||||
const [listGroup, setListGorup] = useState<IDataGroup[]>([]);
|
const [listGroup, setListGorup] = useState<IDataGroup[]>([]);
|
||||||
const [listPosition, setListPosition] = useState<IDataPositionMember[]>([]);
|
const [listPosition, setListPosition] = useState<IDataPositionMember[]>([]);
|
||||||
const [listUserRole, setListUserRole] = useState<IDataROleMember[]>([]);
|
const [listUserRole, setListUserRole] = useState<IDataROleMember[]>([]);
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
const [groupLogin, setGroupLogin] = useState("");
|
||||||
const [touched, setTouched] = useState({
|
const [touched, setTouched] = useState({
|
||||||
nik: false,
|
nik: false,
|
||||||
name: false,
|
name: false,
|
||||||
@@ -54,12 +59,20 @@ export default function CreateMember() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getLogin() {
|
||||||
|
try {
|
||||||
|
const res = await funGetUserByCookies();
|
||||||
|
setGroupLogin(String(res.idGroup));
|
||||||
|
getAllPosition(res.idGroup);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getAllPosition(val: any) {
|
async function getAllPosition(val: any) {
|
||||||
try {
|
try {
|
||||||
if (val != null) {
|
if (val != null) {
|
||||||
const res = await funGetAllPosition(
|
const res = await funGetAllPosition("?active=true" + "&group=" + `${val}`);
|
||||||
"?active=true" + "&group=" + `${val}`
|
|
||||||
);
|
|
||||||
setListPosition(res.data);
|
setListPosition(res.data);
|
||||||
} else {
|
} else {
|
||||||
setListPosition([]);
|
setListPosition([]);
|
||||||
@@ -121,9 +134,13 @@ export default function CreateMember() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useShallowEffect(() => {
|
||||||
getAllGroup();
|
getAllGroup();
|
||||||
getAllUserRole();
|
getAllUserRole();
|
||||||
|
|
||||||
|
if (roleLogin.get() != "supadmin") {
|
||||||
|
getLogin()
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
@@ -140,40 +157,43 @@ export default function CreateMember() {
|
|||||||
>
|
>
|
||||||
<HiUser size={100} color={WARNA.bgWhite} />
|
<HiUser size={100} color={WARNA.bgWhite} />
|
||||||
</Box>
|
</Box>
|
||||||
<Select
|
{
|
||||||
placeholder="Pilih Grup"
|
roleLogin.get() == "supadmin" &&
|
||||||
label="Grup"
|
<Select
|
||||||
w={"100%"}
|
placeholder="Pilih Grup"
|
||||||
size="md"
|
label="Grup"
|
||||||
required
|
w={"100%"}
|
||||||
withAsterisk
|
size="md"
|
||||||
radius={30}
|
required
|
||||||
styles={{
|
withAsterisk
|
||||||
input: {
|
radius={30}
|
||||||
color: WARNA.biruTua,
|
styles={{
|
||||||
borderRadius: WARNA.biruTua,
|
input: {
|
||||||
borderColor: WARNA.biruTua,
|
color: WARNA.biruTua,
|
||||||
},
|
borderRadius: WARNA.biruTua,
|
||||||
}}
|
borderColor: WARNA.biruTua,
|
||||||
data={
|
},
|
||||||
listGroup
|
}}
|
||||||
? listGroup.map((data) => ({
|
data={
|
||||||
value: data.id,
|
listGroup
|
||||||
label: data.name,
|
? listGroup.map((data) => ({
|
||||||
}))
|
value: data.id,
|
||||||
: []
|
label: data.name,
|
||||||
}
|
}))
|
||||||
onChange={(val: any) => {
|
: []
|
||||||
changeGrup(val);
|
}
|
||||||
setTouched({ ...touched, idGroup: false })
|
onChange={(val: any) => {
|
||||||
}}
|
changeGrup(val);
|
||||||
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
setTouched({ ...touched, idGroup: false })
|
||||||
error={
|
}}
|
||||||
touched.idGroup && (
|
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
||||||
listData.idGroup == "" ? "Grup Tidak Boleh Kosong" : null
|
error={
|
||||||
)
|
touched.idGroup && (
|
||||||
}
|
listData.idGroup == "" ? "Grup Tidak Boleh Kosong" : null
|
||||||
/>
|
)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
}
|
||||||
<Select
|
<Select
|
||||||
placeholder="Pilih Jabatan"
|
placeholder="Pilih Jabatan"
|
||||||
label="Jabatan"
|
label="Jabatan"
|
||||||
@@ -274,7 +294,7 @@ export default function CreateMember() {
|
|||||||
error={
|
error={
|
||||||
touched.nik && (
|
touched.nik && (
|
||||||
listData.nik === "" ? "NIK Tidak Boleh Kosong" :
|
listData.nik === "" ? "NIK Tidak Boleh Kosong" :
|
||||||
listData.nik.length !== 16 ? "NIK Harus 16 Karakter" : null
|
listData.nik.length !== 16 ? "NIK Harus 16 Karakter" : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
import { WARNA } from '@/module/_global';
|
import { globalRole, WARNA } from '@/module/_global';
|
||||||
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
import { IoAddCircle } from "react-icons/io5";
|
import { IoAddCircle } from "react-icons/io5";
|
||||||
import { RiFilter2Line } from 'react-icons/ri';
|
import { RiFilter2Line } from 'react-icons/ri';
|
||||||
|
|
||||||
export default function DrawerListMember() {
|
export default function DrawerListMember() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const group = searchParams.get('group')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
@@ -29,20 +33,22 @@ export default function DrawerListMember() {
|
|||||||
<Text c={WARNA.biruTua} ta='center'>Tambah Anggota</Text>
|
<Text c={WARNA.biruTua} ta='center'>Tambah Anggota</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
{
|
||||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
roleLogin.get() === 'supadmin' &&
|
||||||
style={{ cursor: 'pointer' }}
|
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||||
onClick={() => {
|
style={{ cursor: 'pointer' }}
|
||||||
router.push('/member?page=filter')
|
onClick={() => {
|
||||||
}}
|
router.push('/member?page=filter&group=' + group)
|
||||||
>
|
}}
|
||||||
<Box>
|
>
|
||||||
<RiFilter2Line size={30} color={WARNA.biruTua} />
|
<Box>
|
||||||
</Box>
|
<RiFilter2Line size={30} color={WARNA.biruTua} />
|
||||||
<Box>
|
</Box>
|
||||||
<Text c={WARNA.biruTua} ta='center'>Filter</Text>
|
<Box>
|
||||||
</Box>
|
<Text c={WARNA.biruTua} ta='center'>Filter</Text>
|
||||||
</Flex>
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
|
|
||||||
import { SkeletonSingle, WARNA } from "@/module/_global"
|
import { globalRole, SkeletonSingle, WARNA } from "@/module/_global"
|
||||||
import { Box, Group, ActionIcon, Text, TextInput, Divider, Avatar, Grid } from "@mantine/core"
|
import { Box, Text, TextInput, Divider, Avatar, Grid } from "@mantine/core"
|
||||||
import { useShallowEffect } from "@mantine/hooks"
|
import { useShallowEffect } from "@mantine/hooks"
|
||||||
import { useRouter, useSearchParams } from "next/navigation"
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { useEffect, useState } from "react"
|
import { useState } from "react"
|
||||||
import { HiMagnifyingGlass, HiMiniUser } from "react-icons/hi2"
|
import { HiMagnifyingGlass } from "react-icons/hi2"
|
||||||
import { IListMember } from "../lib/type_member"
|
import { IListMember } from "../lib/type_member"
|
||||||
import { funGetAllmember } from "../lib/api_member"
|
import { funGetAllmember } from "../lib/api_member"
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group"
|
import { funGetAllGroup, IDataGroup } from "@/module/group"
|
||||||
import toast from "react-hot-toast"
|
import toast from "react-hot-toast"
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
|
import { useHookstate } from "@hookstate/core"
|
||||||
|
|
||||||
|
|
||||||
export default function TabListMember() {
|
export default function TabListMember() {
|
||||||
@@ -20,13 +21,20 @@ export default function TabListMember() {
|
|||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const group = searchParams.get('group')
|
const group = searchParams.get('group')
|
||||||
const status = searchParams.get('active')
|
const status = searchParams.get('active')
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
const [nameGroup, setNameGroup] = useState('')
|
||||||
|
|
||||||
|
|
||||||
async function getAllUser() {
|
async function getAllUser() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const res = await funGetAllmember('?active=' + status + '&group=' + group + '&search=' + searchQuery)
|
const res = await funGetAllmember('?active=' + status + '&group=' + group + '&search=' + searchQuery)
|
||||||
setDataMember(res.data)
|
if (res.success) {
|
||||||
|
setDataMember(res.data)
|
||||||
|
setNameGroup(res.filter.name)
|
||||||
|
} else {
|
||||||
|
toast.error(res.message)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
throw new Error("Error")
|
throw new Error("Error")
|
||||||
@@ -39,31 +47,6 @@ export default function TabListMember() {
|
|||||||
getAllUser()
|
getAllUser()
|
||||||
}, [status, searchQuery])
|
}, [status, searchQuery])
|
||||||
|
|
||||||
const [checked, setChecked] = useState<IDataGroup[]>([]);
|
|
||||||
|
|
||||||
const groupNameMap = (groupId: string) => {
|
|
||||||
const groupName = checked.find((group) => group.id === groupId)?.name;
|
|
||||||
return groupName || '-';
|
|
||||||
};
|
|
||||||
|
|
||||||
async function getAllGroupFilter() {
|
|
||||||
try {
|
|
||||||
const response = await funGetAllGroup('?active=true')
|
|
||||||
if (response.success) {
|
|
||||||
setChecked(response.data);
|
|
||||||
} else {
|
|
||||||
toast.error(response.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
toast.error("Gagal mendapatkan grup, coba lagi nanti");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
|
||||||
getAllGroupFilter();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Box>
|
<Box>
|
||||||
@@ -92,7 +75,7 @@ export default function TabListMember() {
|
|||||||
))
|
))
|
||||||
:
|
:
|
||||||
<Box>
|
<Box>
|
||||||
{group && <Text>Filter by: {groupNameMap(group)}</Text>}
|
{roleLogin.get() == 'supadmin' && <Text>Filter by: {nameGroup}</Text>}
|
||||||
{dataMember.length == 0 ?
|
{dataMember.length == 0 ?
|
||||||
<Box style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '60vh' }}>
|
<Box style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '60vh' }}>
|
||||||
<Text c="dimmed" ta={"center"} fs={"italic"}>Tidak ada anggota</Text>
|
<Text c="dimmed" ta={"center"} fs={"italic"}>Tidak ada anggota</Text>
|
||||||
@@ -107,7 +90,7 @@ export default function TabListMember() {
|
|||||||
<Grid p={10} gutter={{
|
<Grid p={10} gutter={{
|
||||||
base: 60,
|
base: 60,
|
||||||
xl: "xs"
|
xl: "xs"
|
||||||
}} align="center">
|
}} align="center">
|
||||||
<Grid.Col span={2}>
|
<Grid.Col span={2}>
|
||||||
<Avatar src={`/api/file/img?jenis=image&cat=user&file=${v.img}`} size={50} alt="image" />
|
<Avatar src={`/api/file/img?jenis=image&cat=user&file=${v.img}`} size={50} alt="image" />
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|||||||
Reference in New Issue
Block a user