update: dokumen divisi
Deskripis: - loading saat updload file - upload multiple file No Issues
This commit is contained in:
@@ -6,7 +6,7 @@ import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons";
|
|||||||
import * as DocumentPicker from "expo-document-picker";
|
import * as DocumentPicker from "expo-document-picker";
|
||||||
import { useLocalSearchParams } from "expo-router";
|
import { useLocalSearchParams } from "expo-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { View } from "react-native";
|
import { ActivityIndicator, View } from "react-native";
|
||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import ButtonMenuHeader from "../buttonMenuHeader";
|
import ButtonMenuHeader from "../buttonMenuHeader";
|
||||||
@@ -46,26 +46,31 @@ export default function HeaderRightDocument({ path }: { path: string }) {
|
|||||||
const pickDocumentAsync = async () => {
|
const pickDocumentAsync = async () => {
|
||||||
let result = await DocumentPicker.getDocumentAsync({
|
let result = await DocumentPicker.getDocumentAsync({
|
||||||
type: ["*/*"],
|
type: ["*/*"],
|
||||||
multiple: false,
|
multiple: true,
|
||||||
});
|
});
|
||||||
if (!result.canceled) {
|
if (!result.canceled) {
|
||||||
if (result.assets?.[0].uri) {
|
let file: any[] = []
|
||||||
handleUploadFile(result.assets?.[0])
|
for (let i = 0; i < result.assets?.length; i++) {
|
||||||
|
if (result.assets?.[i].uri) {
|
||||||
|
file.push(result.assets?.[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
handleUploadFile(file)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function handleUploadFile(file: any) {
|
async function handleUploadFile(file: any[]) {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current))
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
fd.append("file", {
|
for (let i = 0; i < file.length; i++) {
|
||||||
uri: file.uri,
|
fd.append(`file${i}`, {
|
||||||
|
uri: file[i].uri,
|
||||||
type: "application/octet-stream",
|
type: "application/octet-stream",
|
||||||
name: file.name,
|
name: file[i].name,
|
||||||
} as any);
|
} as any);
|
||||||
|
}
|
||||||
fd.append(
|
fd.append(
|
||||||
"data",
|
"data",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -73,7 +78,7 @@ export default function HeaderRightDocument({ path }: { path: string }) {
|
|||||||
idDivision: id,
|
idDivision: id,
|
||||||
user: hasil,
|
user: hasil,
|
||||||
})
|
})
|
||||||
);
|
)
|
||||||
|
|
||||||
const response = await apiUploadFileDocument({ data: fd })
|
const response = await apiUploadFileDocument({ data: fd })
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
@@ -106,6 +111,13 @@ export default function HeaderRightDocument({ path }: { path: string }) {
|
|||||||
title="Menu"
|
title="Menu"
|
||||||
>
|
>
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
|
{
|
||||||
|
loading ?
|
||||||
|
<View style={[Styles.contentItemCenter, Styles.w100, Styles.h100]}>
|
||||||
|
<ActivityIndicator size="large" />
|
||||||
|
</View>
|
||||||
|
:
|
||||||
|
<>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={
|
icon={
|
||||||
<MaterialCommunityIcons
|
<MaterialCommunityIcons
|
||||||
@@ -128,6 +140,8 @@ export default function HeaderRightDocument({ path }: { path: string }) {
|
|||||||
title="Upload File"
|
title="Upload File"
|
||||||
onPress={pickDocumentAsync}
|
onPress={pickDocumentAsync}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
</DrawerBottom>
|
</DrawerBottom>
|
||||||
<ModalFloat
|
<ModalFloat
|
||||||
|
|||||||
Reference in New Issue
Block a user