2021-03-08 03:45:57 +00:00
|
|
|
import { Content } from 'antd/lib/layout/layout'
|
2021-03-08 02:17:00 +00:00
|
|
|
import React, { FormEvent } from 'react'
|
2021-03-08 01:18:51 +00:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { useHistory } from 'react-router-dom'
|
|
|
|
import { createClient } from '../api'
|
2021-03-08 02:17:00 +00:00
|
|
|
import settings from '../settings'
|
2021-03-08 01:18:51 +00:00
|
|
|
|
|
|
|
export const Dashboard = () => {
|
|
|
|
const history = useHistory()
|
2021-03-08 03:08:18 +00:00
|
|
|
const [error, setError] = useState<string | null>(null)
|
2021-03-08 01:18:51 +00:00
|
|
|
const [name, setName] = useState('')
|
|
|
|
const [email, setEmail] = useState('')
|
|
|
|
const [phone, setPhone] = useState('')
|
|
|
|
|
|
|
|
const handleReset = () => {
|
|
|
|
//
|
2021-03-08 02:17:00 +00:00
|
|
|
setName('')
|
|
|
|
setEmail('')
|
|
|
|
setPhone('')
|
2021-03-08 01:18:51 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 02:17:00 +00:00
|
|
|
const handleSubmit = async (e: FormEvent) => {
|
|
|
|
e.preventDefault()
|
2021-03-08 01:18:51 +00:00
|
|
|
|
2021-03-08 03:08:18 +00:00
|
|
|
if (phone.length < 10) {
|
|
|
|
// helpful message
|
|
|
|
setError('Phone number needs to be a length of at least 10')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-08 02:17:00 +00:00
|
|
|
if (settings.env === 'jank') {
|
|
|
|
history.push(`/sessions/${phone}`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await createClient({ name, email, phone: parseInt(phone) })
|
2021-03-08 01:18:51 +00:00
|
|
|
history.push(`/sessions/${phone}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-03-08 03:45:57 +00:00
|
|
|
<Content>
|
2021-03-08 01:18:51 +00:00
|
|
|
<h1>Dashboard</h1>
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<label htmlFor="name">
|
|
|
|
Name:
|
2021-03-08 02:17:00 +00:00
|
|
|
<input
|
|
|
|
value={name}
|
|
|
|
onChange={(e) => setName(e.target.value)}
|
|
|
|
name="name"
|
|
|
|
/>
|
2021-03-08 01:18:51 +00:00
|
|
|
</label>
|
|
|
|
<label htmlFor="email">
|
|
|
|
Email:
|
2021-03-08 02:17:00 +00:00
|
|
|
<input
|
|
|
|
value={email}
|
|
|
|
onChange={(e) => setEmail(e.target.value)}
|
|
|
|
type="email"
|
|
|
|
name="email"
|
|
|
|
/>
|
2021-03-08 01:18:51 +00:00
|
|
|
</label>
|
|
|
|
<label htmlFor="phone">
|
|
|
|
Phone:
|
2021-03-08 02:17:00 +00:00
|
|
|
<input
|
|
|
|
value={phone}
|
|
|
|
onChange={(e) => setPhone(e.target.value)}
|
|
|
|
type="tel"
|
|
|
|
name="phone"
|
|
|
|
/>
|
2021-03-08 01:18:51 +00:00
|
|
|
</label>
|
|
|
|
<button type="submit">Start Session</button>
|
2021-03-08 02:17:00 +00:00
|
|
|
<button type="button" onClick={handleReset}>
|
|
|
|
Reset
|
|
|
|
</button>
|
2021-03-08 03:08:18 +00:00
|
|
|
{error && <p className="error">{error}</p>}
|
2021-03-08 01:18:51 +00:00
|
|
|
</form>
|
2021-03-08 03:45:57 +00:00
|
|
|
</Content>
|
2021-03-08 01:18:51 +00:00
|
|
|
)
|
|
|
|
}
|