upd: project
Deskripsi: - update validasi tambah kegiatan - update validasi edit judul kegiatan No Issues
This commit is contained in:
@@ -24,7 +24,6 @@ import ResultsFile from "./results_file";
|
|||||||
|
|
||||||
export default function CreateProject() {
|
export default function CreateProject() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [openDrawer, setOpenDrawer] = useState(false)
|
|
||||||
const [openDrawerFile, setOpenDrawerFile] = useState(false)
|
const [openDrawerFile, setOpenDrawerFile] = useState(false)
|
||||||
const [openDrawerTask, setOpenDrawerTask] = useState(false)
|
const [openDrawerTask, setOpenDrawerTask] = useState(false)
|
||||||
const [isModal, setModal] = useState(false)
|
const [isModal, setModal] = useState(false)
|
||||||
@@ -51,7 +50,6 @@ export default function CreateProject() {
|
|||||||
const [touched, setTouched] = useState({
|
const [touched, setTouched] = useState({
|
||||||
title: false,
|
title: false,
|
||||||
idGroup: false,
|
idGroup: false,
|
||||||
desc: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [data, setDataRealtime] = useWibuRealtime({
|
const [data, setDataRealtime] = useWibuRealtime({
|
||||||
@@ -93,7 +91,7 @@ export default function CreateProject() {
|
|||||||
|
|
||||||
function onChooseGroup(val: any) {
|
function onChooseGroup(val: any) {
|
||||||
member.set([])
|
member.set([])
|
||||||
setBody({ ...body, idGroup: val })
|
onValidation('idGroup', val)
|
||||||
}
|
}
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
@@ -138,6 +136,51 @@ export default function CreateProject() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCheck() {
|
||||||
|
const cek = checkAll()
|
||||||
|
if (!cek)
|
||||||
|
return false
|
||||||
|
|
||||||
|
if (dataTask.length == 0)
|
||||||
|
return toast.error("Error! silahkan tambahkan tugas")
|
||||||
|
|
||||||
|
if (memberValue.length == 0)
|
||||||
|
return toast.error("Error! silahkan pilih anggota")
|
||||||
|
|
||||||
|
setModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAll() {
|
||||||
|
let nilai = true
|
||||||
|
if (body.idGroup === "" || String(body.idGroup) == "null") {
|
||||||
|
setTouched(touched => ({ ...touched, idGroup: true }))
|
||||||
|
nilai = false
|
||||||
|
}
|
||||||
|
if (body.title === "") {
|
||||||
|
setTouched(touched => ({ ...touched, title: true }))
|
||||||
|
nilai = false
|
||||||
|
}
|
||||||
|
return nilai
|
||||||
|
}
|
||||||
|
|
||||||
|
function onValidation(kategori: string, val: string) {
|
||||||
|
if (kategori == 'idGroup') {
|
||||||
|
setBody({ ...body, idGroup: val })
|
||||||
|
if (val === "" || String(val) == "null") {
|
||||||
|
setTouched({ ...touched, idGroup: true })
|
||||||
|
} else {
|
||||||
|
setTouched({ ...touched, idGroup: false })
|
||||||
|
}
|
||||||
|
} else if (kategori == 'title') {
|
||||||
|
setBody({ ...body, title: val })
|
||||||
|
if (val === "") {
|
||||||
|
setTouched({ ...touched, title: true })
|
||||||
|
} else {
|
||||||
|
setTouched({ ...touched, title: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (openTugas) return <ViewDateEndTask onClose={(val) => { setOpenTugas(false) }} onSet={(val) => { setDataTask([...dataTask, val]); setOpenTugas(false) }} />;
|
if (openTugas) return <ViewDateEndTask onClose={(val) => { setOpenTugas(false) }} onSet={(val) => { setDataTask([...dataTask, val]); setOpenTugas(false) }} />;
|
||||||
@@ -169,14 +212,12 @@ export default function CreateProject() {
|
|||||||
}))}
|
}))}
|
||||||
onChange={(val) => {
|
onChange={(val) => {
|
||||||
onChooseGroup(val)
|
onChooseGroup(val)
|
||||||
setTouched({ ...touched, idGroup: false })
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
value={(body.idGroup == "") ? null : body.idGroup}
|
value={(body.idGroup == "") ? null : body.idGroup}
|
||||||
onBlur={() => setTouched({ ...touched, idGroup: true })}
|
|
||||||
error={
|
error={
|
||||||
touched.idGroup && (
|
touched.idGroup && (
|
||||||
body.idGroup == "" ? "Grup Tidak Boleh Kosong" : null
|
body.idGroup == "" || String(body.idGroup) == "null" ? "Grup Tidak Boleh Kosong" : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -195,11 +236,7 @@ export default function CreateProject() {
|
|||||||
placeholder="Nama Kegiatan"
|
placeholder="Nama Kegiatan"
|
||||||
size="md"
|
size="md"
|
||||||
value={body.title}
|
value={body.title}
|
||||||
onChange={(e) => {
|
onChange={(e) => { onValidation('title', e.target.value) }}
|
||||||
setBody({ ...body, title: e.target.value })
|
|
||||||
setTouched({ ...touched, title: false })
|
|
||||||
}}
|
|
||||||
onBlur={() => setTouched({ ...touched, title: true })}
|
|
||||||
error={
|
error={
|
||||||
touched.title && (
|
touched.title && (
|
||||||
body.title == "" ? "Kegiatan Tidak Boleh Kosong" : null
|
body.title == "" ? "Kegiatan Tidak Boleh Kosong" : null
|
||||||
@@ -361,16 +398,7 @@ export default function CreateProject() {
|
|||||||
size="lg"
|
size="lg"
|
||||||
radius={30}
|
radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => {
|
onClick={() => { onCheck() }}>
|
||||||
if (
|
|
||||||
body.title !== "" &&
|
|
||||||
body.idGroup !== ""
|
|
||||||
) {
|
|
||||||
setModal(true)
|
|
||||||
} else {
|
|
||||||
toast.error("Mohon lengkapi data terlebih dahulu");
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -504,7 +532,7 @@ export default function CreateProject() {
|
|||||||
onYes={(val) => {
|
onYes={(val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
onSubmit()
|
onSubmit()
|
||||||
}else{
|
} else {
|
||||||
setModal(false)
|
setModal(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||||
import React, { useState } from 'react';
|
|
||||||
import toast from 'react-hot-toast';
|
|
||||||
import { funEditProject, funGetOneProjectById } from '../lib/api_project';
|
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
|
||||||
import { Box, Button, Input, rem, Skeleton, Stack, TextInput } from '@mantine/core';
|
|
||||||
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 { useHookstate } from '@hookstate/core';
|
||||||
|
import { Box, Button, rem, Skeleton, Stack, TextInput } from '@mantine/core';
|
||||||
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import { funEditProject, funGetOneProjectById } from '../lib/api_project';
|
||||||
|
|
||||||
export default function EditTaskProject() {
|
export default function EditTaskProject() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -20,13 +20,6 @@ export default function EditTaskProject() {
|
|||||||
name: false,
|
name: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
function onVerification() {
|
|
||||||
if (name == "")
|
|
||||||
return toast.error("Error! harus memasukkan judul Kegiatan")
|
|
||||||
|
|
||||||
setOpenModal(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
const res = await funEditProject(param.id, { name })
|
const res = await funEditProject(param.id, { name })
|
||||||
@@ -42,6 +35,27 @@ export default function EditTaskProject() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCheck() {
|
||||||
|
if (name == "") {
|
||||||
|
setTouched({ ...touched, name: true })
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
setOpenModal(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function onValidation(kategori: string, val: string) {
|
||||||
|
if (kategori == 'title') {
|
||||||
|
setName(val)
|
||||||
|
if (val === "") {
|
||||||
|
setTouched({ ...touched, name: true })
|
||||||
|
} else {
|
||||||
|
setTouched({ ...touched, name: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getOneData() {
|
async function getOneData() {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
@@ -79,21 +93,17 @@ export default function EditTaskProject() {
|
|||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
placeholder="Input Kegiatan"
|
placeholder="Nama Kegiatan"
|
||||||
label="Judul Kegiatan"
|
label="Kegiatan"
|
||||||
required
|
required
|
||||||
size="md"
|
size="md"
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => {
|
onChange={(e) => { onValidation('title', e.target.value) }}
|
||||||
setName(e.target.value)
|
|
||||||
setTouched({ ...touched, name: false })
|
|
||||||
}}
|
|
||||||
error={
|
error={
|
||||||
touched.name && (
|
touched.name && (
|
||||||
name == "" ? "Judul Kegiatan Tidak Boleh Kosong" : null
|
name == "" ? "Kegiatan Tidak Boleh Kosong" : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
onBlur={() => setTouched({ ...touched, name: true })}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</Stack>
|
</Stack>
|
||||||
@@ -112,7 +122,7 @@ export default function EditTaskProject() {
|
|||||||
size="lg"
|
size="lg"
|
||||||
radius={30}
|
radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => { onVerification() }}
|
onClick={() => { onCheck() }}
|
||||||
>
|
>
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user