-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
209 lines (192 loc) · 6.08 KB
/
App.js
File metadata and controls
209 lines (192 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import React, { Component } from 'react';
import { Animated, Alert, AlertIOS, Image, StyleSheet, Text, View, Easing, Dimensions, Linking } from 'react-native';
import { LinearGradient, Font, AppLoading } from 'expo';
import Expo from 'expo';
import { Button, Card, Icon} from 'react-native-elements';
import firebase from 'firebase';
import { isNumber } from 'util';
var config = {
};
if(!firebase.apps.length) {
firebase.initializeApp(config);
}
function saveReservation(customerName, numberReservations, paymentMethod){
var today = new Date();
var day = (today.getDate() < 10) ? '0'+today.getDate() : today.getDate();
var month = today.getMonth()+1;//(today.getMonth()+1 < 10) ? today.getMonth()+1 : toString(today.getMonth()+1);
var year = today.getFullYear();
today = month+'/'+day+'/'+year;
var dateReservation = today;
//Save JSON of string
firebase.database().ref("Client Reservations/"+customerName+"/").set({
customerName,
numberReservations,
paymentMethod,
dateReservation
}).then((data) => {
console.log("data", data);
}).catch((error) => {
console.log("error", error)
})
}
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
name: "",
photoURL: "",
isReady: false,
imageHW: new Animated.Value(300),
numReservations: 0,
locationText: "Sproul Hall @ 1:30 P.M.",
}
this.buttonRef = React.createRef();
}
signIn = async () => {
try {
const result = await Expo.Google.logInAsync({
androidClientId: "",
webClientId: "",
iosClientId: "",
scopes: ["profile", "email"]
})
if(result.type === "success") {
this.setState({
signedIn: true,
name: result.user.name,
photoURL: result.user.photoUrl,
});
this.reserveButtonClicked();
} else {
console.log("Login Failed");
}
} catch (e) {
console.log("error", e)
}
}
reserveButtonClicked() {
//1. Check if user logged in
if(this.state.signedIn) {
console.log(this.state.name);
AlertIOS.prompt(
'Number of Reservations:',
'Enter number of reservations for ' + this.state.name + ':',
[ {
text: 'Cancel',
onPress: () => console.log("no reservations this time"),
style: 'cancel'
},
{
text: 'OK',
onPress: (value) => this.checkInput(value)
}
]
)
}
else {
//Login using Google
Alert.alert(
'Authentication Required',
'Please Sign In to continue your reservation!',
[
{text: 'Cancel', onPress: () => console.log("Cancel button pressed"), style: 'cancel'},
{text: 'Will Do!', onPress: () => this.signIn()}
],
{cancelable: false}
);
}
}
checkInput(value) {
console.log(parseInt(value));
if(isNumber(parseInt(value)) && parseInt(value) > 0) {
var intValue = parseInt(value);
Alert.alert(
'Your total for ' + intValue+' meals: $' + intValue*7+'.00',
'Please select your preferred payment method: ',
[
{text: 'PayPal', onPress: () => this.handleReservation(this.state.name, value, "PayPal (paid)")},
{text: 'Cash', onPress: () => this.handleReservation(this.state.name, value, "Cash (collect)")},
{text: 'Back', onPress: () => this.reserveButtonClicked()}
],
{cancelable: false}
);
}
else {
Alert.alert(
'Invalid Reservation Number',
'Please enter a valid number of reservations.',
[
{text: 'OK', onPress: () => this.reserveButtonClicked()}
],
{cancelable: false}
);
}
}
handleReservation(name, amount, paymentMethod) {
saveReservation(name, amount, paymentMethod);
//Call method to change the Reserve button
//this.buttonRef.current.disabled=true;
}
locationIconClicked() {
var locOnly = this.state.locationText.split('@')[0];
Linking.openURL("http://maps.google.com/maps?q=" + locOnly.replace(' ','+'));
}
componentDidMount() {
Animated.loop(
Animated.sequence([
Animated.timing(this.state.imageHW, {
toValue: 310,
duration: 1000,
ease: Easing.bounce
}),
Animated.timing(this.state.imageHW, {
toValue: 300,
duration: 1000,
ease: Easing.bounce
})
])
).start();
}
async componentWillMount() {
await Font.loadAsync({
'zuliapro': require('./assets/fonts/ZuliaPro.otf')
});
this.setState({isReady:true})
}
render() {
if (!this.state.isReady) {
return <AppLoading />;
}
return (
<LinearGradient style={styles.container} colors={['#f59937', '#fb9875', '#cd6385']}>
<View style={{flex: 2}}>
<Text style={{top:50, color: '#fff', fontSize: 50, fontFamily: 'zuliapro'}}>Mealy</Text>
</View>
<View style={{flex: 4}}>
<Animated.Image style={{resizeMode: 'contain', width: this.state.imageHW, height:this.state.imageHW}} source={require('./assets/img/meal1.png')} />
</View>
<View style={{flex: 2}}>
<Text style={{color: '#fff', fontSize: 40, textAlign: 'center'}}>$7 Beef with rice</Text>
<View style={{flexDirection: 'row', justifyContent: 'center'}}>
<Text
style={{color: '#fff', fontSize: 20, textAlign: 'center'}}> {this.state.locationText}
</Text>
<Icon name='location-on' color='white' onPress={this.locationIconClicked.bind(this)} />
</View>
</View>
<View style={{flex: 2}}>
<Button large fontWeight='bold' rounded={true} title='Reserve Now!' backgroundColor='#fdbf2e' onPress={this.reserveButtonClicked.bind(this)}/>
</View>
</LinearGradient>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'transparent',
alignItems: 'center',
justifyContent: 'space-between'
},
});