opnform/resources/js/components/Navbar.vue

215 lines
9.8 KiB
Vue
Raw Normal View History

2022-09-20 19:59:52 +00:00
<template>
2022-10-17 11:02:17 +00:00
<nav v-if="hasNavbar" class="bg-white dark:bg-notion-dark border-b">
2022-09-20 19:59:52 +00:00
<div class="max-w-7xl mx-auto px-8">
<div class="flex items-center justify-between h-16">
<div class="flex items-center">
2022-10-17 15:08:36 +00:00
<router-link :to="{ name: user ? 'home' : 'welcome' }" class="flex-shrink-0 font-semibold hover:no-underline flex items-center">
<img :src="asset('img/logo.svg')" alt="notion tools logo" class="w-8 h-8">
2022-09-20 19:59:52 +00:00
<span
2022-10-17 12:20:13 +00:00
class="ml-2 text-md hidden sm:inline text-black dark:text-white"
2022-09-20 19:59:52 +00:00
>
{{ appName }}</span>
2022-09-20 19:59:52 +00:00
</router-link>
2023-10-14 16:24:44 +00:00
<workspace-dropdown class="ml-6" />
2022-09-20 19:59:52 +00:00
</div>
2023-09-20 10:08:26 +00:00
<div v-if="showAuth" class="hidden md:block ml-auto relative">
2023-10-14 16:24:44 +00:00
<router-link v-if="$route.name !== 'templates'" :to="{name:'templates'}"
class="text-sm text-gray-600 dark:text-white hover:text-gray-800 cursor-pointer mt-1 mr-8"
>
Templates
2022-10-07 07:57:04 +00:00
</router-link>
2023-10-14 16:24:44 +00:00
<router-link v-if="$route.name !== 'aiformbuilder'" :to="{name:'aiformbuilder'}"
class="text-sm text-gray-600 dark:text-white hidden lg:inline hover:text-gray-800 cursor-pointer mt-1 mr-8"
>
2023-09-09 11:10:49 +00:00
AI Form Builder
</router-link>
2023-10-14 16:24:44 +00:00
<router-link v-if="paidPlansEnabled && (user===null || (user && workspace && !workspace.is_pro)) && $route.name !== 'pricing'" :to="{name:'pricing'}"
class="text-sm text-gray-600 dark:text-white hover:text-gray-800 cursor-pointer mt-1 mr-8"
>
<span v-if="user">Upgrade</span>
<span v-else>Pricing</span>
</router-link>
2023-10-14 16:24:44 +00:00
<a v-if="hasCrisp" href="#"
class="text-sm text-gray-600 dark:text-white hover:text-gray-800 cursor-pointer mt-1" @click.prevent="openCrisp"
2022-11-16 10:18:59 +00:00
>
Help
</a>
2023-10-14 16:24:44 +00:00
<a v-else :href="helpUrl"
class="text-sm text-gray-600 dark:text-white hover:text-gray-800 cursor-pointer mt-1" target="_blank"
2022-09-20 19:59:52 +00:00
>
Help
</a>
</div>
2023-10-14 16:24:44 +00:00
<div v-if="showAuth" class="hidden md:block pl-5 border-gray-300 border-r h-5" />
2022-09-20 19:59:52 +00:00
<div v-if="showAuth" class="block">
2022-10-07 07:57:04 +00:00
<div class="flex items-center">
2022-09-20 19:59:52 +00:00
<div class="ml-3 mr-4 relative">
<div class="relative inline-block text-left">
<dropdown v-if="user" dusk="nav-dropdown">
<template #trigger="{toggle}">
<button id="dropdown-menu-button" type="button"
2022-10-17 12:20:13 +00:00
class="flex items-center justify-center w-full rounded-md px-4 py-2 text-sm text-gray-700 dark:text-gray-50 hover:bg-gray-50 dark:hover:bg-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-gray-500"
2022-09-20 19:59:52 +00:00
dusk="nav-dropdown-button" @click.prevent="toggle()"
>
<img :src="user.photo_url" class="rounded-full w-6 h-6">
<p class="ml-2 hidden sm:inline">
{{ user.name }}
</p>
</button>
</template>
<router-link v-if="userOnboarded" :to="{ name: 'home' }"
class="block block px-4 py-2 text-md text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:text-white dark:hover:bg-gray-600 flex items-center"
>
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24"
stroke="currentColor"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"
/>
</svg>
My Forms
</router-link>
<router-link v-if="userOnboarded" :to="{ name: 'my_templates' }"
class="block block px-4 py-2 text-md text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:text-white dark:hover:bg-gray-600 flex items-center"
>
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
</svg>
My Templates
</router-link>
2022-09-20 19:59:52 +00:00
<router-link :to="{ name: 'settings.profile' }"
class="block block px-4 py-2 text-md text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:text-white dark:hover:bg-gray-600 flex items-center"
>
<svg class="w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"
/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
/>
</svg>
2023-10-14 16:24:44 +00:00
Settings
2022-09-20 19:59:52 +00:00
</router-link>
<a href="#"
2022-10-07 07:57:04 +00:00
class="block block px-4 py-2 text-md text-gray-700 dark:text-white hover:bg-gray-100 hover:text-gray-900 dark:text-gray-100 dark:hover:text-white dark:hover:bg-gray-600 flex items-center"
2022-09-20 19:59:52 +00:00
@click.prevent="logout"
>
<svg class="w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"
>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
/>
</svg>
2023-10-14 16:24:44 +00:00
Logout
2022-09-20 19:59:52 +00:00
</a>
</dropdown>
2023-10-14 16:24:44 +00:00
<div v-else class="flex gap-2">
2022-09-20 19:59:52 +00:00
<router-link v-if="$route.name !== 'login'" :to="{ name: 'login' }"
2022-10-17 12:20:13 +00:00
class="text-gray-600 dark:text-white hover:text-gray-800 dark:hover:text-white px-0 sm:px-3 py-2 rounded-md text-sm"
2022-09-20 19:59:52 +00:00
active-class="text-gray-800 dark:text-white"
>
2023-10-14 16:24:44 +00:00
Login
2022-09-20 19:59:52 +00:00
</router-link>
2022-10-17 13:42:04 +00:00
2023-10-14 16:24:44 +00:00
<v-button v-track.nav_create_form_click size="small" :to="{ name: 'forms.create.guest' }" color="outline-blue" :arrow="true">
2022-10-17 13:42:04 +00:00
Create a form
</v-button>
2022-09-20 19:59:52 +00:00
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
</template>
<script>
2023-10-14 16:24:44 +00:00
import { mapGetters } from 'vuex'
import Dropdown from './common/Dropdown.vue'
import WorkspaceDropdown from './WorkspaceDropdown.vue'
2022-09-20 19:59:52 +00:00
export default {
components: {
WorkspaceDropdown,
Dropdown
},
data: () => ({
2023-10-14 16:24:44 +00:00
appName: window.config.appName
2022-09-20 19:59:52 +00:00
}),
computed: {
githubUrl: () => window.config.links.github_url,
helpUrl: () => window.config.links.help_url,
2023-10-14 16:24:44 +00:00
form () {
2022-09-20 19:59:52 +00:00
if (this.$route.name && this.$route.name.startsWith('forms.show_public')) {
return this.$store.getters['open/forms/getBySlug'](this.$route.params.slug)
}
return null
},
workspace () {
return this.$store.getters['open/workspaces/getCurrent']()
},
2023-10-14 16:24:44 +00:00
paidPlansEnabled () {
return window.config.paid_plans_enabled
},
2023-10-14 16:24:44 +00:00
showAuth () {
2022-09-20 19:59:52 +00:00
return this.$route.name && !this.$route.name.startsWith('forms.show_public')
},
2023-10-14 16:24:44 +00:00
hasNavbar () {
2022-09-20 19:59:52 +00:00
if (this.isIframe) return false
if (this.$route.name && this.$route.name.startsWith('forms.show_public')) {
if (this.form) {
// If there is a cover, or if branding is hidden remove nav
if (this.form.cover_picture || this.form.no_branding) {
return false
}
} else {
return false
}
}
2023-09-05 14:25:33 +00:00
return !this.$root.navbarHidden
2022-09-20 19:59:52 +00:00
},
2023-10-14 16:24:44 +00:00
isIframe () {
2022-09-20 19:59:52 +00:00
return window.location !== window.parent.location || window.frameElement
},
...mapGetters({
user: 'auth/user'
}),
2023-10-14 16:24:44 +00:00
userOnboarded () {
2022-09-20 19:59:52 +00:00
return this.user && this.user.workspaces_count > 0
2022-11-16 10:18:59 +00:00
},
2023-10-14 16:24:44 +00:00
hasCrisp () {
2022-11-16 10:18:59 +00:00
return window.config.crisp_website_id
2023-10-14 16:24:44 +00:00
}
2022-09-20 19:59:52 +00:00
},
methods: {
2023-10-14 16:24:44 +00:00
async logout () {
2022-09-20 19:59:52 +00:00
// Log out the user.
await this.$store.dispatch('auth/logout')
// Reset store
this.$store.dispatch('open/workspaces/resetState')
this.$store.dispatch('open/forms/resetState')
// Redirect to login.
2023-10-14 16:24:44 +00:00
this.$router.push({ name: 'login' })
2022-09-20 19:59:52 +00:00
},
openCrisp () {
window.$crisp.push(['do', 'chat:show'])
window.$crisp.push(['do', 'chat:open'])
}
2022-09-20 19:59:52 +00:00
}
}
</script>