Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add useToast hook for toast notifications #3593

Merged
merged 9 commits into from
Sep 2, 2024

Conversation

jamdelion
Copy link
Contributor

@jamdelion jamdelion commented Aug 29, 2024

What is this?

Replacing everywhere we use:

<Snackbar onClose={handleCloseToast} autoHideDuration={6000} open={true}>
      <Alert onClose={handleCloseToast} severity={'success'} sx={{ width: "100%" }}>
        {message}
      </Alert>
    </Snackbar>

With toast.success(message) 🎉

Testing

An easy place to test this is in the Team Members page, when you've successfully added a new editor. You should see the usual toast message pop up on success.

Copy link

github-actions bot commented Sep 2, 2024

Removed vultr server and associated DNS entries

@jamdelion jamdelion marked this pull request as ready for review September 2, 2024 13:25
Copy link
Member

@jessicamcinchak jessicamcinchak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor / very handy 🙌 🍞

}: Readonly<{ children: ReactNode }>) => {
const [state, dispatch] = useReducer(toastReducer, initialState);
const addToast = (type: ToastType, message: string) => {
const id = Math.floor(Math.random() * 10_000_000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we also have the uuid package available on the frontend which would let you generate a unique uuid id like const id = uuidV4()(consistent with how we generate session ids) - happy for this to work either way though / chances of unintentionally colliding/non-unique IDs seems veryyy low here 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tip thanks! I'll include that in the next PR 👍

default:
// @ts-ignore
// Typescript complains because action is of type 'never' here
throw new Error(`Unhandled action type: ${action.type}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jamdelion jamdelion merged commit bc75023 into main Sep 2, 2024
12 checks passed
@jamdelion jamdelion deleted the jh/use-toast-hook branch September 2, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants