mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
add limit banner
This commit is contained in:
@@ -11,8 +11,19 @@ const eventsStackedSelectIndex = ref<number>(0);
|
|||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
|
||||||
|
const limitsInfo = ref<{
|
||||||
|
limited: boolean,
|
||||||
|
maxLimit: number,
|
||||||
|
limit: number,
|
||||||
|
total: number,
|
||||||
|
percent: number
|
||||||
|
}>();
|
||||||
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (route.query.just_logged) return location.href = '/';
|
if (route.query.just_logged) return location.href = '/';
|
||||||
|
limitsInfo.value = await $fetch("/api/project/limits_info", signHeaders());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +80,16 @@ const selectLabelsEvents = [
|
|||||||
|
|
||||||
<div :key="'home-' + isLiveDemo()" v-if="projects && activeProject && firstInteraction">
|
<div :key="'home-' + isLiveDemo()" v-if="projects && activeProject && firstInteraction">
|
||||||
|
|
||||||
|
<div class="w-full px-4 py-2">
|
||||||
|
<div v-if="limitsInfo && limitsInfo.limited"
|
||||||
|
class="bg-orange-600 justify-center flex gap-2 py-2 px-4 font-semibold text-[1.2rem] rounded-lg">
|
||||||
|
<div class="poppins text-text"> Limit reached </div>
|
||||||
|
<NuxtLink to="/plans" class="poppins text-[#393972] underline cursor-pointer">
|
||||||
|
Upgrade project
|
||||||
|
</NuxtLink>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<DashboardTopSection></DashboardTopSection>
|
<DashboardTopSection></DashboardTopSection>
|
||||||
<DashboardTopCards></DashboardTopCards>
|
<DashboardTopCards></DashboardTopCards>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
||||||
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
import { ProjectCountModel } from "@schema/ProjectsCounts";
|
||||||
|
import { UserSettingsModel } from "@schema/UserSettings";
|
||||||
import StripeService from '~/server/services/StripeService';
|
import StripeService from '~/server/services/StripeService';
|
||||||
|
|
||||||
export default defineEventHandler(async event => {
|
export default defineEventHandler(async event => {
|
||||||
@@ -14,8 +15,12 @@ export default defineEventHandler(async event => {
|
|||||||
const userData = getRequestUser(event);
|
const userData = getRequestUser(event);
|
||||||
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
||||||
|
|
||||||
|
const userSettings = await UserSettingsModel.findOne({ user_id: userData.id }, { max_projects: true });
|
||||||
|
|
||||||
|
const maxProjects = userSettings?.max_projects || 3;
|
||||||
|
|
||||||
const existingUserProjects = await ProjectModel.countDocuments({ owner: userData.id });
|
const existingUserProjects = await ProjectModel.countDocuments({ owner: userData.id });
|
||||||
if (existingUserProjects == 3) return setResponseStatus(event, 400, 'Already have 3 projects');
|
if (existingUserProjects >= maxProjects) return setResponseStatus(event, 400, 'Already have max number of projects');
|
||||||
|
|
||||||
const customer = await StripeService.createCustomer(userData.user.email);
|
const customer = await StripeService.createCustomer(userData.user.email);
|
||||||
if (!customer) return setResponseStatus(event, 400, 'Error creating customer');
|
if (!customer) return setResponseStatus(event, 400, 'Error creating customer');
|
||||||
|
|||||||
34
dashboard/server/api/project/limits_info.ts
Normal file
34
dashboard/server/api/project/limits_info.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { ProjectModel, TProject } from "@schema/ProjectSchema";
|
||||||
|
import { ProjectLimitModel } from "@schema/ProjectsLimits";
|
||||||
|
import { UserSettingsModel } from "@schema/UserSettings";
|
||||||
|
import { EVENT_LOG_LIMIT_PERCENT } from '@data/broker/Limits';
|
||||||
|
|
||||||
|
export default defineEventHandler(async event => {
|
||||||
|
|
||||||
|
const userData = getRequestUser(event);
|
||||||
|
if (!userData?.logged) return setResponseStatus(event, 400, 'NotLogged');
|
||||||
|
|
||||||
|
const currentActiveProject = await UserSettingsModel.findOne({ user_id: userData.id });
|
||||||
|
if (!currentActiveProject) return setResponseStatus(event, 400, 'You need to select a project');
|
||||||
|
|
||||||
|
const project_id = currentActiveProject.active_project_id;
|
||||||
|
|
||||||
|
const project = await ProjectModel.findById(project_id);
|
||||||
|
if (!project) return setResponseStatus(event, 400, 'Project not found');
|
||||||
|
|
||||||
|
const projectLimits = await ProjectLimitModel.findOne({ project_id });
|
||||||
|
if (!projectLimits) return;
|
||||||
|
|
||||||
|
const TOTAL_COUNT = projectLimits.events + projectLimits.visits;
|
||||||
|
const COUNT_LIMIT = projectLimits.limit;
|
||||||
|
|
||||||
|
return {
|
||||||
|
total: TOTAL_COUNT,
|
||||||
|
limit: COUNT_LIMIT,
|
||||||
|
maxLimit: Math.round(COUNT_LIMIT * EVENT_LOG_LIMIT_PERCENT),
|
||||||
|
limited: TOTAL_COUNT > COUNT_LIMIT * EVENT_LOG_LIMIT_PERCENT,
|
||||||
|
percent: Math.round(100 / COUNT_LIMIT * TOTAL_COUNT)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user