2020-09-29 09:53:48 +02:00
|
|
|
<template>
|
2022-04-03 22:13:06 +02:00
|
|
|
<div
|
2022-07-12 10:55:28 +02:00
|
|
|
class="bg-white dark:bg-violet-3 border border-gray-300 rounded-lg cursor-pointer"
|
2022-04-03 22:13:06 +02:00
|
|
|
v-if="selectedActor"
|
|
|
|
>
|
2020-09-29 09:53:48 +02:00
|
|
|
<!-- If we have a current actor (inline) -->
|
2020-11-30 10:24:11 +01:00
|
|
|
<div
|
2021-03-29 10:33:19 +02:00
|
|
|
v-if="inline && selectedActor.id"
|
2022-07-12 10:55:28 +02:00
|
|
|
class=""
|
2021-11-07 21:02:06 +01:00
|
|
|
dir="auto"
|
2020-11-30 10:24:11 +01:00
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex gap-1 p-4">
|
|
|
|
<div class="">
|
|
|
|
<figure class="" v-if="selectedActor.avatar">
|
2020-09-29 09:53:48 +02:00
|
|
|
<img
|
2022-07-12 10:55:28 +02:00
|
|
|
class="rounded"
|
2021-03-29 10:33:19 +02:00
|
|
|
:src="selectedActor.avatar.url"
|
2022-07-12 10:55:28 +02:00
|
|
|
:alt="selectedActor.avatar.alt ?? ''"
|
|
|
|
height="48"
|
|
|
|
width="48"
|
2020-09-29 09:53:48 +02:00
|
|
|
/>
|
|
|
|
</figure>
|
2022-07-12 10:55:28 +02:00
|
|
|
<AccountCircle v-else :size="48" />
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex-1" v-if="selectedActor.name">
|
|
|
|
<p class="">{{ selectedActor.name }}</p>
|
|
|
|
<p class="">
|
2021-03-29 10:33:19 +02:00
|
|
|
{{ `@${selectedActor.preferredUsername}` }}
|
2020-11-30 10:24:11 +01:00
|
|
|
</p>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex-1" v-else>
|
2021-03-29 10:33:19 +02:00
|
|
|
{{ `@${selectedActor.preferredUsername}` }}
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-button type="text" @click="isComponentModalActive = true">
|
2020-09-29 09:53:48 +02:00
|
|
|
{{ $t("Change") }}
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-button>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- If we have a current actor -->
|
2020-11-30 10:24:11 +01:00
|
|
|
<span
|
2021-03-29 10:33:19 +02:00
|
|
|
v-else-if="selectedActor.id"
|
2020-11-30 10:24:11 +01:00
|
|
|
class="block"
|
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2020-09-29 09:53:48 +02:00
|
|
|
<img
|
2022-07-12 10:55:28 +02:00
|
|
|
class="rounded"
|
2021-03-29 10:33:19 +02:00
|
|
|
v-if="selectedActor.avatar"
|
|
|
|
:src="selectedActor.avatar.url"
|
|
|
|
:alt="selectedActor.avatar.alt"
|
2022-07-12 10:55:28 +02:00
|
|
|
width="48"
|
|
|
|
height="48"
|
2020-09-29 09:53:48 +02:00
|
|
|
/>
|
2022-07-12 10:55:28 +02:00
|
|
|
<AccountCircle v-else :size="48" />
|
2020-09-29 09:53:48 +02:00
|
|
|
</span>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-modal
|
|
|
|
v-model:active="isComponentModalActive"
|
2021-11-13 12:33:14 +01:00
|
|
|
has-modal-card
|
|
|
|
:close-button-aria-label="$t('Close')"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="p-2 rounded">
|
|
|
|
<header class="">
|
|
|
|
<h2 class="">{{ $t("Pick a profile or a group") }}</h2>
|
2020-09-29 09:53:48 +02:00
|
|
|
</header>
|
2022-07-12 10:55:28 +02:00
|
|
|
<section class="">
|
2022-08-12 16:46:04 +02:00
|
|
|
<div class="flex flex-wrap gap-2 items-center">
|
|
|
|
<div class="max-h-[400px] overflow-y-auto flex-1">
|
2020-09-29 09:53:48 +02:00
|
|
|
<organizer-picker
|
2022-08-12 16:46:04 +02:00
|
|
|
v-if="currentActor"
|
|
|
|
:current-actor="currentActor"
|
|
|
|
:identities="identities ?? []"
|
2021-03-29 10:33:19 +02:00
|
|
|
v-model="selectedActor"
|
2022-08-12 16:46:04 +02:00
|
|
|
@update:model-value="relay"
|
2020-09-29 09:53:48 +02:00
|
|
|
:restrict-moderator-level="true"
|
2022-08-12 16:46:04 +02:00
|
|
|
:group-memberships="groupMemberships"
|
|
|
|
v-model:actorFilter="actorFilter"
|
2020-09-29 09:53:48 +02:00
|
|
|
/>
|
|
|
|
</div>
|
2022-08-12 16:46:04 +02:00
|
|
|
<div class="max-h-[400px] overflow-y-auto">
|
2021-12-13 17:02:10 +01:00
|
|
|
<div v-if="isSelectedActorAGroup">
|
2020-09-29 09:53:48 +02:00
|
|
|
<p>{{ $t("Add a contact") }}</p>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-input
|
2021-08-11 12:43:54 +02:00
|
|
|
:placeholder="$t('Filter by name')"
|
2022-04-03 22:17:07 +02:00
|
|
|
:value="contactFilter"
|
|
|
|
@input="debounceSetFilterByName"
|
2021-11-07 21:02:06 +01:00
|
|
|
dir="auto"
|
2021-08-11 12:43:54 +02:00
|
|
|
/>
|
2021-12-13 17:02:10 +01:00
|
|
|
<div v-if="actorMembers.length > 0">
|
|
|
|
<p
|
|
|
|
class="field"
|
|
|
|
v-for="actor in filteredActorMembers"
|
|
|
|
:key="actor.id"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-checkbox
|
2021-12-13 17:02:10 +01:00
|
|
|
v-model="actualContacts"
|
|
|
|
:native-value="actor.id"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex gap-1">
|
|
|
|
<div class="">
|
|
|
|
<figure class="" v-if="actor.avatar">
|
2021-12-13 17:02:10 +01:00
|
|
|
<img
|
2022-07-12 10:55:28 +02:00
|
|
|
class="rounded"
|
2021-12-13 17:02:10 +01:00
|
|
|
:src="actor.avatar.url"
|
|
|
|
:alt="actor.avatar.alt"
|
2022-07-12 10:55:28 +02:00
|
|
|
width="48"
|
|
|
|
height="48"
|
2021-12-13 17:02:10 +01:00
|
|
|
/>
|
|
|
|
</figure>
|
2022-07-12 10:55:28 +02:00
|
|
|
<AccountCircle v-else :size="48" />
|
2021-12-13 17:02:10 +01:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="" v-if="actor.name">
|
|
|
|
<p class="">{{ actor.name }}</p>
|
|
|
|
<p class="">
|
2021-12-13 17:02:10 +01:00
|
|
|
{{ `@${usernameWithDomain(actor)}` }}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="" v-else>
|
2021-08-01 11:03:48 +02:00
|
|
|
{{ `@${usernameWithDomain(actor)}` }}
|
2021-12-13 17:02:10 +01:00
|
|
|
</div>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-checkbox>
|
2021-12-13 17:02:10 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-else-if="
|
|
|
|
actorMembers.length === 0 && contactFilter.length > 0
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<empty-content icon="account-multiple" :inline="true">
|
|
|
|
{{ $t("No group member found") }}
|
|
|
|
</empty-content>
|
|
|
|
</div>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div v-else class="">
|
2020-09-29 09:53:48 +02:00
|
|
|
<p>{{ $t("Your profile will be shown as contact.") }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
2022-08-12 16:46:04 +02:00
|
|
|
<footer class="my-2">
|
2022-07-12 10:55:28 +02:00
|
|
|
<o-button variant="primary" @click="pickActor">
|
2020-09-29 09:53:48 +02:00
|
|
|
{{ $t("Pick") }}
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-button>
|
2020-09-29 09:53:48 +02:00
|
|
|
</footer>
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
</o-modal>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { IActor, IGroup, usernameWithDomain } from "../../types/actor";
|
2020-09-29 09:53:48 +02:00
|
|
|
import OrganizerPicker from "./OrganizerPicker.vue";
|
2021-12-13 17:02:10 +01:00
|
|
|
import EmptyContent from "../Utils/EmptyContent.vue";
|
2022-08-12 16:46:04 +02:00
|
|
|
import {
|
|
|
|
LOGGED_USER_MEMBERSHIPS,
|
|
|
|
PERSON_GROUP_MEMBERSHIPS,
|
|
|
|
} from "../../graphql/actor";
|
2021-03-29 10:33:19 +02:00
|
|
|
import { GROUP_MEMBERS } from "@/graphql/member";
|
|
|
|
import { ActorType, MemberRole } from "@/types/enums";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { useQuery } from "@vue/apollo-composable";
|
|
|
|
import { computed, ref, watch } from "vue";
|
|
|
|
import {
|
|
|
|
useCurrentActorClient,
|
|
|
|
useCurrentUserIdentities,
|
|
|
|
} from "@/composition/apollo/actor";
|
|
|
|
import { useRoute } from "vue-router";
|
|
|
|
import AccountCircle from "vue-material-design-icons/AccountCircle.vue";
|
2022-04-03 22:17:07 +02:00
|
|
|
import debounce from "lodash/debounce";
|
2022-08-12 16:46:04 +02:00
|
|
|
import { IUser } from "@/types/current-user.model";
|
2021-03-29 10:33:19 +02:00
|
|
|
|
|
|
|
const MEMBER_ROLES = [
|
|
|
|
MemberRole.CREATOR,
|
|
|
|
MemberRole.ADMINISTRATOR,
|
|
|
|
MemberRole.MODERATOR,
|
|
|
|
MemberRole.MEMBER,
|
|
|
|
];
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { currentActor } = useCurrentActorClient();
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const route = useRoute();
|
2022-04-03 22:18:33 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { result: personMembershipsResult } = useQuery(
|
|
|
|
PERSON_GROUP_MEMBERSHIPS,
|
|
|
|
() => ({
|
|
|
|
id: currentActor.value?.id,
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
groupId: route.query?.actorId,
|
|
|
|
})
|
|
|
|
);
|
2021-06-10 10:33:16 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const personMemberships = computed(
|
|
|
|
() =>
|
|
|
|
personMembershipsResult.value?.person.memberships ?? {
|
|
|
|
elements: [],
|
|
|
|
total: 0,
|
|
|
|
}
|
|
|
|
);
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { identities } = useCurrentUserIdentities();
|
2021-08-11 12:43:54 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
modelValue?: IActor;
|
|
|
|
inline?: boolean;
|
|
|
|
contacts?: IActor[];
|
|
|
|
}>(),
|
|
|
|
{ inline: true, contacts: () => [] }
|
|
|
|
);
|
2021-08-01 11:03:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const emit = defineEmits(["update:modelValue", "update:Contacts"]);
|
2021-03-29 10:33:19 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const selectedActor = computed({
|
|
|
|
get(): IActor | undefined {
|
|
|
|
if (props.modelValue?.id) {
|
|
|
|
return props.modelValue;
|
|
|
|
}
|
|
|
|
if (currentActor.value) {
|
|
|
|
return (identities.value ?? []).find(
|
|
|
|
(identity) => identity.id === currentActor.value?.id
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
},
|
2022-08-12 16:46:04 +02:00
|
|
|
set(newSelectedActor: IActor | undefined) {
|
|
|
|
emit("update:modelValue", newSelectedActor);
|
2022-07-12 10:55:28 +02:00
|
|
|
},
|
|
|
|
});
|
2021-03-29 10:33:19 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isComponentModalActive = ref(false);
|
|
|
|
const contactFilter = ref("");
|
|
|
|
const membersPage = ref(1);
|
2021-03-29 10:33:19 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { result: membersResult } = useQuery(
|
|
|
|
GROUP_MEMBERS,
|
|
|
|
() => ({
|
|
|
|
groupName: usernameWithDomain(selectedActor.value),
|
|
|
|
page: membersPage.value,
|
|
|
|
limit: 10,
|
|
|
|
roles: MEMBER_ROLES.join(","),
|
|
|
|
name: contactFilter.value,
|
|
|
|
}),
|
|
|
|
() => ({ enabled: selectedActor.value?.type === ActorType.GROUP })
|
|
|
|
);
|
2022-04-03 22:17:07 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const members = computed(
|
|
|
|
() => membersResult.value?.members ?? { elements: [], total: 0 }
|
|
|
|
);
|
2021-03-29 10:33:19 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const actualContacts = computed({
|
|
|
|
get(): (string | undefined)[] {
|
|
|
|
return props.contacts.map(({ id }) => id);
|
|
|
|
},
|
|
|
|
set(contactsIds: (string | undefined)[]) {
|
|
|
|
emit(
|
|
|
|
"update:Contacts",
|
|
|
|
actorMembers.value.filter(({ id }) => contactsIds.includes(id))
|
2021-03-29 10:33:19 +02:00
|
|
|
);
|
2022-07-12 10:55:28 +02:00
|
|
|
},
|
|
|
|
});
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const setContactFilter = (newContactFilter: string) => {
|
|
|
|
contactFilter.value = newContactFilter;
|
|
|
|
};
|
2022-04-03 22:17:07 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const debounceSetFilterByName = debounce(setContactFilter, 1000);
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
watch(personMemberships, () => {
|
|
|
|
if (
|
|
|
|
personMemberships.value?.elements[0]?.parent?.id === route.query?.actorId
|
|
|
|
) {
|
|
|
|
selectedActor.value = personMemberships.value?.elements[0]?.parent;
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const relay = async (group: IGroup): Promise<void> => {
|
|
|
|
actualContacts.value = [];
|
|
|
|
selectedActor.value = group;
|
|
|
|
};
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const pickActor = (): void => {
|
|
|
|
isComponentModalActive.value = false;
|
|
|
|
};
|
2020-09-29 09:53:48 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const actorMembers = computed((): IActor[] => {
|
|
|
|
if (isSelectedActorAGroup.value) {
|
|
|
|
return members.value.elements.map(({ actor }: { actor: IActor }) => actor);
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
return [];
|
|
|
|
});
|
2021-08-11 12:43:54 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const filteredActorMembers = computed((): IActor[] => {
|
|
|
|
return actorMembers.value.filter((actor) => {
|
|
|
|
return [
|
|
|
|
actor.preferredUsername.toLowerCase(),
|
|
|
|
actor.name?.toLowerCase(),
|
|
|
|
actor.domain?.toLowerCase(),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
});
|
2021-08-11 12:43:54 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const isSelectedActorAGroup = computed((): boolean => {
|
|
|
|
return selectedActor.value?.type === ActorType.GROUP;
|
|
|
|
});
|
2022-08-12 16:46:04 +02:00
|
|
|
|
|
|
|
const actorFilter = ref("");
|
|
|
|
|
|
|
|
const { result: groupMembershipsResult } = useQuery<{
|
|
|
|
loggedUser: Pick<IUser, "memberships">;
|
|
|
|
}>(LOGGED_USER_MEMBERSHIPS, () => ({
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
membershipName: actorFilter.value,
|
|
|
|
}));
|
|
|
|
const groupMemberships = computed(
|
|
|
|
() => groupMembershipsResult.value?.loggedUser.memberships.elements ?? []
|
|
|
|
);
|
2020-09-29 09:53:48 +02:00
|
|
|
</script>
|