From f9b61a0d7fd29c201d2abc34a0d3b1dc25512637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Mon, 30 Dec 2024 10:38:54 +0100 Subject: [PATCH] Add info about MFA methods to user reset modal (#50381) * Rewrite story to use controls * Add info about MFA methods --- .../src/Users/UserReset/UserReset.story.tsx | 81 +++++++++++++------ .../src/Users/UserReset/UserReset.tsx | 36 ++++++--- 2 files changed, 81 insertions(+), 36 deletions(-) diff --git a/web/packages/teleport/src/Users/UserReset/UserReset.story.tsx b/web/packages/teleport/src/Users/UserReset/UserReset.story.tsx index fd74a04b68ded..3a68f43ac6a8f 100644 --- a/web/packages/teleport/src/Users/UserReset/UserReset.story.tsx +++ b/web/packages/teleport/src/Users/UserReset/UserReset.story.tsx @@ -16,40 +16,69 @@ * along with this program. If not, see . */ +import { Meta } from '@storybook/react'; + +import { Attempt } from 'shared/hooks/useAttemptNext'; +import { useEffect, useState } from 'react'; + +import cfg from 'teleport/config'; + import { UserReset } from './UserReset'; -export default { - title: 'Teleport/Users/UserReset', +type StoryProps = { + status: 'processing' | 'success' | 'error'; + isMfaEnabled: boolean; + allowPasswordless: boolean; }; -export const Processing = () => { - return ; +const meta: Meta = { + title: 'Teleport/Users/UserReset', + component: Story, + argTypes: { + status: { + control: { type: 'radio' }, + options: ['processing', 'success', 'error'], + }, + }, + args: { + status: 'processing', + isMfaEnabled: true, + allowPasswordless: true, + }, }; -export const Success = () => { - return ; -}; +export default meta; + +export function Story(props: StoryProps) { + const statusToAttempt: Record = { + processing: { status: 'processing' }, + success: { status: 'success' }, + error: { status: 'failed', statusText: 'some server error' }, + }; + const [, setState] = useState({}); + + useEffect(() => { + const defaultAuth = structuredClone(cfg.auth); + cfg.auth.second_factor = props.isMfaEnabled ? 'on' : 'off'; + cfg.auth.allowPasswordless = props.allowPasswordless; + setState({}); // Force re-render of the component with new cfg. + + return () => { + cfg.auth = defaultAuth; + }; + }, [props.isMfaEnabled, props.allowPasswordless]); -export const Failed = () => { return ( {}} + onClose={() => {}} + attempt={statusToAttempt[props.status]} /> ); -}; - -const props = { - username: 'smith', - token: { - value: '0c536179038b386728dfee6602ca297f', - expires: new Date('2021-04-08T07:30:00Z'), - username: 'Lester', - }, - onReset() {}, - onClose() {}, - attempt: { - status: 'processing', - statusText: '', - }, -}; +} diff --git a/web/packages/teleport/src/Users/UserReset/UserReset.tsx b/web/packages/teleport/src/Users/UserReset/UserReset.tsx index 65e15b1a2f2c2..0eb11518a0fb5 100644 --- a/web/packages/teleport/src/Users/UserReset/UserReset.tsx +++ b/web/packages/teleport/src/Users/UserReset/UserReset.tsx @@ -17,7 +17,7 @@ */ import { useState } from 'react'; -import { ButtonPrimary, ButtonSecondary, Text, Alert } from 'design'; +import { ButtonPrimary, ButtonSecondary, Text, Alert, P2 } from 'design'; import Dialog, { DialogHeader, DialogTitle, @@ -26,6 +26,7 @@ import Dialog, { } from 'design/Dialog'; import { useAttemptNext } from 'shared/hooks'; +import cfg from 'teleport/config'; import { ResetToken } from 'teleport/services/user'; import UserTokenLink from './../UserTokenLink'; @@ -58,16 +59,31 @@ export function UserReset({ {attempt.status === 'failed' && ( - + {attempt.statusText} )} - - You are about to reset authentication for user - - {` ${username} `} + + You are about to reset authentication for user{' '} + + {username} - . This will generate a temporary URL which can be used to set up new - authentication. - + . This will generate a temporary URL which can be used to set up + new authentication. + + {cfg.isMfaEnabled() && ( + + All{' '} + {cfg.isPasswordlessEnabled() + ? 'passkeys and MFA methods' + : 'MFA methods'}{' '} + of this user will be removed. The user will be able to set up{' '} + {cfg.isPasswordlessEnabled() ? ( + <>a new passkey or an MFA method + ) : ( + <>a new method + )}{' '} + after following the URL. + + )} - Generate reset url + Generate Reset URL Cancel