-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create hasty user-entry screen and gate with password (#76)
* Create hasty user-entry screen and gate with password * Add hint text and format validation errors properly * Add password to env.example and main parameters json * Remove comment * rename chatbot password to authpassword
- Loading branch information
1 parent
b1e194f
commit 91e3358
Showing
8 changed files
with
1,419 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
CHAT_URL_API=http://localhost:8010/api/chat | ||
NEXT_PUBLIC_BUILD_NUMBER=20240101.1 | ||
NEXT_PUBLIC_BUILD_NUMBER=20240101.1 | ||
AUTH_PASSWORD=fb1a3bb9-7b35-47e2-8a45-44db18215912 |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import classNames from 'classnames'; | ||
import { SubmitHandler, useForm } from 'react-hook-form'; | ||
|
||
interface AuthData { | ||
password: string; | ||
} | ||
|
||
const UserCredentialEntry = ({ onCorrectEntry, authPassword }: Props) => { | ||
const { | ||
register, | ||
formState: { errors }, | ||
setError, | ||
handleSubmit, | ||
} = useForm<AuthData>(); | ||
|
||
const onSubmit: SubmitHandler<AuthData> = (data) => { | ||
if (data.password === authPassword) { | ||
onCorrectEntry(); | ||
} else { | ||
setError('password', { message: 'Incorrect password', type: 'wrong' }); | ||
} | ||
}; | ||
|
||
return ( | ||
<form id="user-input-form" onSubmit={handleSubmit(onSubmit)}> | ||
<div className={classNames('govuk-form-group')}> | ||
<div className="govuk-form-group"> | ||
<h1 className="govuk-label-wrapper"> | ||
<label | ||
className="govuk-label govuk-label--l" | ||
htmlFor="auth-password" | ||
> | ||
Please enter the password | ||
</label> | ||
</h1> | ||
<div id="account-number-hint" className="govuk-hint"> | ||
This service is still a prototype - access is restricted. | ||
</div> | ||
{errors.password?.type === 'wrong' && ( | ||
<p id="passport-issued-error" className="govuk-error-message"> | ||
<span className="govuk-visually-hidden">Error:</span>The password | ||
was incorrect | ||
</p> | ||
)} | ||
{errors.password?.type === 'required' && ( | ||
<p id="passport-issued-error" className="govuk-error-message"> | ||
<span className="govuk-visually-hidden">Error:</span>A password is | ||
required | ||
</p> | ||
)} | ||
<input | ||
{...register('password', { | ||
required: true, | ||
})} | ||
className="govuk-input" | ||
id="auth-password" | ||
name="password" | ||
type="password" | ||
/> | ||
</div> | ||
<br /> | ||
<button className="govuk-button" data-module="govuk-button"> | ||
Enter | ||
</button> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
interface Props { | ||
onCorrectEntry: () => void; | ||
authPassword?: string; | ||
} | ||
|
||
export default UserCredentialEntry; |
Oops, something went wrong.