diff --git a/app/(application)/position/index.tsx b/app/(application)/position/index.tsx index c180afd..559eecb 100644 --- a/app/(application)/position/index.tsx +++ b/app/(application)/position/index.tsx @@ -251,7 +251,7 @@ export default function Index() { /> - { checkForm() }} /> + { handleEdit() }} disabled={Object.values(error).some((v) => v == true) || chooseData.name == ""} /> diff --git a/components/position/headerRightPositionList.tsx b/components/position/headerRightPositionList.tsx index 6d0daa4..8096ae9 100644 --- a/components/position/headerRightPositionList.tsx +++ b/components/position/headerRightPositionList.tsx @@ -3,7 +3,7 @@ import { apiCreatePosition } from "@/lib/api" import { setUpdatePosition } from "@/lib/positionSlice" import { useAuthSession } from "@/providers/AuthProvider" import { AntDesign } from "@expo/vector-icons" -import { useState } from "react" +import { useEffect, useState } from "react" import { View } from "react-native" import Toast from "react-native-toast-message" import { useDispatch, useSelector } from "react-redux" @@ -26,6 +26,7 @@ export default function HeaderRightPositionList() { const [isFilter, setFilter] = useState(false) const [isSelect, setSelect] = useState(false) const [choose, setChoose] = useState({ val: '', label: '' }) + const [disable, setDisable] = useState(true) const [dataForm, setDataForm] = useState({ name: "", idGroup: "", @@ -54,27 +55,21 @@ export default function HeaderRightPositionList() { } function checkAll() { - let nilai = true + let nilai = false if (dataForm.name == "") { - setError(error => ({ ...error, name: true })) - nilai = false + nilai = true } if ((entityUser.role == "supadmin" || entityUser.role == "developer") && (dataForm.idGroup == "" || String(dataForm.idGroup) == "null")) { - setError(error => ({ ...error, idGroup: true })) - nilai = false + nilai = true } - return nilai - } - - function onCheck() { - const check = checkAll() - if (!check) - return false - handleTambah() + setDisable(nilai) } + useEffect(() => { + checkAll() + }, [dataForm]) async function handleTambah() { try { @@ -155,7 +150,10 @@ export default function HeaderRightPositionList() { /> - { onCheck() }} /> + { handleTambah() }} + disabled={disable} />