upd: button save
Deskripsi: - disable button saat udh submit No Issues
This commit is contained in:
@@ -30,6 +30,7 @@ export default function EditBanner() {
|
||||
const [title, setTitle] = useState("");
|
||||
const [error, setError] = useState(false);
|
||||
const [imgForm, setImgForm] = useState<any>();
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const pickImageAsync = async () => {
|
||||
let result = await ImagePicker.launchImageLibraryAsync({
|
||||
@@ -71,6 +72,7 @@ export default function EditBanner() {
|
||||
|
||||
const handleUpdateEntity = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const fd = new FormData();
|
||||
|
||||
@@ -105,6 +107,8 @@ export default function EditBanner() {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
Toast.show({ type: 'small', text1: 'Gagal mengupdate data', })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -122,7 +126,7 @@ export default function EditBanner() {
|
||||
headerTitle: "Edit Banner",
|
||||
headerTitleAlign: "center",
|
||||
headerRight: () => <ButtonSaveHeader
|
||||
disable={title == "" || error ? true : false}
|
||||
disable={title == "" || error || loading ? true : false}
|
||||
onPress={() => { handleUpdateEntity() }}
|
||||
category="update" />,
|
||||
}}
|
||||
|
||||
@@ -29,6 +29,7 @@ export default function CreateBanner() {
|
||||
const [imgForm, setImgForm] = useState<any>();
|
||||
const [title, setTitle] = useState("");
|
||||
const [error, setError] = useState(false);
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const pickImageAsync = async () => {
|
||||
let result = await ImagePicker.launchImageLibraryAsync({
|
||||
@@ -57,32 +58,40 @@ export default function CreateBanner() {
|
||||
}
|
||||
|
||||
const handleCreateEntity = async () => {
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const fd = new FormData();
|
||||
try {
|
||||
setLoading(true)
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const fd = new FormData();
|
||||
|
||||
fd.append("file", {
|
||||
uri: imgForm.uri,
|
||||
type: imgForm.mimeType,
|
||||
name: imgForm.fileName,
|
||||
} as any);
|
||||
fd.append("file", {
|
||||
uri: imgForm.uri,
|
||||
type: imgForm.mimeType,
|
||||
name: imgForm.fileName,
|
||||
} as any);
|
||||
|
||||
fd.append(
|
||||
"data",
|
||||
JSON.stringify({
|
||||
title,
|
||||
user: hasil,
|
||||
})
|
||||
);
|
||||
|
||||
const createdEntity = await apiCreateBanner(fd);
|
||||
if (createdEntity.success) {
|
||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
||||
apiGetBanner({ user: hasil }).then((data) =>
|
||||
dispatch(setEntities(data.data))
|
||||
fd.append(
|
||||
"data",
|
||||
JSON.stringify({
|
||||
title,
|
||||
user: hasil,
|
||||
})
|
||||
);
|
||||
router.back();
|
||||
} else {
|
||||
|
||||
const createdEntity = await apiCreateBanner(fd);
|
||||
if (createdEntity.success) {
|
||||
Toast.show({ type: 'small', text1: 'Berhasil menambahkan data', })
|
||||
apiGetBanner({ user: hasil }).then((data) =>
|
||||
dispatch(setEntities(data.data))
|
||||
);
|
||||
router.back();
|
||||
} else {
|
||||
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
Toast.show({ type: 'small', text1: 'Gagal menambahkan data', })
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,7 +110,7 @@ export default function CreateBanner() {
|
||||
headerTitleAlign: "center",
|
||||
headerRight: () => (
|
||||
<ButtonSaveHeader
|
||||
disable={title == "" || selectedImage == undefined || error ? true : false}
|
||||
disable={title == "" || selectedImage == undefined || error || loading ? true : false}
|
||||
category="create"
|
||||
onPress={() => {
|
||||
handleCreateEntity();
|
||||
|
||||
Reference in New Issue
Block a user