Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/controllers/verify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ class VerifyController < ApplicationController

check_or_render_not_found -> { IdentityConfig.store.idv_api_enabled }, only: [:show]

def show; end
def show
@app_data = app_data
end

private

def app_data
{
initial_values: { 'personalKey' => '0000-0000-0000-0000' },
}
end
end
12 changes: 12 additions & 0 deletions app/javascript/packages/form-steps/form-steps.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ describe('FormSteps', () => {
expect(event.returnValue).to.be.true();
});

context('promptOnNavigate prop is set to false', () => {
it('does not prompt on navigate', () => {
render(<FormSteps steps={STEPS} promptOnNavigate={false} />);

const event = new window.Event('beforeunload', { cancelable: true, bubbles: false });
window.dispatchEvent(event);

expect(event.defaultPrevented).to.be.false();
expect(event.returnValue).to.be.true();
});
});

it('pushes step to URL', () => {
const { getByText } = render(<FormSteps steps={STEPS} />);

Expand Down
9 changes: 8 additions & 1 deletion app/javascript/packages/form-steps/form-steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ interface FormStepsProps {
* Callback triggered on step change.
*/
onStepChange?: () => void;

/**
* Whether to prompt the user about unsaved changes when navigating away from an in-progress form.
* Defaults to true.
*/
promptOnNavigate?: boolean;
}

/**
Expand Down Expand Up @@ -164,6 +170,7 @@ function FormSteps({
initialValues = {},
initialActiveErrors = [],
autoFocus,
promptOnNavigate = true,
}: FormStepsProps) {
const [values, setValues] = useState(initialValues);
const [activeErrors, setActiveErrors] = useState(initialActiveErrors);
Expand Down Expand Up @@ -278,7 +285,7 @@ function FormSteps({

return (
<form ref={formRef} onSubmit={toNextStep}>
{Object.keys(values).length > 0 && <PromptOnNavigate />}
{promptOnNavigate && Object.keys(values).length > 0 && <PromptOnNavigate />}
{stepErrors.map((error) => (
<Alert key={error.message} type="error" className="margin-bottom-4">
{error.message}
Expand Down
12 changes: 10 additions & 2 deletions app/javascript/packages/verify-flow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { FormSteps } from '@18f/identity-form-steps';
import { STEPS } from './steps';

export function VerifyFlow() {
return <FormSteps steps={STEPS} />;
export interface VerifyFlowValues {
personalKey?: string;
}

interface VerifyFlowProps {
initialValues?: Partial<VerifyFlowValues>;
}

export function VerifyFlow({ initialValues = {} }: VerifyFlowProps) {
return <FormSteps steps={STEPS} initialValues={initialValues} promptOnNavigate={false} />;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
import { PageHeading, Button } from '@18f/identity-components';
import { t } from '@18f/identity-i18n';
import { formatHTML } from '@18f/identity-react-i18n';
import { FormStepsContinueButton } from '@18f/identity-form-steps';
import type { FormStepComponentProps } from '@18f/identity-form-steps';
import type { VerifyFlowValues } from '../..';

interface PersonalKeyStepProps extends FormStepComponentProps<VerifyFlowValues> {}

function PersonalKeyStep({ value }: PersonalKeyStepProps) {
const personalKey = value.personalKey!;

function PersonalKeyStep() {
return (
<>
<PageHeading>{t('headings.personal_key')}</PageHeading>
<p>{t('instructions.personal_key.info')}</p>
<div className="full-width-box margin-y-5" />
<div className="full-width-box margin-y-5">
<div className="border-y border-primary-light bg-primary-lightest padding-y-3 text-center">
<h2 className="margin-y-0">{t('users.personal_key.header')}</h2>
<div className="bg-personal-key padding-top-4 margin-y-2">
<div className="padding-x-0 tablet:padding-x-1 padding-y-2 separator-text bg-pk-box">
{personalKey.split('-').map((segment) => (
<strong key={segment} className="separator-text__code">
{segment}
</strong>
))}
</div>
</div>
<p className="margin-y-0">
{formatHTML(
t('users.personal_key.generated_on_html', {
date: `<strong>${new Intl.DateTimeFormat([], {
dateStyle: 'long',
}).format()}</strong>`,
}),
{ strong: 'strong' },
)}
</p>
</div>
</div>
<Button isOutline className="margin-right-2 margin-bottom-2 tablet:margin-bottom-0">
{t('forms.backup_code.download')}
</Button>
Expand Down
7 changes: 6 additions & 1 deletion app/javascript/packs/verify-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ import { render } from 'react-dom';
import { VerifyFlow } from '@18f/identity-verify-flow';

const appRoot = document.getElementById('app-root')!;
render(<VerifyFlow />, appRoot);
let initialValues;
try {
initialValues = JSON.parse(appRoot.dataset.initialValues!);
} catch {}

render(<VerifyFlow initialValues={initialValues} />, appRoot);
2 changes: 1 addition & 1 deletion app/views/verify/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<div id="app-root"></div>
<%= content_tag(:div, '', id: 'app-root', data: @app_data) %>
<% javascript_packs_tag_once 'verify-flow' %>