2024-12-26 13:57:45 +01:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-col gap-2 h-full w-full overflow-y-auto">
|
|
|
|
<Spinner v-if="loading == 'loading'" class="mx-auto" />
|
|
|
|
<p v-else-if="loading == 'failed'" @click="fetchNewsletterRecipients" class="cursor-pointer">
|
|
|
|
↺ laden fehlgeschlagen
|
|
|
|
</p>
|
|
|
|
|
2024-12-27 13:25:37 +01:00
|
|
|
<select v-model="recipientsByQueryId">
|
|
|
|
<option value="def">Optional</option>
|
|
|
|
<option v-for="query in queries" :key="query.id" :value="query.id">{{ query.title }}</option>
|
|
|
|
</select>
|
|
|
|
<p>Empfänger durch gespeicherte Abfrage</p>
|
|
|
|
<div class="flex flex-col gap-2 grow overflow-y-auto">
|
|
|
|
<div
|
|
|
|
v-for="member in queried"
|
|
|
|
:key="member.id"
|
|
|
|
class="flex flex-row h-fit w-full border border-primary rounded-md bg-primary p-2 text-white justify-between items-center"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<p>{{ member.lastname }}, {{ member.firstname }} {{ member.nameaffix ? `- ${member.nameaffix}` : "" }}</p>
|
|
|
|
<p>Newsletter senden an Typ: {{ member.sendNewsletter?.type.type }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-12-26 13:57:45 +01:00
|
|
|
|
2025-01-20 09:43:48 +01:00
|
|
|
<MemberSearchSelect
|
|
|
|
title="weitere Empfänger suchen"
|
|
|
|
v-model="recipients"
|
|
|
|
:disabled="!can('create', 'club', 'newsletter')"
|
|
|
|
/>
|
2024-12-26 13:57:45 +01:00
|
|
|
|
|
|
|
<p>Ausgewählte Empfänger</p>
|
|
|
|
<div class="flex flex-col gap-2 grow overflow-y-auto">
|
|
|
|
<div
|
|
|
|
v-for="member in selected"
|
|
|
|
:key="member.id"
|
|
|
|
class="flex flex-row h-fit w-full border border-primary rounded-md bg-primary p-2 text-white justify-between items-center"
|
|
|
|
>
|
2024-12-26 19:36:00 +01:00
|
|
|
<div>
|
|
|
|
<p>{{ member.lastname }}, {{ member.firstname }} {{ member.nameaffix ? `- ${member.nameaffix}` : "" }}</p>
|
|
|
|
<p>Newsletter senden an Typ: {{ member.sendNewsletter?.type.type }}</p>
|
|
|
|
</div>
|
|
|
|
|
2024-12-26 13:57:45 +01:00
|
|
|
<TrashIcon
|
|
|
|
v-if="can('create', 'club', 'newsletter')"
|
|
|
|
class="w-5 h-5 p-1 box-content cursor-pointer"
|
|
|
|
@click="removeSelected(member.id)"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import { mapActions, mapState, mapWritableState } from "pinia";
|
|
|
|
import Spinner from "@/components/Spinner.vue";
|
|
|
|
import {
|
|
|
|
Combobox,
|
|
|
|
ComboboxLabel,
|
|
|
|
ComboboxInput,
|
|
|
|
ComboboxButton,
|
|
|
|
ComboboxOptions,
|
|
|
|
ComboboxOption,
|
|
|
|
TransitionRoot,
|
|
|
|
} from "@headlessui/vue";
|
|
|
|
import { CheckIcon, ChevronUpDownIcon } from "@heroicons/vue/20/solid";
|
|
|
|
import { TrashIcon } from "@heroicons/vue/24/outline";
|
2025-01-02 18:28:13 +01:00
|
|
|
import { useMemberStore } from "@/stores/admin/club/member/member";
|
|
|
|
import type { MemberViewModel } from "@/viewmodels/admin/club/member/member.models";
|
|
|
|
import { useNewsletterStore } from "@/stores/admin/club/newsletter/newsletter";
|
|
|
|
import { useNewsletterRecipientsStore } from "@/stores/admin/club/newsletter/newsletterRecipients";
|
2024-12-26 13:57:45 +01:00
|
|
|
import { useAbilityStore } from "@/stores/ability";
|
2025-01-02 18:28:13 +01:00
|
|
|
import { useQueryStoreStore } from "@/stores/admin/settings/queryStore";
|
|
|
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
2024-12-27 13:25:37 +01:00
|
|
|
import cloneDeep from "lodash.clonedeep";
|
2025-01-20 09:43:48 +01:00
|
|
|
import MemberSearchSelect from "@/components/admin/MemberSearchSelect.vue";
|
2024-12-26 13:57:45 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
newsletterId: String,
|
|
|
|
},
|
2024-12-27 13:25:37 +01:00
|
|
|
watch: {
|
|
|
|
recipientsByQuery() {
|
|
|
|
this.loadQuery();
|
|
|
|
},
|
|
|
|
},
|
2024-12-26 13:57:45 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
query: "" as String,
|
2025-01-20 09:43:48 +01:00
|
|
|
members: [] as Array<MemberViewModel>,
|
2024-12-26 13:57:45 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapWritableState(useNewsletterRecipientsStore, ["recipients", "loading"]),
|
2024-12-27 13:25:37 +01:00
|
|
|
...mapWritableState(useNewsletterStore, ["activeNewsletterObj"]),
|
|
|
|
...mapState(useQueryStoreStore, ["queries"]),
|
|
|
|
...mapState(useQueryBuilderStore, ["data"]),
|
2024-12-26 13:57:45 +01:00
|
|
|
...mapState(useAbilityStore, ["can"]),
|
|
|
|
selected(): Array<MemberViewModel> {
|
2025-01-20 09:43:48 +01:00
|
|
|
return this.members
|
|
|
|
.filter((m) => this.recipients.includes(m.id))
|
|
|
|
.sort((a, b) => {
|
|
|
|
if (a.lastname < b.lastname) return -1;
|
|
|
|
if (a.lastname > b.lastname) return 1;
|
|
|
|
if (a.firstname < b.firstname) return -1;
|
|
|
|
if (a.firstname > b.firstname) return 1;
|
|
|
|
return 0;
|
|
|
|
});
|
2024-12-26 13:57:45 +01:00
|
|
|
},
|
2024-12-27 13:25:37 +01:00
|
|
|
queried(): Array<MemberViewModel> {
|
2024-12-30 14:46:39 +01:00
|
|
|
if (this.recipientsByQueryId == "def") return [];
|
2024-12-27 13:25:37 +01:00
|
|
|
let keys = Object.keys(this.data?.[0] ?? {});
|
|
|
|
let memberKey = keys.find((k) => k.includes("member_id"));
|
|
|
|
return this.members.filter((m) =>
|
|
|
|
this.data
|
|
|
|
.map((t) => ({
|
|
|
|
id: t.id,
|
|
|
|
...(memberKey ? { memberId: t[memberKey] } : {}),
|
|
|
|
}))
|
|
|
|
.some((d) => (d.memberId ?? d.id) == m.id)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
recipientsByQueryId: {
|
|
|
|
get() {
|
|
|
|
return this.activeNewsletterObj?.recipientsByQueryId ?? "def";
|
|
|
|
},
|
|
|
|
set(val: string) {
|
|
|
|
if (this.activeNewsletterObj == undefined) return;
|
|
|
|
if (val == "def") {
|
|
|
|
this.activeNewsletterObj.recipientsByQueryId = null;
|
|
|
|
this.activeNewsletterObj.recipientsByQuery = null;
|
|
|
|
} else if (this.queries.find((q) => q.id == parseInt(val))) {
|
|
|
|
this.activeNewsletterObj.recipientsByQueryId = parseInt(val);
|
|
|
|
this.activeNewsletterObj.recipientsByQuery = cloneDeep(this.queries.find((q) => q.id == parseInt(val)));
|
|
|
|
this.sendQuery(0, 1000, this.recipientsByQuery?.query);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
recipientsByQuery() {
|
|
|
|
return this.activeNewsletterObj?.recipientsByQuery;
|
|
|
|
},
|
2024-12-26 13:57:45 +01:00
|
|
|
},
|
|
|
|
mounted() {
|
2025-01-05 12:12:21 +01:00
|
|
|
// this.fetchNewsletterRecipients();
|
2024-12-27 13:25:37 +01:00
|
|
|
this.fetchQueries();
|
|
|
|
this.loadQuery();
|
2025-01-21 08:58:30 +01:00
|
|
|
this.loadMembers();
|
2024-12-26 13:57:45 +01:00
|
|
|
},
|
|
|
|
methods: {
|
2025-01-21 08:58:30 +01:00
|
|
|
...mapActions(useMemberStore, ["getAllMembers"]),
|
2024-12-26 13:57:45 +01:00
|
|
|
...mapActions(useNewsletterRecipientsStore, ["fetchNewsletterRecipients"]),
|
2024-12-27 13:25:37 +01:00
|
|
|
...mapActions(useQueryStoreStore, ["fetchQueries"]),
|
|
|
|
...mapActions(useQueryBuilderStore, ["sendQuery"]),
|
2024-12-26 13:57:45 +01:00
|
|
|
removeSelected(id: number) {
|
|
|
|
let index = this.recipients.findIndex((s) => s == id);
|
|
|
|
if (index != -1) {
|
|
|
|
this.recipients.splice(index, 1);
|
|
|
|
}
|
|
|
|
},
|
2025-01-21 08:58:30 +01:00
|
|
|
loadMembers() {
|
|
|
|
this.getAllMembers()
|
|
|
|
.then((res) => {
|
|
|
|
this.members = res.data;
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
},
|
2024-12-27 13:25:37 +01:00
|
|
|
loadQuery() {
|
|
|
|
if (this.recipientsByQuery) {
|
|
|
|
this.sendQuery(0, 1000, this.recipientsByQuery.query);
|
|
|
|
}
|
|
|
|
},
|
2024-12-26 13:57:45 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|