fleet/frontend/components/forms/RegistrationForm/ConfirmationPage/ConfirmationPage.tsx
Jacob Shandling cb75b975d0
UI: Fix and improve tab experience in setup flow (#11194)
## Addresses #10913 
- Fixes the bug(s) outlined in the issue
- Improves look and feel of the tabbing experience throughout the setup
flow: https://www.loom.com/share/c482317d18314e629b7e5ebab7fd2840

## Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-04-18 10:34:21 -07:00

117 lines
3.2 KiB
TypeScript

import React, { useEffect } from "react";
import classnames from "classnames";
import Button from "components/buttons/Button";
import { IRegistrationFormData } from "interfaces/registration_form_data";
import Checkbox from "components/forms/fields/Checkbox";
const baseClass = "confirm-user-reg";
interface IConfirmationPageProps {
className: string;
currentPage: boolean;
formData: IRegistrationFormData;
handleSubmit: React.FormEventHandler<HTMLFormElement>;
}
const ConfirmationPage = ({
className,
currentPage,
formData,
handleSubmit,
}: IConfirmationPageProps): JSX.Element => {
useEffect(() => {
if (currentPage) {
// Component has a transition duration of 300ms set in
// RegistrationForm/_styles.scss. We need to wait 300ms before
// calling .focus() to preserve smooth transition.
setTimeout(() => {
// wanted to use React ref here instead of class but ref is already used
// in Button.tsx, which could break other button uses
const confirmationButton = document.querySelector(
`.${baseClass} button.button--brand`
) as HTMLElement;
confirmationButton?.focus();
}, 300);
}
}, [currentPage]);
const importOsqueryConfig = () => {
const disableImport = true;
if (disableImport) {
return false;
}
return (
<div className={`${baseClass}__import`}>
<Checkbox name="import-install">
<p>
I am migrating an existing <strong>osquery</strong> installation.
</p>
<p>
Take me to the <strong>Import Configuration</strong> page.
</p>
</Checkbox>
</div>
);
};
const { email, server_url: serverUrl, org_name: orgName, name } = formData;
const tabIndex = currentPage ? 0 : -1;
const confirmRegClasses = classnames(className, baseClass);
return (
<form
onSubmit={handleSubmit}
className={confirmRegClasses}
autoComplete="off"
>
<div className={`${baseClass}__wrapper`}>
<table className={`${baseClass}__table`}>
<caption>Administrator configuration</caption>
<tbody>
<tr>
<th>Full name:</th>
<td>{name}</td>
</tr>
<tr>
<th>Email:</th>
<td className={`${baseClass}__table-email`}>{email}</td>
</tr>
<tr>
<th>Organization:</th>
<td>{orgName}</td>
</tr>
<tr>
<th>Fleet URL:</th>
<td>
<span className={`${baseClass}__table-url`} title={serverUrl}>
{serverUrl}
</span>
</td>
</tr>
</tbody>
</table>
{importOsqueryConfig()}
</div>
<p>
Fleet Device Management Inc. periodically collects information about
your instance. Sending usage statistics from your Fleet instance is
optional and can be disabled in settings.
</p>
<Button
type="submit"
tabIndex={tabIndex}
disabled={!currentPage}
variant="brand"
>
Confirm
</Button>
</form>
);
};
export default ConfirmationPage;