24 lines
627 B
TypeScript
24 lines
627 B
TypeScript
export type ShopToastVariant = 'success' | 'error';
|
|
|
|
type ShopToastListener = (message: string, variant: ShopToastVariant) => void;
|
|
|
|
let listener: ShopToastListener | null = null;
|
|
|
|
export function registerShopToastListener(fn: ShopToastListener | null) {
|
|
listener = fn;
|
|
}
|
|
|
|
export function showShopToast(message: string, variant: ShopToastVariant = 'error') {
|
|
const text = message.trim();
|
|
if (!text || !listener) return;
|
|
listener(text, variant);
|
|
}
|
|
|
|
export function toastError(message: string) {
|
|
showShopToast(message, 'error');
|
|
}
|
|
|
|
export function toastSuccess(message: string) {
|
|
showShopToast(message, 'success');
|
|
}
|