feat(#274): add back button to password prompt
This commit is contained in:
parent
3b5c566807
commit
3b24c5275d
@ -1,4 +1,5 @@
|
|||||||
import { ChangeEvent, useState, SyntheticEvent } from 'react'
|
import { ChangeEvent, useState, SyntheticEvent, useMemo } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
import Dialog from '@mui/material/Dialog'
|
import Dialog from '@mui/material/Dialog'
|
||||||
@ -6,6 +7,7 @@ import DialogActions from '@mui/material/DialogActions'
|
|||||||
import DialogContent from '@mui/material/DialogContent'
|
import DialogContent from '@mui/material/DialogContent'
|
||||||
import DialogContentText from '@mui/material/DialogContentText'
|
import DialogContentText from '@mui/material/DialogContentText'
|
||||||
import DialogTitle from '@mui/material/DialogTitle'
|
import DialogTitle from '@mui/material/DialogTitle'
|
||||||
|
import { QueryParamKeys } from 'models/shell'
|
||||||
|
|
||||||
interface PasswordPromptProps {
|
interface PasswordPromptProps {
|
||||||
isOpen: boolean
|
isOpen: boolean
|
||||||
@ -18,6 +20,15 @@ export const PasswordPrompt = ({
|
|||||||
}: PasswordPromptProps) => {
|
}: PasswordPromptProps) => {
|
||||||
const [password, setPassword] = useState('')
|
const [password, setPassword] = useState('')
|
||||||
|
|
||||||
|
const queryParams = useMemo(
|
||||||
|
() => new URLSearchParams(window.location.search),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
const isEmbedded = queryParams.has(QueryParamKeys.IS_EMBEDDED)
|
||||||
|
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const handleFormSubmit = (event: SyntheticEvent<HTMLFormElement>) => {
|
const handleFormSubmit = (event: SyntheticEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
onPasswordEntered(password)
|
onPasswordEntered(password)
|
||||||
@ -27,6 +38,10 @@ export const PasswordPrompt = ({
|
|||||||
setPassword(e.target.value)
|
setPassword(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleGoBackClick = () => {
|
||||||
|
navigate(-1)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpen}>
|
<Dialog open={isOpen}>
|
||||||
<form onSubmit={handleFormSubmit}>
|
<form onSubmit={handleFormSubmit}>
|
||||||
@ -55,6 +70,11 @@ export const PasswordPrompt = ({
|
|||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
{!isEmbedded && (
|
||||||
|
<Button color="secondary" onClick={handleGoBackClick}>
|
||||||
|
Go back
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button type="submit" disabled={password.length === 0}>
|
<Button type="submit" disabled={password.length === 0}>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user