Use of api instead of json file for the creating, deletion and edition
This commit is contained in:
@@ -6,16 +6,15 @@ import {
|
||||
ScrollView,
|
||||
} from "react-native";
|
||||
import { TextInput, Button, Snackbar } from "react-native-paper";
|
||||
import useLocationStore from "@/store";
|
||||
import { addLocation } from "@/api/locations";
|
||||
|
||||
export default function FormScreen() {
|
||||
const addLocation = useLocationStore((state) => state.addLocation);
|
||||
const [formData, setFormData] = useState({
|
||||
name: "",
|
||||
description: "",
|
||||
image: "",
|
||||
area: "",
|
||||
population: "",
|
||||
area: 0,
|
||||
population: 0,
|
||||
});
|
||||
const [message, setMessage] = useState("");
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -33,8 +32,8 @@ export default function FormScreen() {
|
||||
name: formData.name,
|
||||
description: formData.description,
|
||||
image: formData.image,
|
||||
area: formData.area,
|
||||
population: formData.population,
|
||||
area: parseFloat(formData.area),
|
||||
population: parseInt(formData.population),
|
||||
};
|
||||
|
||||
addLocation(newLocation);
|
||||
@@ -43,11 +42,16 @@ export default function FormScreen() {
|
||||
name: "",
|
||||
description: "",
|
||||
image: "",
|
||||
area: "",
|
||||
population: "",
|
||||
area: 0,
|
||||
population: 0,
|
||||
});
|
||||
setMessage("Lokalizacja została dodana!");
|
||||
setVisible(true);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user