upd: announcement
Deskripsi: - tambah - edit - detail No Issues
This commit is contained in:
@@ -1,40 +1,25 @@
|
||||
'use client'
|
||||
import { LayoutNavbarNew, WARNA } from "@/module/_global";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { globalMemberDivision } from "@/module/division_new/lib/val_division";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { Avatar, Box, Button, Flex, Group, Stack, Text, Textarea, TextInput } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { HiOutlineChevronRight } from "react-icons/hi2";
|
||||
import { IoIosArrowForward } from "react-icons/io";
|
||||
import CreateUsersAnnouncement from "./create_users_announcement";
|
||||
import { globalMemberAnnouncement } from "../lib/val_announcement";
|
||||
import { funCreateAnnouncement } from "../lib/api_announcement";
|
||||
import { group } from "console";
|
||||
import { GroupData, ICreateData, IGroupData } from "../lib/type_announcement";
|
||||
|
||||
export type DataMember = DataGroup[]
|
||||
|
||||
export interface DataGroup {
|
||||
id: string
|
||||
name: string
|
||||
Division: Division[]
|
||||
}
|
||||
|
||||
export interface Division {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
|
||||
export default function CreateAnnouncement() {
|
||||
const [isOpen, setOpen] = useState(false)
|
||||
const memberGroup = useHookstate(globalMemberAnnouncement)
|
||||
const memberValue = memberGroup.get() as GroupData[]
|
||||
const [selectedFiles, setSelectedFiles] = useState<any>([]);
|
||||
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
||||
|
||||
|
||||
const [isChooseMember, setIsChooseMember] = useState(false)
|
||||
const [isData, setisData] = useState({
|
||||
@@ -43,27 +28,31 @@ export default function CreateAnnouncement() {
|
||||
})
|
||||
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
const response = await funCreateAnnouncement({
|
||||
title: isData.title,
|
||||
desc: isData.desc,
|
||||
groups: memberValue
|
||||
})
|
||||
|
||||
function onTrue(val: boolean) {
|
||||
if (val) {
|
||||
toast.success("Sukses! Data tersimpan");
|
||||
if (response.success) {
|
||||
toast.success(response.message)
|
||||
setisData({
|
||||
...isData,
|
||||
title: "",
|
||||
desc: "",
|
||||
})
|
||||
memberGroup.set([])
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.error("Gagal menambahkan pengumuman, coba lagi nanti");
|
||||
}
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
async function onSubmit(val: boolean) {
|
||||
// const response = await funCreateAnnouncement(
|
||||
// {
|
||||
// title: isData.title,
|
||||
// desc: isData.desc,
|
||||
// groups: memberValue
|
||||
// },
|
||||
|
||||
// )
|
||||
setOpen(false)
|
||||
console.log(isData)
|
||||
console.log(memberValue)
|
||||
|
||||
}
|
||||
|
||||
async function loadData() {
|
||||
@@ -78,7 +67,7 @@ export default function CreateAnnouncement() {
|
||||
setIsChooseMember(true)
|
||||
}
|
||||
|
||||
if (isChooseMember) return <CreateUsersAnnouncement onClose={() => { setIsChooseMember(false) }} />
|
||||
if (isChooseMember) return <CreateUsersAnnouncement onClose={() => { setIsChooseMember(false) }} />
|
||||
|
||||
return (
|
||||
<Box>
|
||||
@@ -95,6 +84,7 @@ export default function CreateAnnouncement() {
|
||||
borderColor: WARNA.biruTua,
|
||||
},
|
||||
}}
|
||||
value={isData.title}
|
||||
onChange={(e) => { setisData({ ...isData, title: e.target.value }) }}
|
||||
/>
|
||||
<Textarea
|
||||
@@ -111,6 +101,7 @@ export default function CreateAnnouncement() {
|
||||
borderColor: WARNA.biruTua,
|
||||
},
|
||||
}}
|
||||
value={isData.desc}
|
||||
onChange={(e) => { setisData({ ...isData, desc: e.target.value }) }}
|
||||
/>
|
||||
<Box pt={10}>
|
||||
@@ -122,29 +113,29 @@ export default function CreateAnnouncement() {
|
||||
onClick={() => { onToChooseMember() }}
|
||||
>
|
||||
<Text size="sm">
|
||||
Tambah Anggota
|
||||
Tambah divisi penerima pengumuman
|
||||
</Text>
|
||||
<IoIosArrowForward />
|
||||
</Group>
|
||||
</Box>
|
||||
<Box pt={20}>
|
||||
<Text c={WARNA.biruTua} mb={10}>Anggota Terpilih</Text>
|
||||
{(memberGroup.length === 0) ? (
|
||||
<Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada anggota</Text>
|
||||
) : memberGroup.get().map((v: any, i: any) => {
|
||||
return (
|
||||
<Box key={i} mt={10}>
|
||||
<Text fw={"bold"}>{v.name}</Text>
|
||||
<Box pl={20}>
|
||||
<Flex direction={"column"} gap={"md"}>
|
||||
{v.Division.map((division: any) => (
|
||||
<li key={division.id}>{division.name}</li>
|
||||
))}
|
||||
</Flex>
|
||||
<Text c={WARNA.biruTua} mb={10}>Divisi Terpilih</Text>
|
||||
{(memberGroup.length === 0) ? (
|
||||
<Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada anggota</Text>
|
||||
) : memberGroup.get().map((v: any, i: any) => {
|
||||
return (
|
||||
<Box key={i} mt={10}>
|
||||
<Text fw={"bold"}>{v.name}</Text>
|
||||
<Box pl={20}>
|
||||
<Flex direction={"column"} gap={"md"}>
|
||||
{v.Division.map((division: any) => (
|
||||
<li key={division.id}>{division.name}</li>
|
||||
))}
|
||||
</Flex>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Stack>
|
||||
<Box mt={30} mx={20}>
|
||||
@@ -161,7 +152,12 @@ export default function CreateAnnouncement() {
|
||||
</Box>
|
||||
<LayoutModal opened={isOpen} onClose={() => setOpen(false)}
|
||||
description="Apakah Anda yakin ingin menambahkan data?"
|
||||
onYes={(val) => { onSubmit(val) }} />
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit()
|
||||
}
|
||||
setOpen(false)
|
||||
}} />
|
||||
</Box>
|
||||
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user