|
|
|
@ -1,11 +1,10 @@
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput } from 'react-native';
|
|
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
|
import * as DocumentPicker from 'expo-document-picker';
|
|
|
|
|
import TopBar from '../components/TopBar';
|
|
|
|
|
import { addXlsFile } from '../redux/actions/sessions';
|
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
import * as DocumentPicker from 'expo-document-picker';
|
|
|
|
|
export default function NewTrack(props: { navigation: any }) {
|
|
|
|
|
const { navigation } = props;
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
@ -28,20 +27,103 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const handleConfirm = async () => {
|
|
|
|
|
// if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// const formData = new FormData();
|
|
|
|
|
// formData.append('file', {
|
|
|
|
|
// uri: pickedDocument.uri,
|
|
|
|
|
// type: pickedDocument.type,
|
|
|
|
|
// name: pickedDocument.name,
|
|
|
|
|
// });
|
|
|
|
|
// try {
|
|
|
|
|
// await dispatch(addXlsFile(formData, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training'));
|
|
|
|
|
// navigation.goBack();
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.log('Error - POST FILE', error);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
// const handleConfirm = async () => {
|
|
|
|
|
// if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// try {
|
|
|
|
|
// const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
|
|
|
|
|
// const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weekend&nameCircuit=test_CIRCUIT&typeSession=Training';
|
|
|
|
|
// const options = {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// body: file,
|
|
|
|
|
// headers: {
|
|
|
|
|
// 'Content-Type': 'application/octet-stream',
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
// await fetch(url, options);
|
|
|
|
|
// navigation.goBack();
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.log('Error - POST FILE', error);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
// const handleConfirm = async () => {
|
|
|
|
|
// if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// try {
|
|
|
|
|
// const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
|
|
|
|
|
// const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weekend&nameCircuit=test_CIRCUIT&typeSession=Training';
|
|
|
|
|
// const options = {
|
|
|
|
|
// method: 'POST',
|
|
|
|
|
// body: file,
|
|
|
|
|
// headers: {
|
|
|
|
|
// 'Content-Type': 'application/octet-stream',
|
|
|
|
|
// },
|
|
|
|
|
// };
|
|
|
|
|
// const response = await fetch(url, options);
|
|
|
|
|
// const responseData = await response.text(); // or response.text() or response.blob() depending on the expected response type
|
|
|
|
|
// navigation.goBack();
|
|
|
|
|
// console.log(responseData);
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
// console.log('Error - POST FILE', error);
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
const handleConfirm = async () => {
|
|
|
|
|
if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await dispatch(addXlsFile(pickedDocument.uri, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training'));
|
|
|
|
|
const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
|
|
|
|
|
const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weeke&nameCircuit=test_CIRCUIT&typeSession=Training';
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
// formData.append('pseudoPilote', 'test_PILOTE');
|
|
|
|
|
// formData.append('nameSession', sessionName);
|
|
|
|
|
// formData.append('nameCircuit', 'test_CIRCUIT');
|
|
|
|
|
// formData.append('typeSession', 'Training');
|
|
|
|
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: file,
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: '*/*',
|
|
|
|
|
'Content-Type': 'multipart/form-data',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error('Failed to upload file');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
console.log('API response:', data);
|
|
|
|
|
navigation.goBack();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('Error - POST FILE', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SafeAreaView>
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|