-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverse anchor input control flow (#925)
* Use obj as props in mkAnchorInput * Extend anchorInput to avoid global IDs * Use proper mkAnchorInput in unknown login * Use proper z-inder for anchor tooltip * Remove unused dependency * Select anchorInput in unknown login
- Loading branch information
Showing
7 changed files
with
199 additions
and
217 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,58 @@ | ||
import { html, render } from "lit-html"; | ||
import { parseUserNumber } from "../../../utils/userNumber"; | ||
import { registerTentativeDevice } from "./registerTentativeDevice"; | ||
import { toggleErrorMessage } from "../../../utils/errorHelper"; | ||
import { mkAnchorInput } from "../../../components/anchorInput"; | ||
import { Connection } from "../../../utils/iiConnection"; | ||
|
||
const pageContent = (userNumber?: bigint) => html` | ||
<div class="l-container c-card c-card--highlight"> | ||
<hgroup> | ||
<h1 class="t-title t-title--main">New Device</h1> | ||
<p class="t-paragraph t-lead"> | ||
Please provide the Identity Anchor to which you want to add your device. | ||
</p> | ||
<p id="invalidAnchorMessage" class="is-hidden"> | ||
Please enter a valid Identity Anchor. | ||
</p> | ||
</hgroup> | ||
${mkAnchorInput("addDeviceUserNumber", userNumber).template} | ||
<div class="c-button-group"> | ||
<button | ||
@click="${ | ||
window.location.reload /* TODO: L2-309: do this without reload */ | ||
}" | ||
class="c-button c-button--secondary" | ||
id="addDeviceUserNumberCancel" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
class="c-button c-button--primary" | ||
id="addDeviceUserNumberContinue" | ||
> | ||
Continue | ||
</button> | ||
const pageContent = (connection: Connection, userNumber?: bigint) => { | ||
const anchorInput = mkAnchorInput({ | ||
inputId: "addDeviceUserNumber", | ||
userNumber, | ||
onSubmit: (userNumber) => registerTentativeDevice(userNumber, connection), | ||
}); | ||
|
||
return html` | ||
<div class="l-container c-card c-card--highlight"> | ||
<hgroup> | ||
<h1 class="t-title t-title--main">New Device</h1> | ||
<p class="t-paragraph t-lead"> | ||
Please provide the Identity Anchor to which you want to add your | ||
device. | ||
</p> | ||
<p id="invalidAnchorMessage" class="is-hidden"> | ||
Please enter a valid Identity Anchor. | ||
</p> | ||
</hgroup> | ||
${anchorInput.template} | ||
<div class="c-button-group"> | ||
<button | ||
@click="${ | ||
window.location.reload /* TODO: L2-309: do this without reload */ | ||
}" | ||
class="c-button c-button--secondary" | ||
id="addDeviceUserNumberCancel" | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
@click="${anchorInput.submit}" | ||
class="c-button c-button--primary" | ||
id="addDeviceUserNumberContinue" | ||
> | ||
Continue | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
`; | ||
}; | ||
|
||
/** | ||
* Entry point for the flow of adding a new authenticator when starting from the welcome view (by clicking 'Already have an anchor but using a new device?'). | ||
* This shows a prompt to enter the identity anchor to add this new device to. | ||
*/ | ||
export const addRemoteDevice = async ( | ||
export const addRemoteDevice = ( | ||
connection: Connection, | ||
userNumber?: bigint | ||
): Promise<void> => { | ||
): void => { | ||
const container = document.getElementById("pageContent") as HTMLElement; | ||
render(pageContent(userNumber), container); | ||
return init(connection); | ||
}; | ||
|
||
const init = (connection: Connection) => { | ||
const continueButton = document.getElementById( | ||
"addDeviceUserNumberContinue" | ||
) as HTMLButtonElement; | ||
const userNumberInput = document.getElementById( | ||
"addDeviceUserNumber" | ||
) as HTMLInputElement; | ||
|
||
userNumberInput.onkeypress = (e) => { | ||
// submit if user hits enter | ||
if (e.key === "Enter") { | ||
e.preventDefault(); | ||
continueButton.click(); | ||
} | ||
}; | ||
|
||
continueButton.onclick = async () => { | ||
const userNumber = parseUserNumber(userNumberInput.value); | ||
if (userNumber !== null) { | ||
toggleErrorMessage("addDeviceUserNumber", "invalidAnchorMessage", false); | ||
await registerTentativeDevice(userNumber, connection); | ||
} else { | ||
toggleErrorMessage("addDeviceUserNumber", "invalidAnchorMessage", true); | ||
userNumberInput.placeholder = "Please enter your Identity Anchor first"; | ||
} | ||
}; | ||
render(pageContent(connection, userNumber), container); | ||
}; |
Oops, something went wrong.