first commit
This commit is contained in:
41
resources/js/composables/useNotification.ts
Normal file
41
resources/js/composables/useNotification.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user