upd: apaa aja aku lupa
This commit is contained in:
@@ -33,7 +33,8 @@ export const API_ADDRESS = {
|
||||
"apiCreatePosition": "/api/position/post?path=create-position",
|
||||
"apiUpdatePosition": "/api/position/post?path=update-position",
|
||||
"apiDeletePosition": "/api/position/post?path=delete-position",
|
||||
|
||||
|
||||
|
||||
// Division
|
||||
"apiGetAllDivision": "/api/division/get?path=get-all-division",
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { WARNA } from '../fun/WARNA';
|
||||
import LayoutIconBack from './layout_icon_back';
|
||||
import _ from 'lodash';
|
||||
|
||||
export const LayoutNavbarNew = ({ back, title, menu }: { back: string, title: string, menu: React.ReactNode }) => {
|
||||
export const LayoutNavbarNew = ({ back, title, menu }: { back?: string, title: string, menu: React.ReactNode }) => {
|
||||
return (
|
||||
<Box pt={25} pl={20} pr={20} m={0} pos={'sticky'} top={0} pb={25} bg={WARNA.biruTua}
|
||||
style={{
|
||||
@@ -17,7 +17,9 @@ export const LayoutNavbarNew = ({ back, title, menu }: { back: string, title: st
|
||||
>
|
||||
<Grid justify='center' align='center'>
|
||||
<Grid.Col span="auto">
|
||||
<LayoutIconBack back={back} />
|
||||
{
|
||||
back!=undefined && (<LayoutIconBack back={back} />)
|
||||
}
|
||||
</Grid.Col>
|
||||
<Grid.Col span={8}>
|
||||
<Title c={WARNA.bgWhite} ta={'center'} order={5}>{_.startCase(title)}</Title>
|
||||
|
||||
@@ -16,5 +16,5 @@ export default async function funGetUserByCookies() {
|
||||
},
|
||||
});
|
||||
|
||||
return { id: user?.id, name: user?.name, idVillage: user?.idVillage };
|
||||
return { id: user?.id, idUserRole: user?.idUserRole, name: user?.name, idVillage: user?.idVillage, idGroup: user?.idGroup, idPosition: user?.idPosition };
|
||||
}
|
||||
@@ -1,17 +1,27 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export default async function getAllDivision(req: NextRequest) {
|
||||
try {
|
||||
let grup
|
||||
const user = await funGetUserByCookies()
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const groupID = searchParams.get('groupID');
|
||||
let groupID = searchParams.get('groupID');
|
||||
if (groupID == null || groupID == undefined) {
|
||||
grup = user.idGroup
|
||||
} else {
|
||||
grup = groupID
|
||||
}
|
||||
|
||||
const division = await prisma.division.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idGroup: String(groupID)
|
||||
idGroup: grup
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return Response.json(division);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import NavbarAdminDivision from './ui/navbar_admin_division';
|
||||
|
||||
export default function CreateAdminDivision() {
|
||||
export default function CreateAdminDivision({ data }: { data: any }) {
|
||||
return (
|
||||
<NavbarAdminDivision />
|
||||
);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use client";
|
||||
import { LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import { API_ADDRESS, LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import { TypeGroup } from "@/module/group";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import {
|
||||
Avatar,
|
||||
Box,
|
||||
@@ -12,65 +14,108 @@ import {
|
||||
Textarea,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { IoIosArrowDropright } from "react-icons/io";
|
||||
const dataUser = [
|
||||
{
|
||||
id: 1,
|
||||
img: "https://i.pravatar.cc/1000?img=3",
|
||||
name: "Doni Setiawan",
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
img: "https://i.pravatar.cc/1000?img=10",
|
||||
name: "Ilham Udin",
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
img: "https://i.pravatar.cc/1000?img=11",
|
||||
name: "Didin Anang",
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
img: "https://i.pravatar.cc/1000?img=21",
|
||||
name: "Angga Saputra",
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
img: "https://i.pravatar.cc/1000?img=32",
|
||||
name: "Marcel Widianto",
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
img: "https://i.pravatar.cc/1000?img=37",
|
||||
name: "Bagas Nusantara",
|
||||
},
|
||||
];
|
||||
import { globalMemberDivision } from "../lib/val_division";
|
||||
import toast from "react-hot-toast";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import CreateAdminDivision from "./create_admin_division";
|
||||
import CreateUsers from "./create_users";
|
||||
import NavbarCreateUsers from "./ui/navbar_create_users";
|
||||
|
||||
|
||||
export default function CreateDivision() {
|
||||
const router = useRouter();
|
||||
const [dataGroup, setDataGroup] = useState<TypeGroup>();
|
||||
const [roleUser, setRoleUser] = useState<any>("")
|
||||
const [isChooseAnggota, setChooseAnggota] = useState(false)
|
||||
const [isChooseAdmin, setChooseAdmin] = useState(false)
|
||||
const member = useHookstate(globalMemberDivision)
|
||||
const [body, setBody] = useState<any>({
|
||||
idGroup: "",
|
||||
name: "",
|
||||
desc: "",
|
||||
});
|
||||
|
||||
async function loadData() {
|
||||
const loadGroup = await fetch(API_ADDRESS.apiGetAllGroup + '&active=true');
|
||||
const dataGroup = await loadGroup.json();
|
||||
setDataGroup(dataGroup);
|
||||
|
||||
const loadUser = await funGetUserByCookies();
|
||||
setRoleUser(loadUser.idUserRole)
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
if (roleUser == "supadmin" && (body.idGroup == "" || body.idGroup == null)) {
|
||||
return toast.error("Error! grup harus diisi")
|
||||
}
|
||||
|
||||
if (body.name == "") {
|
||||
return toast.error("Error! nama divisi harus diisi")
|
||||
}
|
||||
|
||||
if (member.length == 0) {
|
||||
return toast.error("Error! belum ada anggota yang terdaftar")
|
||||
}
|
||||
|
||||
|
||||
|
||||
setChooseAdmin(true)
|
||||
|
||||
}
|
||||
|
||||
function onToChooseAnggota() {
|
||||
if (roleUser == "supadmin" && body.idGroup == "")
|
||||
return toast.error("Error! grup harus diisi")
|
||||
setChooseAnggota(true)
|
||||
}
|
||||
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
loadData();
|
||||
}, []);
|
||||
|
||||
if (isChooseAdmin) return <CreateAdminDivision data={body} />
|
||||
|
||||
if (isChooseAnggota) return <NavbarCreateUsers grup={body.idGroup} />
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back="/division" title="Tambah Divisi" menu />
|
||||
<Box p={20}>
|
||||
<Stack>
|
||||
<Select
|
||||
placeholder="Grup"
|
||||
label="Grup"
|
||||
size="md"
|
||||
required
|
||||
radius={40}
|
||||
/>
|
||||
{
|
||||
(roleUser == "supadmin") && (
|
||||
<Select
|
||||
placeholder="Grup"
|
||||
label="Grup"
|
||||
size="md"
|
||||
required
|
||||
radius={40}
|
||||
data={dataGroup?.map((pro: any) => ({
|
||||
value: String(pro.id),
|
||||
label: pro.name
|
||||
}))}
|
||||
onChange={(val) => {
|
||||
setBody({ ...body, idGroup: val })
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
<TextInput
|
||||
placeholder="Judul"
|
||||
label="Judul"
|
||||
placeholder="Nama Divisi"
|
||||
label="Nama Divisi"
|
||||
size="md"
|
||||
required
|
||||
radius={40}
|
||||
onChange={(val) => { setBody({ ...body, name: val.target.value }) }}
|
||||
/>
|
||||
<Textarea placeholder="Deskripsi" label="Deskripsi" radius={10} />
|
||||
<Box onClick={() => router.push("/division/create?page=anggota")}>
|
||||
<Textarea size="md" placeholder="Deskripsi" label="Deskripsi" radius={10} onChange={(val) => { setBody({ ...body, desc: val }) }} />
|
||||
<Box onClick={() => { onToChooseAnggota() }}>
|
||||
<Group
|
||||
justify="space-between"
|
||||
p={10}
|
||||
@@ -86,7 +131,7 @@ export default function CreateDivision() {
|
||||
<Box pt={20}>
|
||||
<Group justify="space-between">
|
||||
<Text c={WARNA.biruTua}>Anggota Terpilih</Text>
|
||||
<Text c={WARNA.biruTua}>Total 10 Anggota</Text>
|
||||
<Text c={WARNA.biruTua}>Total {member.length} Anggota</Text>
|
||||
</Group>
|
||||
<Box pt={10}>
|
||||
<Box mb={20}>
|
||||
@@ -98,7 +143,9 @@ export default function CreateDivision() {
|
||||
px={20}
|
||||
py={10}
|
||||
>
|
||||
{dataUser.map((v, i) => {
|
||||
{(member.length === 0) ? (
|
||||
<Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada anggota</Text>
|
||||
) : member.get().map((v: any, i: any) => {
|
||||
return (
|
||||
<Flex
|
||||
justify={"space-between"}
|
||||
@@ -131,7 +178,10 @@ export default function CreateDivision() {
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => router.push("/division/create?page=pilih-admin")}
|
||||
onClick={() => {
|
||||
onSubmit()
|
||||
// router.push("/division/create?page=pilih-admin")
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
import NavbarCreateUsers from './ui/navbar_create_users';
|
||||
|
||||
export default function CreateUsers() {
|
||||
export default function CreateUsers({ grup }: { grup: string }) {
|
||||
return (
|
||||
<NavbarCreateUsers/>
|
||||
<NavbarCreateUsers grup={grup} />
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"use client"
|
||||
import { LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||
import { API_ADDRESS, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { Avatar, Box, Button, Center, Input, SimpleGrid, Stack, Text, TextInput } from '@mantine/core';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
import { BsFiletypeCsv } from 'react-icons/bs';
|
||||
import { HiMagnifyingGlass } from 'react-icons/hi2';
|
||||
import { globalMemberDivision } from '../../lib/val_division';
|
||||
|
||||
const dataUser = [
|
||||
{
|
||||
@@ -40,9 +42,10 @@ const dataUser = [
|
||||
];
|
||||
|
||||
|
||||
export default function NavbarCreateUsers() {
|
||||
export default function NavbarCreateUsers({ grup }: { grup?: string }) {
|
||||
const router = useRouter()
|
||||
const [selectedFiles, setSelectedFiles] = useState<Record<number, boolean>>({});
|
||||
const member = useHookstate(globalMemberDivision)
|
||||
|
||||
const handleFileClick = (index: number) => {
|
||||
setSelectedFiles((prevSelectedFiles) => ({
|
||||
@@ -51,9 +54,17 @@ export default function NavbarCreateUsers() {
|
||||
}));
|
||||
};
|
||||
|
||||
async function loadData() {
|
||||
const loadMember = await fetch(API_ADDRESS.apiGetAllUser + '&active=true&idGroup=' + grup);
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back="/division/create" title="Pilih Anggota" menu />
|
||||
<LayoutNavbarNew title="Pilih Anggota" menu />
|
||||
<Box p={20}>
|
||||
<Stack>
|
||||
<TextInput
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
'use client'
|
||||
import { LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||
import { API_ADDRESS, LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global';
|
||||
import { ActionIcon, Avatar, Box, Card, Center, Divider, Flex, Grid, Group, Text, TextInput, Title } from '@mantine/core';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React, { useState } from 'react';
|
||||
@@ -7,49 +7,39 @@ import { HiMenu } from 'react-icons/hi';
|
||||
import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiMiniUserGroup, HiOutlineListBullet, HiSquares2X2 } from 'react-icons/hi2';
|
||||
import { MdAccountCircle } from 'react-icons/md';
|
||||
import DrawerDivision from './drawer_division';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
|
||||
const dataDivisi = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'DIVISI 1',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'DIVISI 2',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'DIVISI 3',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: 'DIVISI 4',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: 'DIVISI5',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
title: 'DIVISI 6',
|
||||
description: 'Tempat berkumpul semua anggota / staff perbekal darmasaba',
|
||||
},
|
||||
]
|
||||
type TypeDivision = {
|
||||
id: string
|
||||
name: string
|
||||
idGroup: string
|
||||
idVillage: string
|
||||
desc: string
|
||||
isActive: boolean
|
||||
}[]
|
||||
|
||||
export default function NavbarDivision() {
|
||||
const [isList, setIsList] = useState(false)
|
||||
const router = useRouter()
|
||||
const [openDrawer, setOpenDrawer] = useState(false)
|
||||
const [data, setData] = useState<TypeDivision>()
|
||||
const [jumlah, setJumlah] = useState(0)
|
||||
|
||||
const handleList = () => {
|
||||
setIsList(!isList)
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
const response = await fetch(API_ADDRESS.apiGetAllDivision)
|
||||
const data = await response.json()
|
||||
setData(data)
|
||||
setJumlah(data.length)
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
loadData()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<LayoutNavbarNew back='/home' title='Divisi'
|
||||
@@ -87,13 +77,13 @@ export default function NavbarDivision() {
|
||||
<Box bg={WARNA.biruTua} p={10} style={{ borderRadius: 10 }}>
|
||||
<Text fw={'bold'} c={'white'}>Total Divisi</Text>
|
||||
<Flex justify={'center'} align={'center'} h={'100%'}>
|
||||
<Text fz={40} fw={'bold'} c={'white'}>35</Text>
|
||||
<Text fz={40} fw={'bold'} c={'white'}>{jumlah}</Text>
|
||||
</Flex>
|
||||
</Box>
|
||||
</Box>
|
||||
{isList ? (
|
||||
<Box pt={20}>
|
||||
{dataDivisi.map((v, i) => {
|
||||
{data?.map((v: any, i: any) => {
|
||||
return (
|
||||
<Box key={i}>
|
||||
<Group justify="space-between" mb={10} onClick={() => router.push(`/division/${v.id}`)}>
|
||||
@@ -113,7 +103,7 @@ export default function NavbarDivision() {
|
||||
<HiMiniUserGroup size={25} color={WARNA.biruTua} />
|
||||
</ActionIcon>
|
||||
</Center>
|
||||
<Text>{v.title}</Text>
|
||||
<Text>{v.name}</Text>
|
||||
</Group>
|
||||
</Group>
|
||||
<Divider my="sm" />
|
||||
@@ -123,19 +113,19 @@ export default function NavbarDivision() {
|
||||
</Box>
|
||||
) : (
|
||||
<Box pt={20}>
|
||||
{dataDivisi.map((v, i) => {
|
||||
{data?.map((v: any, i: any) => {
|
||||
return (
|
||||
<Box key={i} mb={20}>
|
||||
<Card shadow="sm" padding="md" component="a" radius={10} onClick={() => router.push(`/division/${v.id}`)}>
|
||||
<Card.Section>
|
||||
<Box h={120} bg={WARNA.biruTua}>
|
||||
<Flex justify={'center'} align={'center'} h={"100%"}>
|
||||
<Title order={3} c={"white"}>{v.title}</Title>
|
||||
<Title order={3} c={"white"}>{v.name}</Title>
|
||||
</Flex>
|
||||
</Box>
|
||||
</Card.Section>
|
||||
<Box pt={10}>
|
||||
<Text>{v.description}</Text>
|
||||
<Text>{v.desc}</Text>
|
||||
<Group align='center' pt={10} justify='flex-end'>
|
||||
<Avatar.Group>
|
||||
<Avatar>
|
||||
@@ -153,7 +143,7 @@ export default function NavbarDivision() {
|
||||
)}
|
||||
</Box>
|
||||
<LayoutDrawer opened={openDrawer} title={'Menu'} onClose={() => setOpenDrawer(false)}>
|
||||
<DrawerDivision/>
|
||||
<DrawerDivision />
|
||||
</LayoutDrawer>
|
||||
</Box>
|
||||
);
|
||||
|
||||
4
src/module/division_new/lib/val_division.ts
Normal file
4
src/module/division_new/lib/val_division.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { TypeUser } from "@/module/user";
|
||||
import { hookstate } from "@hookstate/core";
|
||||
|
||||
export const globalMemberDivision = hookstate<TypeUser>([]);
|
||||
@@ -1,11 +1,12 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export async function listGroups(req: NextRequest): Promise<Response> {
|
||||
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
const searchParams = req.nextUrl.searchParams
|
||||
const villaId = "121212"
|
||||
const villaId = user.idVillage
|
||||
const active = searchParams.get('active');
|
||||
const groups = await prisma.group.findMany({
|
||||
where: {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { TypeGroup } from './lib/type_group';
|
||||
import { apiGroup } from "./api/api_group";
|
||||
import ViewGroup from "./view/view_group";
|
||||
|
||||
export { ViewGroup };
|
||||
export { apiGroup };
|
||||
export type { TypeGroup }
|
||||
|
||||
5
src/module/group/lib/type_group.ts
Normal file
5
src/module/group/lib/type_group.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export type TypeGroup = {
|
||||
id: string
|
||||
name: string
|
||||
isActive: boolean
|
||||
}[]
|
||||
@@ -4,7 +4,7 @@ import { NextRequest } from "next/server";
|
||||
export async function getAllUser(req: NextRequest) {
|
||||
try {
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const idGroup = "2";
|
||||
const idGroup = searchParams.get("idGroup");;
|
||||
const idVillage = "121212";
|
||||
const active = searchParams.get("active");
|
||||
const idPosition = searchParams.get("idPosition");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { TypeUser } from './lib/type_user';
|
||||
import { apiUser } from "./api/api_user";
|
||||
import createLogUser from "./log/fun/createLogUser";
|
||||
import ViewEditProfile from "./profile/view/view_edit_profile";
|
||||
@@ -7,3 +8,4 @@ export { ViewProfile };
|
||||
export { ViewEditProfile };
|
||||
export { apiUser };
|
||||
export { createLogUser };
|
||||
export type { TypeUser }
|
||||
|
||||
11
src/module/user/lib/type_user.ts
Normal file
11
src/module/user/lib/type_user.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export type TypeUser = {
|
||||
id: string
|
||||
name: string
|
||||
nik: string
|
||||
phone: string
|
||||
email: string
|
||||
gender: string
|
||||
isActive: boolean,
|
||||
group: string,
|
||||
position: string
|
||||
}[]
|
||||
Reference in New Issue
Block a user