You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.7 KiB
71 lines
1.7 KiB
import { env } from 'process' |
|
import React, { FormEvent } from 'react' |
|
import { useState } from 'react' |
|
import { useHistory } from 'react-router-dom' |
|
import { createClient } from '../api' |
|
import settings from '../settings' |
|
|
|
export const Dashboard = () => { |
|
const history = useHistory() |
|
const [name, setName] = useState('') |
|
const [email, setEmail] = useState('') |
|
const [phone, setPhone] = useState('') |
|
|
|
const handleReset = () => { |
|
// |
|
setName('') |
|
setEmail('') |
|
setPhone('') |
|
} |
|
|
|
const handleSubmit = async (e: FormEvent) => { |
|
e.preventDefault() |
|
|
|
if (settings.env === 'jank') { |
|
history.push(`/sessions/${phone}`) |
|
return |
|
} |
|
|
|
await createClient({ name, email, phone: parseInt(phone) }) |
|
history.push(`/sessions/${phone}`) |
|
} |
|
|
|
return ( |
|
<div> |
|
<h1>Dashboard</h1> |
|
<form onSubmit={handleSubmit}> |
|
<label htmlFor="name"> |
|
Name: |
|
<input |
|
value={name} |
|
onChange={(e) => setName(e.target.value)} |
|
name="name" |
|
/> |
|
</label> |
|
<label htmlFor="email"> |
|
Email: |
|
<input |
|
value={email} |
|
onChange={(e) => setEmail(e.target.value)} |
|
type="email" |
|
name="email" |
|
/> |
|
</label> |
|
<label htmlFor="phone"> |
|
Phone: |
|
<input |
|
value={phone} |
|
onChange={(e) => setPhone(e.target.value)} |
|
type="tel" |
|
name="phone" |
|
/> |
|
</label> |
|
<button type="submit">Start Session</button> |
|
<button type="button" onClick={handleReset}> |
|
Reset |
|
</button> |
|
</form> |
|
<div>TODO: List of past sessions for review?</div> |
|
</div> |
|
) |
|
}
|
|
|