-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deb4c04
commit 6647913
Showing
7 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
<template> | ||
<div v-if="userIsTrialing" :class="$style.container"> | ||
<div v-if="!trialExpired && trialHasExecutionsLeft" :class="$style.usageText"> | ||
<i18n path="executionUsage.currentUsage"> | ||
<template #text> | ||
<n8n-text size="xsmall" color="text-dark"> | ||
{{ locale.baseText('executionUsage.currentUsage.text') }} | ||
</n8n-text> | ||
</template> | ||
<template #count> | ||
<n8n-text size="xsmall" :bold="true" color="warning"> | ||
{{ daysLeftOnTrial }} {{ locale.baseText('executionUsage.currentUsage.count') }} | ||
</n8n-text> | ||
</template> | ||
</i18n> | ||
</div> | ||
<div v-if="trialExpired" :class="$style.usageText"> | ||
<n8n-text size="xsmall" color="danger"> | ||
{{ locale.baseText('executionUsage.expired.text') }} | ||
</n8n-text> | ||
</div> | ||
<div v-if="!trialHasExecutionsLeft" :class="$style.usageText"> | ||
<n8n-text size="xsmall"> | ||
{{ locale.baseText('executionUsage.ranOutOfExecutions.text') }} | ||
</n8n-text> | ||
</div> | ||
<div v-if="!trialExpired" :class="$style.usageCounter"> | ||
<div :class="$style.progressBarSection"> | ||
<progress | ||
:class="[ | ||
trialHasExecutionsLeft ? $style.progressBarSuccess : $style.progressBarDanger, | ||
$style.progressBar, | ||
]" | ||
:value="currentExecutions" | ||
:max="maxExecutions" | ||
></progress> | ||
</div> | ||
<div :class="$style.executionsCountSection"> | ||
<n8n-text size="xsmall" :color="trialHasExecutionsLeft ? 'text-dark' : 'danger'"> | ||
{{ currentExecutions }}/{{ maxExecutions }} | ||
</n8n-text> | ||
<n8n-text size="xsmall" :color="trialHasExecutionsLeft ? 'text-dark' : 'danger'">{{ | ||
locale.baseText('executionUsage.label.executions') | ||
}}</n8n-text> | ||
</div> | ||
</div> | ||
|
||
<div :class="$style.upgradeButtonSection"> | ||
<n8n-button | ||
:label="locale.baseText('executionUsage.button.upgrade')" | ||
:class="$style.upgrade" | ||
size="mini" | ||
icon="gem" | ||
type="success" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { onMounted, ref, computed } from 'vue'; | ||
import { i18n as locale } from '@/plugins/i18n'; | ||
import type { PlanData } from '@/Interface'; | ||
import { DateTime } from 'luxon'; | ||
const daysLeftOnTrial = ref(0); | ||
const trialExpired = ref(false); | ||
const currentPlan = ref<PlanData>({ | ||
planSpec: { | ||
planId: 43039, | ||
monthlyExecutionsLimit: 200, | ||
activeWorkflowsLimit: 10, | ||
credentialsLimit: 100, | ||
isActive: false, | ||
displayName: 'Trial', | ||
metadata: { | ||
version: 'v1', | ||
group: 'trial', | ||
slug: 'trial-1', | ||
trial: { | ||
length: 7, | ||
gracePeriod: 3, | ||
}, | ||
}, | ||
}, | ||
instance: { | ||
createdAt: '2023-05-01T01:47:47Z', | ||
}, | ||
usage: { | ||
executions: 100, | ||
activeWorkflows: 10, | ||
}, | ||
}); | ||
onMounted(async () => { | ||
const now = DateTime.utc(); | ||
if (isTrialExpired(now)) { | ||
trialExpired.value = true; | ||
} | ||
daysLeftOnTrial.value = getDaysSinceTrialStarted(now); | ||
}); | ||
const getDaysSinceTrialStarted = (now: DateTime) => { | ||
const { days = 0 } = now.diff(getPlanStartingDate(), ['days']).toObject(); | ||
return Math.trunc(days); | ||
}; | ||
const isTrialExpired = (now: DateTime) => { | ||
const trialEndsAt = getPlanStartingDate() | ||
.plus({ days: currentPlan.value.planSpec.metadata.trial.length }) | ||
.endOf('day'); | ||
return now.toMillis() > trialEndsAt.toMillis(); | ||
}; | ||
const getPlanStartingDate = () => | ||
DateTime.fromISO(currentPlan.value.instance.createdAt).startOf('day'); | ||
const trialHasExecutionsLeft = computed( | ||
() => currentPlan.value.usage.executions < currentPlan.value.planSpec.monthlyExecutionsLimit, | ||
); | ||
const userIsTrialing = computed(() => currentPlan.value.planSpec.metadata.group === 'trial'); | ||
const currentExecutions = computed(() => currentPlan.value.usage.executions); | ||
const maxExecutions = computed(() => currentPlan.value.planSpec.monthlyExecutionsLimit); | ||
</script> | ||
|
||
<style module lang="scss"> | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--color-background-light); | ||
border-radius: 0px; | ||
margin: 0; | ||
border: var(--border-base); | ||
border-right: 0; | ||
} | ||
.progressBar { | ||
width: 62.4px; | ||
} | ||
.progressBarSuccess { | ||
accent-color: var(--color-foreground-xdark); | ||
} | ||
.progressBarDanger { | ||
accent-color: var(--color-danger); | ||
} | ||
.usageText { | ||
margin-left: var(--spacing-s); | ||
margin-right: var(--spacing-s); | ||
margin-top: var(--spacing-xs); | ||
line-height: 12.5px; | ||
} | ||
.usageCounter { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
margin-left: var(--spacing-s); | ||
margin-top: var(--spacing-2xs); | ||
font-size: var(--font-size-3xs); | ||
} | ||
.progressBarSection { | ||
width: 62.4px; | ||
justify-content: center; | ||
margin-right: 0px; | ||
} | ||
.danger { | ||
color: var(--color-danger); | ||
} | ||
.executionsCountSection { | ||
margin-left: var(--spacing-xs); | ||
} | ||
.upgradeButtonSection { | ||
margin: var(--spacing-s); | ||
} | ||
.upgrade { | ||
width: 100%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters