initial commit
This commit is contained in:
36
front/src/hooks/useAlert.js
Normal file
36
front/src/hooks/useAlert.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import {useSnackbar} from "notistack";
|
||||
|
||||
export function useAlert() {
|
||||
// variant could be success, error, warning, info, or default
|
||||
const {enqueueSnackbar} = useSnackbar();
|
||||
|
||||
function createAlert(message, variant) {
|
||||
const options = {
|
||||
...variant,
|
||||
anchorOrigin: {vertical: 'top', horizontal: 'right'},
|
||||
}
|
||||
enqueueSnackbar(message, options);
|
||||
}
|
||||
|
||||
function notImplement() {
|
||||
createAlert("Данный функционал пока не реализован", {variant: 'warning'});
|
||||
}
|
||||
|
||||
function createWarning(message) {
|
||||
createAlert(message, {variant: 'warning'})
|
||||
}
|
||||
|
||||
function createError(message) {
|
||||
createAlert(message, {variant: "error"});
|
||||
}
|
||||
|
||||
function getError() {
|
||||
createAlert("Ошибка получения данных", {variant: "error"});
|
||||
}
|
||||
|
||||
function createSuccess(message) {
|
||||
createAlert(message, {variant: "success"});
|
||||
}
|
||||
|
||||
return {createAlert, notImplement, createError, getError, createSuccess, createWarning}
|
||||
}
|
||||
Reference in New Issue
Block a user