import { StyleSheet, TextInput, View, Image } from "react-native"; import { useState } from "react"; import Button from "@components/Button"; import { colors } from "@components/style"; import * as ImagePicker from "expo-image-picker"; import { Picker } from "@react-native-picker/picker"; export default function BeerAdd() { const [b_name, setBName] = useState(""); const [b_degree, setBDegree] = useState(""); const [b_packaging, setBPackaging] = useState(""); const [b_brand, setBBrand] = useState(""); const [image, setImage] = useState(null); const [selectPackaging, setSelectedPackaging] = useState(); ImagePicker.getCameraPermissionsAsync(); //check if the user has granted permission to access the camera const pickImage = async () => { // No permissions request is necessary for launching the image library let result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ImagePicker.MediaTypeOptions.All, allowsEditing: true, aspect: [4, 3], quality: 1, }); console.log(result); if (!result.canceled) { setImage(result.assets[0].uri); } }; async function addBeer() { // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/add`, { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ brand: b_brand, name: b_name, degree: b_degree, packaging: b_packaging, photos: null, }), }); const res = await req.json(); if (res.success & res.new_beer_id) { window.location.href = `/beer/${res.new_beer_id}`; } else { alert( "Beer was not added successfully. Please check your data and try again.", ); } } return ( setBName(text)} placeholderTextColor="#aaaaaa" /> setBBrand(text)} placeholderTextColor="#aaaaaa" /> setBDegree(text)} placeholderTextColor="#aaaaaa" /> setBPackaging(text)} placeholderTextColor="#aaaaaa" /> setSelectedPackaging(itemValue) } >