Merge pull request #189 from bipproduction/amalia/04-september-24
Amalia/04 september 24
This commit is contained in:
@@ -1,17 +1,18 @@
|
|||||||
import { pwd_key_config } from "@/module/_global"
|
import { WrapLayout } from "@/module/_global"
|
||||||
import { funDetectCookies } from "@/module/auth"
|
import { funDetectCookies, funGetUserByCookies } from "@/module/auth"
|
||||||
import { unsealData } from "iron-session"
|
|
||||||
import _ from "lodash"
|
import _ from "lodash"
|
||||||
import { cookies } from "next/headers"
|
|
||||||
import { redirect } from "next/navigation"
|
import { redirect } from "next/navigation"
|
||||||
|
|
||||||
export default async function Layout({ children }: { children: React.ReactNode }) {
|
export default async function Layout({ children }: { children: React.ReactNode }) {
|
||||||
const cookies = await funDetectCookies()
|
const cookies = await funDetectCookies()
|
||||||
if (!cookies) return redirect('/')
|
if (!cookies) return redirect('/')
|
||||||
|
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{children}
|
<WrapLayout role={user.idUserRole}>
|
||||||
|
{children}
|
||||||
|
</WrapLayout>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
@@ -80,6 +81,8 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate status data jabatan', table: 'position', data: id })
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ success: true, message: "Berhasil mengubah status jabatan" },
|
{ success: true, message: "Berhasil mengubah status jabatan" },
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
@@ -104,8 +107,12 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
where: {
|
where: {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
idGroup: data.idGroup,
|
idGroup: data.idGroup,
|
||||||
|
NOT: {
|
||||||
|
id: id
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cek == 0) {
|
if (cek == 0) {
|
||||||
const positions = await prisma.position.update({
|
const positions = await prisma.position.update({
|
||||||
where: {
|
where: {
|
||||||
@@ -113,10 +120,13 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
idGroup: data.idGroup,
|
// idGroup: data.idGroup,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mengedit jabatan", positions, }, { status: 200 });
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data jabatan', table: 'position', data: id })
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mengedit jabatan", }, { status: 200 });
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ success: false, message: "Jabatan sudah ada" },
|
{ success: false, message: "Jabatan sudah ada" },
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { revalidatePath, revalidateTag } from "next/cache";
|
import { revalidatePath, revalidateTag } from "next/cache";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
@@ -21,9 +22,9 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
if (idGroup == "null" || idGroup == undefined) {
|
if (idGroup == "null" || idGroup == undefined) {
|
||||||
grup = user.idGroup
|
grup = user.idGroup
|
||||||
} else {
|
} else {
|
||||||
grup = idGroup
|
grup = idGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
const cek = await prisma.group.count({
|
const cek = await prisma.group.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -36,10 +37,20 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const filter = await prisma.group.findUnique({
|
||||||
|
where: {
|
||||||
|
id: grup
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const positions = await prisma.position.findMany({
|
const positions = await prisma.position.findMany({
|
||||||
where: {
|
where: {
|
||||||
idGroup: grup,
|
idGroup: grup,
|
||||||
isActive: (active == "true" ? true : false),
|
isActive: active == 'false' ? false : true,
|
||||||
name: {
|
name: {
|
||||||
contains: (name == undefined || name == null) ? "" : name,
|
contains: (name == undefined || name == null) ? "" : name,
|
||||||
mode: "insensitive"
|
mode: "insensitive"
|
||||||
@@ -62,7 +73,7 @@ export async function GET(request: Request) {
|
|||||||
group: v.Group.name
|
group: v.Group.name
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan jabatan", data: allData, }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan jabatan", data: allData, filter }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||||
@@ -78,18 +89,26 @@ export async function POST(request: Request) {
|
|||||||
if (user.id == undefined) {
|
if (user.id == undefined) {
|
||||||
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 { name, idGroup } = await request.json();
|
||||||
|
|
||||||
|
let groupFix = idGroup
|
||||||
|
|
||||||
|
if (groupFix == null || groupFix == undefined || groupFix == "") {
|
||||||
|
groupFix = user.idGroup
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const cek = await prisma.position.count({
|
const cek = await prisma.position.count({
|
||||||
where: {
|
where: {
|
||||||
name: data.name,
|
name: name,
|
||||||
idGroup: data.idGroup,
|
idGroup: groupFix,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (cek == 0) {
|
if (cek == 0) {
|
||||||
const positions = await prisma.position.create({
|
const positions = await prisma.position.create({
|
||||||
data: {
|
data: {
|
||||||
name: data.name,
|
name: name,
|
||||||
idGroup: data.idGroup,
|
idGroup: groupFix,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
@@ -102,6 +121,9 @@ export async function POST(request: Request) {
|
|||||||
revalidatePath('/position?active=true', 'page')
|
revalidatePath('/position?active=true', 'page')
|
||||||
revalidateTag('position')
|
revalidateTag('position')
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'CREATE', desc: 'User membuat data jabatan baru', table: 'position', data: positions.id })
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil menambahkan jabatan", positions, }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil menambahkan jabatan", positions, }, { status: 200 });
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@@ -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 +1,4 @@
|
|||||||
export const pwd_key_config = "fchgvjknlmdfnbvghhujlaknsdvjbhknlkmsdbdyu567t8y9u30r4587638y9uipkoeghjvuyi89ipkoefmnrjbhtiu4or9ipkoemnjfbhjiuoijdklnjhbviufojkejnshbiuojijknehgruyu"
|
import { hookstate } from "@hookstate/core"
|
||||||
|
|
||||||
|
export const pwd_key_config = "fchgvjknlmdfnbvghhujlaknsdvjbhknlkmsdbdyu567t8y9u30r4587638y9uipkoeghjvuyi89ipkoefmnrjbhtiu4or9ipkoemnjfbhjiuoijdklnjhbviufojkejnshbiuojijknehgruyu"
|
||||||
|
export const globalRole = hookstate<string>('')
|
||||||
17
src/module/_global/components/wrap_layout.tsx
Normal file
17
src/module/_global/components/wrap_layout.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
'use client'
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
import { globalRole } from "../bin/val_global";
|
||||||
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
|
||||||
|
export default function WrapLayout({ children, role }: { children: React.ReactNode, role: any }) {
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
roleLogin.set(role)
|
||||||
|
}, [])
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{children}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import prisma from "./bin/prisma";
|
import prisma from "./bin/prisma";
|
||||||
import { pwd_key_config } from "./bin/val_global";
|
import { globalRole, pwd_key_config } from "./bin/val_global";
|
||||||
import SkeletonDetailDiscussionComment from "./components/skeleton_detail_discussion_comment";
|
import SkeletonDetailDiscussionComment from "./components/skeleton_detail_discussion_comment";
|
||||||
import SkeletonDetailDiscussionMember from "./components/skeleton_detail_discussion_member";
|
import SkeletonDetailDiscussionMember from "./components/skeleton_detail_discussion_member";
|
||||||
import SkeletonDetailListTugasTask from "./components/skeleton_detail_list_tugas_task";
|
import SkeletonDetailListTugasTask from "./components/skeleton_detail_list_tugas_task";
|
||||||
import SkeletonDetailProfile from "./components/skeleton_detail_profile";
|
import SkeletonDetailProfile from "./components/skeleton_detail_profile";
|
||||||
import SkeletonSingle from "./components/skeleton_single";
|
import SkeletonSingle from "./components/skeleton_single";
|
||||||
|
import WrapLayout from "./components/wrap_layout";
|
||||||
import { WARNA } from "./fun/WARNA";
|
import { WARNA } from "./fun/WARNA";
|
||||||
import LayoutDrawer from "./layout/layout_drawer";
|
import LayoutDrawer from "./layout/layout_drawer";
|
||||||
import LayoutIconBack from "./layout/layout_icon_back";
|
import LayoutIconBack from "./layout/layout_icon_back";
|
||||||
@@ -31,3 +32,5 @@ export { SkeletonDetailDiscussionMember }
|
|||||||
export { SkeletonDetailProfile }
|
export { SkeletonDetailProfile }
|
||||||
export { SkeletonDetailListTugasTask }
|
export { SkeletonDetailListTugasTask }
|
||||||
export { LayoutModalViewFile }
|
export { LayoutModalViewFile }
|
||||||
|
export { globalRole }
|
||||||
|
export { WrapLayout }
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { Box, Group, Divider, Button, Text, Skeleton, rem } from "@mantine/core";
|
import { Box, Group, Divider, Button, Text, Skeleton, rem } from "@mantine/core";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { FaCheck } from "react-icons/fa6";
|
import { FaCheck } from "react-icons/fa6";
|
||||||
import { WARNA } from "../fun/WARNA";
|
import { WARNA } from "../fun/WARNA";
|
||||||
import LayoutNavbarNew from "../layout/layout_navbar_new";
|
import LayoutNavbarNew from "../layout/layout_navbar_new";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
export default function ViewFilter({ linkFilter }: { linkFilter: string }) {
|
export default function ViewFilter({ linkFilter }: { linkFilter: string }) {
|
||||||
const [selectedFilter, setSelectedFilter] = useState<string | null>(null);
|
const [selectedFilter, setSelectedFilter] = useState<any>('');
|
||||||
const [checked, setChecked] = useState<IDataGroup[]>([]);
|
const [checked, setChecked] = useState<IDataGroup[]>([]);
|
||||||
const [searchParams, setSearchParams] = useState({ groupId: '' });
|
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const group = searchParams.get('group')
|
||||||
|
|
||||||
const handleFilterClick = (id: string) => {
|
|
||||||
setSelectedFilter(id);
|
|
||||||
};
|
|
||||||
|
|
||||||
async function getAllGroupFilter() {
|
async function getAllGroupFilter() {
|
||||||
try {
|
try {
|
||||||
@@ -37,15 +35,14 @@ export default function ViewFilter({ linkFilter }: { linkFilter: string }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useShallowEffect(() => {
|
||||||
if (selectedFilter) {
|
setSelectedFilter(group)
|
||||||
setSearchParams({ groupId: selectedFilter });
|
}, [group]);
|
||||||
}
|
|
||||||
}, [selectedFilter]);
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
getAllGroupFilter();
|
getAllGroupFilter();
|
||||||
}, [searchParams.groupId]);
|
}, []);
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -71,7 +68,7 @@ export default function ViewFilter({ linkFilter }: { linkFilter: string }) {
|
|||||||
justify="space-between"
|
justify="space-between"
|
||||||
align="center"
|
align="center"
|
||||||
mb={10}
|
mb={10}
|
||||||
onClick={() => handleFilterClick(filter.id)}
|
onClick={() => setSelectedFilter(filter.id)}
|
||||||
>
|
>
|
||||||
<Text fw={selectedFilter === filter.id ? 'bold' : 'normal'}>
|
<Text fw={selectedFilter === filter.id ? 'bold' : 'normal'}>
|
||||||
{filter.name}
|
{filter.name}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { LayoutNavbarNew, WARNA } from '@/module/_global';
|
import { globalRole, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||||
import { ActionIcon, Box, Center, SimpleGrid, Text } from '@mantine/core';
|
import { ActionIcon, Box, Center, SimpleGrid, Text } from '@mantine/core';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { HiMiniUserGroup, HiMiniPresentationChartBar, HiMegaphone, HiSquares2X2, HiChevronLeft, HiUserGroup, HiUsers } from "react-icons/hi2";
|
import { HiMiniUserGroup, HiMiniPresentationChartBar, HiMegaphone, HiSquares2X2, HiChevronLeft, HiUserGroup, HiUsers } from "react-icons/hi2";
|
||||||
import { PiUsersFourFill } from "react-icons/pi";
|
import { PiUsersFourFill } from "react-icons/pi";
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { FaUserTag, FaUserTie } from 'react-icons/fa6';
|
import { FaUserTag, FaUserTie } from 'react-icons/fa6';
|
||||||
|
import { useHookstate } from '@hookstate/core';
|
||||||
|
|
||||||
export default function ViewDetailFeature() {
|
export default function ViewDetailFeature() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LayoutNavbarNew back='/home' title='Fitur' menu={<></>} />
|
<LayoutNavbarNew back='/home' title='Fitur' menu={<></>} />
|
||||||
@@ -73,7 +75,7 @@ export default function ViewDetailFeature() {
|
|||||||
<Text fz={15} c={WARNA.biruTua}>Anggota</Text>
|
<Text fz={15} c={WARNA.biruTua}>Anggota</Text>
|
||||||
</Center>
|
</Center>
|
||||||
</Box>
|
</Box>
|
||||||
<Box onClick={() => router.push('position?active=true')}>
|
<Box onClick={() => router.push('/position')}>
|
||||||
<Center>
|
<Center>
|
||||||
<ActionIcon variant="gradient"
|
<ActionIcon variant="gradient"
|
||||||
size={68}
|
size={68}
|
||||||
@@ -87,20 +89,24 @@ export default function ViewDetailFeature() {
|
|||||||
<Text fz={15} c={WARNA.biruTua}>Jabatan</Text>
|
<Text fz={15} c={WARNA.biruTua}>Jabatan</Text>
|
||||||
</Center>
|
</Center>
|
||||||
</Box>
|
</Box>
|
||||||
<Box onClick={() => router.push('/group')}>
|
{
|
||||||
<Center>
|
roleLogin.get() == "supadmin" &&
|
||||||
<ActionIcon variant="gradient"
|
<Box onClick={() => router.push('/group')}>
|
||||||
size={68}
|
<Center>
|
||||||
aria-label="Gradient action icon"
|
<ActionIcon variant="gradient"
|
||||||
radius={100}
|
size={68}
|
||||||
gradient={{ from: '#DFDA7C', to: '#F2AF46', deg: 174 }}>
|
aria-label="Gradient action icon"
|
||||||
<FaUserTag size={35} color={WARNA.biruTua} />
|
radius={100}
|
||||||
</ActionIcon>
|
gradient={{ from: '#DFDA7C', to: '#F2AF46', deg: 174 }}>
|
||||||
</Center>
|
<FaUserTag size={35} color={WARNA.biruTua} />
|
||||||
<Center>
|
</ActionIcon>
|
||||||
<Text fz={15} c={WARNA.biruTua}>Grup</Text>
|
</Center>
|
||||||
</Center>
|
<Center>
|
||||||
</Box>
|
<Text fz={15} c={WARNA.biruTua}>Grup</Text>
|
||||||
|
</Center>
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ export default function DrawerDetailPosition({ onUpdated, id, isActive }: {
|
|||||||
</Box>
|
</Box>
|
||||||
:
|
:
|
||||||
<Box>
|
<Box>
|
||||||
<Select
|
{/* <Select
|
||||||
label="Grup"
|
label="Grup"
|
||||||
placeholder="Pilih grup"
|
placeholder="Pilih grup"
|
||||||
size="md"
|
size="md"
|
||||||
@@ -192,7 +192,7 @@ export default function DrawerDetailPosition({ onUpdated, id, isActive }: {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
||||||
/>
|
/> */}
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Jabatan"
|
label="Jabatan"
|
||||||
styles={{
|
styles={{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { WARNA, LayoutDrawer } from "@/module/_global";
|
import { WARNA, LayoutDrawer, globalRole } from "@/module/_global";
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
||||||
import { Box, Stack, SimpleGrid, Flex, TextInput, Button, Text, Select } from "@mantine/core";
|
import { Box, Stack, SimpleGrid, Flex, TextInput, Button, Text, Select } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { IoAddCircle } from "react-icons/io5";
|
import { IoAddCircle } from "react-icons/io5";
|
||||||
@@ -13,14 +13,17 @@ import { globalRefreshPosition } from "../lib/val_posisition";
|
|||||||
|
|
||||||
|
|
||||||
export default function DrawerListPosition({ onCreated }: { onCreated: (val: boolean) => void }) {
|
export default function DrawerListPosition({ onCreated }: { onCreated: (val: boolean) => void }) {
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
const [openDrawerGroup, setOpenDrawerGroup] = useState(false)
|
const [openDrawerGroup, setOpenDrawerGroup] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [listGroup, setListGorup] = useState<IDataGroup[]>([])
|
const [listGroup, setListGorup] = useState<IDataGroup[]>([])
|
||||||
const refresh = useHookstate(globalRefreshPosition)
|
const refresh = useHookstate(globalRefreshPosition)
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
const group = searchParams.get('group')
|
||||||
const [touched, setTouched] = useState({
|
const [touched, setTouched] = useState({
|
||||||
name: false,
|
name: false,
|
||||||
idGroup: false
|
idGroup: false
|
||||||
});
|
});
|
||||||
|
|
||||||
const [listData, setListData] = useState({
|
const [listData, setListData] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
@@ -60,6 +63,8 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo
|
|||||||
onCreated(true)
|
onCreated(true)
|
||||||
} else {
|
} else {
|
||||||
toast.error(res.message)
|
toast.error(res.message)
|
||||||
|
setOpenDrawerGroup(false)
|
||||||
|
onCreated(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -82,55 +87,61 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo
|
|||||||
<Text ta={'center'} c={WARNA.biruTua}>Tambah Jabatan</Text>
|
<Text ta={'center'} c={WARNA.biruTua}>Tambah Jabatan</Text>
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex justify={'center'} align={'center'} direction={'column'} onClick={() => router.push('/position?active=true&page=filter')}>
|
{
|
||||||
<Box>
|
roleLogin.get() == "supadmin" &&
|
||||||
<RiFilter2Line size={30} color={WARNA.biruTua} />
|
<Flex justify={'center'} align={'center'} direction={'column'} onClick={() => router.push('/position?page=filter&group=' + group)}>
|
||||||
</Box>
|
<Box>
|
||||||
<Box>
|
<RiFilter2Line size={30} color={WARNA.biruTua} />
|
||||||
<Text ta={'center'} c={WARNA.biruTua}>Filter</Text>
|
</Box>
|
||||||
</Box>
|
<Box>
|
||||||
</Flex>
|
<Text ta={'center'} c={WARNA.biruTua}>Filter</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
}
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
<LayoutDrawer opened={openDrawerGroup} onClose={() => setOpenDrawerGroup(false)} title={'Tambah Jabatan'} size="lg">
|
<LayoutDrawer opened={openDrawerGroup} onClose={() => setOpenDrawerGroup(false)} title={'Tambah Jabatan'} size="lg">
|
||||||
<Box pt={10} pos={"relative"} h={"70vh"}>
|
<Box pt={10} pos={"relative"} h={"70vh"}>
|
||||||
<Select
|
{
|
||||||
label="Grup"
|
roleLogin.get() == "supadmin" &&
|
||||||
placeholder="Pilih grup"
|
<Select
|
||||||
data={
|
label="Grup"
|
||||||
listGroup
|
placeholder="Pilih grup"
|
||||||
? listGroup.map((data) => ({
|
data={
|
||||||
value: data.id,
|
listGroup
|
||||||
label: data.name,
|
? listGroup.map((data) => ({
|
||||||
}))
|
value: data.id,
|
||||||
: []
|
label: data.name,
|
||||||
}
|
}))
|
||||||
size="md"
|
: []
|
||||||
radius={10}
|
}
|
||||||
mb={5}
|
size="md"
|
||||||
withAsterisk
|
radius={10}
|
||||||
onChange={(val: any) => {
|
mb={5}
|
||||||
setListData({
|
withAsterisk
|
||||||
...listData,
|
onChange={(val: any) => {
|
||||||
idGroup: val
|
setListData({
|
||||||
})
|
...listData,
|
||||||
setTouched({ ...touched, idGroup: false })
|
idGroup: val
|
||||||
}}
|
})
|
||||||
styles={{
|
setTouched({ ...touched, idGroup: false })
|
||||||
input: {
|
}}
|
||||||
color: WARNA.biruTua,
|
styles={{
|
||||||
borderRadius: WARNA.biruTua,
|
input: {
|
||||||
borderColor: WARNA.biruTua,
|
color: WARNA.biruTua,
|
||||||
},
|
borderRadius: WARNA.biruTua,
|
||||||
}}
|
borderColor: WARNA.biruTua,
|
||||||
error={
|
},
|
||||||
touched.idGroup && (
|
}}
|
||||||
listData.idGroup == "" ? "Grup Tidak Boleh Kosong" : null
|
error={
|
||||||
)
|
touched.idGroup && (
|
||||||
}
|
listData.idGroup == "" ? "Grup Tidak Boleh Kosong" : null
|
||||||
onFocus={() => setTouched({ ...touched, idGroup: true })}
|
)
|
||||||
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
}
|
||||||
/>
|
onFocus={() => setTouched({ ...touched, idGroup: true })}
|
||||||
|
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
||||||
|
/>
|
||||||
|
}
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Jabatan"
|
label="Jabatan"
|
||||||
styles={{
|
styles={{
|
||||||
@@ -153,9 +164,9 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo
|
|||||||
placeholder="Nama Jabatan"
|
placeholder="Nama Jabatan"
|
||||||
error={
|
error={
|
||||||
touched.name && (
|
touched.name && (
|
||||||
listData.name == "" ? "Nama Jabatan Tidak Boleh Kosong" : null
|
listData.name == "" ? "Nama Jabatan Tidak Boleh Kosong" : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onFocus={() => setTouched({ ...touched, name: true })}
|
onFocus={() => setTouched({ ...touched, name: true })}
|
||||||
onBlur={() => setTouched({ ...touched, name: true })}
|
onBlur={() => setTouched({ ...touched, name: true })}
|
||||||
required
|
required
|
||||||
@@ -169,7 +180,7 @@ export default function DrawerListPosition({ onCreated }: { onCreated: (val: boo
|
|||||||
fullWidth
|
fullWidth
|
||||||
onClick={onSubmit}
|
onClick={onSubmit}
|
||||||
>
|
>
|
||||||
MASUK
|
SIMPAN
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { LayoutDrawer, SkeletonSingle, WARNA } from "@/module/_global";
|
import { globalRole, LayoutDrawer, SkeletonSingle, WARNA } from "@/module/_global";
|
||||||
import { ActionIcon, Box, Group, Text, TextInput } from "@mantine/core";
|
import { ActionIcon, Box, Group, Text, TextInput } from "@mantine/core";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { FaUserTie } from "react-icons/fa6";
|
import { FaUserTie } from "react-icons/fa6";
|
||||||
import { HiMagnifyingGlass } from "react-icons/hi2";
|
import { HiMagnifyingGlass } from "react-icons/hi2";
|
||||||
import DrawerDetailPosition from "./drawer_detail_position";
|
import DrawerDetailPosition from "./drawer_detail_position";
|
||||||
@@ -12,7 +12,6 @@ import { funGetAllPosition } from "../lib/api_position";
|
|||||||
import { IDataPosition } from "../lib/type_position";
|
import { IDataPosition } from "../lib/type_position";
|
||||||
import { useHookstate } from "@hookstate/core";
|
import { useHookstate } from "@hookstate/core";
|
||||||
import { globalRefreshPosition } from "../lib/val_posisition";
|
import { globalRefreshPosition } from "../lib/val_posisition";
|
||||||
import { funGetAllGroup, IDataGroup } from "@/module/group";
|
|
||||||
|
|
||||||
|
|
||||||
export default function ListPositionActive() {
|
export default function ListPositionActive() {
|
||||||
@@ -27,14 +26,16 @@ export default function ListPositionActive() {
|
|||||||
const group = searchParams.get('group')
|
const group = searchParams.get('group')
|
||||||
const status = searchParams.get('active')
|
const status = searchParams.get('active')
|
||||||
const refresh = useHookstate(globalRefreshPosition)
|
const refresh = useHookstate(globalRefreshPosition)
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
|
const [nameGroup, setNameGroup] = useState('')
|
||||||
|
|
||||||
async function getAllPosition() {
|
async function getAllPosition() {
|
||||||
try {
|
try {
|
||||||
// setDataPosition([]);
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const res = await funGetAllPosition('?active=' + status + '&group=' + group + '&search=' + searchQuery)
|
const res = await funGetAllPosition('?active=' + status + '&group=' + group + '&search=' + searchQuery)
|
||||||
setDataPosition(res.data);
|
setDataPosition(res.data);
|
||||||
setLoading(false);
|
setNameGroup(res.filter.name)
|
||||||
|
setLoading(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error("Gagal mendapatkan position, coba lagi nanti");
|
toast.error("Gagal mendapatkan position, coba lagi nanti");
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -47,30 +48,6 @@ export default function ListPositionActive() {
|
|||||||
getAllPosition();
|
getAllPosition();
|
||||||
}, [status, group, searchQuery, refresh.get()])
|
}, [status, group, searchQuery, refresh.get()])
|
||||||
|
|
||||||
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 pt={20}>
|
<Box pt={20}>
|
||||||
@@ -94,7 +71,7 @@ export default function ListPositionActive() {
|
|||||||
</Box>
|
</Box>
|
||||||
)) :
|
)) :
|
||||||
<Box pt={20}>
|
<Box pt={20}>
|
||||||
{group && <Text>Filter by: {groupNameMap(group)}</Text>}
|
{roleLogin.get() == 'supadmin' && <Text>Filter by: {nameGroup}</Text>}
|
||||||
{isDataPosition.length == 0 ?
|
{isDataPosition.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 jabatan</Text>
|
<Text c="dimmed" ta={"center"} fs={"italic"}>Tidak ada jabatan</Text>
|
||||||
@@ -112,10 +89,12 @@ export default function ListPositionActive() {
|
|||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setData(v.name);
|
if (roleLogin.get() != 'user') {
|
||||||
setOpenDrawer(true);
|
setData(v.name);
|
||||||
setSelectId(v.id);
|
setOpenDrawer(true);
|
||||||
setActive(v.isActive);
|
setSelectId(v.id);
|
||||||
|
setActive(v.isActive);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { WARNA, LayoutDrawer, LayoutNavbarNew } from "@/module/_global";
|
import { WARNA, LayoutDrawer, LayoutNavbarNew, globalRole } from "@/module/_global";
|
||||||
import { ActionIcon, Box } from "@mantine/core";
|
import { ActionIcon, Box } from "@mantine/core";
|
||||||
import { HiMenu } from "react-icons/hi";
|
import { HiMenu } from "react-icons/hi";
|
||||||
import DrawerListPosition from "./drawer_list_position";
|
import DrawerListPosition from "./drawer_list_position";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import { useHookstate } from "@hookstate/core";
|
||||||
|
|
||||||
export default function NavbarListPosition() {
|
export default function NavbarListPosition() {
|
||||||
const [isOpen, setOpen] = useState(false)
|
const [isOpen, setOpen] = useState(false)
|
||||||
|
const roleLogin = useHookstate(globalRole)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LayoutNavbarNew back="/home" title="Jabatan"
|
<LayoutNavbarNew back="/home" title="Jabatan"
|
||||||
menu={
|
menu={(roleLogin.get() != "user") ?
|
||||||
<ActionIcon onClick={() => setOpen(true)} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
<ActionIcon onClick={() => setOpen(true)} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
<HiMenu size={20} color='white' />
|
<HiMenu size={20} color='white' />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
|
: <></>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
|
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
|
||||||
|
|||||||
@@ -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