diff --git a/src/components/CreateChatComponent.vue b/src/components/CreateChatComponent.vue index 8c8351a..283968d 100644 --- a/src/components/CreateChatComponent.vue +++ b/src/components/CreateChatComponent.vue @@ -67,7 +67,8 @@ import { computed, ref } from 'vue'; import ProfileCardComponent from './ProfileCardComponent.vue'; import { useUserStore } from 'src/stores/user-store'; - import type { ptpUser } from 'src/models'; + import type { ptpUser, responseModel } from 'src/models'; + import {sendNotification} from 'src/utils'; import { useQuasar } from 'quasar'; import { useChatStore } from 'src/stores/chat-store'; @@ -79,8 +80,6 @@ import { useChatStore } from 'src/stores/chat-store'; const searchResults = ref([] as ptpUser[]); - const $q = useQuasar(); - const emit = defineEmits(['update:showDialog', 'showModal']); const props = defineProps({ showDialog: Boolean, @@ -117,36 +116,16 @@ import { useChatStore } from 'src/stores/chat-store'; let errorOccured = false; if(usersForChat.value.length == 0) { - $q.notify({ - message: 'Du hast keine Mitglieder ausgewählt', - position: 'top', - timeout: 2000, - color: "red", - icon: 'warning' - }); + sendNotification("Du hast keine Mitglieder ausgewählt", false); errorOccured = true; } if(chatName.value == "") { - $q.notify({ - message: 'Du hast keinen Namen festgelegt', - position: 'top', - timeout: 2000, - color: "red", - icon: 'warning' - }); + sendNotification("Du hast keinen Namen festgelegt", false); errorOccured = true; } if(!errorOccured) { - $q.notify({ - message: 'Der Chat "'+chatName.value+'" wurde erstellt', - position: 'top', - timeout: 2000, - color: "green", - type: "positive" - }); - setupChat(chatName.value); closeDialog(); chatName.value = ""; @@ -157,8 +136,11 @@ import { useChatStore } from 'src/stores/chat-store'; const chatStore = useChatStore(); const setupChat = async(chatName: string)=>{ - await chatStore.createChat(chatName, usersForChat.value.map((user) => user.id)); - reloadChats(); + chatStore.createChat(chatName, usersForChat.value.map((user) => user.id), userStore.user!.id).then((response : responseModel) => { + sendNotification(response.message, response.success); + reloadChats(); + }); + } const reloadChats = async() => { diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..326d4ef --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,16 @@ +import { Notify } from "quasar"; +import { responseModel } from "./models"; + +export const sendRestResponseAsNotification = (response : responseModel) => { + +} + +export const sendNotification = (message : string, successful : Boolean) => { + Notify.create({ + message: message, + position: 'top', + timeout: 2000, + color: successful ? "green" : "red", + icon: successful ? "success" : "warning" + }); +} \ No newline at end of file