Skip to content

Commit 891b045

Browse files
ValentinCrochemorealanpoulain
authored andcommitted
Update notification management
1 parent d6ec96e commit 891b045

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

templates/quasar/components/foo/UpdateComponent.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { storeToRefs } from 'pinia';
2828
import { use{{titleUcFirst}}DeleteStore } from 'src/stores/{{lc}}/delete';
2929
import { onBeforeUnmount } from 'vue';
3030
import { {{titleUcFirst}} } from 'src/types/{{lc}}';
31-
import { displaySuccessNotification } from 'src/utils/notifications';
31+
import { useNotifications } from 'src/composables/notifications';
3232
import { useI18n } from 'vue-i18n';
3333
import { useBreadcrumb } from 'src/composables/breadcrumb';
3434
import { useWatchErrors } from 'src/composables/errors';
@@ -38,6 +38,7 @@ const { t } = useI18n();
3838
const route = useRoute();
3939
const router = useRouter();
4040
const breadcrumb = useBreadcrumb();
41+
const { displaySuccessNotification } = useNotifications();
4142
4243
const {{lc}}UpdateStore = use{{titleUcFirst}}UpdateStore();
4344
const {
@@ -78,7 +79,7 @@ async function submitForm(item: {{titleUcFirst}}) {
7879
return;
7980
}
8081
81-
displaySuccessNotification(`${item['@id']} ${t('updated')}.`, t('close'));
82+
displaySuccessNotification(`${item['@id']} ${t('updated')}.`);
8283
}
8384
8485
useWatchErrors([error, deleteError]);
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { Ref, watch } from 'vue';
2-
import { displayErrorNotification } from 'src/utils/notifications';
3-
import { useI18n } from 'vue-i18n';
2+
import { useNotifications } from './notifications';
43

54
export function useWatchErrors(
65
errors: (Ref<string | undefined> | undefined)[]
76
) {
8-
const { t } = useI18n();
7+
const { displayErrorNotification } = useNotifications();
98

109
watch(errors, (newErrors) => {
1110
newErrors.forEach((newError) => {
1211
if (!newError?.value) {
1312
return;
1413
}
1514

16-
displayErrorNotification(newError.value, t('close'));
15+
displayErrorNotification(newError.value);
1716
});
1817
});
1918
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useQuasar } from 'quasar';
2+
import { useI18n } from 'vue-i18n';
3+
4+
export function useNotifications() {
5+
const $q = useQuasar();
6+
const { t } = useI18n();
7+
8+
const displayErrorNotification = (message: string) => {
9+
$q.notify({
10+
message,
11+
color: 'red',
12+
icon: 'error',
13+
closeBtn: t('close'),
14+
});
15+
};
16+
17+
const displaySuccessNotification = (message: string) => {
18+
$q.notify({
19+
message,
20+
color: 'green',
21+
icon: 'tag_faces',
22+
closeBtn: t('close'),
23+
});
24+
};
25+
26+
return {
27+
displayErrorNotification,
28+
displaySuccessNotification,
29+
};
30+
}

templates/quasar/utils/notifications.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)