upd: pengumuman
deskripsi: - validasi tambah pengumuman - validasi edit pengumuman - button back anggota tambah pengumuman - button back anggota edit pengumuman - tampilan border radius edit pengumuman - tampilan list kosong divisi pada edit pengumuman - loading button save tambah pengumuman No Issues
This commit is contained in:
@@ -19,14 +19,13 @@ export default function CreateAnnouncement() {
|
|||||||
const memberGroup = useHookstate(globalMemberAnnouncement)
|
const memberGroup = useHookstate(globalMemberAnnouncement)
|
||||||
const memberValue = memberGroup.get() as GroupData[]
|
const memberValue = memberGroup.get() as GroupData[]
|
||||||
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
||||||
|
const [loadingKonfirmasi, setLoadingKonfirmasi] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
const [data, setData] = useWibuRealtime({
|
const [data, setData] = useWibuRealtime({
|
||||||
WIBU_REALTIME_TOKEN: keyWibu,
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
project: "sdm"
|
project: "sdm"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const [isChooseMember, setIsChooseMember] = useState(false)
|
const [isChooseMember, setIsChooseMember] = useState(false)
|
||||||
const [isData, setisData] = useState({
|
const [isData, setisData] = useState({
|
||||||
title: "",
|
title: "",
|
||||||
@@ -37,8 +36,10 @@ export default function CreateAnnouncement() {
|
|||||||
desc: false
|
desc: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
|
setLoadingKonfirmasi(true)
|
||||||
const response = await funCreateAnnouncement({
|
const response = await funCreateAnnouncement({
|
||||||
title: isData.title,
|
title: isData.title,
|
||||||
desc: isData.desc,
|
desc: isData.desc,
|
||||||
@@ -56,9 +57,11 @@ export default function CreateAnnouncement() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Gagal menambahkan pengumuman, coba lagi nanti");
|
toast.error("Gagal menambahkan pengumuman, coba lagi nanti");
|
||||||
|
} finally {
|
||||||
|
setLoadingKonfirmasi(false)
|
||||||
|
setOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
setOpen(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
@@ -69,18 +72,31 @@ export default function CreateAnnouncement() {
|
|||||||
loadData()
|
loadData()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
function onToChooseMember() {
|
|
||||||
setIsChooseMember(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isChooseMember) return <CreateUsersAnnouncement onClose={() => { setIsChooseMember(false) }} />
|
|
||||||
|
|
||||||
function onCheck() {
|
function onCheck() {
|
||||||
if (Object.values(touched).some((v) => v == true))
|
const cek = checkAll()
|
||||||
|
if (!cek)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
if (memberValue.length == 0)
|
||||||
|
return toast.error("Error! silahkan pilih divisi")
|
||||||
|
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkAll() {
|
||||||
|
let nilai = true
|
||||||
|
if (isData.title === "") {
|
||||||
|
setTouched(touched => ({ ...touched, title: true }))
|
||||||
|
nilai = false
|
||||||
|
}
|
||||||
|
if (isData.desc === "") {
|
||||||
|
setTouched(touched => ({ ...touched, desc: true }))
|
||||||
|
nilai = false
|
||||||
|
}
|
||||||
|
return nilai
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function onValidation(kategori: string, val: string) {
|
function onValidation(kategori: string, val: string) {
|
||||||
if (kategori == 'title') {
|
if (kategori == 'title') {
|
||||||
@@ -100,6 +116,8 @@ export default function CreateAnnouncement() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isChooseMember) return <CreateUsersAnnouncement onClose={() => { setIsChooseMember(false) }} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<LayoutNavbarNew back="/announcement/" title="Tambah Pengumuman" menu={<></>} />
|
<LayoutNavbarNew back="/announcement/" title="Tambah Pengumuman" menu={<></>} />
|
||||||
@@ -151,7 +169,7 @@ export default function CreateAnnouncement() {
|
|||||||
padding: 10,
|
padding: 10,
|
||||||
borderRadius: 10
|
borderRadius: 10
|
||||||
}}
|
}}
|
||||||
onClick={() => { onToChooseMember() }}
|
onClick={() => { setIsChooseMember(true) }}
|
||||||
>
|
>
|
||||||
<Text size="sm">
|
<Text size="sm">
|
||||||
Tambah divisi penerima pengumuman
|
Tambah divisi penerima pengumuman
|
||||||
@@ -162,7 +180,7 @@ export default function CreateAnnouncement() {
|
|||||||
<Box pt={20} mb={100}>
|
<Box pt={20} mb={100}>
|
||||||
<Text c={tema.get().utama} mb={10}>Divisi Terpilih</Text>
|
<Text c={tema.get().utama} mb={10}>Divisi Terpilih</Text>
|
||||||
{(memberGroup.length === 0) ? (
|
{(memberGroup.length === 0) ? (
|
||||||
<Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada anggota</Text>
|
<Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada divisi yang dipilih</Text>
|
||||||
) : memberGroup.get().map((v: any, i: any) => {
|
) : memberGroup.get().map((v: any, i: any) => {
|
||||||
return (
|
return (
|
||||||
<Box key={i} mt={10}>
|
<Box key={i} mt={10}>
|
||||||
@@ -195,13 +213,14 @@ export default function CreateAnnouncement() {
|
|||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
<LayoutModal opened={isOpen} onClose={() => setOpen(false)}
|
<LayoutModal loading={loadingKonfirmasi} opened={isOpen} onClose={() => setOpen(false)}
|
||||||
description="Apakah Anda yakin ingin menambahkan data?"
|
description="Apakah Anda yakin ingin menambahkan data?"
|
||||||
onYes={(val) => {
|
onYes={(val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
onSubmit()
|
onSubmit()
|
||||||
|
} else {
|
||||||
|
setOpen(false)
|
||||||
}
|
}
|
||||||
setOpen(false)
|
|
||||||
}} />
|
}} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { LayoutNavbarNew, TEMA, WARNA } from '@/module/_global';
|
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||||
import { funGetGroupDivision } from '@/module/group/lib/api_group';
|
import { funGetGroupDivision } from '@/module/group/lib/api_group';
|
||||||
import { Box, Button, Divider, Flex, Group, rem, Skeleton, Stack, Text } from '@mantine/core';
|
|
||||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import { FaCheck } from 'react-icons/fa';
|
|
||||||
import { GroupData } from '../lib/type_announcement';
|
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { globalMemberAnnouncement } from '../lib/val_announcement';
|
import { ActionIcon, Box, Button, Divider, Group, rem, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
import { FaMinus } from 'react-icons/fa6';
|
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { FaCheck } from 'react-icons/fa';
|
||||||
|
import { FaMinus } from 'react-icons/fa6';
|
||||||
|
import { HiChevronLeft } from 'react-icons/hi2';
|
||||||
|
import { GroupData } from '../lib/type_announcement';
|
||||||
|
import { globalMemberAnnouncement } from '../lib/val_announcement';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +113,13 @@ export default function CreateUsersAnnouncement({ onClose }: { onClose: (val: an
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<LayoutNavbarNew back="" title="Tambah Divisi Penerima Pengumuman" menu={<></>} />
|
<LayoutNavbarNew state={
|
||||||
|
<Box>
|
||||||
|
<ActionIcon variant="light" onClick={() => { onClose(true) }} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
|
<HiChevronLeft size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
|
</Box>
|
||||||
|
} title="Tambah Divisi Penerima Pengumuman" menu={<></>} />
|
||||||
<Box p={20} pb={100}>
|
<Box p={20} pb={100}>
|
||||||
<Group justify='flex-end' mb={20}>
|
<Group justify='flex-end' mb={20}>
|
||||||
<Text
|
<Text
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { LayoutNavbarNew, TEMA, WARNA } from "@/module/_global";
|
import { LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||||
|
import { useHookstate } from "@hookstate/core";
|
||||||
import { Box, Button, Flex, Group, List, rem, Skeleton, Stack, Text, Textarea, TextInput } from "@mantine/core";
|
import { Box, Button, Flex, Group, List, rem, Skeleton, Stack, Text, Textarea, TextInput } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
|
import { useParams, useRouter } from "next/navigation";
|
||||||
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 { funEditAnnouncement, funGetAnnouncementById } from "../lib/api_announcement";
|
|
||||||
import { useParams, useRouter } from "next/navigation";
|
|
||||||
import { useHookstate } from "@hookstate/core";
|
|
||||||
import { globalMemberEditAnnouncement } from "../lib/val_announcement";
|
|
||||||
import { GroupData, GroupDataEditAnnouncement } from "../lib/type_announcement";
|
|
||||||
import EditChooseMember from "./edit_choose_member";
|
|
||||||
import { IoIosArrowForward } from "react-icons/io";
|
import { IoIosArrowForward } from "react-icons/io";
|
||||||
|
import { funEditAnnouncement, funGetAnnouncementById } from "../lib/api_announcement";
|
||||||
|
import { GroupData } from "../lib/type_announcement";
|
||||||
|
import { globalMemberEditAnnouncement } from "../lib/val_announcement";
|
||||||
|
import EditChooseMember from "./edit_choose_member";
|
||||||
|
|
||||||
export default function EditAnnouncement() {
|
export default function EditAnnouncement() {
|
||||||
const [isOpen, setOpen] = useState(false)
|
const [isOpen, setOpen] = useState(false)
|
||||||
|
const [loadingKonfirmasi, setLoadingKonfirmasi] = useState(false)
|
||||||
const [isChooseDivisi, setChooseDivisi] = useState(false)
|
const [isChooseDivisi, setChooseDivisi] = useState(false)
|
||||||
const param = useParams<{ id: string }>()
|
const param = useParams<{ id: string }>()
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
@@ -75,6 +75,7 @@ export default function EditAnnouncement() {
|
|||||||
toast.error("Gagal mendapatkan pengumuman, coba lagi nanti")
|
toast.error("Gagal mendapatkan pengumuman, coba lagi nanti")
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
setOpen(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,30 +95,24 @@ export default function EditAnnouncement() {
|
|||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
setLoadingSubmit(false)
|
|
||||||
router.push(`/announcement/${param.id}`)
|
router.push(`/announcement/${param.id}`)
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message)
|
toast.error(response.message)
|
||||||
}
|
}
|
||||||
setLoadingSubmit(false)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
toast.error("Gagal mengedit pengumuman, coba lagi nanti");
|
toast.error("Gagal mengedit pengumuman, coba lagi nanti");
|
||||||
} finally {
|
} finally {
|
||||||
setLoadingSubmit(false)
|
setLoadingSubmit(false)
|
||||||
|
setOpen(false)
|
||||||
}
|
}
|
||||||
setOpen(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isChooseDivisi) return <EditChooseMember onClose={() => { setChooseDivisi(false) }} />
|
|
||||||
|
|
||||||
|
|
||||||
function onCheck() {
|
function onCheck() {
|
||||||
if (Object.values(touched).some((v) => v == true))
|
if (Object.values(touched).some((v) => v == true))
|
||||||
return false
|
return false
|
||||||
|
if (memberGroup.get().length == 0)
|
||||||
|
return toast.error("Error! silahkan pilih divisi")
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +135,8 @@ export default function EditAnnouncement() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isChooseDivisi) return <EditChooseMember onClose={() => { setChooseDivisi(false) }} />
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LayoutNavbarNew back="" title="Edit Pengumuman" menu={<></>} />
|
<LayoutNavbarNew back="" title="Edit Pengumuman" menu={<></>} />
|
||||||
@@ -160,7 +157,7 @@ export default function EditAnnouncement() {
|
|||||||
:
|
:
|
||||||
<>
|
<>
|
||||||
<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: tema.get().utama,
|
color: tema.get().utama,
|
||||||
@@ -231,28 +228,34 @@ export default function EditAnnouncement() {
|
|||||||
))
|
))
|
||||||
|
|
||||||
:
|
:
|
||||||
memberGroup.get().map((v: any, i: any) => {
|
<>
|
||||||
return (
|
<Text c={tema.get().utama} mb={10}>Divisi Terpilih</Text>
|
||||||
<Box key={i} mt={10}>
|
{
|
||||||
<Text fw={"bold"}>{v.name}</Text>
|
memberGroup.get().length == 0 ? <Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada divisi yang dipilih</Text> :
|
||||||
<Box pl={20} pr={10}>
|
memberGroup.get().map((v: any, i: any) => {
|
||||||
<Flex direction={"column"} gap={"md"}>
|
return (
|
||||||
<List>
|
<Box key={i} mt={10}>
|
||||||
{
|
<Text fw={"bold"}>{v.name}</Text>
|
||||||
v.Division.map((division: any) => {
|
<Box pl={20} pr={10}>
|
||||||
return <List.Item key={division.id}>
|
<Flex direction={"column"} gap={"md"}>
|
||||||
<Text lineClamp={1}>{division.name}</Text>
|
<List>
|
||||||
</List.Item>
|
{
|
||||||
})
|
v.Division.map((division: any) => {
|
||||||
}
|
return <List.Item key={division.id}>
|
||||||
</List>
|
<Text lineClamp={1}>{division.name}</Text>
|
||||||
</Flex>
|
</List.Item>
|
||||||
</Box>
|
})
|
||||||
</Box>
|
}
|
||||||
);
|
</List>
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
@@ -282,8 +285,9 @@ export default function EditAnnouncement() {
|
|||||||
onYes={(val) => {
|
onYes={(val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
onSubmit()
|
onSubmit()
|
||||||
|
} else {
|
||||||
|
setOpen(false)
|
||||||
}
|
}
|
||||||
setOpen(false)
|
|
||||||
}} />
|
}} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { LayoutNavbarNew, TEMA, WARNA } from '@/module/_global';
|
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||||
import { funGetGroupDivision } from '@/module/group/lib/api_group';
|
import { funGetGroupDivision } from '@/module/group/lib/api_group';
|
||||||
import { Box, Button, Divider, Flex, Group, rem, Skeleton, Stack, Text } from '@mantine/core';
|
|
||||||
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import { FaCheck } from 'react-icons/fa';
|
|
||||||
import { GroupData, GroupDataEditAnnouncement } from '../lib/type_announcement';
|
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { globalMemberEditAnnouncement } from '../lib/val_announcement';
|
import { ActionIcon, Box, Button, Divider, Group, rem, Skeleton, Stack, Text } from '@mantine/core';
|
||||||
import { FaMinus } from 'react-icons/fa6';
|
import { useMediaQuery, useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
|
import { FaCheck } from 'react-icons/fa';
|
||||||
|
import { FaMinus } from 'react-icons/fa6';
|
||||||
|
import { HiChevronLeft } from 'react-icons/hi2';
|
||||||
|
import { GroupData } from '../lib/type_announcement';
|
||||||
|
import { globalMemberEditAnnouncement } from '../lib/val_announcement';
|
||||||
|
|
||||||
interface CheckedState {
|
interface CheckedState {
|
||||||
[key: string]: string[];
|
[key: string]: string[];
|
||||||
@@ -111,7 +110,13 @@ export default function EditChooseMember({ onClose }: { onClose: (val: any) => v
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<LayoutNavbarNew back="" title="Tambah Divisi Penerima Pengumuman" menu={<></>} />
|
<LayoutNavbarNew state={
|
||||||
|
<Box>
|
||||||
|
<ActionIcon variant="light" onClick={() => { onClose(true) }} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
|
<HiChevronLeft size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
|
</Box>
|
||||||
|
} title="Tambah Divisi Penerima Pengumuman" menu={<></>} />
|
||||||
<Box p={20} pb={100}>
|
<Box p={20} pb={100}>
|
||||||
<Group justify='flex-end' mb={20}>
|
<Group justify='flex-end' mb={20}>
|
||||||
<Text
|
<Text
|
||||||
|
|||||||
Reference in New Issue
Block a user