upd: tambah jabatan
Deskripsi: - pisah class modal form tambah jabatan supaya bisa double modal No Issues
This commit is contained in:
@@ -1,93 +1,19 @@
|
|||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
import { apiCreatePosition } from "@/lib/api"
|
|
||||||
import { setUpdatePosition } from "@/lib/positionSlice"
|
|
||||||
import { useAuthSession } from "@/providers/AuthProvider"
|
|
||||||
import { AntDesign } from "@expo/vector-icons"
|
import { AntDesign } from "@expo/vector-icons"
|
||||||
import { useEffect, useState } from "react"
|
import { useState } from "react"
|
||||||
import { View } from "react-native"
|
import { View } from "react-native"
|
||||||
import Toast from "react-native-toast-message"
|
import { useSelector } from "react-redux"
|
||||||
import { useDispatch, useSelector } from "react-redux"
|
|
||||||
import { ButtonForm } from "../buttonForm"
|
|
||||||
import ButtonMenuHeader from "../buttonMenuHeader"
|
import ButtonMenuHeader from "../buttonMenuHeader"
|
||||||
import DrawerBottom from "../drawerBottom"
|
import DrawerBottom from "../drawerBottom"
|
||||||
import { InputForm } from "../inputForm"
|
|
||||||
import MenuItemRow from "../menuItemRow"
|
import MenuItemRow from "../menuItemRow"
|
||||||
import ModalFilter from "../modalFilter"
|
import ModalFilter from "../modalFilter"
|
||||||
import ModalSelect from "../modalSelect"
|
import ModalFormCreatePosition from "./modalFormCreatePosition"
|
||||||
import SelectForm from "../selectForm"
|
|
||||||
|
|
||||||
export default function HeaderRightPositionList() {
|
export default function HeaderRightPositionList() {
|
||||||
const dispatch = useDispatch()
|
|
||||||
const update = useSelector((state: any) => state.positionUpdate)
|
|
||||||
const { token, decryptToken } = useAuthSession()
|
|
||||||
const entityUser = useSelector((state: any) => state.user)
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
const [isVisible, setVisible] = useState(false)
|
const [isVisible, setVisible] = useState(false)
|
||||||
const [isVisibleTambah, setVisibleTambah] = useState(false)
|
const [isVisibleTambah, setVisibleTambah] = useState(false)
|
||||||
const [isFilter, setFilter] = useState(false)
|
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: "",
|
|
||||||
})
|
|
||||||
const [error, setError] = useState({
|
|
||||||
name: false,
|
|
||||||
idGroup: false
|
|
||||||
});
|
|
||||||
|
|
||||||
function validationForm(val: any, cat: 'name' | 'idGroup') {
|
|
||||||
if (cat === 'name') {
|
|
||||||
setDataForm({ ...dataForm, name: val })
|
|
||||||
if (val == "") {
|
|
||||||
setError({ ...error, name: true })
|
|
||||||
} else {
|
|
||||||
setError({ ...error, name: false })
|
|
||||||
}
|
|
||||||
} else if (cat === "idGroup") {
|
|
||||||
setDataForm({ ...dataForm, idGroup: val })
|
|
||||||
if (val == "") {
|
|
||||||
setError({ ...error, idGroup: true })
|
|
||||||
} else {
|
|
||||||
setError({ ...error, idGroup: false })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkAll() {
|
|
||||||
let nilai = false
|
|
||||||
if (dataForm.name == "") {
|
|
||||||
nilai = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((entityUser.role == "supadmin" || entityUser.role == "developer") && (dataForm.idGroup == "" || String(dataForm.idGroup) == "null")) {
|
|
||||||
nilai = true
|
|
||||||
}
|
|
||||||
|
|
||||||
setDisable(nilai)
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
checkAll()
|
|
||||||
}, [dataForm])
|
|
||||||
|
|
||||||
async function handleTambah() {
|
|
||||||
try {
|
|
||||||
setDisable(true)
|
|
||||||
const hasil = await decryptToken(String(token?.current))
|
|
||||||
const response = await apiCreatePosition({ user: hasil, name: dataForm.name, idGroup: dataForm.idGroup })
|
|
||||||
dispatch(setUpdatePosition(!update))
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
} finally {
|
|
||||||
setDisable(false)
|
|
||||||
setVisibleTambah(false)
|
|
||||||
setVisible(false)
|
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -121,64 +47,13 @@ export default function HeaderRightPositionList() {
|
|||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
<DrawerBottom animation="slide" height={45} keyboard isVisible={isVisibleTambah} setVisible={() => setVisibleTambah(false)} title="Tambah Jabatan">
|
<DrawerBottom animation="slide" height={45} keyboard isVisible={isVisibleTambah} setVisible={() => setVisibleTambah(false)} title="Tambah Jabatan">
|
||||||
<View style={{ flex: 1, justifyContent: 'space-between' }}>
|
<ModalFormCreatePosition onClose={() => setVisibleTambah(false)} />
|
||||||
<View>
|
|
||||||
{
|
|
||||||
(entityUser.role == 'supadmin' || entityUser.role == 'developer') &&
|
|
||||||
<SelectForm
|
|
||||||
label="Lembaga Desa"
|
|
||||||
placeholder="Pilih Lembaga Desa"
|
|
||||||
value={choose.label}
|
|
||||||
required
|
|
||||||
onPress={() => {
|
|
||||||
setVisibleTambah(false)
|
|
||||||
setTimeout(() => {
|
|
||||||
setSelect(true)
|
|
||||||
}, 600)
|
|
||||||
}}
|
|
||||||
error={error.idGroup}
|
|
||||||
errorText="Lembaga Desa harus diisi"
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
<InputForm
|
|
||||||
type="default"
|
|
||||||
placeholder="Nama Jabatan"
|
|
||||||
required
|
|
||||||
label="Jabatan"
|
|
||||||
onChange={(value) => { validationForm(value, 'name') }}
|
|
||||||
error={error.name}
|
|
||||||
errorText="Nama jabatan harus diisi"
|
|
||||||
value={dataForm.name}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
<View style={Styles.mb30}>
|
|
||||||
<ButtonForm
|
|
||||||
text="SIMPAN"
|
|
||||||
onPress={() => { handleTambah() }}
|
|
||||||
disabled={disable} />
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|
||||||
<ModalFilter close={() => {
|
<ModalFilter close={() => {
|
||||||
setFilter(false)
|
setFilter(false)
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
}} open={isFilter} page="position" />
|
}} open={isFilter} page="position" />
|
||||||
|
|
||||||
<ModalSelect
|
|
||||||
category="group"
|
|
||||||
close={setSelect}
|
|
||||||
onSelect={(value) => {
|
|
||||||
validationForm(value.val, 'idGroup')
|
|
||||||
setChoose(value)
|
|
||||||
setSelect(false)
|
|
||||||
setTimeout(() => {
|
|
||||||
setVisibleTambah(true)
|
|
||||||
}, 600)
|
|
||||||
}}
|
|
||||||
title="Lembaga Desa"
|
|
||||||
open={isSelect}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
133
components/position/modalFormCreatePosition.tsx
Normal file
133
components/position/modalFormCreatePosition.tsx
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import Styles from "@/constants/Styles"
|
||||||
|
import { apiCreatePosition } from "@/lib/api"
|
||||||
|
import { setUpdatePosition } from "@/lib/positionSlice"
|
||||||
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
|
import { update } from "@react-native-firebase/database"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { View } from "react-native"
|
||||||
|
import Toast from "react-native-toast-message"
|
||||||
|
import { useDispatch, useSelector } from "react-redux"
|
||||||
|
import { ButtonForm } from "../buttonForm"
|
||||||
|
import { InputForm } from "../inputForm"
|
||||||
|
import SelectForm from "../selectForm"
|
||||||
|
import ModalSelect from "../modalSelect"
|
||||||
|
|
||||||
|
export default function ModalFormCreatePosition({ onClose }: { onClose: () => void }) {
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
const { token, decryptToken } = useAuthSession()
|
||||||
|
const entityUser = useSelector((state: any) => state.user)
|
||||||
|
const [choose, setChoose] = useState({ val: '', label: '' })
|
||||||
|
const [isSelect, setSelect] = useState(false)
|
||||||
|
const [disable, setDisable] = useState(true)
|
||||||
|
const [dataForm, setDataForm] = useState({
|
||||||
|
name: "",
|
||||||
|
idGroup: "",
|
||||||
|
})
|
||||||
|
const [error, setError] = useState({
|
||||||
|
name: false,
|
||||||
|
idGroup: false
|
||||||
|
});
|
||||||
|
|
||||||
|
function validationForm(val: any, cat: 'name' | 'idGroup') {
|
||||||
|
if (cat === 'name') {
|
||||||
|
setDataForm({ ...dataForm, name: val })
|
||||||
|
if (val == "") {
|
||||||
|
setError({ ...error, name: true })
|
||||||
|
} else {
|
||||||
|
setError({ ...error, name: false })
|
||||||
|
}
|
||||||
|
} else if (cat === "idGroup") {
|
||||||
|
setDataForm({ ...dataForm, idGroup: val })
|
||||||
|
if (val == "") {
|
||||||
|
setError({ ...error, idGroup: true })
|
||||||
|
} else {
|
||||||
|
setError({ ...error, idGroup: false })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAll() {
|
||||||
|
let nilai = false
|
||||||
|
if (dataForm.name == "") {
|
||||||
|
nilai = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((entityUser.role == "supadmin" || entityUser.role == "developer") && (dataForm.idGroup == "" || String(dataForm.idGroup) == "null")) {
|
||||||
|
nilai = true
|
||||||
|
}
|
||||||
|
|
||||||
|
setDisable(nilai)
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
checkAll()
|
||||||
|
}, [dataForm])
|
||||||
|
|
||||||
|
async function handleTambah() {
|
||||||
|
try {
|
||||||
|
setDisable(true)
|
||||||
|
const hasil = await decryptToken(String(token?.current))
|
||||||
|
const response = await apiCreatePosition({ user: hasil, name: dataForm.name, idGroup: dataForm.idGroup })
|
||||||
|
dispatch(setUpdatePosition(!update))
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
} finally {
|
||||||
|
setDisable(false)
|
||||||
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<View style={{ flex: 1, justifyContent: 'space-between' }}>
|
||||||
|
<View>
|
||||||
|
{
|
||||||
|
(entityUser.role == 'supadmin' || entityUser.role == 'developer') &&
|
||||||
|
<SelectForm
|
||||||
|
label="Lembaga Desa"
|
||||||
|
placeholder="Pilih Lembaga Desa"
|
||||||
|
value={choose.label}
|
||||||
|
required
|
||||||
|
onPress={() => {
|
||||||
|
setSelect(true)
|
||||||
|
}}
|
||||||
|
error={error.idGroup}
|
||||||
|
errorText="Lembaga Desa harus diisi"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
<InputForm
|
||||||
|
type="default"
|
||||||
|
placeholder="Nama Jabatan"
|
||||||
|
required
|
||||||
|
label="Jabatan"
|
||||||
|
onChange={(value) => { validationForm(value, 'name') }}
|
||||||
|
error={error.name}
|
||||||
|
errorText="Nama jabatan harus diisi"
|
||||||
|
value={dataForm.name}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<View style={Styles.mb30}>
|
||||||
|
<ButtonForm
|
||||||
|
text="SIMPAN"
|
||||||
|
onPress={() => { handleTambah() }}
|
||||||
|
disabled={disable} />
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<ModalSelect
|
||||||
|
category="group"
|
||||||
|
close={setSelect}
|
||||||
|
onSelect={(value) => {
|
||||||
|
validationForm(value.val, 'idGroup')
|
||||||
|
setChoose(value)
|
||||||
|
setSelect(false)
|
||||||
|
}}
|
||||||
|
title="Lembaga Desa"
|
||||||
|
open={isSelect}
|
||||||
|
valChoose={choose.val}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user