Skip to content

Commit 3c7be0f

Browse files
committed
polish(settings): Add callback so calling code knows when MfaGuard is dismissed.
1 parent 234a1d8 commit 3c7be0f

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

packages/fxa-settings/src/components/Settings/MfaGuard/index.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,20 @@ describe('MfaGuard', () => {
220220
expect(mockAlertBar.error).toHaveBeenCalledWith('Unexpected error');
221221
});
222222
});
223+
224+
it('invokes onDismiss when dialog is dismissed', async () => {
225+
const mockOnDismiss = jest.fn().mockResolvedValue(undefined);
226+
227+
renderWithRouter(
228+
<AppContext.Provider value={mockAppContext()}>
229+
<MfaGuard requiredScope={mockScope} onDismissCallback={mockOnDismiss}>
230+
<div>secured</div>
231+
</MfaGuard>
232+
</AppContext.Provider>
233+
);
234+
235+
await userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
236+
237+
expect(mockOnDismiss).toHaveBeenCalledTimes(1);
238+
});
223239
});

packages/fxa-settings/src/components/Settings/MfaGuard/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ import { getLocalizedErrorMessage } from '../../../lib/error-utils';
3838
export const MfaGuard = ({
3939
children,
4040
requiredScope,
41+
onDismissCallback = async () => {},
4142
}: {
4243
children: ReactNode;
4344
requiredScope: MfaScope;
45+
onDismissCallback?: () => Promise<void>;
4446
}) => {
4547
// Let errors be handled by error boundaries in async contexts
4648
const handleError = useErrorHandler();
@@ -76,9 +78,11 @@ export const MfaGuard = ({
7678
const alertBar = useAlertBar();
7779

7880
const onDismiss = useCallback(() => {
79-
resetStates();
80-
navigate('/settings');
81-
}, [navigate, resetStates]);
81+
onDismissCallback().then(() => {
82+
resetStates();
83+
navigate('/settings');
84+
});
85+
}, [navigate, resetStates, onDismissCallback]);
8286

8387
// If no session token exists, kick them to sign-in
8488
if (!sessionToken) {

0 commit comments

Comments
 (0)