-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add secret recovery request form.
- Loading branch information
Showing
14 changed files
with
440 additions
and
45 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
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
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
118 changes: 118 additions & 0 deletions
118
src/pages/public/secretrecoveryrequest/SecretRecoveryRequestForm.tsx
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,118 @@ | ||
import { UUID } from "@logion/node-api"; | ||
import { useCallback } from "react"; | ||
import { Form } from "react-bootstrap"; | ||
import { Control, Controller, FieldErrors, UseFormSetValue } from "react-hook-form"; | ||
import Button from "src/common/Button"; | ||
import { BackgroundAndForegroundColors } from "src/common/ColorTheme"; | ||
import FormGroup from "src/common/FormGroup"; | ||
import { useLogionChain } from "src/logion-chain"; | ||
|
||
export interface FormValues { | ||
locId: string; | ||
secretName: string; | ||
challenge: string; | ||
} | ||
|
||
export interface Props { | ||
control: Control<FormValues>; | ||
errors: FieldErrors<FormValues>; | ||
colors: BackgroundAndForegroundColors; | ||
setValue: UseFormSetValue<FormValues>; | ||
} | ||
|
||
export default function SecretRecoveryRequestForm(props: Props) { | ||
const { control, errors, colors, setValue } = props; | ||
const { client } = useLogionChain(); | ||
|
||
const validateLocId = useCallback(async (locIdString: string) => { | ||
const locId = UUID.fromAnyString(locIdString); | ||
if(locId === undefined) { | ||
return "Invalid LOC ID"; | ||
} | ||
if(client) { | ||
const loc = await client?.public.findLocById({ locId }); | ||
if(loc === undefined) { | ||
return "LOC not found"; | ||
} | ||
if(loc.data.locType !== "Identity") { | ||
return "LOC is not an Identity LOC"; | ||
} | ||
if(loc.data.status !== "CLOSED") { | ||
return "LOC is not closed"; | ||
} | ||
} | ||
}, [ client ]); | ||
|
||
return ( | ||
<div className="SecretRecoveryRequestForm"> | ||
<FormGroup | ||
id="locId" | ||
label="Identity LOC ID" | ||
control={ | ||
<Controller | ||
name="locId" | ||
control={ control } | ||
defaultValue="" | ||
rules={ { validate: validateLocId } } | ||
render={ ({ field }) => ( | ||
<Form.Control | ||
isInvalid={ !!errors.locId?.message } | ||
type="text" | ||
{ ...field } | ||
/> | ||
) } | ||
/> | ||
} | ||
feedback={ errors.locId?.message } | ||
colors={ colors } | ||
/> | ||
<FormGroup | ||
id="secretName" | ||
label="Secret name" | ||
control={ | ||
<Controller | ||
name="secretName" | ||
control={ control } | ||
defaultValue="" | ||
rules={ { required: "Secret name is required" } } | ||
render={ ({ field }) => ( | ||
<Form.Control | ||
isInvalid={ !!errors.secretName?.message } | ||
type="text" | ||
{ ...field } | ||
/> | ||
) } | ||
/> | ||
} | ||
feedback={ errors.secretName?.message } | ||
colors={ colors } | ||
/> | ||
<FormGroup | ||
id="challenge" | ||
label="Challenge" | ||
control={ | ||
<Controller | ||
name="challenge" | ||
control={ control } | ||
defaultValue="" | ||
rules={ { required: "A challenge is required" } } | ||
render={ ({ field }) => ( | ||
<Form.Control | ||
isInvalid={ !!errors.challenge?.message } | ||
type="text" | ||
{ ...field } | ||
/> | ||
) } | ||
/> | ||
} | ||
feedback={ errors.challenge?.message } | ||
colors={ colors } | ||
/> | ||
|
||
<p>The challenge is a random value that is attached to your request. <strong>You will have to provide it again | ||
upon actual secret retrieval. Make sure to keep it in a safe place until the procedure is over.</strong></p> | ||
|
||
<Button onClick={ () => setValue("challenge", window.crypto.randomUUID()) }>Generate random challenge</Button> | ||
</div> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/pages/public/secretrecoveryrequest/SecretRecoveryRequestFormPage.css
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,33 @@ | ||
.SecretRecoveryRequestFormPage { | ||
background-color: #0c163d; | ||
padding-top: 30px; | ||
padding-bottom: 30px; | ||
min-height: 100vh; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .container > .row { | ||
margin-bottom: 30px; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .container > .row:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .alert-container { | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .success-frame { | ||
text-align: center; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .success-icon { | ||
margin-bottom: 30px; | ||
} | ||
|
||
.SecretRecoveryRequestFormPage .challenge { | ||
text-align: center; | ||
font-weight: bold; | ||
font-size: 1.5rem; | ||
} |
Oops, something went wrong.