bigbuffet-rw/app/soapbox/actions/snackbar.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import { ALERT_SHOW } from './alerts';
import type { MessageDescriptor } from 'react-intl';
2022-05-27 12:22:20 -07:00
export type SnackbarActionSeverity = 'info' | 'success' | 'error'
type SnackbarMessage = string | MessageDescriptor
export type SnackbarAction = {
type: typeof ALERT_SHOW
message: SnackbarMessage
actionLabel?: SnackbarMessage
actionLink?: string
severity: SnackbarActionSeverity
}
export const show = (severity: SnackbarActionSeverity, message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string): SnackbarAction => ({
type: ALERT_SHOW,
message,
actionLabel,
actionLink,
severity,
});
export const info = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('info', message, actionLabel, actionLink);
export const success = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('success', message, actionLabel, actionLink);
export const error = (message: SnackbarMessage, actionLabel?: SnackbarMessage, actionLink?: string) =>
show('error', message, actionLabel, actionLink);
export default {
info,
success,
error,
show,
};