upd: member
Deskripsi: - load member - search member - filter member - active member - tambah member nb: blm bisa upload gambar No Issues
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { valueGender } from "@/constants/Gender"
|
||||
import { valueRoleUser } from "@/constants/RoleUser"
|
||||
import Styles from "@/constants/Styles"
|
||||
import { apiGetGroup } from "@/lib/api"
|
||||
import { apiGetGroup, apiGetPosition } from "@/lib/api"
|
||||
import { setEntityFilterGroup } from "@/lib/filterSlice"
|
||||
import { useAuthSession } from "@/providers/AuthProvider"
|
||||
import { AntDesign } from "@expo/vector-icons"
|
||||
@@ -12,17 +14,18 @@ type Props = {
|
||||
open: boolean
|
||||
close: (value: boolean) => void
|
||||
title: string
|
||||
category: 'group' | 'status-task'
|
||||
|
||||
category: 'group' | 'status-task' | 'position' | 'role' | 'gender'
|
||||
idParent?: string
|
||||
onSelect: (value: { val: string, label: string }) => void
|
||||
}
|
||||
|
||||
export default function ModalSelect({ open, close, title, category, onSelect }: Props) {
|
||||
// const [isChoose, setChoose] = useState(choose)
|
||||
export default function ModalSelect({ open, close, title, category, idParent, onSelect }: Props) {
|
||||
const { token, decryptToken } = useAuthSession()
|
||||
const entityUser = useSelector((state: any) => state.user)
|
||||
const dispatch = useDispatch()
|
||||
const entitiesGroup = useSelector((state: any) => state.filterGroup)
|
||||
const [chooseValue, setChooseValue] = useState({ val: '', label: '' })
|
||||
const [data, setData] = useState<any>([])
|
||||
|
||||
async function handleLoadGroup() {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
@@ -30,11 +33,39 @@ export default function ModalSelect({ open, close, title, category, onSelect }:
|
||||
dispatch(setEntityFilterGroup(response.data))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (entitiesGroup.length == 0 && category == 'group') {
|
||||
handleLoadGroup()
|
||||
async function handleLoadPosition() {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
if (idParent == undefined || idParent == '' || idParent == null) {
|
||||
setData([])
|
||||
} else {
|
||||
const response = await apiGetPosition({ active: 'true', user: hasil, search: '', group: idParent })
|
||||
setData(response.data)
|
||||
}
|
||||
}, [dispatch]);
|
||||
}
|
||||
|
||||
function handleLoadUserRole() {
|
||||
const filter = valueRoleUser.filter((v) => v.login == entityUser.role)[0]?.data
|
||||
setData(filter)
|
||||
}
|
||||
|
||||
function handleLoadGender() {
|
||||
setData(valueGender)
|
||||
}
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (category == 'group') {
|
||||
if (entitiesGroup.length == 0)
|
||||
handleLoadGroup()
|
||||
setData(entitiesGroup)
|
||||
} else if (category == 'position') {
|
||||
handleLoadPosition()
|
||||
} else if (category == "role") {
|
||||
handleLoadUserRole()
|
||||
} else if (category == "gender") {
|
||||
handleLoadGender()
|
||||
}
|
||||
}, [dispatch, open]);
|
||||
|
||||
function onChoose(val: string, label: string) {
|
||||
setChooseValue({ val, label })
|
||||
@@ -43,19 +74,22 @@ export default function ModalSelect({ open, close, title, category, onSelect }:
|
||||
}
|
||||
|
||||
return (
|
||||
<DrawerBottom animation="none" isVisible={open} setVisible={close} title={title} height={75}>
|
||||
<DrawerBottom animation="none" isVisible={open} setVisible={close} title={title} height={category == 'gender' ? 25 : 75}>
|
||||
<ScrollView>
|
||||
<View>
|
||||
{
|
||||
category == 'group' ?
|
||||
entitiesGroup.map((item: any, index: any) => (
|
||||
<Pressable key={index} style={[Styles.itemSelectModal]} onPress={() => { onChoose(item.id, item.name) }}>
|
||||
<Text style={[chooseValue.val == item.id ? Styles.textDefaultSemiBold : Styles.textDefault]}>{item.name}</Text>
|
||||
{
|
||||
chooseValue.val == item.id && <AntDesign name="check" size={20} />
|
||||
}
|
||||
</Pressable>
|
||||
))
|
||||
category != 'status-task' ?
|
||||
data.length > 0 ?
|
||||
data.map((item: any, index: any) => (
|
||||
<Pressable key={index} style={[Styles.itemSelectModal]} onPress={() => { onChoose(item.id, item.name) }}>
|
||||
<Text style={[chooseValue.val == item.id ? Styles.textDefaultSemiBold : Styles.textDefault]}>{item.name}</Text>
|
||||
{
|
||||
chooseValue.val == item.id && <AntDesign name="check" size={20} />
|
||||
}
|
||||
</Pressable>
|
||||
))
|
||||
:
|
||||
<Text style={[Styles.textDefault, { textAlign: 'center' }]}>Tidak ada data</Text>
|
||||
:
|
||||
<>
|
||||
<Pressable style={[Styles.itemSelectModal]} onPress={() => {
|
||||
|
||||
Reference in New Issue
Block a user