import { useState } from "react"; import { StyleSheet, Platform, KeyboardAvoidingView, ScrollView, } from "react-native"; import { TextInput, Button, Snackbar } from "react-native-paper"; import { addLocation } from "@/api/locations"; export default function FormScreen() { const [formData, setFormData] = useState({ name: "", description: "", image: "", area: 0, population: 0, }); const [message, setMessage] = useState(""); const [visible, setVisible] = useState(false); const handleAddLocation = () => { if ( formData.name && formData.description && formData.image && formData.area && formData.population ) { const newLocation = { id: Date.now(), name: formData.name, description: formData.description, image: formData.image, area: parseFloat(formData.area), population: parseInt(formData.population), }; addLocation(newLocation); setFormData({ name: "", description: "", image: "", area: 0, population: 0, }); if(addLocation != null) { setMessage("Lokalizacja została dodana!"); setVisible(true); } else { setMessage("Wystąpił błąd podczas dodawania lokalizacji!"); setVisible(true); } } else { setMessage("Wypełnij wszystkie pola!"); setVisible(true); } }; return ( setVisible(false)} duration={3000} > {message} setFormData({ ...formData, name: e })} /> setFormData({ ...formData, description: e })} /> setFormData({ ...formData, image: e })} /> setFormData({ ...formData, area: e })} /> setFormData({ ...formData, population: e })} /> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#25292e", justifyContent: "flex-start", alignItems: "center", }, });