2022-12-20 01:52:01 -08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, onMounted, ref } from 'vue';
|
2023-07-28 00:51:07 -07:00
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2023-05-05 01:41:54 -07:00
|
|
|
import type { UsageTelemetry } from '@/stores/usage.store';
|
|
|
|
import { useUsageStore } from '@/stores/usage.store';
|
2022-12-20 01:52:01 -08:00
|
|
|
import { telemetry } from '@/plugins/telemetry';
|
|
|
|
import { i18n as locale } from '@/plugins/i18n';
|
2023-11-28 03:15:08 -08:00
|
|
|
import { useUIStore } from '@/stores/ui.store';
|
|
|
|
import { useToast } from '@/composables/useToast';
|
2024-09-30 01:57:25 -07:00
|
|
|
import { useDocumentTitle } from '@/composables/useDocumentTitle';
|
2024-06-06 06:30:17 -07:00
|
|
|
import { hasPermission } from '@/utils/rbac/permissions';
|
2024-10-09 04:21:34 -07:00
|
|
|
import N8nInfoTip from 'n8n-design-system/components/N8nInfoTip';
|
|
|
|
import { COMMUNITY_PLUS_ENROLLMENT_MODAL } from '@/constants';
|
2024-10-21 01:02:18 -07:00
|
|
|
import { useUsersStore } from '@/stores/users.store';
|
|
|
|
import { getResourcePermissions } from '@/permissions';
|
2022-12-20 01:52:01 -08:00
|
|
|
|
|
|
|
const usageStore = useUsageStore();
|
|
|
|
const route = useRoute();
|
|
|
|
const router = useRouter();
|
2023-06-05 10:39:04 -07:00
|
|
|
const uiStore = useUIStore();
|
2024-10-21 01:02:18 -07:00
|
|
|
const usersStore = useUsersStore();
|
2023-07-28 00:51:07 -07:00
|
|
|
const toast = useToast();
|
2024-09-30 01:57:25 -07:00
|
|
|
const documentTitle = useDocumentTitle();
|
2022-12-20 01:52:01 -08:00
|
|
|
|
|
|
|
const queryParamCallback = ref<string>(
|
|
|
|
`callback=${encodeURIComponent(`${window.location.origin}${window.location.pathname}`)}`,
|
|
|
|
);
|
2023-01-09 04:57:51 -08:00
|
|
|
const viewPlansUrl = computed(
|
|
|
|
() => `${usageStore.viewPlansUrl}&${queryParamCallback.value}&source=usage_page`,
|
|
|
|
);
|
2022-12-20 01:52:01 -08:00
|
|
|
const managePlanUrl = computed(() => `${usageStore.managePlanUrl}&${queryParamCallback.value}`);
|
|
|
|
const activationKeyModal = ref(false);
|
|
|
|
const activationKey = ref('');
|
|
|
|
const activationKeyInput = ref<HTMLInputElement | null>(null);
|
|
|
|
|
2023-11-23 03:22:47 -08:00
|
|
|
const canUserActivateLicense = computed(() =>
|
2024-03-18 03:39:15 -07:00
|
|
|
hasPermission(['rbac'], { rbac: { scope: 'license:manage' } }),
|
2023-11-23 03:22:47 -08:00
|
|
|
);
|
|
|
|
|
2024-10-03 04:39:48 -07:00
|
|
|
const badgedPlanName = computed(() => {
|
2024-10-07 04:09:58 -07:00
|
|
|
const [badge, name] = usageStore.planName.split(' ');
|
2024-10-03 04:39:48 -07:00
|
|
|
return {
|
|
|
|
name,
|
|
|
|
badge,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2024-10-09 04:21:34 -07:00
|
|
|
const isCommunity = computed(() => usageStore.planName.toLowerCase() === 'community');
|
|
|
|
|
2024-10-03 04:39:48 -07:00
|
|
|
const isCommunityEditionRegistered = computed(
|
2024-10-07 04:09:58 -07:00
|
|
|
() => usageStore.planName.toLowerCase() === 'registered community',
|
2024-10-03 04:39:48 -07:00
|
|
|
);
|
|
|
|
|
2024-10-21 01:02:18 -07:00
|
|
|
const canUserRegisterCommunityPlus = computed(
|
|
|
|
() => getResourcePermissions(usersStore.currentUser?.globalScopes).community.register,
|
|
|
|
);
|
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
const showActivationSuccess = () => {
|
2023-07-28 00:51:07 -07:00
|
|
|
toast.showMessage({
|
|
|
|
type: 'success',
|
2022-12-20 01:52:01 -08:00
|
|
|
title: locale.baseText('settings.usageAndPlan.license.activation.success.title'),
|
|
|
|
message: locale.baseText('settings.usageAndPlan.license.activation.success.message', {
|
|
|
|
interpolate: {
|
|
|
|
name: usageStore.planName,
|
|
|
|
type: usageStore.planId
|
|
|
|
? locale.baseText('settings.usageAndPlan.plan')
|
|
|
|
: locale.baseText('settings.usageAndPlan.edition'),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const showActivationError = (error: Error) => {
|
2023-07-28 00:51:07 -07:00
|
|
|
toast.showError(
|
|
|
|
error,
|
|
|
|
locale.baseText('settings.usageAndPlan.license.activation.error.title'),
|
|
|
|
error.message,
|
|
|
|
);
|
2022-12-20 01:52:01 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
const onLicenseActivation = async () => {
|
|
|
|
try {
|
|
|
|
await usageStore.activateLicense(activationKey.value);
|
|
|
|
activationKeyModal.value = false;
|
|
|
|
showActivationSuccess();
|
|
|
|
} catch (error) {
|
|
|
|
showActivationError(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2024-09-30 01:57:25 -07:00
|
|
|
documentTitle.set(locale.baseText('settings.usageAndPlan.title'));
|
2022-12-29 00:42:38 -08:00
|
|
|
usageStore.setLoading(true);
|
|
|
|
if (route.query.key) {
|
2022-12-20 01:52:01 -08:00
|
|
|
try {
|
2022-12-29 00:42:38 -08:00
|
|
|
await usageStore.activateLicense(route.query.key as string);
|
|
|
|
await router.replace({ query: {} });
|
|
|
|
showActivationSuccess();
|
2022-12-20 01:52:01 -08:00
|
|
|
usageStore.setLoading(false);
|
2022-12-29 00:42:38 -08:00
|
|
|
return;
|
2022-12-20 01:52:01 -08:00
|
|
|
} catch (error) {
|
2022-12-29 00:42:38 -08:00
|
|
|
showActivationError(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
2023-11-23 03:22:47 -08:00
|
|
|
if (!route.query.key && canUserActivateLicense.value) {
|
2022-12-29 00:42:38 -08:00
|
|
|
await usageStore.refreshLicenseManagementToken();
|
|
|
|
} else {
|
|
|
|
await usageStore.getLicenseInfo();
|
|
|
|
}
|
|
|
|
usageStore.setLoading(false);
|
|
|
|
} catch (error) {
|
|
|
|
if (!error.name) {
|
|
|
|
error.name = locale.baseText('settings.usageAndPlan.error');
|
2022-12-20 01:52:01 -08:00
|
|
|
}
|
2023-07-28 00:51:07 -07:00
|
|
|
toast.showError(error, error.name, error.message);
|
2022-12-20 01:52:01 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const sendUsageTelemetry = (action: UsageTelemetry['action']) => {
|
|
|
|
const telemetryPayload = usageStore.telemetryPayload;
|
|
|
|
telemetryPayload.action = action;
|
|
|
|
telemetry.track('User clicked button on usage page', telemetryPayload);
|
|
|
|
};
|
|
|
|
|
|
|
|
const onAddActivationKey = () => {
|
|
|
|
activationKeyModal.value = true;
|
|
|
|
sendUsageTelemetry('add_activation_key');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onViewPlans = () => {
|
2023-10-06 04:16:27 -07:00
|
|
|
void uiStore.goToUpgrade('usage_page', 'open');
|
2022-12-20 01:52:01 -08:00
|
|
|
sendUsageTelemetry('view_plans');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onManagePlan = () => {
|
|
|
|
sendUsageTelemetry('manage_plan');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDialogClosed = () => {
|
|
|
|
activationKey.value = '';
|
|
|
|
};
|
|
|
|
|
|
|
|
const onDialogOpened = () => {
|
|
|
|
activationKeyInput.value?.focus();
|
|
|
|
};
|
2024-10-09 04:21:34 -07:00
|
|
|
|
|
|
|
const openCommunityRegisterModal = () => {
|
|
|
|
uiStore.openModal(COMMUNITY_PLUS_ENROLLMENT_MODAL);
|
|
|
|
};
|
2022-12-20 01:52:01 -08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-07-28 00:51:07 -07:00
|
|
|
<div class="settings-usage-and-plan">
|
2024-10-03 04:39:48 -07:00
|
|
|
<n8n-heading tag="h2" size="2xlarge">{{
|
|
|
|
locale.baseText('settings.usageAndPlan.title')
|
|
|
|
}}</n8n-heading>
|
2024-09-20 05:24:08 -07:00
|
|
|
<div v-if="!usageStore.isLoading">
|
2024-10-03 04:39:48 -07:00
|
|
|
<n8n-heading tag="h3" :class="$style.title" size="large">
|
2023-07-28 00:51:07 -07:00
|
|
|
<i18n-t keypath="settings.usageAndPlan.description" tag="span">
|
2024-10-09 04:21:34 -07:00
|
|
|
<template #name>{{ badgedPlanName.name ?? usageStore.planName }}</template>
|
2022-12-28 08:07:34 -08:00
|
|
|
<template #type>
|
|
|
|
<span v-if="usageStore.planId">{{
|
|
|
|
locale.baseText('settings.usageAndPlan.plan')
|
2022-12-20 01:52:01 -08:00
|
|
|
}}</span>
|
2022-12-28 08:07:34 -08:00
|
|
|
<span v-else>{{ locale.baseText('settings.usageAndPlan.edition') }}</span>
|
2022-12-20 01:52:01 -08:00
|
|
|
</template>
|
2023-07-28 00:51:07 -07:00
|
|
|
</i18n-t>
|
2024-10-09 04:21:34 -07:00
|
|
|
<span v-if="badgedPlanName.badge && badgedPlanName.name" :class="$style.titleTooltip">
|
|
|
|
<N8nTooltip placement="top">
|
2024-10-03 04:39:48 -07:00
|
|
|
<template #content>
|
|
|
|
<i18n-t
|
|
|
|
v-if="isCommunityEditionRegistered"
|
|
|
|
keypath="settings.usageAndPlan.license.communityRegistered.tooltip"
|
|
|
|
>
|
|
|
|
</i18n-t>
|
|
|
|
</template>
|
|
|
|
<N8nBadge>{{ badgedPlanName.badge }}</N8nBadge>
|
|
|
|
</N8nTooltip>
|
|
|
|
</span>
|
2022-12-28 08:07:34 -08:00
|
|
|
</n8n-heading>
|
|
|
|
|
2024-10-21 01:02:18 -07:00
|
|
|
<N8nNotice v-if="isCommunity && canUserRegisterCommunityPlus" class="mt-0" theme="warning">
|
2024-10-09 04:21:34 -07:00
|
|
|
<i18n-t keypath="settings.usageAndPlan.callOut">
|
|
|
|
<template #link>
|
|
|
|
<N8nButton
|
|
|
|
class="pl-0 pr-0"
|
|
|
|
text
|
|
|
|
:label="locale.baseText('settings.usageAndPlan.callOut.link')"
|
|
|
|
@click="openCommunityRegisterModal"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</i18n-t>
|
|
|
|
</N8nNotice>
|
|
|
|
|
2022-12-28 08:07:34 -08:00
|
|
|
<div :class="$style.quota">
|
|
|
|
<n8n-text size="medium" color="text-light">
|
|
|
|
{{ locale.baseText('settings.usageAndPlan.activeWorkflows') }}
|
|
|
|
</n8n-text>
|
|
|
|
<div :class="$style.chart">
|
|
|
|
<span v-if="usageStore.executionLimit > 0" :class="$style.chartLine">
|
|
|
|
<span
|
|
|
|
:class="$style.chartBar"
|
|
|
|
:style="{ width: `${usageStore.executionPercentage}%` }"
|
|
|
|
></span>
|
|
|
|
</span>
|
2023-07-28 00:51:07 -07:00
|
|
|
<i18n-t
|
|
|
|
tag="span"
|
|
|
|
:class="$style.count"
|
|
|
|
keypath="settings.usageAndPlan.activeWorkflows.count"
|
|
|
|
>
|
2022-12-28 08:07:34 -08:00
|
|
|
<template #count>{{ usageStore.executionCount }}</template>
|
|
|
|
<template #limit>
|
|
|
|
<span v-if="usageStore.executionLimit < 0">{{
|
|
|
|
locale.baseText('settings.usageAndPlan.activeWorkflows.unlimited')
|
|
|
|
}}</span>
|
|
|
|
<span v-else>{{ usageStore.executionLimit }}</span>
|
|
|
|
</template>
|
2023-07-28 00:51:07 -07:00
|
|
|
</i18n-t>
|
2022-12-28 08:07:34 -08:00
|
|
|
</div>
|
2022-12-20 01:52:01 -08:00
|
|
|
</div>
|
|
|
|
|
2024-10-09 04:21:34 -07:00
|
|
|
<N8nInfoTip>{{ locale.baseText('settings.usageAndPlan.activeWorkflows.hint') }}</N8nInfoTip>
|
2022-12-20 01:52:01 -08:00
|
|
|
|
2022-12-28 08:07:34 -08:00
|
|
|
<div :class="$style.buttons">
|
|
|
|
<n8n-button
|
2023-11-23 03:22:47 -08:00
|
|
|
v-if="canUserActivateLicense"
|
2023-12-28 00:49:58 -08:00
|
|
|
:class="$style.buttonTertiary"
|
2022-12-28 08:07:34 -08:00
|
|
|
type="tertiary"
|
|
|
|
size="large"
|
2023-12-28 00:49:58 -08:00
|
|
|
@click="onAddActivationKey"
|
2022-12-28 08:07:34 -08:00
|
|
|
>
|
2023-11-01 05:33:36 -07:00
|
|
|
<span>{{ locale.baseText('settings.usageAndPlan.button.activation') }}</span>
|
2022-12-28 08:07:34 -08:00
|
|
|
</n8n-button>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-button v-if="usageStore.managementToken" size="large" @click="onManagePlan">
|
2022-12-28 08:07:34 -08:00
|
|
|
<a :href="managePlanUrl" target="_blank">{{
|
|
|
|
locale.baseText('settings.usageAndPlan.button.manage')
|
|
|
|
}}</a>
|
2022-12-20 01:52:01 -08:00
|
|
|
</n8n-button>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-button v-else size="large" @click.prevent="onViewPlans">
|
2022-12-28 08:07:34 -08:00
|
|
|
<a :href="viewPlansUrl" target="_blank">{{
|
|
|
|
locale.baseText('settings.usageAndPlan.button.plans')
|
|
|
|
}}</a>
|
2022-12-20 01:52:01 -08:00
|
|
|
</n8n-button>
|
2022-12-28 08:07:34 -08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<el-dialog
|
2023-12-28 00:49:58 -08:00
|
|
|
v-model="activationKeyModal"
|
2022-12-28 08:07:34 -08:00
|
|
|
width="480px"
|
|
|
|
top="0"
|
|
|
|
:title="locale.baseText('settings.usageAndPlan.dialog.activation.title')"
|
2023-08-01 04:52:33 -07:00
|
|
|
:modal-class="$style.center"
|
2023-12-28 00:49:58 -08:00
|
|
|
@closed="onDialogClosed"
|
|
|
|
@opened="onDialogOpened"
|
2022-12-28 08:07:34 -08:00
|
|
|
>
|
|
|
|
<template #default>
|
|
|
|
<n8n-input
|
|
|
|
ref="activationKeyInput"
|
|
|
|
v-model="activationKey"
|
|
|
|
:placeholder="locale.baseText('settings.usageAndPlan.dialog.activation.label')"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #footer>
|
2023-12-28 00:49:58 -08:00
|
|
|
<n8n-button type="secondary" @click="activationKeyModal = false">
|
2022-12-28 08:07:34 -08:00
|
|
|
{{ locale.baseText('settings.usageAndPlan.dialog.activation.cancel') }}
|
|
|
|
</n8n-button>
|
2023-07-28 00:51:07 -07:00
|
|
|
<n8n-button @click="onLicenseActivation">
|
2022-12-28 08:07:34 -08:00
|
|
|
{{ locale.baseText('settings.usageAndPlan.dialog.activation.activate') }}
|
|
|
|
</n8n-button>
|
|
|
|
</template>
|
|
|
|
</el-dialog>
|
|
|
|
</div>
|
2022-12-20 01:52:01 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2023-12-29 02:13:24 -08:00
|
|
|
@import '@/styles/variables';
|
2022-12-20 01:52:01 -08:00
|
|
|
|
2023-08-01 04:52:33 -07:00
|
|
|
.center > div {
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
2022-12-28 08:07:34 -08:00
|
|
|
.actionBox {
|
|
|
|
margin: var(--spacing-2xl) 0 0;
|
|
|
|
}
|
|
|
|
|
2022-12-20 01:52:01 -08:00
|
|
|
.spacedFlex {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
2024-10-03 04:39:48 -07:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2022-12-20 01:52:01 -08:00
|
|
|
padding: var(--spacing-2xl) 0 var(--spacing-m);
|
|
|
|
}
|
|
|
|
|
|
|
|
.quota {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
height: 54px;
|
|
|
|
padding: 0 var(--spacing-s);
|
|
|
|
margin: 0 0 var(--spacing-xs);
|
|
|
|
background: var(--color-background-xlight);
|
|
|
|
border-radius: var(--border-radius-large);
|
2023-11-14 08:13:30 -08:00
|
|
|
border: 1px solid var(--color-foreground-base);
|
2022-12-20 01:52:01 -08:00
|
|
|
white-space: nowrap;
|
|
|
|
|
|
|
|
.count {
|
|
|
|
text-transform: lowercase;
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.buttons {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
padding: var(--spacing-xl) 0 0;
|
|
|
|
|
|
|
|
button {
|
|
|
|
margin-left: var(--spacing-xs);
|
|
|
|
|
|
|
|
a {
|
|
|
|
display: inline-block;
|
|
|
|
color: inherit;
|
|
|
|
text-decoration: none;
|
|
|
|
padding: var(--spacing-xs) var(--spacing-m);
|
|
|
|
margin: calc(var(--spacing-xs) * -1) calc(var(--spacing-m) * -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.chart {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: flex-end;
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.chartLine {
|
|
|
|
display: block;
|
|
|
|
height: 10px;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 260px;
|
|
|
|
margin: 0 var(--spacing-m);
|
|
|
|
border-radius: 10px;
|
|
|
|
background: var(--color-background-base);
|
|
|
|
}
|
|
|
|
|
|
|
|
.chartBar {
|
|
|
|
float: left;
|
|
|
|
height: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
background: var(--color-secondary);
|
|
|
|
border-radius: 10px;
|
|
|
|
transition: width 0.2s $ease-out-expo;
|
|
|
|
}
|
|
|
|
|
|
|
|
div[class*='info'] > span > span:last-child {
|
|
|
|
line-height: 1.4;
|
|
|
|
padding: 0 0 0 var(--spacing-4xs);
|
|
|
|
}
|
2024-10-03 04:39:48 -07:00
|
|
|
|
|
|
|
.titleTooltip {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin: 0 0 0 var(--spacing-2xs);
|
|
|
|
}
|
2022-12-20 01:52:01 -08:00
|
|
|
</style>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2023-07-28 00:51:07 -07:00
|
|
|
.settings-usage-and-plan {
|
|
|
|
:deep(.el-dialog__wrapper) {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
.el-dialog {
|
|
|
|
margin: 0;
|
|
|
|
|
|
|
|
.el-dialog__footer {
|
|
|
|
button {
|
|
|
|
margin-left: var(--spacing-xs);
|
|
|
|
}
|
2022-12-20 01:52:01 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|