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
14 changes: 13 additions & 1 deletion app/assets/stylesheets/components/_spinner-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ lg-spinner-button {
button:not([type]),
[type='submit'],
[type='button'] {
background-color: color('primary-darker');
color: transparent;
opacity: 1;
}
}

&:not(.spinner-button--outline) .spinner-button__content {
a,
button:not([type]),
[type='submit'],
[type='button'] {
background-color: color('primary-darker');
}

.spinner-dots {
color: color('white');
}
}
}

.spinner-button__action-message {
Expand Down
6 changes: 3 additions & 3 deletions app/components/spinner_button_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<lg-spinner-button>
<%= content_tag(:'lg-spinner-button', class: css_class) do %>
<div class="spinner-button__content">
<%= render ButtonComponent.new(type: :button, **button_options).with_content(content) %>
<span class="spinner-dots spinner-dots--centered text-white" aria-hidden="true">
<span class="spinner-dots spinner-dots--centered" aria-hidden="true">
<span class="spinner-dots__dot"></span>
<span class="spinner-dots__dot"></span>
<span class="spinner-dots__dot"></span>
Expand All @@ -13,4 +13,4 @@
data: { message: action_message },
class: 'spinner-button__action-message usa-sr-only' %>
<% end %>
</lg-spinner-button>
<% end %>
7 changes: 6 additions & 1 deletion app/components/spinner_button_component.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
class SpinnerButtonComponent < BaseComponent
attr_reader :action_message, :button_options
attr_reader :action_message, :button_options, :outline

# @param [String] action_message Message describing the action being performed, shown visually to
# users when the animation has been active for a long time, and
# immediately to users of assistive technology.
def initialize(action_message: nil, **button_options)
@action_message = action_message
@button_options = button_options
@outline = button_options[:outline]
end

def css_class
'spinner-button--outline' if outline
end
end
23 changes: 23 additions & 0 deletions app/controllers/api/verify/password_reset_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Api
module Verify
class PasswordResetController < Api::BaseController
def create
analytics.idv_forgot_password_confirmed
request_id = sp_session[:request_id]
email = current_user.email
reset_password(email, request_id)

render json: { redirect_url: forgot_password_url(request_id: request_id) },
status: :accepted
end

private

def reset_password(email, request_id)
sign_out
RequestPasswordReset.new(email: email, request_id: request_id, analytics: analytics).perform
session[:email] = email
end
end
end
end
1 change: 0 additions & 1 deletion app/controllers/verify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class VerifyController < ApplicationController
before_action :confirm_profile_has_been_created, if: :first_step_is_personal_key?

def show
session[:email] = 'bruce.wayne@batcave.com'
@app_data = app_data
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ describe('SpinnerButton', () => {

expect(button.classList.contains('usa-button--outline')).to.be.true();
});

it('includes additional class for outline buttons', () => {
const { getByRole } = render(<SpinnerButton isOutline />);

const button = getByRole('button')!;
const spinner = button.closest('lg-spinner-button')!;

expect(spinner.classList.contains('spinner-button--outline')).to.be.true();
});
});
17 changes: 13 additions & 4 deletions app/javascript/packages/spinner-button/spinner-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare global {
namespace JSX {
interface IntrinsicElements {
'lg-spinner-button': HTMLAttributes<SpinnerButtonElement> &
RefAttributes<SpinnerButtonElement>;
RefAttributes<SpinnerButtonElement> & { class?: string };
}
}
}
Expand All @@ -34,21 +34,30 @@ interface SpinnerButtonProps extends ButtonProps {
export type SpinnerButtonRefHandle = SpinnerButtonElement;

function SpinnerButton(
{ spinOnClick = true, actionMessage, longWaitDurationMs, ...buttonProps }: SpinnerButtonProps,
{
spinOnClick = true,
actionMessage,
longWaitDurationMs,
isOutline,
...buttonProps
}: SpinnerButtonProps,
ref: ForwardedRef<SpinnerButtonElement | null>,
) {
const elementRef = useRef<SpinnerButtonRefHandle>(null);
useImperativeHandle(ref, () => elementRef.current!);

const classes = isOutline ? 'spinner-button--outline' : undefined;

return (
<lg-spinner-button
spin-on-click={spinOnClick}
long-wait-duration-ms={longWaitDurationMs}
ref={elementRef}
class={classes}
>
<div className="spinner-button__content">
<Button {...buttonProps} />
<span className="spinner-dots spinner-dots--centered text-white" aria-hidden="true">
<Button isOutline={isOutline} {...buttonProps} />
<span className="spinner-dots spinner-dots--centered" aria-hidden="true">
<span className="spinner-dots__dot" />
<span className="spinner-dots__dot" />
<span className="spinner-dots__dot" />
Expand Down
5 changes: 0 additions & 5 deletions app/javascript/packages/verify-flow/context/flow-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const FlowContext = createContext({
* The path to which the current step is appended to create the current step URL.
*/
basePath: '',

/**
* URL for reset password page in rails used for redirect
*/
resetPasswordUrl: '',
});

FlowContext.displayName = 'FlowContext';
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/packages/verify-flow/services/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ErrorResponse<Field extends string> {
export interface ErrorResponse<Field extends string = string> {
error: Record<Field, [string, ...string[]]>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('StartOverOrCancel', () => {
cancelURL: 'http://example.test/cancel',
currentStep: 'one',
basePath: '',
resetPasswordUrl: '',
}}
>
<StartOverOrCancel />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { useContext } from 'react';
import { PageHeading, Button } from '@18f/identity-components';
import { t } from '@18f/identity-i18n';
import { getAssetPath } from '@18f/identity-assets';
import { FlowContext } from '@18f/identity-verify-flow';
import PasswordResetButton from './password-reset-button';

interface ForgotPasswordProps {
goBack: () => void;
}

export function ForgotPassword({ goBack }: ForgotPasswordProps) {
const { resetPasswordUrl } = useContext(FlowContext);

function goToResetPassword() {
window.location.href = resetPasswordUrl!;
}

return (
<>
<img
Expand All @@ -36,9 +29,7 @@ export function ForgotPassword({ goBack }: ForgotPasswordProps) {
</Button>
</div>
<div className="margin-top-2">
<Button isBig isOutline isWide onClick={goToResetPassword}>
{t('idv.forgot_password.reset_password')}
</Button>
<PasswordResetButton />
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useSandbox } from '@18f/identity-test-helpers';
import PasswordResetButton, { API_ENDPOINT } from './password-reset-button';

describe('PasswordResetButton', () => {
const sandbox = useSandbox();

const REDIRECT_URL = '/password_reset';

before(() => {
sandbox
.stub(window, 'fetch')
.withArgs(API_ENDPOINT)
.resolves({
status: 202,
json: () => Promise.resolve({ redirect_url: REDIRECT_URL }),
} as Response);
});

it('triggers password reset API call and redirects', (done) => {
const { getByRole } = render(<PasswordResetButton onNavigate={() => done()} />);

const button = getByRole('button');
userEvent.click(button);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { SpinnerButton } from '@18f/identity-spinner-button';
import { t } from '@18f/identity-i18n';
import { isErrorResponse, post } from '../../services/api';
import type { ErrorResponse } from '../../services/api';

/**
* API endpoint for password reset.
*/
export const API_ENDPOINT = '/api/verify/v2/password_reset';

/**
* API response shape.
*/
interface PasswordResetSuccessResponse {
redirect_url: string;
}

/**
* API response shape.
*/
type PasswordResetResponse = PasswordResetSuccessResponse | ErrorResponse;

/**
* Navigates user to the given URL.
*
* @param url Destination URL.
*/
function navigate(url) {
window.location.href = url;
}

function PasswordResetButton({ onNavigate = navigate }) {
async function requestReset() {
const json = await post<PasswordResetResponse>(API_ENDPOINT, {}, { csrf: true, json: true });
if (!isErrorResponse(json)) {
const { redirect_url: redirectURL } = json;
onNavigate(redirectURL);
}
}

return (
<SpinnerButton isBig isOutline isWide onClick={requestReset}>
{t('idv.forgot_password.reset_password')}
</SpinnerButton>
);
}

export default PasswordResetButton;
8 changes: 1 addition & 7 deletions app/javascript/packages/verify-flow/verify-flow.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ describe('VerifyFlow', () => {
const onComplete = sandbox.spy();

const { getByText, findByText, getByLabelText } = render(
<VerifyFlow
initialValues={{ personalKey }}
onComplete={onComplete}
basePath="/"
resetPasswordUrl=""
/>,
<VerifyFlow initialValues={{ personalKey }} onComplete={onComplete} basePath="/" />,
);

// Password confirm
Expand Down Expand Up @@ -64,7 +59,6 @@ describe('VerifyFlow', () => {
onComplete={() => {}}
enabledStepNames={[STEPS[1].name]}
basePath="/"
resetPasswordUrl=""
/>,
);

Expand Down
14 changes: 1 addition & 13 deletions app/javascript/packages/verify-flow/verify-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ interface VerifyFlowProps {
* Callback invoked after completing the form.
*/
onComplete: () => void;

/**
* URL for reset password page in rails used for redirect
*/
resetPasswordUrl: string;
}

/**
Expand Down Expand Up @@ -102,7 +97,6 @@ function VerifyFlow({
basePath,
startOverURL = '',
cancelURL = '',
resetPasswordUrl,
onComplete,
}: VerifyFlowProps) {
let steps = STEPS;
Expand All @@ -114,13 +108,7 @@ function VerifyFlow({
const [currentStep, setCurrentStep] = useState(steps[0].name);
const [values, setValues] = useState(syncedValues);
const [initialStep, setCompletedStep] = useInitialStepValidation(basePath, steps);
const context = useObjectMemo({
startOverURL,
cancelURL,
currentStep,
basePath,
resetPasswordUrl,
});
const context = useObjectMemo({ startOverURL, cancelURL, currentStep, basePath });
useEffect(() => {
logStepVisited(currentStep);
}, [currentStep]);
Expand Down
7 changes: 0 additions & 7 deletions app/javascript/packs/verify-flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ interface AppRootValues {
*/
storeKey: string;

/**
* URL for reset password page in rails used for redirect
*/
resetPasswordUrl: string;

/**
* Signed JWT containing user data.
*/
Expand All @@ -62,7 +57,6 @@ const {
startOverUrl: startOverURL,
cancelUrl: cancelURL,
completionUrl: completionURL,
resetPasswordUrl,
storeKey: storeKeyBase64,
} = appRoot.dataset;
const storeKey = s2ab(atob(storeKeyBase64));
Expand Down Expand Up @@ -106,7 +100,6 @@ const storage = new SecretSessionStorage<SecretValues>('verify');
enabledStepNames={enabledStepNames}
startOverURL={startOverURL}
cancelURL={cancelURL}
resetPasswordUrl={resetPasswordUrl}
basePath={basePath}
onComplete={onComplete}
/>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@

namespace :api do
post '/verify/v2/password_confirm' => 'verify/password_confirm#create'
post '/verify/v2/password_reset' => 'verify/password_reset#create'
end

get '/account/verify' => 'idv/gpo_verify#index', as: :idv_gpo_verify
Expand Down
8 changes: 8 additions & 0 deletions spec/components/spinner_button_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
expect(rendered).to have_css('.spinner-button__action-message[data-message="Verifying..."]')
end
end

context 'with outline button' do
it 'renders with additional css class' do
rendered = render_inline SpinnerButtonComponent.new(outline: true).with_content('')

expect(rendered).to have_css('lg-spinner-button.spinner-button--outline')
end
end
end
Loading