fix: jabatan
Deskripsi: - loading button on form edit dan tambah data - toast error api edit jabatan No Issues
This commit is contained in:
@@ -34,7 +34,7 @@ export default function Index() {
|
|||||||
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
const arrSkeleton = Array.from({ length: 5 }, (_, index) => index)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [status, setStatus] = useState<'true' | 'false'>('true')
|
const [status, setStatus] = useState<'true' | 'false'>('true')
|
||||||
|
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
||||||
const [idChoose, setIdChoose] = useState('')
|
const [idChoose, setIdChoose] = useState('')
|
||||||
const [activeChoose, setActiveChoose] = useState(true)
|
const [activeChoose, setActiveChoose] = useState(true)
|
||||||
const [titleChoose, setTitleChoose] = useState('')
|
const [titleChoose, setTitleChoose] = useState('')
|
||||||
@@ -49,12 +49,14 @@ export default function Index() {
|
|||||||
|
|
||||||
async function handleEdit() {
|
async function handleEdit() {
|
||||||
try {
|
try {
|
||||||
|
setLoadingSubmit(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiEditGroup({ user: hasil, name: titleChoose }, idChoose)
|
const response = await apiEditGroup({ user: hasil, name: titleChoose }, idChoose)
|
||||||
dispatch(setUpdateGroup(!update))
|
dispatch(setUpdateGroup(!update))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
|
setLoadingSubmit(false)
|
||||||
setVisibleEdit(false)
|
setVisibleEdit(false)
|
||||||
setModal(false)
|
setModal(false)
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
|
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
|
||||||
@@ -234,7 +236,7 @@ export default function Index() {
|
|||||||
onChange={(val) => { validationForm(val, 'title') }} />
|
onChange={(val) => { validationForm(val, 'title') }} />
|
||||||
</View>
|
</View>
|
||||||
<View>
|
<View>
|
||||||
<ButtonForm text="SIMPAN" disabled={Object.values(error).some((v) => v == true) || titleChoose == ""} onPress={() => { handleEdit() }} />
|
<ButtonForm text="SIMPAN" disabled={Object.values(error).some((v) => v == true) || titleChoose == "" || loadingSubmit} onPress={() => { handleEdit() }} />
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export default function Index() {
|
|||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([])
|
||||||
const [search, setSearch] = useState('')
|
const [search, setSearch] = useState('')
|
||||||
const [nameGroup, setNameGroup] = useState('')
|
const [nameGroup, setNameGroup] = useState('')
|
||||||
|
const [loadingSubmit, setLoadingSubmit] = useState(false)
|
||||||
const [chooseData, setChooseData] = useState({ name: '', id: '', active: false, idGroup: '' })
|
const [chooseData, setChooseData] = useState({ name: '', id: '', active: false, idGroup: '' })
|
||||||
const [error, setError] = useState({
|
const [error, setError] = useState({
|
||||||
name: false,
|
name: false,
|
||||||
@@ -94,15 +95,20 @@ export default function Index() {
|
|||||||
|
|
||||||
async function handleEdit() {
|
async function handleEdit() {
|
||||||
try {
|
try {
|
||||||
|
setLoadingSubmit(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiEditPosition({ user: hasil, name: chooseData.name, idGroup: chooseData.idGroup }, chooseData.id)
|
const response = await apiEditPosition({ user: hasil, name: chooseData.name, idGroup: chooseData.idGroup }, chooseData.id)
|
||||||
dispatch(setUpdatePosition(!update))
|
if (response.success) {
|
||||||
|
dispatch(setUpdatePosition(!update))
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: 'small', text1: response.message, })
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
|
setLoadingSubmit(false)
|
||||||
setVisibleEdit(false)
|
setVisibleEdit(false)
|
||||||
setModal(false)
|
setModal(false)
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil mengupdate data', })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -251,7 +257,7 @@ export default function Index() {
|
|||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View style={Styles.mb30}>
|
<View style={Styles.mb30}>
|
||||||
<ButtonForm text="SIMPAN" onPress={() => { handleEdit() }} disabled={Object.values(error).some((v) => v == true) || chooseData.name == ""} />
|
<ButtonForm text="SIMPAN" onPress={() => { handleEdit() }} disabled={Object.values(error).some((v) => v == true) || chooseData.name == "" || loadingSubmit} />
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
|
|||||||
@@ -73,12 +73,14 @@ export default function HeaderRightPositionList() {
|
|||||||
|
|
||||||
async function handleTambah() {
|
async function handleTambah() {
|
||||||
try {
|
try {
|
||||||
|
setDisable(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const response = await apiCreatePosition({ user: hasil, name: dataForm.name, idGroup: dataForm.idGroup })
|
const response = await apiCreatePosition({ user: hasil, name: dataForm.name, idGroup: dataForm.idGroup })
|
||||||
dispatch(setUpdatePosition(!update))
|
dispatch(setUpdatePosition(!update))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} finally {
|
||||||
|
setDisable(false)
|
||||||
setVisibleTambah(false)
|
setVisibleTambah(false)
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
||||||
|
|||||||
@@ -138,12 +138,8 @@ export const apiDeletePosition = async (data: { user: string, isActive: boolean
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const apiEditPosition = async (data: { user: string, name: string, idGroup: string }, id: string) => {
|
export const apiEditPosition = async (data: { user: string, name: string, idGroup: string }, id: string) => {
|
||||||
await api.put(`mobile/position/${id}`, data).then(response => {
|
const response = await api.put(`mobile/position/${id}`, data)
|
||||||
return response.data;
|
return response.data
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiGetUser = async ({ user, active, search, group, page }: { user: string, active: string, search: string, group?: string, page?: number }) => {
|
export const apiGetUser = async ({ user, active, search, group, page }: { user: string, active: string, search: string, group?: string, page?: number }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user