diff --git a/components/HistoryDisplay.vue b/components/HistoryDisplay.vue index b1796d2..3b0f00a 100644 --- a/components/HistoryDisplay.vue +++ b/components/HistoryDisplay.vue @@ -69,6 +69,10 @@ setup() const addHistoryItemData = ref({ text: "", + config: { + type: type, + id: elementId + } }) const addHistoryItem = async () => { @@ -120,6 +124,29 @@ const addHistoryItem = async () => { if(error) { console.log(error) } else { + if(addHistoryItemData.value.text.includes("@")){ + let usernames = [...addHistoryItemData.value.text.matchAll(/@(\S*)/gm)] + + const {data:profiles} = await supabase.from("profiles").select("id,username") + + let notifications = usernames.map(i => { + let rawUsername = i[1] + + return { + tenant: dataStore.currentTenant, + profile: profiles.find(x => x.username === rawUsername).id, + initiatingProfile: dataStore.activeProfile.id, + title: "Sie wurden im Logbuch erwähnt", + link: `/${type}s/show/${elementId}`, + message: addHistoryItemData.value.text + } + }) + + console.log(notifications) + + const {error} = await supabase.from("notifications").insert(notifications) + } + addHistoryItemData.value = {} toast.add({title: "Eintrag erfolgreich erstellt"}) showAddHistoryItemModal.value = false @@ -188,7 +215,6 @@ const renderText = (text) => { -