Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify user premium perks #1104

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/components/dashboard/DashboardShareCodeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const router = useRouter()
const url = useRequestURL()
const { refreshDashboards } = useUserDashboardStore()
const { fetch } = useCustomFetch()
const { user } = useUserStore()
const { userPremiumPerks } = useUserStore()

const isUpdating = ref(false)

Expand Down Expand Up @@ -100,7 +100,7 @@ const unpublish = async () => {
$t("dashboard.share_dialog.share_public_disclaimer")
}}</label>
<label
v-if="!user?.premium_perks?.share_custom_dashboards"
v-if="!userPremiumPerks?.share_custom_dashboards"
class="disclaimer"
>{{ $t("dashboard.share_dialog.upgrade") }}<BcPremiumGem class="gem" /></label>
<div
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/dashboard/DashboardShareModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const dashboardName = ref('')
const shareGroups = ref(true)
const isUpdating = ref(false)
const isNew = ref(true)
const { user } = useUserStore()
const { userPremiumPerks } = useUserStore()

const isPremiumUser = computed(
() => !!user.value?.premium_perks?.share_custom_dashboards,
() => !!userPremiumPerks.value?.share_custom_dashboards,
)

watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const {
= useDashboardKey()
const { updateHash } = useUserDashboardStore()
const {
isLoggedIn, user,
isLoggedIn,
userPremiumPerks,
} = useUserStore()

const initialQuery = {
Expand Down Expand Up @@ -211,7 +212,7 @@ function isSearchResultRestricted(result: ResultSuggestion): boolean {
case ResultType.ValidatorsByPubkey:
return false
default:
return isPublic.value || !user.value?.premium_perks?.ad_free
return isPublic.value || !userPremiumPerks.value?.bulk_adding
}
}

Expand Down Expand Up @@ -334,9 +335,9 @@ const removeRow = (row: VDBManageValidatorsTableRow) => {
const total = computed(() => addUpValues(overview.value?.validators))

const maxValidatorsPerDashboard = computed(() =>
isPublic.value || !user.value?.premium_perks?.validators_per_dashboard
isPublic.value || !userPremiumPerks.value?.validators_per_dashboard
? 20
: user.value.premium_perks.validators_per_dashboard,
: userPremiumPerks.value?.validators_per_dashboard,
)

const premiumLimit = computed(
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/dashboard/GroupManagementModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const visible = defineModel<boolean>()
const { refreshOverview } = useValidatorDashboardOverviewStore()
const { groups } = useValidatorDashboardGroups()
const { dashboards } = useUserDashboardStore()
const { user } = useUserStore()
const { userPremiumPerks } = useUserStore()

const cursor = ref<Cursor>(0)
const pageSize = ref<number>(25)
Expand Down Expand Up @@ -186,9 +186,9 @@ const dashboardName = computed(() => {
})

const maxGroupsPerDashboard = computed(() =>
isPublic.value || !user.value?.premium_perks?.validator_groups_per_dashboard
isPublic.value || !userPremiumPerks.value?.validator_groups_per_dashboard
? 1
: user.value.premium_perks.validator_groups_per_dashboard,
: userPremiumPerks.value?.validator_groups_per_dashboard,
)
const premiumLimit = computed(
() => (data.value?.paging?.total_count ?? 0) >= maxGroupsPerDashboard.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
= useUserDashboardStore()
const { dashboards } = useUserDashboardStore()
const {
isLoggedIn, user,
isLoggedIn,
userPremiumPerks,
} = useUserStore()
const { currentNetwork } = useNetworkStore()

Expand Down Expand Up @@ -41,7 +42,7 @@ const route = useRoute()
const maxDashboards = computed(() => {
// TODO: currently there is no value for "amount of account dashboards", using
// "amount of validator dashboards" instead for now
return user.value?.premium_perks.validator_dashboards ?? 1
return userPremiumPerks.value?.validator_dashboards ?? 1
})
const accountsDisabled = computed(() => {
// TODO: Once account dashboards are being tackled, use something like
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/notifications/NotificationsOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const notificationsTotal = computed(() => {
return last24hEmailsCount.value + last24hWebhookCount.value + last24hPushCount.value
})

const { user } = useUserStore()
const mailLimit = computed(() => user.value?.premium_perks.email_notifications_per_day ?? 0)
const { userPremiumPerks } = useUserStore()
const mailLimit = computed(() => userPremiumPerks.value?.email_notifications_per_day ?? 0)

const resetHours = computed(() => overview.value?.next_email_count_reset_timestamp ?? 0)
const tooltipEmail = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { useNotificationsManagementStore } from '~/stores/notifications/useNotificationsManagementStore'

const { t: $t } = useTranslation()
const { user } = useUserStore()
const hasAbilityCustomMachineAlerts = computed(() => user.value?.premium_perks.notifications_machine_custom_threshold)
const { userPremiumPerks } = useUserStore()
const hasAbilityCustomMachineAlerts = computed(() => userPremiumPerks.value?.notifications_machine_custom_threshold)

const notificationsManagementStore = useNotificationsManagementStore()
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const {
secondsPerEpoch,
} = useNetworkStore()

const { user } = useUserStore()
const { userPremiumPerks } = useUserStore()
const hasPremiumPerkGroupEfficiency = computed(
() => user.value?.premium_perks.notifications_validator_dashboard_group_efficiency,
() => userPremiumPerks.value?.notifications_validator_dashboard_group_efficiency,
)
function closeDialog(): void {
dialogRef?.value.close()
Expand Down
6 changes: 4 additions & 2 deletions frontend/components/pricing/PremiumAddonBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { Target } from '~/types/links'

const { t: $t } = useTranslation()
const {
isLoggedIn, user,
isLoggedIn,
user,
userPremiumPerks,
} = useUserStore()
const {
isStripeDisabled, stripeCustomerPortal, stripePurchase,
Expand Down Expand Up @@ -125,7 +127,7 @@ const addonButton = computed(() => {
const maximumQuantity = computed(() => {
return Math.floor(
((props.maximumValidatorLimit || 10000)
- (user.value?.premium_perks.validators_per_dashboard || 0))
- (userPremiumPerks.value?.validators_per_dashboard || 0))
/ props.addon.extra_dashboard_validators,
)
})
Expand Down
5 changes: 5 additions & 0 deletions frontend/stores/useUserStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ export function useUserStore() {
return !!user.value
})

const userPremiumPerks = computed(() => {
return user.value?.premium_perks
})

return {
doLogin,
doLogout,
getUser,
isLoggedIn,
user,
userPremiumPerks,
}
}
Loading