2018-01-09 17:52:26 +01:00
|
|
|
<template>
|
2022-09-01 10:42:05 +02:00
|
|
|
<nav
|
|
|
|
class="bg-white border-gray-200 px-2 sm:px-4 py-2.5 dark:bg-zinc-900"
|
|
|
|
id="navbar"
|
|
|
|
>
|
2022-10-05 17:42:12 +02:00
|
|
|
<div
|
|
|
|
class="container mx-auto flex flex-wrap items-center mx-auto gap-2 sm:gap-4"
|
|
|
|
>
|
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.HOME }"
|
|
|
|
class="flex items-center"
|
|
|
|
:class="{ 'flex-1': !currentActor?.id }"
|
|
|
|
>
|
2022-07-12 10:55:28 +02:00
|
|
|
<MobilizonLogo class="w-40" />
|
2022-07-12 10:55:28 +02:00
|
|
|
</router-link>
|
2022-08-12 16:46:44 +02:00
|
|
|
<div class="flex items-center md:order-2 ml-auto" v-if="currentActor?.id">
|
2022-08-26 16:08:58 +02:00
|
|
|
<o-dropdown position="bottom-left">
|
2022-07-12 10:55:28 +02:00
|
|
|
<template #trigger>
|
|
|
|
<button
|
|
|
|
type="button"
|
2022-10-05 17:42:12 +02:00
|
|
|
class="flex sm:mr-3 text-sm rounded-full md:mr-0 focus:ring-4 focus:ring-gray-300 dark:focus:ring-gray-600"
|
2022-07-12 10:55:28 +02:00
|
|
|
id="user-menu-button"
|
|
|
|
aria-expanded="false"
|
|
|
|
>
|
|
|
|
<span class="sr-only">{{ t("Open user menu") }}</span>
|
2022-08-26 16:08:58 +02:00
|
|
|
<figure class="h-8 w-8" v-if="currentActor?.avatar">
|
2022-07-12 10:55:28 +02:00
|
|
|
<img
|
2022-08-26 16:08:58 +02:00
|
|
|
class="rounded-full w-full h-full object-cover"
|
2022-07-12 10:55:28 +02:00
|
|
|
alt=""
|
|
|
|
:src="currentActor?.avatar.url"
|
|
|
|
width="32"
|
|
|
|
height="32"
|
2022-10-05 12:13:19 +02:00
|
|
|
loading="lazy"
|
2022-07-12 10:55:28 +02:00
|
|
|
/>
|
|
|
|
</figure>
|
2022-08-26 16:08:58 +02:00
|
|
|
<AccountCircle v-else :size="32" />
|
2022-07-12 10:55:28 +02:00
|
|
|
</button>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<!-- Dropdown menu -->
|
|
|
|
<div
|
2022-08-26 16:08:58 +02:00
|
|
|
class="z-50 text-base list-none bg-white rounded divide-y divide-gray-100 dark:bg-zinc-700 dark:divide-gray-600 max-w-xs"
|
2022-07-12 10:55:28 +02:00
|
|
|
position="bottom-left"
|
|
|
|
>
|
|
|
|
<o-dropdown-item aria-role="listitem">
|
2022-08-26 16:08:58 +02:00
|
|
|
<div class="px-4">
|
|
|
|
<span class="block text-sm text-zinc-900 dark:text-white">{{
|
2022-07-12 10:55:28 +02:00
|
|
|
displayName(currentActor)
|
|
|
|
}}</span>
|
|
|
|
<span
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block text-sm font-medium text-zinc-500 truncate dark:text-zinc-400"
|
|
|
|
v-if="currentUser?.role === ICurrentUserRole.ADMINISTRATOR"
|
|
|
|
>{{ t("Administrator") }}</span
|
2022-07-12 10:55:28 +02:00
|
|
|
>
|
2022-08-26 16:08:58 +02:00
|
|
|
<span
|
|
|
|
class="block text-sm font-medium text-zinc-500 truncate dark:text-zinc-400"
|
|
|
|
v-if="currentUser?.role === ICurrentUserRole.MODERATOR"
|
|
|
|
>{{ t("Moderator") }}</span
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</o-dropdown-item>
|
|
|
|
<o-dropdown-item
|
|
|
|
v-for="identity in identities"
|
|
|
|
:active="identity.id === currentActor.id"
|
|
|
|
:key="identity.id"
|
|
|
|
tabindex="0"
|
|
|
|
@click="
|
|
|
|
setIdentity({
|
|
|
|
preferredUsername: identity.preferredUsername,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
@keyup.enter="
|
|
|
|
setIdentity({
|
|
|
|
preferredUsername: identity.preferredUsername,
|
|
|
|
})
|
|
|
|
"
|
|
|
|
>
|
|
|
|
<div class="flex gap-1 items-center">
|
|
|
|
<div class="flex-none">
|
2022-10-31 13:03:03 +01:00
|
|
|
<figure class="h-8 w-8" v-if="identity.avatar">
|
2022-08-26 16:08:58 +02:00
|
|
|
<img
|
2022-10-31 13:03:03 +01:00
|
|
|
class="rounded-full object-cover h-full"
|
2022-08-26 16:08:58 +02:00
|
|
|
loading="lazy"
|
|
|
|
:src="identity.avatar.url"
|
|
|
|
alt=""
|
|
|
|
height="32"
|
|
|
|
width="32"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
<AccountCircle v-else :size="32" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
class="text-base text-zinc-700 dark:text-zinc-100 flex flex-col flex-auto overflow-hidden items-start"
|
|
|
|
>
|
|
|
|
<p class="truncate">{{ displayName(identity) }}</p>
|
|
|
|
<p class="truncate text-sm" v-if="identity.name">
|
|
|
|
@{{ identity.preferredUsername }}
|
|
|
|
</p>
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
</div>
|
|
|
|
</o-dropdown-item>
|
|
|
|
<o-dropdown-item
|
|
|
|
aria-role="listitem"
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.SETTINGS }"
|
|
|
|
>
|
|
|
|
<span
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 px-4 text-sm text-zinc-700 dark:text-zinc-200 dark:hover:text-white"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ t("My account") }}</span
|
|
|
|
>
|
|
|
|
</o-dropdown-item>
|
|
|
|
<o-dropdown-item
|
|
|
|
aria-role="listitem"
|
|
|
|
v-if="currentUser?.role === ICurrentUserRole.ADMINISTRATOR"
|
|
|
|
tag="router-link"
|
|
|
|
:to="{ name: RouteName.ADMIN_DASHBOARD }"
|
|
|
|
>
|
|
|
|
<span
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 px-4 text-sm text-zinc-700 dark:text-zinc-200 dark:hover:text-white"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ t("Administration") }}</span
|
|
|
|
>
|
|
|
|
</o-dropdown-item>
|
|
|
|
<o-dropdown-item
|
|
|
|
aria-role="listitem"
|
|
|
|
@click="logout"
|
|
|
|
@keyup.enter="logout"
|
|
|
|
>
|
|
|
|
<span
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 px-4 text-sm text-zinc-700 dark:text-zinc-200 dark:hover:text-white"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ t("Log out") }}</span
|
|
|
|
>
|
|
|
|
</o-dropdown-item>
|
|
|
|
</div>
|
|
|
|
</o-dropdown>
|
|
|
|
</div>
|
|
|
|
<button
|
2022-08-12 16:46:44 +02:00
|
|
|
@click="showMobileMenu = !showMobileMenu"
|
2022-07-12 10:55:28 +02:00
|
|
|
type="button"
|
2022-08-26 16:08:58 +02:00
|
|
|
class="inline-flex items-center p-2 ml-1 text-sm text-zinc-500 rounded-lg md:hidden hover:bg-zinc-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-zinc-400 dark:hover:bg-zinc-700 dark:focus:ring-gray-600"
|
2022-07-12 10:55:28 +02:00
|
|
|
aria-controls="mobile-menu-2"
|
|
|
|
aria-expanded="false"
|
|
|
|
>
|
|
|
|
<span class="sr-only">{{ t("Open main menu") }}</span>
|
|
|
|
<svg
|
|
|
|
class="w-6 h-6"
|
|
|
|
aria-hidden="true"
|
|
|
|
fill="currentColor"
|
|
|
|
viewBox="0 0 20 20"
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
>
|
|
|
|
<path
|
|
|
|
fill-rule="evenodd"
|
|
|
|
d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
|
|
|
|
clip-rule="evenodd"
|
|
|
|
></path>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
<div
|
|
|
|
class="justify-between items-center w-full md:flex md:w-auto md:order-1"
|
|
|
|
id="mobile-menu-2"
|
|
|
|
:class="{ hidden: !showMobileMenu }"
|
|
|
|
>
|
|
|
|
<ul
|
2022-08-26 16:08:58 +02:00
|
|
|
class="flex flex-col md:flex-row md:space-x-8 mt-2 md:mt-0 md:font-lightbold"
|
2022-07-12 10:55:28 +02:00
|
|
|
>
|
2022-08-12 16:46:44 +02:00
|
|
|
<li v-if="currentActor?.id">
|
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.MY_EVENTS }"
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 pr-4 pl-3 text-zinc-700 border-b border-gray-100 hover:bg-zinc-50 md:hover:bg-transparent md:border-0 md:hover:text-mbz-purple-700 md:p-0 dark:text-zinc-400 md:dark:hover:text-white dark:hover:bg-zinc-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"
|
2022-08-12 16:46:44 +02:00
|
|
|
>{{ t("My events") }}</router-link
|
|
|
|
>
|
|
|
|
</li>
|
|
|
|
<li v-if="currentActor?.id">
|
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.MY_GROUPS }"
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 pr-4 pl-3 text-zinc-700 border-b border-gray-100 hover:bg-zinc-50 md:hover:bg-transparent md:border-0 md:hover:text-mbz-purple-700 md:p-0 dark:text-zinc-400 md:dark:hover:text-white dark:hover:bg-zinc-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"
|
2022-08-12 16:46:44 +02:00
|
|
|
>{{ t("My groups") }}</router-link
|
|
|
|
>
|
|
|
|
</li>
|
2022-07-12 10:55:28 +02:00
|
|
|
<li v-if="!currentActor?.id">
|
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.LOGIN }"
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 pr-4 pl-3 text-zinc-700 border-b border-gray-100 hover:bg-zinc-50 md:hover:bg-transparent md:border-0 md:hover:text-mbz-purple-700 md:p-0 dark:text-zinc-400 md:dark:hover:text-white dark:hover:bg-zinc-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ t("Login") }}</router-link
|
|
|
|
>
|
|
|
|
</li>
|
2022-10-28 16:05:55 +02:00
|
|
|
<li v-if="!currentActor?.id && canRegister">
|
2022-07-12 10:55:28 +02:00
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.REGISTER }"
|
2022-08-26 16:08:58 +02:00
|
|
|
class="block py-2 pr-4 pl-3 text-zinc-700 border-b border-gray-100 hover:bg-zinc-50 md:hover:bg-transparent md:border-0 md:hover:text-mbz-purple-700 md:p-0 dark:text-zinc-400 md:dark:hover:text-white dark:hover:bg-zinc-700 dark:hover:text-white md:dark:hover:bg-transparent dark:border-gray-700"
|
2022-07-12 10:55:28 +02:00
|
|
|
>{{ t("Register") }}</router-link
|
|
|
|
>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2018-01-09 17:52:26 +01:00
|
|
|
</template>
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2022-07-12 10:55:28 +02:00
|
|
|
import MobilizonLogo from "@/components/MobilizonLogo.vue";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { ICurrentUserRole } from "@/types/enums";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { logout } from "../utils/auth";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { displayName } from "../types/actor";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../router/name";
|
2022-10-28 16:05:55 +02:00
|
|
|
import { computed, ref, watch } from "vue";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import AccountCircle from "vue-material-design-icons/AccountCircle.vue";
|
|
|
|
import { useCurrentUserClient } from "@/composition/apollo/user";
|
2022-07-12 10:55:28 +02:00
|
|
|
import {
|
|
|
|
useCurrentActorClient,
|
|
|
|
useCurrentUserIdentities,
|
|
|
|
} from "@/composition/apollo/actor";
|
2022-08-26 16:08:58 +02:00
|
|
|
import { useMutation } from "@vue/apollo-composable";
|
|
|
|
import { UPDATE_DEFAULT_ACTOR } from "@/graphql/actor";
|
|
|
|
import { changeIdentity } from "@/utils/identity";
|
2022-10-28 12:58:52 +02:00
|
|
|
import { useRegistrationConfig } from "@/composition/apollo/config";
|
2019-08-12 16:04:16 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { currentUser } = useCurrentUserClient();
|
|
|
|
const { currentActor } = useCurrentActorClient();
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const router = useRouter();
|
2020-10-28 18:58:43 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { identities } = useCurrentUserIdentities();
|
2022-10-28 16:05:55 +02:00
|
|
|
const { registrationsOpen, registrationsAllowlist, databaseLogin } =
|
|
|
|
useRegistrationConfig();
|
|
|
|
|
|
|
|
const canRegister = computed(() => {
|
|
|
|
return (
|
|
|
|
(registrationsOpen.value || registrationsAllowlist.value) &&
|
|
|
|
databaseLogin.value
|
|
|
|
);
|
|
|
|
});
|
2019-10-08 18:13:06 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2021-10-06 18:00:50 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
watch(identities, () => {
|
2022-07-12 10:55:28 +02:00
|
|
|
// If we don't have any identities, the user has validated their account,
|
|
|
|
// is logging for the first time but didn't create an identity somehow
|
2022-07-12 10:55:28 +02:00
|
|
|
if (identities.value && identities.value.length === 0) {
|
2022-09-27 10:50:14 +02:00
|
|
|
console.warn(
|
2022-07-12 10:55:28 +02:00
|
|
|
"We have no identities listed for current user",
|
|
|
|
identities.value
|
|
|
|
);
|
2022-09-27 10:50:14 +02:00
|
|
|
console.info("Pushing route to REGISTER_PROFILE");
|
2022-07-12 10:55:28 +02:00
|
|
|
router.push({
|
|
|
|
name: RouteName.REGISTER_PROFILE,
|
|
|
|
params: {
|
|
|
|
email: currentUser.value?.email,
|
|
|
|
userAlreadyActivated: "true",
|
|
|
|
},
|
|
|
|
});
|
2021-10-06 18:00:50 +02:00
|
|
|
}
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const { onDone, mutate: setIdentity } = useMutation<{
|
|
|
|
changeDefaultActor: { id: string; defaultActor: { id: string } };
|
|
|
|
}>(UPDATE_DEFAULT_ACTOR);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
onDone(({ data }) => {
|
|
|
|
const identity = identities.value?.find(
|
|
|
|
({ id }) => id === data?.changeDefaultActor?.defaultActor?.id
|
|
|
|
);
|
|
|
|
if (!identity) return;
|
|
|
|
changeIdentity(identity);
|
|
|
|
});
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const showMobileMenu = ref(false);
|
2018-12-21 15:41:34 +01:00
|
|
|
</script>
|