upd: position
Deskripsi: - update load list data position - update filter page - update select form - tambah data position No Issues
This commit is contained in:
@@ -9,22 +9,88 @@ import ModalSelect from "@/components/modalSelect"
|
||||
import SelectForm from "@/components/selectForm"
|
||||
import { Headers } from "@/constants/Headers"
|
||||
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 { router, Stack } from "expo-router"
|
||||
import { useState } from "react"
|
||||
import { ToastAndroid, View } from "react-native"
|
||||
import { useDispatch, useSelector } from "react-redux"
|
||||
|
||||
export default function RootLayout() {
|
||||
const dispatch = useDispatch()
|
||||
const update = useSelector((state: any) => state.positionUpdate)
|
||||
const { token, decryptToken } = useAuthSession()
|
||||
const entityUser = useSelector((state: any) => state.user)
|
||||
const [isVisible, setVisible] = useState(false)
|
||||
const [isVisibleTambah, setVisibleTambah] = useState(false)
|
||||
const [isFilter, setFilter] = useState(false)
|
||||
const [isSelect, setSelect] = useState(false)
|
||||
const [choose, setChoose] = useState({ val: '', label: '' })
|
||||
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 = true
|
||||
if (dataForm.name == "") {
|
||||
setError(error => ({ ...error, name: true }))
|
||||
nilai = false
|
||||
}
|
||||
|
||||
if ((entityUser.role == "supadmin" || entityUser.role == "developer") && (dataForm.idGroup == "" || String(dataForm.idGroup) == "null")) {
|
||||
setError(error => ({ ...error, idGroup: true }))
|
||||
nilai = false
|
||||
}
|
||||
|
||||
return nilai
|
||||
}
|
||||
|
||||
function onCheck() {
|
||||
const check = checkAll()
|
||||
if (!check)
|
||||
return false
|
||||
handleTambah()
|
||||
}
|
||||
|
||||
|
||||
async function handleTambah() {
|
||||
try {
|
||||
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 {
|
||||
setVisibleTambah(false)
|
||||
setVisible(false)
|
||||
ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
|
||||
}
|
||||
|
||||
function handleTambah() {
|
||||
setVisibleTambah(false)
|
||||
setVisible(false)
|
||||
ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -34,7 +100,7 @@ export default function RootLayout() {
|
||||
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||
headerTitle: 'Jabatan',
|
||||
headerTitleAlign: 'center',
|
||||
headerRight: () => <ButtonMenuHeader onPress={() => { setVisible(true) }} />
|
||||
headerRight: () => entityUser.role != 'user' ? <ButtonMenuHeader onPress={() => { setVisible(true) }} /> : <></>
|
||||
}} />
|
||||
</Stack>
|
||||
|
||||
@@ -48,25 +114,47 @@ export default function RootLayout() {
|
||||
setVisibleTambah(true)
|
||||
}}
|
||||
/>
|
||||
<MenuItemRow
|
||||
icon={<AntDesign name="filter" color="black" size={25} />}
|
||||
title="Filter"
|
||||
onPress={() => { setFilter(true) }}
|
||||
/>
|
||||
{
|
||||
(entityUser.role == 'supadmin' || entityUser.role == 'developer') &&
|
||||
<MenuItemRow
|
||||
icon={<AntDesign name="filter" color="black" size={25} />}
|
||||
title="Filter"
|
||||
onPress={() => { setFilter(true) }}
|
||||
/>
|
||||
}
|
||||
</View>
|
||||
</DrawerBottom>
|
||||
|
||||
<DrawerBottom animation="slide" isVisible={isVisibleTambah} setVisible={setVisibleTambah} title="Tambah Lembaga Desa">
|
||||
<View style={{ justifyContent: 'space-between', flex: 1 }}>
|
||||
<DrawerBottom animation="slide" height={45} isVisible={isVisibleTambah} setVisible={setVisibleTambah} title="Tambah Jabatan">
|
||||
<View style={{ flex: 1, justifyContent: 'space-between' }}>
|
||||
<View>
|
||||
<SelectForm label="Lembaga Desa" placeholder="Pilih Lembaga Desa" value={choose.label} required onPress={() => {
|
||||
setVisibleTambah(false)
|
||||
setSelect(true)
|
||||
}} />
|
||||
<InputForm type="default" placeholder="Nama Jabatan" required label="Jabatan" />
|
||||
{
|
||||
(entityUser.role == 'supadmin' || entityUser.role == 'developer') &&
|
||||
<SelectForm
|
||||
label="Lembaga Desa"
|
||||
placeholder="Pilih Lembaga Desa"
|
||||
value={choose.label}
|
||||
required
|
||||
onPress={() => {
|
||||
setVisibleTambah(false)
|
||||
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"
|
||||
/>
|
||||
</View>
|
||||
<View>
|
||||
<ButtonForm text="SIMPAN" onPress={() => { handleTambah() }} />
|
||||
<View style={Styles.mb30}>
|
||||
<ButtonForm text="SIMPAN" onPress={() => { onCheck() }} />
|
||||
</View>
|
||||
</View>
|
||||
</DrawerBottom>
|
||||
@@ -80,12 +168,12 @@ export default function RootLayout() {
|
||||
category="group"
|
||||
close={setSelect}
|
||||
onSelect={(value) => {
|
||||
validationForm(value.val, 'idGroup')
|
||||
setChoose(value)
|
||||
setSelect(false)
|
||||
setVisibleTambah(true)
|
||||
}}
|
||||
title="Lembaga Desa"
|
||||
choose={choose.val}
|
||||
open={isSelect}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -8,15 +8,49 @@ import InputSearch from "@/components/inputSearch";
|
||||
import MenuItemRow from "@/components/menuItemRow";
|
||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
||||
import Styles from "@/constants/Styles";
|
||||
import { apiGetPosition } from "@/lib/api";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { AntDesign, Feather, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SafeAreaView, ScrollView, Text, ToastAndroid, View } from "react-native";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
type Props = {
|
||||
name: string;
|
||||
idGroup: string;
|
||||
group: string;
|
||||
id: string;
|
||||
isActive: boolean
|
||||
}
|
||||
|
||||
export default function Index() {
|
||||
const { active } = useLocalSearchParams<{ active?: string }>()
|
||||
const { token, decryptToken } = useAuthSession()
|
||||
const entityUser = useSelector((state: any) => state.user)
|
||||
const { active, group } = useLocalSearchParams<{ active?: string, group?: string }>()
|
||||
const [isModal, setModal] = useState(false)
|
||||
const [isVisibleEdit, setVisibleEdit] = useState(false)
|
||||
const [data, setData] = useState<Props[]>([])
|
||||
const [search, setSearch] = useState('')
|
||||
const [nameGroup, setNameGroup] = useState('')
|
||||
|
||||
const dispatch = useDispatch()
|
||||
const update = useSelector((state: any) => state.positionUpdate)
|
||||
|
||||
async function handleLoad() {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const response = await apiGetPosition({ user: hasil, active: String(active), search: search, group: String(group) })
|
||||
setData(response.data)
|
||||
setNameGroup(response.filter.name)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad()
|
||||
}, [active, search, group, update])
|
||||
|
||||
function handleEdit() {
|
||||
setVisibleEdit(false)
|
||||
@@ -44,77 +78,35 @@ export default function Index() {
|
||||
icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
|
||||
n={2} />
|
||||
</View>
|
||||
<InputSearch />
|
||||
<View style={[Styles.mv05]}>
|
||||
<Text>Filter : Dinas</Text>
|
||||
</View>
|
||||
<InputSearch onChange={setSearch} />
|
||||
{
|
||||
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
||||
<View style={[Styles.mv05]}>
|
||||
<Text>Filter : {nameGroup}</Text>
|
||||
</View>
|
||||
}
|
||||
<View>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Anggota"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Bendahara"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Ketua"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Sekretaris"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Kepala TU"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Wakil Kepala TU"
|
||||
subtitle="Dinas"
|
||||
/>
|
||||
{
|
||||
data.length > 0 ?
|
||||
data.map((item, index) => {
|
||||
return (
|
||||
<BorderBottomItem
|
||||
key={index}
|
||||
onPress={() => { setModal(true) }}
|
||||
borderType="all"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialCommunityIcons name="account-tie" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title={item.name}
|
||||
subtitle={item.group}
|
||||
/>
|
||||
)
|
||||
})
|
||||
:
|
||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada data</Text>
|
||||
}
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
Reference in New Issue
Block a user