ERROR [AxiosError: Request failed with status code 401] // screens/ProgressScreen.js…
- User
ERROR [AxiosError: Request failed with status code 401] // screens/ProgressScreen.js import React from 'react'; import { ScrollView, StyleSheet } from 'react-native'; import ProgressInput from '../Components/ProgressInput'; import ProgressChart from '../Components/ProgressChart';
const ProgressScreen = ({ token }) => { return ( ); };
const styles = StyleSheet.create({ container: { padding: 20 }, });
export default ProgressScreen;
// components/ProgressInput.js import React, { useState } from 'react'; import { View, TextInput, Button, StyleSheet, Alert, ScrollView, Text } from 'react-native'; import axios from 'axios';
const ProgressInput = ({ token }) => { const [weight, setWeight] = useState(''); const [muscleMass, setMuscleMass] = useState(''); const [fatPercentage, setFatPercentage] = useState(''); const [chest, setChest] = useState(''); const [waist, setWaist] = useState(''); const [hips, setHips] = useState('');
const submitProgress = async () => { if (!weight || !muscleMass || !fatPercentage) { Alert.alert('Missing Data', 'Please fill in all required fields.'); return; } const payload = { weight: parseFloat(weight), muscleMass: parseFloat(muscleMass), fatPercentage: parseFloat(fatPercentage), measurements: { chest: chest ? parseFloat(chest) : undefined, waist: waist ? parseFloat(waist) : undefined, hips: hips ? parseFloat(hips) : undefined, } }; try { await axios.post('http://10.0.0.203:5000/api/progress', payload, { headers: { 'Authorization': token, 'Content-Type': 'application/json' } }); Alert.alert('Success', 'Progress recorded successfully!'); // Reset form setWeight(''); setMuscleMass(''); setFatPercentage(''); setChest(''); setWaist(''); setHips(''); } catch (err) { console.error(err); Alert.alert('Error', 'Failed to record progress.'); } }; return ( <ScrollView contentContainerStyle={styles.container}> <Text style={styles.label}>Weight (kg/lbs)</Text> <TextInput style={styles.input} value={weight} onChangeText={setWeight} keyboardType="numeric" placeholder="e.g., 70" /> <Text style={styles.label}>Muscle Mass (kg)</Text> <TextInput style={styles.input} value={muscleMass} onChangeText={setMuscleMass} keyboardType="numeric" placeholder="e.g., 30" /> <Text style={styles.label}>Fat Percentage (%)</Text> <TextInput style={styles.input} value={fatPercentage} onChangeText={setFatPercentage} keyboardType="numeric" placeholder="e.g., 15" /> <Text style={styles.label}>Chest (cm/in)</Text> <TextInput style={styles.input} value={chest} onChangeText={setChest} keyboardType="numeric" placeholder="optional" /> <Text style={styles.label}>Waist (cm/in)</Text> <TextInput style={styles.input} value={waist} onChangeText={setWaist} keyboardType="numeric" placeholder="optional" /> <Text style={styles.label}>Hips (cm/in)</Text> <TextInput style={styles.input} value={hips} onChangeText={setHips} keyboardType="numeric" placeholder="optional" /> <Button title="Submit Progress" onPress={submitProgress} /> </ScrollView> ); - Assistant