-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfirmRide.js
113 lines (102 loc) · 3.31 KB
/
ConfirmRide.js
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
/**
* Copyright (c) Grab Taxi Holdings PTE LTD (GRAB)
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as GrabID from '@grab-id/grab-id-client/dist/bundle';
import React, { Component } from 'react';
import { getDestination } from '../repo/DestinationsRepo';
import Hero from './Hero';
import { clientConfig } from '../config';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
const styles = theme => ({
paper: {
padding: theme.spacing.unit * 2,
height: '100%',
color: theme.palette.text.secondary,
},
card: {
marginTop: 20,
padding: 8,
},
});
class ConfirmRide extends Component {
static getDerivedStateFromProps(props, state) {
if (state && state.destination && state.destination.id !== props.propertyId) {
return {
destination: getDestination(props.propertyId),
};
}
return null;
}
constructor ({date, propertyId, onGoHome}) {
super();
const destination = getDestination(propertyId);
this.state ={destination};
let appConfig = {
clientId: clientConfig.clientId,
redirectUri: `${window.location.origin}/token.html`,
scope: clientConfig.scopes.join(' '),
acrValues: {
service: 'PASSENGER',
consentContext: {
countryCode: 'sg'
}
}
};
this.grabClient = new GrabID(clientConfig.openIdUrl, appConfig);
this.grabClient.makeTokenRequest()
.then(() => {
let tokenResult = GrabID.getResult();
window.fetch("https://" + clientConfig.grabApiDomain + "/grabid/v1/oauth2/userinfo", {
method: 'GET',
headers: {
'Accept-Content': 'application/json; charset=utf-8',
Authorization: "Bearer " + tokenResult.accessToken,
},
mode: 'cors',
})
.then((response) => {
response.json().then((userInfo) => {
this.setState({
userName: userInfo.name,
userEmail: userInfo.email,
});
});
})
});
}
render() {
const {classes} = this.props;
return(
<React.Fragment>
<Hero imageUri='/images/grab-food.jpg' titleText='Happy travel with Grab' />
<Grid container justify='center' alignItems='center' className={classes.paper}>
<Grid item xs={6}>
<Paper className={classes.card}>
<Typography gutterBottom variant="headline" component="p">
Your ride to {this.state.destination.title} is confirmed!
</Typography>
<Typography gutterBottom variant="subheading" component="p">
Name: {this.state.userName}
</Typography>
<Typography gutterBottom variant="subheading" component="p">
Email: {this.state.userEmail}
</Typography>
<Button color='secondary' onClick={this.props.onGoHome}>
Return Home
</Button>
</Paper>
</Grid>
</Grid>
</React.Fragment>
);
}
}
export default withStyles(styles)(ConfirmRide);