feat : update announcement

This commit is contained in:
lukman
2024-08-07 17:31:01 +08:00
parent 0918aac887
commit ed8cd059bc
6 changed files with 97 additions and 43 deletions

View File

@@ -175,17 +175,13 @@ Content-Type: application/json
"title": "cobaannouncement1 dsdsd", "title": "cobaannouncement1 dsdsd",
"desc": "coba announcement sdsdsd", "desc": "coba announcement sdsdsd",
"idVillage": "121212", "idVillage": "desa1",
"createBy": "111", "createBy": "superAdminLukman",
"groups": [ "groups": [
{ {
"idGroup": "1", "idGroup": "group1",
"idDivision": "1" "idDivision": "1"
}, },
{
"idGroup": "1",
"idDivision": "2"
}
] ]
} }
@@ -196,7 +192,7 @@ GET http://localhost:3000/api/announcement/get?path=get-all-announcement HTTP/1.
GET http://localhost:3000/api/announcement/get?path=get-all-announcement&divisionI=1 HTTP/1.1 GET http://localhost:3000/api/announcement/get?path=get-all-announcement&divisionI=1 HTTP/1.1
### ###
GET http://localhost:3000/api/announcement/get?path=get-one-announcement&announcementId=clz6kqzvt000eb3mle1nyz6fd HTTP/1.1 GET http://localhost:3000/api/announcement/get?path=get-one-announcement&announcementId=1 HTTP/1.1
### ###
POST http://localhost:3000/api/announcement/post?path=update-announcement HTTP/1.1 POST http://localhost:3000/api/announcement/post?path=update-announcement HTTP/1.1

View File

