mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-05 14:50:29 +02:00
modify error page redirects (#2518)
This commit is contained in:
parent
a53e947489
commit
84a3f8f1fb
@ -260,7 +260,8 @@
|
||||
"error.workspace-undefined": "Not a valid workspace.",
|
||||
"error.page.title": "Sorry, something went wrong",
|
||||
"error.not-logged-in": "Your session may have expired or you're not logged in.",
|
||||
"error.go-dashboard": "Go to the Dashboard",
|
||||
"error.back-to-home": "Back to Home",
|
||||
"error.back-to-boards": "Back to boards",
|
||||
"error.go-login": "Log in",
|
||||
"error.unknown": "An error occurred.",
|
||||
"login.register-button": "or create an account if you don't have one",
|
||||
|
@ -15,11 +15,13 @@ type ErrorDef = {
|
||||
button1Text: string
|
||||
button1Redirect: string | (() => string)
|
||||
button1Fill: boolean
|
||||
button1ClearHistory: boolean
|
||||
|
||||
button2Enabled: boolean
|
||||
button2Text: string
|
||||
button2Redirect: string | (() => string)
|
||||
button2Fill: boolean
|
||||
button2ClearHistory: boolean
|
||||
}
|
||||
|
||||
function errorDefFromId(id: ErrorId | null): ErrorDef {
|
||||
@ -29,10 +31,12 @@ function errorDefFromId(id: ErrorId | null): ErrorDef {
|
||||
button1Text: '',
|
||||
button1Redirect: '',
|
||||
button1Fill: false,
|
||||
button1ClearHistory: false,
|
||||
button2Enabled: false,
|
||||
button2Text: '',
|
||||
button2Redirect: '',
|
||||
button2Fill: false,
|
||||
button2ClearHistory: false,
|
||||
}
|
||||
|
||||
const intl = useIntl()
|
||||
@ -41,15 +45,15 @@ function errorDefFromId(id: ErrorId | null): ErrorDef {
|
||||
case ErrorId.WorkspaceUndefined: {
|
||||
errDef.title = intl.formatMessage({id: 'error.workspace-undefined', defaultMessage: 'Not a valid workspace.'})
|
||||
errDef.button1Enabled = true
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.go-dashboard', defaultMessage: 'Go to the Dashboard'})
|
||||
errDef.button1Redirect = '/dashboard'
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.back-to-home', defaultMessage: 'Back to Home'})
|
||||
errDef.button1Redirect = window.location.origin
|
||||
errDef.button1Fill = true
|
||||
break
|
||||
}
|
||||
case ErrorId.NotLoggedIn: {
|
||||
errDef.title = intl.formatMessage({id: 'error.not-logged-in', defaultMessage: 'Your session may have expired or you\'re not logged in. Log in again to access Boards.'})
|
||||
errDef.button1Enabled = true
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.go-login', defaultMessage: 'Log in'})
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.go-login', defaultMessage: 'Login'})
|
||||
errDef.button1Redirect = '/login'
|
||||
errDef.button1Fill = true
|
||||
break
|
||||
@ -57,9 +61,10 @@ function errorDefFromId(id: ErrorId | null): ErrorDef {
|
||||
default: {
|
||||
errDef.title = intl.formatMessage({id: 'error.unknown', defaultMessage: 'An error occurred.'})
|
||||
errDef.button1Enabled = true
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.go-dashboard', defaultMessage: 'Go to the Dashboard'})
|
||||
errDef.button1Redirect = '/dashboard'
|
||||
errDef.button1Text = intl.formatMessage({id: 'error.back-to-boards', defaultMessage: 'Go to the Dashboard'})
|
||||
errDef.button1Redirect = '/'
|
||||
errDef.button1Fill = true
|
||||
errDef.button1ClearHistory = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import Button from '../widgets/buttons/button'
|
||||
import './errorPage.scss'
|
||||
|
||||
import {errorDefFromId, ErrorId} from '../errors'
|
||||
import {UserSettings} from '../userSettings'
|
||||
|
||||
const ErrorPage = () => {
|
||||
const history = useHistory()
|
||||
@ -17,23 +18,31 @@ const ErrorPage = () => {
|
||||
const errid = queryString.get('id')
|
||||
const errorDef = errorDefFromId(errid as ErrorId)
|
||||
|
||||
const handleButtonClick = useCallback((path: string | (()=>string)) => {
|
||||
let url = '/dashboard'
|
||||
const handleButtonClick = useCallback((path: string | (()=>string), clearHistory: boolean) => {
|
||||
let url = '/'
|
||||
if (typeof path === 'function') {
|
||||
url = path()
|
||||
} else if (path) {
|
||||
url = path as string
|
||||
}
|
||||
history.push(url)
|
||||
if (clearHistory) {
|
||||
UserSettings.lastBoardId = ''
|
||||
UserSettings.lastViewId = ''
|
||||
}
|
||||
if (url === window.location.origin) {
|
||||
window.location.href = url
|
||||
} else {
|
||||
history.push(url)
|
||||
}
|
||||
}, [history])
|
||||
|
||||
const makeButton = ((path: string | (()=>string), txt: string, fill: boolean) => {
|
||||
const makeButton = ((path: string | (()=>string), txt: string, fill: boolean, clearHistory: boolean) => {
|
||||
return (
|
||||
<Button
|
||||
filled={fill}
|
||||
size='large'
|
||||
onClick={async () => {
|
||||
handleButtonClick(path)
|
||||
handleButtonClick(path, clearHistory)
|
||||
}}
|
||||
>
|
||||
{txt}
|
||||
@ -56,10 +65,10 @@ const ErrorPage = () => {
|
||||
<ErrorIllustration/>
|
||||
<br/>
|
||||
{
|
||||
(errorDef.button1Enabled ? makeButton(errorDef.button1Redirect, errorDef.button1Text, errorDef.button1Fill) : null)
|
||||
(errorDef.button1Enabled ? makeButton(errorDef.button1Redirect, errorDef.button1Text, errorDef.button1Fill, errorDef.button1ClearHistory) : null)
|
||||
}
|
||||
{
|
||||
(errorDef.button2Enabled ? makeButton(errorDef.button2Redirect, errorDef.button2Text, errorDef.button2Fill) : null)
|
||||
(errorDef.button2Enabled ? makeButton(errorDef.button2Redirect, errorDef.button2Text, errorDef.button2Fill, errorDef.button2ClearHistory) : null)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user