Deskripsi: - update load list data position - update filter page - update select form - tambah data position No Issues
149 lines
6.0 KiB
TypeScript
149 lines
6.0 KiB
TypeScript
import AlertKonfirmasi from "@/components/alertKonfirmasi";
|
|
import BorderBottomItem from "@/components/borderBottomItem";
|
|
import { ButtonForm } from "@/components/buttonForm";
|
|
import ButtonTab from "@/components/buttonTab";
|
|
import DrawerBottom from "@/components/drawerBottom";
|
|
import { InputForm } from "@/components/inputForm";
|
|
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 { 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 { 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)
|
|
setModal(false)
|
|
ToastAndroid.show('Berhasil mengupdate data', ToastAndroid.SHORT)
|
|
}
|
|
|
|
return (
|
|
<SafeAreaView>
|
|
<ScrollView>
|
|
<View style={[Styles.p15]}>
|
|
<View style={[Styles.wrapBtnTab]}>
|
|
<ButtonTab
|
|
active={active == "false" ? "false" : "true"}
|
|
value="true"
|
|
onPress={() => { router.push('/position?active=true') }}
|
|
label="Aktif"
|
|
icon={<Feather name="check-circle" color={active == "true" ? 'white' : 'black'} size={20} />}
|
|
n={2} />
|
|
<ButtonTab
|
|
active={active == "false" ? "false" : "true"}
|
|
value="false"
|
|
onPress={() => { router.push('/position?active=false') }}
|
|
label="Tidak Aktif"
|
|
icon={<AntDesign name="closecircleo" color={active == "false" ? 'white' : 'black'} size={20} />}
|
|
n={2} />
|
|
</View>
|
|
<InputSearch onChange={setSearch} />
|
|
{
|
|
(entityUser.role == "supadmin" || entityUser.role == "developer") &&
|
|
<View style={[Styles.mv05]}>
|
|
<Text>Filter : {nameGroup}</Text>
|
|
</View>
|
|
}
|
|
<View>
|
|
{
|
|
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>
|
|
|
|
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
|
<View style={Styles.rowItemsCenter}>
|
|
<MenuItemRow
|
|
icon={<MaterialCommunityIcons name="toggle-switch-off-outline" color="black" size={25} />}
|
|
title="Non Aktifkan"
|
|
onPress={() => {
|
|
AlertKonfirmasi({
|
|
title: 'Konfirmasi',
|
|
desc: 'Apakah anda yakin ingin menonaktifkan data?',
|
|
onPress: () => { handleEdit() }
|
|
})
|
|
}}
|
|
/>
|
|
<MenuItemRow
|
|
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
|
title="Edit"
|
|
onPress={() => { setVisibleEdit(true) }}
|
|
/>
|
|
</View>
|
|
</DrawerBottom>
|
|
|
|
|
|
<DrawerBottom animation="none" isVisible={isVisibleEdit} setVisible={setVisibleEdit} title="Edit Jabatan">
|
|
<View style={{ justifyContent: 'space-between', flex: 1 }}>
|
|
<View>
|
|
<InputForm type="default" placeholder="Nama Jabatan" required label="Jabatan" />
|
|
</View>
|
|
<View>
|
|
<ButtonForm text="SIMPAN" onPress={() => { handleEdit() }} />
|
|
</View>
|
|
</View>
|
|
</DrawerBottom>
|
|
|
|
</SafeAreaView>
|
|
)
|
|
} |