-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎯 merge pull request #5 from lachlanshoesmith/bugfix/handle-duplicate…
…-phone-numbers 📱 bugfix - handle duplicate phone numbers
- Loading branch information
Showing
10 changed files
with
209 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,8 @@ | |
margin: 0 0.5rem; | ||
} | ||
} | ||
|
||
.smallText { | ||
color: #999; | ||
font-size: 0.5rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,6 @@ | |
color-scheme: light dark; | ||
color: #dbdbdb; | ||
background-color: #222; | ||
max-width: 480px; | ||
margin: 0 auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,64 @@ | ||
import { Form } from 'react-router-dom'; | ||
import Button from '../components/Button/Button'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { useState } from 'react'; | ||
|
||
function login() { | ||
type Inputs = { | ||
username: string; | ||
password: string; | ||
}; | ||
|
||
export default function Login() { | ||
const { | ||
register, | ||
formState: { errors }, | ||
handleSubmit, | ||
} = useForm<Inputs>(); | ||
const [loginErrors, setLoginErrors] = useState(''); | ||
|
||
const onSubmit: SubmitHandler<Inputs> = async (data) => { | ||
const res = await fetch('https://webdevcamp.fly.dev/login', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const responseJSON = await res.json(); | ||
const responseDetail: string = responseJSON.detail; | ||
|
||
if (!res.ok) { | ||
setLoginErrors(responseDetail); | ||
} else { | ||
console.log(responseDetail); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<h1>Login Page</h1> | ||
<Form method="get"> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<input | ||
type="text" | ||
{...register('username', { | ||
required: true, | ||
minLength: 3, | ||
maxLength: 20, | ||
})} | ||
aria-invalid={errors.username ? 'true' : 'false'} | ||
placeholder="Username" | ||
/> | ||
<input | ||
type="password" | ||
{...register('password', { | ||
required: true, | ||
minLength: 8, | ||
})} | ||
aria-invalid={errors.password ? 'true' : 'false'} | ||
placeholder="Password" | ||
/> | ||
<Button type="submit">Login</Button> | ||
</Form> | ||
</form> | ||
{loginErrors && <p>{loginErrors}</p>} | ||
</> | ||
); | ||
} | ||
|
||
export default login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import Button from '../components/Button/Button'; | ||
import { useForm, SubmitHandler } from 'react-hook-form'; | ||
import { useState } from 'react'; | ||
|
||
type Inputs = { | ||
given_name: string; | ||
family_name: string; | ||
username: string; | ||
hashed_password: string; | ||
account_type: string; | ||
email: string; | ||
phone_number: string; | ||
}; | ||
|
||
export default function Register() { | ||
const { | ||
register, | ||
formState: { errors }, | ||
handleSubmit, | ||
} = useForm<Inputs>(); | ||
const [registerErrors, setRegisterErrors] = useState(''); | ||
|
||
const onSubmit: SubmitHandler<Inputs> = async (data) => { | ||
data.account_type = 'administrator'; | ||
const res = await fetch('https://webdevcamp.fly.dev/register', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const responseJSON = await res.json(); | ||
|
||
if (!res.ok) { | ||
setRegisterErrors(responseJSON.detail); | ||
} else { | ||
console.log(res.json()); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<h1>Register new administrator</h1> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<input | ||
type="text" | ||
{...register('given_name', { | ||
required: true, | ||
})} | ||
aria-invalid={errors.given_name ? 'true' : 'false'} | ||
placeholder="Given name" | ||
/> | ||
<input | ||
type="text" | ||
{...register('family_name', { | ||
required: true, | ||
})} | ||
aria-invalid={errors.family_name ? 'true' : 'false'} | ||
placeholder="Family name" | ||
/> | ||
<input | ||
type="text" | ||
{...register('username', { | ||
required: true, | ||
minLength: 3, | ||
maxLength: 20, | ||
})} | ||
aria-invalid={errors.username ? 'true' : 'false'} | ||
placeholder="Username" | ||
/> | ||
<input | ||
type="password" | ||
{...register('hashed_password', { | ||
required: true, | ||
minLength: 8, | ||
})} | ||
aria-invalid={errors.hashed_password ? 'true' : 'false'} | ||
placeholder="Password" | ||
/> | ||
<input | ||
type="email" | ||
{...register('email', { | ||
required: true, | ||
})} | ||
aria-invalid={errors.email ? 'true' : 'false'} | ||
placeholder="Email" | ||
/> | ||
<input | ||
type="text" | ||
{...register('phone_number', { | ||
required: false, | ||
})} | ||
aria-invalid={errors.phone_number ? 'true' : 'false'} | ||
placeholder="Phone number" | ||
/> | ||
<Button type="submit">Register</Button> | ||
</form> | ||
{registerErrors && <p>{registerErrors}</p>} | ||
</> | ||
); | ||
} |