-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make error screens more visually consistent
This change gives our error screens a more consistent visual appearance and lets us easily present any new errors that we come up with in the future with custom React components. This will make it easy to, for example, throw an error if the JWT service is unreachable, present that error in non-technical language, while also letting admins dig deeper into the details on the error screen.
- Loading branch information
Showing
15 changed files
with
276 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.error { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: var(--cpd-space-2x); | ||
max-inline-size: 480px; | ||
} | ||
|
||
.icon { | ||
margin-block-end: var(--cpd-space-4x); | ||
} | ||
|
||
.error > h1 { | ||
margin: 0; | ||
} | ||
|
||
.error > p { | ||
font: var(--cpd-font-body-lg-regular); | ||
color: var(--cpd-color-text-secondary); | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
Copyright 2025 New Vector Ltd. | ||
SPDX-License-Identifier: AGPL-3.0-only | ||
Please see LICENSE in the repository root for full details. | ||
*/ | ||
|
||
import { BigIcon, Button, Heading } from "@vector-im/compound-web"; | ||
import { | ||
useCallback, | ||
type ComponentType, | ||
type FC, | ||
type ReactNode, | ||
type SVGAttributes, | ||
} from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { RageshakeButton } from "./settings/RageshakeButton"; | ||
import styles from "./ErrorView.module.css"; | ||
import { useUrlParams } from "./UrlParams"; | ||
import { LinkButton } from "./button"; | ||
|
||
interface Props { | ||
Icon: ComponentType<SVGAttributes<SVGElement>>; | ||
title: string; | ||
/** | ||
* Show an option to submit a rageshake. | ||
* @default false | ||
*/ | ||
rageshake?: boolean; | ||
/** | ||
* Whether the error is considered fatal, i.e. non-recoverable. Causes the app | ||
* to fully reload when clicking 'return to home'. | ||
* @default false | ||
*/ | ||
fatal?: boolean; | ||
children: ReactNode; | ||
} | ||
|
||
export const ErrorView: FC<Props> = ({ | ||
Icon, | ||
title, | ||
rageshake, | ||
fatal, | ||
children, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const { confineToRoom } = useUrlParams(); | ||
|
||
const onReload = useCallback(() => { | ||
window.location.href = "/"; | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.error}> | ||
<BigIcon className={styles.icon}> | ||
<Icon /> | ||
</BigIcon> | ||
<Heading as="h1" weight="semibold" size="md"> | ||
{title} | ||
</Heading> | ||
{children} | ||
{rageshake && ( | ||
<RageshakeButton description={`***Error View***: ${title}`} /> | ||
)} | ||
{!confineToRoom && | ||
(fatal || location.pathname === "/" ? ( | ||
<Button | ||
kind="tertiary" | ||
className={styles.homeLink} | ||
onClick={onReload} | ||
> | ||
{t("return_home_button")} | ||
</Button> | ||
) : ( | ||
<LinkButton kind="tertiary" className={styles.homeLink} to="/"> | ||
{t("return_home_button")} | ||
</LinkButton> | ||
))} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.