@@ -1,4 +1,5 @@
import { prisma } from "@/module/_global"; import { prisma } from "@/module/_global";
import _ from "lodash";
import { NextRequest } from "next/server"; import { NextRequest } from "next/server";
export async function getOneAnnouncement(req: NextRequest) { export async function getOneAnnouncement(req: NextRequest) {
@@ -23,10 +24,20 @@ export async function getOneAnnouncement(req: NextRequest) {
idAnnouncement: true, idAnnouncement: true,
idGroup: true, idGroup: true,
idDivision: true, idDivision: true,
Group: {
select: {
name: true,
},
},
}, },
}); });
return Response.json({ announcement, announcementMember }); const allAnnouncementMember = announcementMember.map((v: any) => ({
..._.omit(v, ["Group"]),
group: v.Group.name,
}))
return Response.json({ announcement, allAnnouncementMember });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
return Response.json( return Response.json(

View File

@@ -1,10 +1,11 @@
'use client' 'use client'
import { WARNA } from "@/module/_global"; import { WARNA } from "@/module/_global";
import LayoutModal from "@/module/_global/layout/layout_modal"; import LayoutModal from "@/module/_global/layout/layout_modal";
import { Box, Button, Stack, Textarea, TextInput } from "@mantine/core"; import { Box, Button, Group, Stack, Text, Textarea, TextInput } from "@mantine/core";
import { useState } from "react"; import { useState } from "react";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { HiOutlineChevronRight } from "react-icons/hi2"; import { HiOutlineChevronRight } from "react-icons/hi2";
import { IoIosArrowForward } from "react-icons/io";
export default function CreateAnnouncement() { export default function CreateAnnouncement() {
const [isOpen, setOpen] = useState(false) const [isOpen, setOpen] = useState(false)
@@ -19,14 +20,10 @@ export default function CreateAnnouncement() {
return ( return (
<Box> <Box>
<Stack <Stack
align="center" p={20}
justify="center"
gap="xs"
pt={30}
px={20}
> >
<TextInput <TextInput
size="md" type="text" radius={30} placeholder="Judul Pengumuman" withAsterisk label="Judul" w={"100%"} size="md" type="text" radius={10} placeholder="Judul Pengumuman" withAsterisk label="Judul" w={"100%"}
styles={{ styles={{
input: { input: {
color: WARNA.biruTua, color: WARNA.biruTua,
@@ -37,7 +34,7 @@ export default function CreateAnnouncement() {
/> />
<Textarea <Textarea
size="md" size="md"
radius={20} radius={10}
w={"100%"} w={"100%"}
label="Pengumuman" label="Pengumuman"
withAsterisk withAsterisk
@@ -50,10 +47,18 @@ export default function CreateAnnouncement() {
}, },
}} }}
/> />
<Box pt={10}>
<Button rightSection={<HiOutlineChevronRight size={14} />} variant="default" fullWidth radius={30} size="md" mt={10}> <Group justify="space-between" style={{
Pilih Anggota border: `1px solid ${WARNA.biruTua}`,
</Button> padding: 10,
borderRadius: 10
}}>
<Text size="sm">
Tambah Anggota
</Text>
<IoIosArrowForward />
</Group>
</Box>
</Stack> </Stack>
<Box mt={30} mx={20}> <Box mt={30} mx={20}>
<Button <Button

View File

@@ -1,37 +1,80 @@
import { Box, Group, Stack, Text } from "@mantine/core"; "use client"
import { API_ADDRESS } from "@/module/_global";
import { Box, Flex, Grid, Group, Spoiler, Stack, Text } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useState } from "react";
import { BsCardText } from "react-icons/bs"; import { BsCardText } from "react-icons/bs";
import { TfiAnnouncement } from "react-icons/tfi"; import { TfiAnnouncement } from "react-icons/tfi";
export default function DetailAnnouncement() { export interface RootAll {
announcement: Announcement
allAnnouncementMember: AllAnnouncementMember[]
}
export interface Announcement {
id: string
title: string
desc: string
}
export interface AllAnnouncementMember {
idAnnouncement: string
idGroup: string
idDivision: string
group: string
}
export default function DetailAnnouncement({ id }: { id: string }) {
const [isData, setIsData] = useState<RootAll>()
async function fetchOneAnnouncement() {
try {
const res = await fetch(`${API_ADDRESS.apiGetOneAnnouncement}&announcementId=${id}`)
const data = await res.json()
setIsData(data)
} catch (error) {
console.error(error)
throw new Error("Error")
}
}
useShallowEffect(() => {
fetchOneAnnouncement()
}, [])
return ( return (
<Box py={30} px={20}> <Box py={30} px={20}>
<Box p={20} style={{ borderRadius: 10, border: '1px solid #E5E5E5' }} bg={'white'} > <Box p={20} style={{ borderRadius: 10, border: '1px solid #E5E5E5' }} bg={'white'} >
<Stack> <Stack>
<Group> <Group>
<TfiAnnouncement size={25} /> <TfiAnnouncement size={25} />
<Text fw={'bold'}>Pengumuman Dinas</Text> <Text fw={'bold'}>{isData?.announcement.title}</Text>
</Group>
<Group>
<BsCardText size={25} />
<Text>Pengumuman agar menggunakan</Text>
</Group> </Group>
<Grid gutter={'md'}>
<Grid.Col span={1}>
<BsCardText size={25} />
</Grid.Col>
<Grid.Col span={11}>
<Spoiler maxHeight={100} showLabel="Lebih banyak" hideLabel="Lebih sedikit">
<Text>{isData?.announcement.desc}</Text>
</Spoiler>
</Grid.Col>
</Grid>
</Stack> </Stack>
</Box> </Box>
<Box my={15} p={20} style={{ borderRadius: 10, border: '1px solid #E5E5E5' }} bg={'white'} > <Box my={15} p={20} style={{ borderRadius: 10, border: '1px solid #E5E5E5' }} bg={'white'} >
<Stack> {isData?.allAnnouncementMember.map((v, i) => {
<Text fw={'bold'}>Anggota</Text> return (
<Group> <Stack key={i}>
<Text>LPD</Text> <Text fw={'bold'}>Anggota</Text>
</Group> <Flex direction={"column"} gap={10}>
<Group> <Text>{v.group}</Text>
<Text>PKK</Text> </Flex>
</Group> </Stack>
<Group> )
<Text>Karang Taruna</Text> })}
</Group>
</Stack>
</Box> </Box>
</Box> </Box>
) )
} }

View File

@@ -6,7 +6,7 @@ export default function ViewDetailAnnouncement({ data }: { data: string }) {
return ( return (
<Box> <Box>
<NavbarDetailAnnouncement /> <NavbarDetailAnnouncement />
<DetailAnnouncement /> <DetailAnnouncement id={data} />
</Box> </Box>
) )
} }

View File

@@ -12,7 +12,6 @@ export async function getAllPosition(req: NextRequest) {
const active = searchParams.get('active'); const active = searchParams.get('active');
const name = searchParams.get('name') const name = searchParams.get('name')
const user = await funGetUserByCookies() const user = await funGetUserByCookies()
console.log(groupID)
if (groupID == "null") { if (groupID == "null") {
grupFix = user.idGroup grupFix = user.idGroup