fix : group

Deskripsi:
- validasi tambah group
- validasi edit group
- load refresh modal

No Issues
This commit is contained in:
2025-08-05 15:34:40 +08:00
parent 308fda6920
commit 7470e8a9c2
3 changed files with 32 additions and 19 deletions

View File

@@ -42,14 +42,9 @@ export default function Index() {
const dispatch = useDispatch()
const update = useSelector((state: any) => state.groupUpdate)
const [data11, setData1] = useState(Array.from({ length: 20 }, (_, i) => `Item ${i}`));
const renderItem = ({ item }: { item: string }) => (
<View style={{ padding: 20, borderBottomWidth: 1, borderColor: '#ccc' }}>
<Text>{item}</Text>
</View>
);
const [error, setError] = useState({
title: false,
});
async function handleEdit() {
@@ -109,6 +104,17 @@ export default function Index() {
setRefreshing(false)
};
function validationForm(val: any, cat: 'title') {
if (cat === 'title') {
setTitleChoose(val)
if (val == "" || val.length < 3) {
setError((prev) => ({ ...prev, title: true }))
} else {
setError((prev) => ({ ...prev, title: false }))
}
}
}
return (
<SafeAreaView>
@@ -207,10 +213,18 @@ export default function Index() {
<DrawerBottom animation="none" keyboard height={30} isVisible={isVisibleEdit} setVisible={() => setVisibleEdit(false)} title="Edit Lembaga Desa">
<View style={{ flex: 1 }}>
<View>
<InputForm type="default" placeholder="Nama Lembaga Desa" required label="Lembaga Desa" value={titleChoose} onChange={setTitleChoose} />
<InputForm
type="default"
placeholder="Nama Lembaga Desa"
required
label="Lembaga Desa"
value={titleChoose}
error={error.title}
errorText="Lembaga Desa tidak boleh kosong & minimal 3 karakter"
onChange={(val) => { validationForm(val, 'title') }} />
</View>
<View>
<ButtonForm text="SIMPAN" onPress={() => { handleEdit() }} />
<ButtonForm text="SIMPAN" disabled={Object.values(error).some((v) => v == true) || titleChoose == ""} onPress={() => { handleEdit() }} />
</View>
</View>
</DrawerBottom>

View File

@@ -48,9 +48,9 @@ export default function HeaderRightGroupList() {
if (cat === 'title') {
setTitle(val)
if (val == "" || val.length < 3) {
setError({ ...error, title: true })
setError((prev) => ({ ...prev, title: true }))
} else {
setError({ ...error, title: false })
setError((prev) => ({ ...prev, title: false }))
}
}
}
@@ -91,7 +91,7 @@ export default function HeaderRightGroupList() {
/>
</View>
<View>
<ButtonForm text="SIMPAN" onPress={() => { onCheck() }} />
<ButtonForm text="SIMPAN" disabled={Object.values(error).some((v) => v == true) || title == ""} onPress={() => { onCheck() }} />
</View>
</View>
</DrawerBottom>

View File

@@ -9,13 +9,13 @@ import { useAuthSession } from "@/providers/AuthProvider"
import { AntDesign } from "@expo/vector-icons"
import { useEffect, useState } from "react"
import { Pressable, ScrollView, View } from "react-native"
import Text from "./Text";
import { useDispatch, useSelector } from "react-redux"
import { ButtonForm } from "./buttonForm"
import DrawerBottom from "./drawerBottom"
import ImageUser from "./imageNew"
import ImageWithLabel from "./imageWithLabel"
import InputSearch from "./inputSearch"
import Text from "./Text"
type Props = {
open: boolean
@@ -89,8 +89,7 @@ export default function ModalSelect({ open, close, title, category, idParent, on
useEffect(() => {
if (category == 'group') {
if (entitiesGroup.length == 0)
handleLoadGroup()
handleLoadGroup()
setData(entitiesGroup)
} else if (category == 'position') {
handleLoadPosition()
@@ -174,9 +173,9 @@ export default function ModalSelect({ open, close, title, category, idParent, on
{
(category == 'member')
?
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'}/>
selectMember.some((i: any) => i.idUser == item.id) && <AntDesign name="check" size={20} color={'black'} />
:
chooseValue.val == item.id && <AntDesign name="check" size={20} color={'black'}/>
chooseValue.val == item.id && <AntDesign name="check" size={20} color={'black'} />
}
</Pressable>
))
@@ -192,7 +191,7 @@ export default function ModalSelect({ open, close, title, category, idParent, on
}}>
<Text style={[chooseValue.val == item.val ? Styles.textDefaultSemiBold : Styles.textDefault]}>{item.label}</Text>
{
valChoose == item.val && <AntDesign name="check" size={20} color={'black'}/>
valChoose == item.val && <AntDesign name="check" size={20} color={'black'} />
}
</Pressable>
))