Outsourced notify funtionality into utils file
This commit is contained in:
@@ -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));
|
||||
chatStore.createChat(chatName, usersForChat.value.map((user) => user.id), userStore.user!.id).then((response : responseModel) => {
|
||||
sendNotification(response.message, response.success);
|
||||
reloadChats();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
const reloadChats = async() => {
|
||||
|
||||
16
src/utils.ts
Normal file
16
src/utils.ts
Normal file
@@ -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"
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user