Skip to content
Snippets Groups Projects
Commit f339b739 authored by Antoine Marquis's avatar Antoine Marquis
Browse files

equipment and simple fetch on new_place

parent d383ad22
No related branches found
No related tags found
No related merge requests found
import { useState } from "react";
import { TextInput, View, Text, Button, StyleSheet, Dimensions, ScrollView, TouchableOpacity } from "react-native";
import { baseIPAddress } from "../../../constants/server";
import { window } from "../../../constants/Layout";
import { TextInput, View, Text, StyleSheet, Dimensions, ScrollView, TouchableOpacity, Checkbox } from "react-native";
import { baseIPAddress, newPlacePath } from "../../../constants/server";
import { SelectInput } from "../../components/form/select";
export default function NewPlace() {
......@@ -12,21 +11,60 @@ export default function NewPlace() {
const [placesRestantes, setplacesRestantes] = useState("");
const [prix, setprix] = useState("");
const [type, settype] = useState("");
const [equip, setequip] = useState({});
const [isMainCity, setIsMainCity] = useState(true);
const [isMainType, setIsMainType] = useState(true);
const cityList = ["Compiègne", "Margny", "Venette"]
const typeList = ["Maison", "Appartement", "Studio"]
const equipmentList = ["wifi", "canap"]
{
let dic = {}
equipmentList.forEach(element => {
dic[element] = false
});
setequip(dic)
}
function createPlace() {
if (!address || !city || !name || !prix || !type)
{
//Render error
/**
* If a necessary var is undefined, render a user friendly error
*/
return
}
/**
* Création de l'object JSON
*/
let place =
{
"formatted_address": [address, city].join(", "),
"name": name,
"place_restant": placesRestantes,
"price": prix,
"types": type,
"equipment" : equip
}
/**
* Appel du back avec fetch
* Either render an error or go to the next page
*/
let ans = fetch(baseIPAddress + newPlacePath, {
method: "post",
body: JSON.stringify(place)
})
}
console.log("Attente de la request")
function modifyElement(map, i, newVal)
{
map[i] = newVal
return map
}
......@@ -65,6 +103,13 @@ export default function NewPlace() {
<TouchableOpacity style={{borderRadius:1, backgroundColor:"black", padding:10, width:180}} onPress={createPlace}>
<Text style={{fontSize:16, color:"white", fontWeight:"bold", textAlign:"center"}}>Ajouter le logement</Text>
</TouchableOpacity>
<View style={{flexDirection:"row"}}>
{equipmentList.map((item) =>{
return (
<Checkbox value={equip[item]} onValueChange={(val) => setequip(modifyElement(val))} />
)
})}
</View>
</ScrollView>
</View>
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment