Webatrice: Registration toasts (#4566)

* wip

* Registration Success Toast

* remove debugging code

* remove unused field

* Show toast on successful password reset

* Toast on account activation success

* lint and PR feedback

* Rework interface names to avoid collision

* Move CssBaseline to sibling of ToastProvider

Co-authored-by: Brent Clark <brent@backboneiq.com>
This commit is contained in:
Brent Clark 2022-02-15 19:40:30 -06:00 committed by GitHub
parent 88b861d632
commit 4c04b4ef5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 164 additions and 13 deletions

View file

@ -0,0 +1,48 @@
export const ACTIONS = {
ADD_TOAST: 'ADD_TOAST',
OPEN_TOAST: 'OPEN_TOAST',
CLOSE_TOAST: 'CLOSE_TOAST',
REMOVE_TOAST: 'REMOVE_TOAST',
}
export const initialState = {
toasts: new Map()
}
export function reducer(state, action) {
const { type, payload } = action
switch (type) {
case ACTIONS.ADD_TOAST: {
const newState = { ...state }
newState.toasts = new Map(Array.from(state.toasts))
const { toasts } = newState;
const { key, children } = payload
toasts.set(key, { isOpen: false, children })
return newState
}
case ACTIONS.OPEN_TOAST: {
const newState = { ...state }
newState.toasts = new Map(Array.from(state.toasts))
const { toasts } = newState;
const toast = toasts.get(payload)
toasts.set(payload, { isOpen: true, children: toast.children })
return newState
}
case ACTIONS.CLOSE_TOAST: {
const newState = { ...state }
newState.toasts = new Map(Array.from(state.toasts))
const { toasts } = newState;
const toast = toasts.get(payload)
toasts.set(payload, { isOpen: false, children: toast.children })
return newState
}
case ACTIONS.REMOVE_TOAST: {
const newState = { ...state }
newState.toasts = new Map(Array.from(state.toasts))
newState.toasts.delete(payload)
return newState
}
default:
throw Error('Please pick an available action')
}
}