fix: fixing super admin
Deskripsi: - tugas divisi - kegiatan - home - filter No Issues
This commit is contained in:
@@ -2,43 +2,61 @@
|
||||
import { keyWibu, LayoutNavbarNew, TEMA } from "@/module/_global";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { Box, Button, Group, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||
import { Box, Button, Flex, Group, rem, SimpleGrid, Stack, Text, TextInput } from "@mantine/core";
|
||||
import { DatePicker } from "@mantine/dates";
|
||||
import moment from "moment";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { funCreateDetailTask } from "../lib/api_task";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import { funCreateDetailTask } from "../lib/api_task";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
|
||||
export default function AddDetailTask() {
|
||||
const [value, setValue] = useState<[Date | null, Date | null]>([null, null]);
|
||||
const router = useRouter()
|
||||
const [title, setTitle] = useState("")
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const tema = useHookstate(TEMA)
|
||||
const [acuan, setAcuan] = useState(false)
|
||||
const [touched, setTouched] = useState({
|
||||
title: false,
|
||||
date: false
|
||||
});
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
|
||||
function onVerification() {
|
||||
if (value[0] == null || value[1] == null)
|
||||
return toast.error("Error! harus memilih tanggal")
|
||||
|
||||
if (title == "")
|
||||
return toast.error("Error! harus memasukkan judul tugas")
|
||||
|
||||
function onCheck() {
|
||||
const cek = checkAll()
|
||||
if (!cek)
|
||||
return false
|
||||
setOpenModal(true)
|
||||
}
|
||||
|
||||
function checkAll() {
|
||||
let nilai = true
|
||||
|
||||
if (title == "") {
|
||||
setTouched(touched => ({ ...touched, title: true }))
|
||||
nilai = false
|
||||
}
|
||||
|
||||
if (value[0] == null || value[1] == null) {
|
||||
setTouched(touched => ({ ...touched, date: true }))
|
||||
nilai = false
|
||||
}
|
||||
|
||||
return nilai
|
||||
|
||||
}
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const res = await funCreateDetailTask(param.detail, {
|
||||
title,
|
||||
dateStart: (value[0] != null) ? value[0] : new Date,
|
||||
@@ -52,7 +70,6 @@ export default function AddDetailTask() {
|
||||
id: param.detail,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
setOpenModal(false)
|
||||
router.push(`/division/${param.id}/task/${param.detail}`)
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
@@ -60,10 +77,39 @@ export default function AddDetailTask() {
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal menambahkan tugas, coba lagi nanti")
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
setOpenModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onValidation(kategori: string, val: string) {
|
||||
if (kategori == 'title') {
|
||||
setTitle(val)
|
||||
if (val === "") {
|
||||
setTouched({ ...touched, title: true })
|
||||
} else {
|
||||
setTouched({ ...touched, title: false })
|
||||
}
|
||||
} else if (kategori == 'date') {
|
||||
const array = val.split(",")
|
||||
if (array[0] == '' || array[1] == '') {
|
||||
setTouched({ ...touched, date: true })
|
||||
} else {
|
||||
setTouched({ ...touched, date: false })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (acuan) {
|
||||
onValidation('date', String(value))
|
||||
} else {
|
||||
setAcuan(true)
|
||||
}
|
||||
}, [value])
|
||||
|
||||
|
||||
return (
|
||||
<Box>
|
||||
@@ -86,7 +132,9 @@ export default function AddDetailTask() {
|
||||
</Group>
|
||||
<SimpleGrid cols={{ base: 2, sm: 2, lg: 2 }} mt={20}>
|
||||
<Box>
|
||||
<Text>Tanggal Mulai</Text>
|
||||
<Flex justify="flex-start" align="flex-start" direction="row" wrap="nowrap" gap={5}>
|
||||
<Text fw={500}>Tanggal Mulai</Text> <Text c={"red"}>*</Text>
|
||||
</Flex>
|
||||
<Group
|
||||
justify="center"
|
||||
bg={"white"}
|
||||
@@ -97,7 +145,9 @@ export default function AddDetailTask() {
|
||||
</Group>
|
||||
</Box>
|
||||
<Box>
|
||||
<Text >Tanggal Berakhir</Text>
|
||||
<Flex justify="flex-start" align="flex-start" direction="row" wrap="nowrap" gap={5}>
|
||||
<Text fw={500}>Tanggal Berakhir</Text> <Text c={"red"}>*</Text>
|
||||
</Flex>
|
||||
<Group
|
||||
justify="center"
|
||||
bg={"white"}
|
||||
@@ -108,6 +158,11 @@ export default function AddDetailTask() {
|
||||
</Group>
|
||||
</Box>
|
||||
</SimpleGrid>
|
||||
{
|
||||
(touched && touched.date)
|
||||
? <Text size="sm" c={"red"}>Tanggal Tidak Boleh Kosong</Text>
|
||||
: <></>
|
||||
}
|
||||
<Stack pt={15} pb={100}>
|
||||
<TextInput
|
||||
styles={{
|
||||
@@ -116,20 +171,15 @@ export default function AddDetailTask() {
|
||||
borderRadius: 10,
|
||||
},
|
||||
}}
|
||||
label="Judul Tahapan"
|
||||
placeholder="Input Judul Tahapan"
|
||||
placeholder="Input Judul Tugas"
|
||||
label="Judul Tugas"
|
||||
size="md"
|
||||
required
|
||||
value={title}
|
||||
onChange={(e) => {
|
||||
setTitle(e.target.value)
|
||||
setTouched({ ...touched, title: false })
|
||||
}
|
||||
}
|
||||
onBlur={() => setTouched({ ...touched, title: true })}
|
||||
onChange={(e) => { onValidation('title', e.target.value) }}
|
||||
error={
|
||||
touched.title && (
|
||||
title == "" ? "Judul Tahapan Tidak Boleh Kosong" : null
|
||||
title == "" ? "Judul Tugas Tidak Boleh Kosong" : null
|
||||
)
|
||||
}
|
||||
/>
|
||||
@@ -146,19 +196,20 @@ export default function AddDetailTask() {
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => { onVerification() }}
|
||||
onClick={() => { onCheck() }}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<LayoutModal opened={openModal} onClose={() => setOpenModal(false)}
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menambahkan tugas?"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit()
|
||||
} else {
|
||||
setOpenModal(false)
|
||||
}
|
||||
setOpenModal(false)
|
||||
}} />
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user