-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneNumber.jsx
More file actions
89 lines (83 loc) · 2.67 KB
/
PhoneNumber.jsx
File metadata and controls
89 lines (83 loc) · 2.67 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
import '../App.css';
import React from 'react';
import FormSection from './FormSection'
class PhoneNumber extends React.Component {
constructor() {
super();
this.state = {value: ""};
}
handleChange = (e) => {
this.setState({value: e.target.value})
}
handleSubmit = () => {
const { innerWidth } = window;
const newPageUrl = innerWidth < 1024 ? `http://api.whatsapp.com/send?phone=91${this.state.value}` : `http://web.whatsapp.com/send?phone=91${this.state.value}`
window.open(newPageUrl, "_blank")
}
render() {
const {value} = this.state
const phoneRegEx = new RegExp(/^[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-/\s.]?[0-9]{4}$/);
const valid = phoneRegEx.test(value)
// if(valid){
// return(
// <Form>
// <FormGroup>
// <Label for="exampleEmail">
// Phone Number
// </Label>
// <Input
// autoFocus="autofocus"
// valid
// value={value}
// onChange={this.handleChange}
// />
// <FormText>Number Count : {value.length || 0}</FormText>
// <FormFeedback valid>Sweet! You are good to go</FormFeedback>
// </FormGroup>
// <Button color="success" disabled={!valid} onClick={this.handleSubmit}>Send</Button>
// </Form>
// )}
// else {
// return(
// <Form>
// <FormGroup>
// <Label for="exampleEmail">
// Phone Number
// </Label>
// {value.length === 0 ?
// <React.Fragment>
// <Input
// autoFocus="autofocus"
// value={value}
// onChange={this.handleChange}
// />
// <FormText>Number Count : {value.length || 0}</FormText>
// </React.Fragment>
// :
// <React.Fragment>
// <Input
// autoFocus="autofocus"
// invalid
// value={value}
// onChange={this.handleChange}
// />
// <FormText>Number Count : {value.length || 0}</FormText>
// <FormFeedback>Oh noes! check the number again</FormFeedback>
// </React.Fragment>
// }
// </FormGroup>
// <Button color="success" disabled={!valid} onClick={this.handleSubmit}>Send</Button>
// </Form>
// )
// }
return (
<FormSection
{...this.state}
valid={valid}
handleChange={this.handleChange}
handleSubmit={this.handleSubmit}
/>
)
}
}
export default PhoneNumber