|
|
@ -3,23 +3,45 @@ import { Pressable, StyleSheet, Text, View, Image, TouchableOpacity, TextInput }
|
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
import * as DocumentPicker from 'expo-document-picker';
|
|
|
|
import * as DocumentPicker from 'expo-document-picker';
|
|
|
|
import TopBar from '../components/TopBar';
|
|
|
|
import TopBar from '../components/TopBar';
|
|
|
|
|
|
|
|
import { addXlsFile } from '../redux/actions/sessions';
|
|
|
|
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
|
|
|
|
export default function NewTrack(props: { navigation: any }) {
|
|
|
|
export default function NewTrack(props: { navigation: any }) {
|
|
|
|
const { navigation } = props;
|
|
|
|
const { navigation } = props;
|
|
|
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
|
|
const [pickedDocument, setPickedDocument] = useState<DocumentPicker.DocumentResult | null>(null);
|
|
|
|
const [pickedDocument, setPickedDocument] = useState<DocumentPicker.DocumentResult | null>(null);
|
|
|
|
|
|
|
|
const [trackName, setTrackName] = useState('');
|
|
|
|
|
|
|
|
const [sessionName, setSessionName] = useState('');
|
|
|
|
|
|
|
|
|
|
|
|
const handlePickDocument = async () => {
|
|
|
|
const handlePickDocument = async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const result = await DocumentPicker.getDocumentAsync({ type: 'excel/xls' });
|
|
|
|
const result = await DocumentPicker.getDocumentAsync({});
|
|
|
|
if (result.type === 'success') {
|
|
|
|
if (result.type === 'success') {
|
|
|
|
setPickedDocument(result);
|
|
|
|
setPickedDocument(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(result.type === 'cancel'){
|
|
|
|
|
|
|
|
console.log("AAA");
|
|
|
|
|
|
|
|
setPickedDocument(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleConfirm = async () => {
|
|
|
|
|
|
|
|
if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
await dispatch(addXlsFile(pickedDocument.uri, 'test_PILOTE', 'test@gmail.com', 'test123', sessionName, trackName, 'Training'));
|
|
|
|
|
|
|
|
navigation.goBack();
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.log('Error - POST FILE', error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<SafeAreaView>
|
|
|
|
<SafeAreaView>
|
|
|
|
<View style={styles.container}>
|
|
|
|
<View style={styles.container}>
|
|
|
@ -33,7 +55,8 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
<Text style={{ paddingTop: 20 }}>Track name: </Text>
|
|
|
|
<Text style={{ paddingTop: 20 }}>Track name: </Text>
|
|
|
|
<TextInput
|
|
|
|
<TextInput
|
|
|
|
style={styles.textInput}
|
|
|
|
style={styles.textInput}
|
|
|
|
secureTextEntry={true}
|
|
|
|
onChangeText={setTrackName}
|
|
|
|
|
|
|
|
value={trackName}
|
|
|
|
placeholder="Track name"
|
|
|
|
placeholder="Track name"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
@ -42,7 +65,8 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
<Text style={{ paddingTop: 20 }}>Session name: </Text>
|
|
|
|
<Text style={{ paddingTop: 20 }}>Session name: </Text>
|
|
|
|
<TextInput
|
|
|
|
<TextInput
|
|
|
|
style={styles.textInput}
|
|
|
|
style={styles.textInput}
|
|
|
|
secureTextEntry={true}
|
|
|
|
onChangeText={setSessionName}
|
|
|
|
|
|
|
|
value={sessionName}
|
|
|
|
placeholder="Session name"
|
|
|
|
placeholder="Session name"
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
@ -67,7 +91,7 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
source={require('../assets/images/return.png')}
|
|
|
|
source={require('../assets/images/return.png')}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</Pressable>
|
|
|
|
</Pressable>
|
|
|
|
<Pressable style={styles.button} onPress={() => navigation.goBack()}>
|
|
|
|
<Pressable style={styles.button} onPress={handleConfirm}>
|
|
|
|
<Image
|
|
|
|
<Image
|
|
|
|
style={styles.return}
|
|
|
|
style={styles.return}
|
|
|
|
source={require('../assets/images/checked.png')}
|
|
|
|
source={require('../assets/images/checked.png')}
|
|
|
|