From fb5b23a30d5492c7b5a16e6bd19588a84e5160d4 Mon Sep 17 00:00:00 2001 From: amel Date: Thu, 29 Aug 2024 17:22:29 +0800 Subject: [PATCH 1/2] upd: search deskripsi: - cek search - img profile - link sesuai fitur - pembatasan sesuai role No Issues --- src/app/api/home/search/route.ts | 52 +++++++-- src/module/home/lib/type_search.ts | 17 ++- src/module/home/ui/view_detail_feature.tsx | 2 +- src/module/home/ui/view_search.tsx | 123 ++++++++++++--------- 4 files changed, 126 insertions(+), 68 deletions(-) diff --git a/src/app/api/home/search/route.ts b/src/app/api/home/search/route.ts index fd9c017..103220d 100644 --- a/src/app/api/home/search/route.ts +++ b/src/app/api/home/search/route.ts @@ -4,12 +4,13 @@ import { prisma } from "@/module/_global"; import { funGetUserByCookies } from "@/module/auth"; +import _ from "lodash"; import { NextResponse } from "next/server"; export async function GET(request: Request) { try { - const { searchParams } = new URL(request.url); - const search = searchParams.get("search"); + const { searchParams } = new URL(request.url) + const search = searchParams.get("search") const userId = await funGetUserByCookies() if (userId.id == undefined) { return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); @@ -69,31 +70,68 @@ export async function GET(request: Request) { select: { id: true, name: true, - email: true + email: true, + img: true, + Position: { + select: { + name: true + } + }, + Group: { + select: { + name: true + } + } } }) + const userOmit = user.map((v: any) => ({ + ..._.omit(v, ["Position", "Group"]), + position: v.Position.name, + group: v.Group.name + })) + const divisions = await prisma.division.findMany({ where: kondisi, select: { id: true, name: true, - desc: true + desc: true, + Group: { + select: { + name: true + } + } } }) + const divisionOmit = divisions.map((v: any) => ({ + ..._.omit(v, ["Group"]), + group: v.Group.name + })) + const projects = await prisma.project.findMany({ where: kondisiProject, select: { id: true, title: true, + Group: { + select: { + name: true + } + } } }) + const projectOmit = projects.map((v: any) => ({ + ..._.omit(v, ["Group"]), + group: v.Group.name + })) + const allDataSearch = { - user: user, - division: divisions, - project: projects + user: userOmit, + division: divisionOmit, + project: projectOmit } return NextResponse.json({ success: true, data: allDataSearch }, { status: 200 }); diff --git a/src/module/home/lib/type_search.ts b/src/module/home/lib/type_search.ts index d2100d7..22bbc1a 100644 --- a/src/module/home/lib/type_search.ts +++ b/src/module/home/lib/type_search.ts @@ -2,15 +2,20 @@ export interface IDataUserSearch { id: string name: string email: string + position: string + group: string + img: string +} + +export interface IDataProjectSearch { + id: string + title: string + group: string } export interface IDataDivisionSearch { - id: string - title: string -} - -export interface IDataProjectSearch { id: string name: string desc: string - } + group: string +} diff --git a/src/module/home/ui/view_detail_feature.tsx b/src/module/home/ui/view_detail_feature.tsx index 3e88820..6c46c01 100644 --- a/src/module/home/ui/view_detail_feature.tsx +++ b/src/module/home/ui/view_detail_feature.tsx @@ -98,7 +98,7 @@ export default function ViewDetailFeature() {
- Group + Grup
diff --git a/src/module/home/ui/view_search.tsx b/src/module/home/ui/view_search.tsx index 93a6fd2..5d40560 100644 --- a/src/module/home/ui/view_search.tsx +++ b/src/module/home/ui/view_search.tsx @@ -1,17 +1,19 @@ "use client" import { LayoutNavbarNew, WARNA } from '@/module/_global'; -import { ActionIcon, Box, Divider, Grid, Group, Text, TextInput } from '@mantine/core'; +import { ActionIcon, Avatar, Box, Divider, Grid, Group, Text, TextInput } from '@mantine/core'; import React, { useState } from 'react'; -import { HiMagnifyingGlass, HiMiniUser } from 'react-icons/hi2'; +import { HiMagnifyingGlass, HiMiniPresentationChartBar, HiMiniUserGroup } from 'react-icons/hi2'; import { funGetSearchAll } from '../lib/api_search'; import { useShallowEffect } from '@mantine/hooks'; import { IDataDivisionSearch, IDataProjectSearch, IDataUserSearch } from '../lib/type_search'; +import { useRouter } from 'next/navigation'; export default function ViewSearch() { const [search, setSearch] = useState(''); const [dataUser, setDataUser] = useState([]); - const [dataProject, setDataProject] = useState([]); - const [dataDivision, setDataDivision] = useState([]); + const [dataProject, setDataProject] = useState([]); + const [dataDivision, setDataDivision] = useState([]); + const router = useRouter() async function featchSearch() { try { @@ -26,8 +28,12 @@ export default function ViewSearch() { } useShallowEffect(() => { - if (search !== '') { + if (search != '') { featchSearch() + } else { + setDataUser([]); + setDataProject([]); + setDataDivision([]); } }, [search]) @@ -58,32 +64,39 @@ export default function ViewSearch() { borderRadius: 10, }}> ANGGOTA - {dataUser.length > 0 ? ( - - {dataUser.map((v, i) => { - return ( - - - - - - - - - {v.name} - {v.email} - - - - - ) - })} - - ) : - Tidak Ada Anggota - } + + {dataUser.length > 0 ? ( + + {dataUser.map((v, i) => { + return ( + router.push(`/member/${v.id}`)}> + + + + {v.name} + {v.group + ' - ' + v.position} + + + + + ) + })} + + ) : + Tidak Ada Anggota + } + + DIVISI {dataDivision.map((v, i) => { return ( - + router.push(`/division/${v.id}`)}> - + {v.name.toUpperCase()} + {v.group} {v.desc} @@ -131,28 +145,29 @@ export default function ViewSearch() { borderRadius: 5 }}> {dataProject.length > 0 ? ( - - {dataProject.map((v, i) => { - return ( - - - - - - - - - {v.title.toUpperCase()} - - - - - ) - })} - + + {dataProject.map((v, i) => { + return ( + router.push(`/project/${v.id}`)}> + + + + + + + + {v.title.toUpperCase()} + {v.group} + + + + + ) + })} + ) - : Tidak Ada Kegiatan - } + : Tidak Ada Kegiatan + } From 9f4ad942caf41290c021aba60c5b72fd07fdc72b Mon Sep 17 00:00:00 2001 From: amel Date: Thu, 29 Aug 2024 17:33:27 +0800 Subject: [PATCH 2/2] upd: profile Deskripsi : - view profile - clear No Issues --- src/module/user/index.ts | 2 - .../component/ui/header_edit_profile.tsx | 11 --- .../user/profile/component/ui/ui_profile.tsx | 14 --- src/module/user/profile/ui/profile.tsx | 6 +- src/module/user/profile/view/view_profile.tsx | 93 ------------------- 5 files changed, 3 insertions(+), 123 deletions(-) delete mode 100644 src/module/user/profile/component/ui/header_edit_profile.tsx delete mode 100644 src/module/user/profile/component/ui/ui_profile.tsx delete mode 100644 src/module/user/profile/view/view_profile.tsx diff --git a/src/module/user/index.ts b/src/module/user/index.ts index e898624..ee5ef0f 100644 --- a/src/module/user/index.ts +++ b/src/module/user/index.ts @@ -1,11 +1,9 @@ import { TypeUser } from './lib/type_user'; import createLogUser from "./log/fun/createLogUser"; -import ViewProfile from "./profile/view/view_profile"; import { funGetAllmember } from './member/lib/api_member'; import Profile from './profile/ui/profile'; import EditProfile from './profile/ui/edit_profile'; -export { ViewProfile }; export { createLogUser }; export type { TypeUser } export { funGetAllmember } diff --git a/src/module/user/profile/component/ui/header_edit_profile.tsx b/src/module/user/profile/component/ui/header_edit_profile.tsx deleted file mode 100644 index c41217b..0000000 --- a/src/module/user/profile/component/ui/header_edit_profile.tsx +++ /dev/null @@ -1,11 +0,0 @@ -'use client' -import { LayoutIconBack, LayoutNavbarHome, LayoutNavbarNew } from '@/module/_global'; -import { Box, Grid, Text } from '@mantine/core'; -import React from 'react'; - -export default function HeaderEditProfile() { - return ( - - ); -} - diff --git a/src/module/user/profile/component/ui/ui_profile.tsx b/src/module/user/profile/component/ui/ui_profile.tsx deleted file mode 100644 index a1f4397..0000000 --- a/src/module/user/profile/component/ui/ui_profile.tsx +++ /dev/null @@ -1,14 +0,0 @@ -'use client' -import { Group, Text } from "@mantine/core"; -import { useRouter } from "next/navigation"; - - -export function InfoTitleProfile() { - const router = useRouter() - return ( - - Informasi - router.push('/profile/edit')}>Edit - - ) -} \ No newline at end of file diff --git a/src/module/user/profile/ui/profile.tsx b/src/module/user/profile/ui/profile.tsx index 8154c70..2b07fe5 100644 --- a/src/module/user/profile/ui/profile.tsx +++ b/src/module/user/profile/ui/profile.tsx @@ -107,7 +107,7 @@ export default function Profile() { No Telepon - {isData?.phone} + +62{isData?.phone} @@ -119,7 +119,7 @@ export default function Profile() { - Gender + Jenis Kelamin {isData?.gender === 'M' ? 'Laki-laki' : isData?.gender === 'F' ? 'Perempuan' : ''} @@ -130,7 +130,7 @@ export default function Profile() { } setOpenModal(false)} - description="Apakah Anda yakin ingin Keluar?" + description="Apakah Anda yakin ingin keluar?" onYes={(val) => onLogout(val)} /> ) diff --git a/src/module/user/profile/view/view_profile.tsx b/src/module/user/profile/view/view_profile.tsx deleted file mode 100644 index 5b8e22b..0000000 --- a/src/module/user/profile/view/view_profile.tsx +++ /dev/null @@ -1,93 +0,0 @@ -"use client" -import { LayoutIconBack, LayoutNavbarHome, WARNA } from "@/module/_global"; -import { ActionIcon, Anchor, Box, Button, Flex, Group, Stack, Text } from "@mantine/core"; -import { BsInfo } from "react-icons/bs"; -import { HiUser } from "react-icons/hi2"; -import { RiIdCardFill } from "react-icons/ri"; -import { FaSquarePhone } from "react-icons/fa6"; -import { MdEmail } from "react-icons/md"; -import { InfoTitleProfile } from "../component/ui/ui_profile"; -import { IoMaleFemale } from "react-icons/io5"; -import toast from "react-hot-toast"; -import { LuLogOut } from "react-icons/lu"; -import LayoutModal from "@/module/_global/layout/layout_modal"; -import { useState } from "react"; - -export default function ViewProfile() { - const [openModal, setOpenModal] = useState(false); - - async function onLogout(val: boolean) { - try { - if (val) { - await fetch('/api/auth/logout', { - method: 'DELETE', - }); - toast.success('Logout Success') - window.location.href = '/'; - } - - setOpenModal(false) - - } catch (error) { - console.error(error); - } - } - return ( - <> - - - - - { setOpenModal(true) }} variant="light" bg={WARNA.bgIcon} size="lg" radius="lg" aria-label="Info"> - - - - - - Fibra Marcell - Kepala Urusan Pengembangan - - - - - - - - NIK - - 513177782899 - - - - - NoTelepon - - +62038939293 - - - - - Email - - marcel@gmail.com - - - - - Gender - - Laki-laki - - - - - setOpenModal(false)} - description="Apakah Anda yakin ingin Keluar?" - onYes={(val) => onLogout(val)} /> - - ) -} \ No newline at end of file