From 1600ed7633827051b92bf94e83b01bc493473da9 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 5 Jun 2024 09:40:16 +0100 Subject: [PATCH] feat: Improve API key UX (#4102) --- frontend/web/components/AdminAPIKeys.js | 40 +++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/frontend/web/components/AdminAPIKeys.js b/frontend/web/components/AdminAPIKeys.js index 22589592733a..f2451b34111c 100644 --- a/frontend/web/components/AdminAPIKeys.js +++ b/frontend/web/components/AdminAPIKeys.js @@ -18,6 +18,8 @@ import { getRolesMasterAPIKeyWithMasterAPIKeyRoles, updateMasterAPIKeyWithMasterAPIKeyRoles, } from 'common/services/useMasterAPIKeyWithMasterAPIKeyRole' +import { setInterceptClose, setModalTitle } from './modals/base/ModalDefault' +import SuccessMessage from './SuccessMessage' export class CreateAPIKey extends PureComponent { state = { @@ -31,6 +33,28 @@ export class CreateAPIKey extends PureComponent { componentDidMount() { this.props.isEdit && this.getApiKeyByPrefix(this.props.prefix) + if (!this.props.isEdit) { + setInterceptClose(() => { + if (!this.state.key) { + return Promise.resolve(true) + } else { + return new Promise((resolve) => { + openConfirm({ + body: 'Please confirm you have a copy of the API key prior to closing.', + noText: 'Cancel', + onNo: () => resolve(false), + onYes: () => resolve(true), + title: 'Confirm saved API key', + yesText: 'Confirm', + }) + }) + } + }) + } + } + + componentWillUnmount() { + setInterceptClose(null) } submit = () => { @@ -50,6 +74,7 @@ export class CreateAPIKey extends PureComponent { isSaving: false, key: res.key, }) + setModalTitle('Save your new API key') Promise.all( this.state.roles.map((role) => createRoleMasterApiKey(getStore(), { @@ -163,6 +188,11 @@ export class CreateAPIKey extends PureComponent { { + setTimeout(() => { + v.focus() + }, 500) + }} value={this.state.name} onChange={(e) => this.setState({ name: Utils.safeParseEventValue(e) }) @@ -257,11 +287,11 @@ export class CreateAPIKey extends PureComponent { )} {this.state.key && ( -
- - Please keep a note of your API key once it's created, we do not - store it. - +
+ + Your key has been created. Please keep a note of your API key + once it's created, we do not store it. +