Skip to content

feat: add success modal with token value to create token page #7170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
added token success modal
  • Loading branch information
Kira-Pilot committed Apr 17, 2023
commit 2fddf5313ffc6995f0976dbd620c842faad2c11e
6 changes: 5 additions & 1 deletion site/src/i18n/en/tokensPage.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"submit": "Create token"
},
"createSuccess": "Token has been created",
"createError": "Failed to create token"
"createError": "Failed to create token",
"successModal": {
"title": "Creation successful",
"description": "Make sure you copy the below token before proceeding:"
}
}
}
34 changes: 33 additions & 1 deletion site/src/pages/CreateTokenPage/CreateTokenPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { createToken, getTokenConfig } from "api/api"
import { CreateTokenForm } from "./CreateTokenForm"
import { NANO_HOUR, CreateTokenData } from "./utils"
import { AlertBanner } from "components/AlertBanner/AlertBanner"
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
import { CodeExample } from "components/CodeExample/CodeExample"
import { makeStyles } from "@material-ui/core/styles"

const initialValues: CreateTokenData = {
name: "",
Expand All @@ -20,12 +23,15 @@ const initialValues: CreateTokenData = {

const CreateTokenPage: FC = () => {
const { t } = useTranslation("tokensPage")
const styles = useStyles()
const navigate = useNavigate()

const {
mutate: saveToken,
isLoading: isCreating,
isError: creationFailed,
isSuccess: creationSuccessful,
data: newToken,
} = useMutation(createToken)
const {
data: tokenConfig,
Expand Down Expand Up @@ -60,12 +66,18 @@ const CreateTokenPage: FC = () => {
},
{
onError: onCreateError,
onSuccess: onCreateSuccess,
},
)
},
})

const tokenDescription = (
<>
<p>{t("createToken.successModal.description")}</p>
<CodeExample code={newToken?.key ?? ""} className={styles.codeExample} />
</>
)

if (fetchingTokenConfig) {
return <Loader />
}
Expand All @@ -90,9 +102,29 @@ const CreateTokenPage: FC = () => {
isCreating={isCreating}
creationFailed={creationFailed}
/>

<ConfirmDialog
type="info"
hideCancel
title={t("createToken.successModal.title")}
description={tokenDescription}
open={creationSuccessful && Boolean(newToken.key)}
confirmLoading={isCreating}
onConfirm={onCreateSuccess}
onClose={onCreateSuccess}
/>
</FullPageHorizontalForm>
</>
)
}

const useStyles = makeStyles((theme) => ({
codeExample: {
minHeight: "auto",
userSelect: "all",
width: "100%",
marginTop: theme.spacing(3),
},
}))

export default CreateTokenPage