42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { NotificationOptions } from 'naive-ui';
|
||
|
||
/**
|
||
* Обёртка над discrete notification API NaiveUI с удобными хелперами.
|
||
* Перенесено и упрощено из проекта onboard (Composables/useNotification.js).
|
||
*/
|
||
export function useNotification() {
|
||
const showNotification = (options: NotificationOptions) => {
|
||
return window.$notification?.create(options) ?? null;
|
||
};
|
||
|
||
const success = (
|
||
title: string,
|
||
description = '',
|
||
options: Partial<NotificationOptions> = {},
|
||
) => {
|
||
return showNotification({
|
||
title,
|
||
description,
|
||
meta: options.meta ?? new Date().toLocaleDateString(),
|
||
...options,
|
||
type: 'success',
|
||
});
|
||
};
|
||
|
||
const error = (
|
||
title = 'Произошла ошибка',
|
||
description = '',
|
||
options: Partial<NotificationOptions> = {},
|
||
) => {
|
||
return showNotification({
|
||
title,
|
||
description,
|
||
meta: options.meta ?? new Date().toLocaleDateString(),
|
||
...options,
|
||
type: 'error',
|
||
});
|
||
};
|
||
|
||
return { success, error };
|
||
}
|