- Notifications
You must be signed in to change notification settings - Fork1.1k
refactor(site): Refactor alerts#7587
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
26d7edd550959e40994774831c6dd56172c8fe971998b97e3709b1ed94ba2ea21aa9a2669527d112aa1200b5e4eFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -128,6 +128,10 @@ rules: | ||
| message: | ||
| "You should use the Avatar component provided on | ||
| components/Avatar/Avatar" | ||
| - name: "@mui/material/Alert" | ||
| message: | ||
| "You should use the Alert component provided on | ||
| components/Alert/Alert" | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nice! | ||
| no-unused-vars: "off" | ||
| "object-curly-spacing": "off" | ||
| react-hooks/exhaustive-deps: warn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { Alert } from "./Alert" | ||
| import Button from "@mui/material/Button" | ||
| import { mockApiError } from "testHelpers/entities" | ||
| import Link from "@mui/material/Link" | ||
| import { getErrorMessage } from "api/errors" | ||
| import type { Meta, StoryObj } from "@storybook/react" | ||
| import { action } from "@storybook/addon-actions" | ||
| const meta: Meta<typeof Alert> = { | ||
| title: "components/Alert", | ||
| component: Alert, | ||
| args: { | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export default meta | ||
| type Story = StoryObj<typeof Alert> | ||
| const ExampleAction = ( | ||
| <Button onClick={() => null} size="small"> | ||
| Button | ||
| </Button> | ||
| ) | ||
| const mockError = mockApiError({ | ||
| message: "Email or password was invalid", | ||
| detail: "Password is invalid", | ||
| }) | ||
| export const Warning: Story = { | ||
| args: { | ||
| children: "This is a warning", | ||
| severity: "warning", | ||
| }, | ||
| } | ||
| export const ErrorWithDefaultMessage: Story = { | ||
| args: { | ||
| children: "This is an error", | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const ErrorWithErrorMessage: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Error default message"), | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const WarningWithDismiss: Story = { | ||
| args: { | ||
| children: "This is a warning", | ||
| dismissible: true, | ||
| severity: "warning", | ||
| }, | ||
| } | ||
| export const ErrorWithDismiss: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| dismissible: true, | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const WarningWithAction: Story = { | ||
| args: { | ||
| children: "This is a warning", | ||
| actions: [ExampleAction], | ||
| severity: "warning", | ||
| }, | ||
| } | ||
| export const ErrorWithAction: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| actions: [ExampleAction], | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const WarningWithActionAndDismiss: Story = { | ||
| args: { | ||
| children: "This is a warning", | ||
| actions: [ExampleAction], | ||
| dismissible: true, | ||
| severity: "warning", | ||
| }, | ||
| } | ||
| export const ErrorWithActionAndDismiss: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| actions: [ExampleAction], | ||
| dismissible: true, | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const ErrorWithRetry: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| onRetry: action("retry"), | ||
| dismissible: true, | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const ErrorWithActionRetryAndDismiss: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| actions: [ExampleAction], | ||
| onRetry: action("retry"), | ||
| dismissible: true, | ||
| severity: "error", | ||
| }, | ||
| } | ||
| export const ErrorAsWarning: Story = { | ||
| args: { | ||
| children: getErrorMessage(mockError, "Default error message"), | ||
| severity: "warning", | ||
| }, | ||
| } | ||
| export const WithChildren: Story = { | ||
| args: { | ||
| children: ( | ||
| <div> | ||
| This is a message with a <Link href="#">link</Link> | ||
| </div> | ||
| ), | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| import { useState, FC, ReactNode, PropsWithChildren } from "react" | ||
| import Collapse from "@mui/material/Collapse" | ||
| import { Stack } from "components/Stack/Stack" | ||
| // eslint-disable-next-line no-restricted-imports -- It is the base component | ||
| import MuiAlert, { AlertProps as MuiAlertProps } from "@mui/material/Alert" | ||
| import Button from "@mui/material/Button" | ||
| export interfaceAlertProps { | ||
| severity:MuiAlertProps["severity"] | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. If ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
| ||
| actions?: ReactNode[] | ||
| dismissible?: boolean | ||
| onRetry?: () => void | ||
| onDismiss?: () => void | ||
| } | ||
| export constAlert: FC<PropsWithChildren<AlertProps>> = ({ | ||
| children, | ||
| actions = [], | ||
| onRetry, | ||
| @@ -24,7 +25,7 @@ export const AlertBanner: FC<PropsWithChildren<AlertBannerProps>> = ({ | ||
| return ( | ||
| <Collapse in={open}> | ||
| <MuiAlert | ||
| severity={severity} | ||
| action={ | ||
| <Stack direction="row"> | ||
| @@ -58,7 +59,7 @@ export const AlertBanner: FC<PropsWithChildren<AlertBannerProps>> = ({ | ||
| } | ||
| > | ||
| {children} | ||
| </MuiAlert> | ||
| </Collapse> | ||
| ) | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,7 +9,7 @@ import { OAuthSignInForm } from "./OAuthSignInForm" | ||
| import { BuiltInAuthFormValues } from "./SignInForm.types" | ||
| import Button from "@mui/material/Button" | ||
| import EmailIcon from "@mui/icons-material/EmailOutlined" | ||
| import {Alert } from "components/Alert/Alert" | ||
| import { getErrorMessage } from "api/errors" | ||
| export const Language = { | ||
| @@ -101,9 +101,9 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({ | ||
| </h1> | ||
| <Maybe condition={error !== undefined}> | ||
| <div className={styles.error}> | ||
| <Alert severity="error"> | ||
| {getErrorMessage(error, "Error on sign in")} | ||
| </Alert> | ||
| </div> | ||
| </Maybe> | ||
| <Maybe condition={passwordEnabled && showPasswordAuth}> | ||
| @@ -129,9 +129,7 @@ export const SignInForm: FC<React.PropsWithChildren<SignInFormProps>> = ({ | ||
| </Maybe> | ||
| <Maybe condition={!passwordEnabled && !oAuthEnabled}> | ||
| <Alert severity="error">No authentication methods configured!</Alert> | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Related to my comment above, what is the difference between these two ways of displaying errors? ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I answered in the previous comment. | ||
| </Maybe> | ||
| <Maybe condition={passwordEnabled && !showPasswordAuth}> | ||
Uh oh!
There was an error while loading.Please reload this page.