/
ContactRequest.js
111 lines (104 loc) · 2.42 KB
/
ContactRequest.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
import React, { Component } from 'react'
import { TextInput, Text, View, Button, Alert, StyleSheet } from 'react-native'
import { graphql, commitMutation } from 'react-relay'
import environment from '../../relay.js'
var fields = {
id: '',
email: '',
phone: '',
}
export default class ContactRequest extends Component {
render = () => {
return (
<View style={styles.contactView}>
<Input
label='Berty ID'
placeholder='Please enter a Berty ID ...'
type='username'
state='id'
/>
<Input
label='Email address'
placeholder='Please enter an email address ...'
type='emailAddress'
state='email'
/>
<Input
label='Phone number'
placeholder='Please enter a phone number ...'
type='telephoneNumber'
state='phone'
/>
<Button title='Request' onPress={handleRequestButton} />
</View>
)
}
}
class Input extends Component {
render = () => {
return (
<View>
<Text style={styles.label}>{this.props.label}</Text>
<TextInput
onChangeText={text => {
fields[this.props.state] = text
}}
style={styles.input}
placeholder={this.props.placeholder}
textContentType={this.props.type}
/>
</View>
)
}
}
const mutation = graphql`
mutation ContactRequestMutation($id: String) {
ContactRequest(id: $id) {
id
}
}
`
const commit = (variables = {}) =>
commitMutation(environment, {
mutation,
variables,
onCompleted: (res, errs) =>
console.log('Response receive from server.', res, errs),
onError: err => console.error(err),
})
function handleRequestButton () {
let body = `
Contact request sent:
Berty ID = ${fields['id']}
Email Adress = ${fields['email']}
Phone number = ${fields['phone']}
`
console.log(body)
Alert.alert(
'Request',
body,
[{ text: 'OK', onPress: () => console.log('OK Pressed') }],
{ cancelable: false }
)
commit({ id: fields['id'] })
}
const styles = StyleSheet.create({
contactView: {
marginTop: 50,
alignItems: 'center',
justifyContent: 'center',
},
input: {
borderColor: 'gray',
borderBottomWidth: 1,
width: 350,
height: 30,
fontSize: 20,
marginTop: 5,
marginBottom: 30,
},
label: {
fontSize: 16,
fontWeight: 'bold',
},
})