11 import React, {useState} from 'react';
22 import {
33 Alert,
44 Image,
55 SafeAreaView,
66 StatusBar,
77 StyleSheet,
88 View,
99 } from 'react-native';
1010 import Parse from 'parse/react-native';
1111 import {
1212 Button as PaperButton,
1313 Switch as PaperSwitch,
1414 Text as PaperText,
1515 TextInput as PaperTextInput,
1616 } from 'react-native-paper';
1717
1818 export const ProductCreation = () => {
1919
2020 const [productName, setProductName] = useState('');
2121 const [productQuantity, setProductQuantity] = useState('');
2222 const [productPrice, setProductPrice] = useState('');
2323 const [productAvailable, setProductAvailable] = useState(false);
2424 const [productExpirationDate, setProductExpirationDate] = useState('');
2525 const [productCategories, setProductCategories] = useState('');
2626
2727 const toggleProductAvailable = () => setProductAvailable(!productAvailable);
2828
2929 return (
3030 <>
3131 <StatusBar backgroundColor="#208AEC" />
3232 <SafeAreaView style={Styles.container}>
3333 <View style={Styles.header}>
3434 <Image
3535 style={Styles.header_logo}
3636 source={ { uri: 'https://blog.back4app.com/wp-content/uploads/2019/05/back4app-white-logo-500px.png', } }
3737 />
3838 <PaperText style={Styles.header_text_bold}>
3939 {'React Native on Back4App'}
4040 </PaperText>
4141 <PaperText style={Styles.header_text}>{'Product Creation'}</PaperText>
4242 </View>
4343 <View style={Styles.wrapper}>
4444 {}
4545 <View style={Styles.switch_container}>
4646 <PaperText>{'Available?'}</PaperText>
4747 <PaperSwitch
4848 value={productAvailable}
4949 onValueChange={toggleProductAvailable}
5050 />
5151 </View>
5252 {}
5353 <PaperTextInput
5454 value={productName}
5555 onChangeText={(text) => setProductName(text)}
5656 label="Name"
5757 mode="outlined"
5858 style={Styles.form_input}
5959 />
6060 {}
6161 <PaperTextInput
6262 value={productQuantity}
6363 onChangeText={(text) => setProductQuantity(text)}
6464 label="Quantity"
6565 mode="outlined"
6666 keyboardType={'number-pad'}
6767 style={Styles.form_input}
6868 />
6969 {}
7070 <PaperTextInput
7171 value={productPrice}
7272 onChangeText={(text) => setProductPrice(text)}
7373 label="Price"
7474 mode="outlined"
7575 keyboardType={'numeric'}
7676 style={Styles.form_input}
7777 />
7878 {}
7979 <PaperTextInput
8080 value={productExpirationDate}
8181 onChangeText={(text) => setProductExpirationDate(text)}
8282 label="Expiration Date (mm/dd/yyyy)"
8383 mode="outlined"
8484 keyboardType={'numbers-and-punctuation'}
8585 style={Styles.form_input}
8686 />
8787 {}
8888 <PaperTextInput
8989 value={productCategories}
9090 onChangeText={(text) => setProductCategories(text)}
9191 label="Categories (separated by commas)"
9292 mode="outlined"
9393 style={Styles.form_input}
9494 />
9595 {}
9696 <PaperButton
9797 onPress={() => createProduct()}
9898 mode="contained"
9999 icon="plus"
100100 style={Styles.submit_button}>
101101 {'Create Product'}
102102 </PaperButton>
103103 </View>
104104 </SafeAreaView>
105105 </>
106106 );
107107 };
108108
109109
110110 const Styles = StyleSheet.create({
111111 container: {
112112 flex: 1,
113113 backgroundColor: '#FFF',
114114 },
115115 wrapper: {
116116 width: '90%',
117117 alignSelf: 'center',
118118 },
119119 header: {
120120 alignItems: 'center',
121121 paddingTop: 10,
122122 paddingBottom: 20,
123123 backgroundColor: '#208AEC',
124124 },
125125 header_logo: {
126126 width: 170,
127127 height: 40,
128128 marginBottom: 10,
129129 resizeMode: 'contain',
130130 },
131131 header_text_bold: {
132132 color: '#fff',
133133 fontSize: 14,
134134 fontWeight: 'bold',
135135 },
136136 header_text: {
137137 marginTop: 3,
138138 color: '#fff',
139139 fontSize: 14,
140140 },
141141 form_input: {
142142 height: 44,
143143 marginBottom: 16,
144144 backgroundColor: '#FFF',
145145 fontSize: 14,
146146 },
147147 switch_container: {
148148 flexDirection: 'row',
149149 alignItems: 'center',
150150 justifyContent: 'space-between',
151151 paddingVertical: 12,
152152 marginBottom: 16,
153153 borderBottomWidth: 1,
154154 borderBottomColor: 'rgba(0, 0, 0, 0.3)',
155155 },
156156 submit_button: {
157157 width: '100%',
158158 maxHeight: 50,
159159 alignSelf: 'center',
160160 backgroundColor: '#208AEC',
161161 },
162162 });