2023-12-09 15:47:03 +01:00
|
|
|
<template>
|
2024-05-06 14:12:05 +02:00
|
|
|
<div class="mb-8">
|
2024-04-22 16:11:21 +02:00
|
|
|
<div
|
|
|
|
|
v-if="userInfo"
|
2024-05-06 14:12:05 +02:00
|
|
|
class="flex gap-2 items-center flex-wrap"
|
2024-04-22 16:11:21 +02:00
|
|
|
>
|
|
|
|
|
<h1 class="text-xl">
|
|
|
|
|
{{ userInfo.name }}
|
|
|
|
|
</h1>
|
|
|
|
|
<div class="text-xs select-all bg-gray-50 rounded-md px-2 py-1 border">
|
|
|
|
|
{{ userInfo.id }}
|
|
|
|
|
</div>
|
|
|
|
|
<div class="text-xs select-all bg-gray-50 rounded-md px-2 py-1 border">
|
|
|
|
|
{{ userInfo.email }}
|
|
|
|
|
</div>
|
2024-04-15 19:39:03 +02:00
|
|
|
<a
|
2024-04-22 16:11:21 +02:00
|
|
|
v-if="userInfo.stripe_id"
|
|
|
|
|
:href="'https://dashboard.stripe.com/customers/'+userInfo.stripe_id"
|
2024-04-15 19:39:03 +02:00
|
|
|
target="_blank"
|
2024-04-22 16:11:21 +02:00
|
|
|
class="text-xs select-all bg-purple-50 border-purple-200 text-purple-500 rounded-md px-2 py-1 border"
|
2024-04-15 19:39:03 +02:00
|
|
|
>
|
2024-04-22 16:11:21 +02:00
|
|
|
<Icon
|
|
|
|
|
name="bx:bxl-stripe"
|
|
|
|
|
class="h-4 w-4 inline-block"
|
|
|
|
|
/>
|
|
|
|
|
{{ userInfo.stripe_id }}
|
2023-12-09 15:47:03 +01:00
|
|
|
</a>
|
2024-05-06 14:12:05 +02:00
|
|
|
<div
|
|
|
|
|
v-if="userPlan"
|
|
|
|
|
:class="userPlanStyles"
|
|
|
|
|
>
|
|
|
|
|
{{ userPlan }}
|
|
|
|
|
</div>
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
2024-04-22 16:11:21 +02:00
|
|
|
<h3
|
|
|
|
|
v-else
|
|
|
|
|
class="font-semibold text-2xl text-gray-900 mb-4"
|
2024-04-15 19:39:03 +02:00
|
|
|
>
|
2024-04-22 16:11:21 +02:00
|
|
|
Admin settings
|
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<template v-if="!userInfo">
|
|
|
|
|
<form
|
|
|
|
|
class="pb-8 max-w-lg"
|
|
|
|
|
@submit.prevent="fetchUser"
|
|
|
|
|
@keydown="fetchUserForm.onKeydown($event)"
|
|
|
|
|
>
|
|
|
|
|
<text-input
|
|
|
|
|
name="identifier"
|
|
|
|
|
:form="fetchUserForm"
|
|
|
|
|
label="Identifier"
|
|
|
|
|
:required="true"
|
|
|
|
|
help="User Id, User Email, Form Slug or View Slug"
|
|
|
|
|
/>
|
|
|
|
|
<v-button
|
|
|
|
|
:loading="loading"
|
|
|
|
|
type="success"
|
|
|
|
|
color="blue"
|
|
|
|
|
class="mt-4 w-full"
|
|
|
|
|
>
|
|
|
|
|
Fetch User
|
|
|
|
|
</v-button>
|
|
|
|
|
</form>
|
|
|
|
|
</template>
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
<div
|
|
|
|
|
v-else
|
|
|
|
|
class="flex flex-col"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
id="admin-buttons"
|
|
|
|
|
class="flex gap-1 my-4"
|
2024-04-15 19:39:03 +02:00
|
|
|
>
|
2024-04-22 16:11:21 +02:00
|
|
|
<impersonate-user :user="userInfo" />
|
2024-05-06 14:12:05 +02:00
|
|
|
<send-password-reset-email :user="userInfo" />
|
2024-04-22 16:11:21 +02:00
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="w-full grid gap-2 grid-cols-1 lg:grid-cols-2"
|
|
|
|
|
>
|
|
|
|
|
<discount-on-subscription
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
/>
|
|
|
|
|
<extend-trial
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
/>
|
|
|
|
|
<cancel-subscription
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
/>
|
2024-05-06 14:12:05 +02:00
|
|
|
<billing-email
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
/>
|
|
|
|
|
<user-workspaces
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
/>
|
|
|
|
|
<user-subscriptions
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
class="lg:col-span-2"
|
|
|
|
|
/>
|
|
|
|
|
<user-payments
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
class="lg:col-span-2"
|
|
|
|
|
/>
|
|
|
|
|
<deleted-forms
|
|
|
|
|
:user="userInfo"
|
|
|
|
|
class="lg:col-span-2"
|
|
|
|
|
/>
|
2024-04-22 16:11:21 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-12-09 15:47:03 +01:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
<script>
|
|
|
|
|
import { computed } from 'vue'
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
export default {
|
2024-05-06 14:12:05 +02:00
|
|
|
setup() {
|
2024-04-22 16:11:21 +02:00
|
|
|
useOpnSeoMeta({
|
|
|
|
|
title: 'Admin'
|
|
|
|
|
})
|
|
|
|
|
definePageMeta({
|
|
|
|
|
middleware: 'moderator'
|
|
|
|
|
})
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
return {
|
|
|
|
|
authStore,
|
|
|
|
|
user: computed(() => authStore.user),
|
|
|
|
|
useAlert: useAlert()
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-01-04 18:38:50 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
data: () => ({
|
|
|
|
|
userInfo: null,
|
2024-05-06 14:12:05 +02:00
|
|
|
userPlan: 'free',
|
2024-04-22 16:11:21 +02:00
|
|
|
fetchUserForm: useForm({
|
|
|
|
|
identifier: ''
|
|
|
|
|
}),
|
|
|
|
|
loading: false
|
|
|
|
|
}),
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
computed: {
|
2024-05-06 14:12:05 +02:00
|
|
|
userPlanStyles() {
|
|
|
|
|
switch (this.userPlan) {
|
|
|
|
|
case 'pro':
|
|
|
|
|
return 'capitalize text-xs select-all bg-green-50 rounded-md px-2 py-1 border border-green-200 text-green-500'
|
|
|
|
|
case 'enterprise':
|
|
|
|
|
return 'capitalize text-xs select-all bg-blue-50 rounded-md px-2 py-1 border border-blue-200 text-blue-500'
|
|
|
|
|
default:
|
|
|
|
|
return 'capitalize text-xs select-all bg-gray-50 rounded-md px-2 py-1 border'
|
|
|
|
|
}
|
2024-04-22 16:11:21 +02:00
|
|
|
}
|
|
|
|
|
},
|
2024-01-12 17:35:16 +01:00
|
|
|
|
2024-05-06 14:12:05 +02:00
|
|
|
mounted() {
|
2024-04-22 16:11:21 +02:00
|
|
|
// Shortcut link to impersonate users
|
|
|
|
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
|
|
|
const params = Object.fromEntries(urlSearchParams.entries())
|
|
|
|
|
if (params.impersonate) {
|
|
|
|
|
this.fetchUserForm.identifier = params.impersonate
|
|
|
|
|
}
|
|
|
|
|
if (params.user_id) {
|
|
|
|
|
this.fetchUserForm.identifier = params.user_id
|
|
|
|
|
}
|
2024-05-06 14:12:05 +02:00
|
|
|
if (this.fetchUserForm.identifier) {
|
|
|
|
|
this.fetchUser()
|
|
|
|
|
}
|
2024-04-22 16:11:21 +02:00
|
|
|
},
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
methods: {
|
2024-05-06 14:12:05 +02:00
|
|
|
async fetchUser() {
|
2024-04-22 16:11:21 +02:00
|
|
|
if (!this.fetchUserForm.identifier) {
|
|
|
|
|
this.useAlert.error('Identifier is required.')
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
|
2024-04-22 16:11:21 +02:00
|
|
|
this.loading = true
|
|
|
|
|
opnFetch(`/moderator/fetch-user/${encodeURI(this.fetchUserForm.identifier)}`).then(async (data) => {
|
|
|
|
|
this.loading = false
|
2024-05-06 14:12:05 +02:00
|
|
|
this.userInfo = { ...data.user, workspaces: data.workspaces }
|
|
|
|
|
this.getUserPlan(data.workspaces)
|
2024-04-22 16:11:21 +02:00
|
|
|
this.useAlert.success(`User Fetched: ${this.userInfo.name}`)
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
this.useAlert.error(error.data.message)
|
|
|
|
|
this.loading = false
|
|
|
|
|
})
|
2024-05-06 14:12:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
getUserPlan(workspaces) {
|
|
|
|
|
if (workspaces.some(w => w.plan === 'enterprise')) {
|
|
|
|
|
this.userPlan = 'enterprise'
|
|
|
|
|
} else if (workspaces.some(w => w.plan === 'pro')) {
|
|
|
|
|
this.userPlan = 'pro'
|
|
|
|
|
}
|
2024-04-22 16:11:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-09 15:47:03 +01:00
|
|
|
}
|
2024-05-06 14:12:05 +02:00
|
|
|
</script>
|