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