Skip to content

Commit

Permalink
fix: trial limit
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Nov 17, 2024
1 parent 2058856 commit eee2bf8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
6 changes: 0 additions & 6 deletions apps/renderer/src/constants/limit.ts

This file was deleted.

7 changes: 5 additions & 2 deletions apps/renderer/src/hooks/biz/useFollow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { t } from "i18next"
import { useCallback } from "react"
import { useEventCallback } from "usehooks-ts"

import { useServerConfigs } from "~/atoms/server-configs"
import { useUserRole } from "~/atoms/user"
import { useModalStack } from "~/components/ui/modal/stacked/hooks"
import { MAX_TRIAL_USER_FEED_SUBSCRIPTION } from "~/constants/limit"
import { CustomSafeError } from "~/errors/CustomSafeError"
import { useActivationModal } from "~/modules/activation"
import type { FeedFormDataValuesType } from "~/modules/discover/feed-form"
Expand All @@ -23,11 +23,14 @@ const useCanFollowMoreInboxAndNotify = () => {
const listCurrentCount = useListSubscriptionCount()
const feedCurrentCount = useFeedSubscriptionCount()
const presentActivationModal = useActivationModal()
const serverConfigs = useServerConfigs()

return useEventCallback((type: "list" | "feed") => {
if (role === UserRole.Trial) {
const LIMIT =
type !== "list" ? MAX_TRIAL_USER_FEED_SUBSCRIPTION : MAX_TRIAL_USER_FEED_SUBSCRIPTION
(type !== "list"
? serverConfigs?.MAX_TRIAL_USER_FEED_SUBSCRIPTION
: serverConfigs?.MAX_TRIAL_USER_LIST_SUBSCRIPTION) || 50
const CURRENT = type === "list" ? listCurrentCount : feedCurrentCount
const can = CURRENT < LIMIT
if (!can) {
Expand Down
11 changes: 3 additions & 8 deletions apps/renderer/src/modules/discover/inbox-list-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,26 @@ import { useEventCallback } from "usehooks-ts"
import { useUserRole } from "~/atoms/user"
import { CopyButton } from "~/components/ui/code-highlighter"
import { useCurrentModal, useModalStack } from "~/components/ui/modal/stacked/hooks"
import { MAX_TRIAL_USER_INBOX_SUBSCRIPTION } from "~/constants/limit"
import { CustomSafeError } from "~/errors/CustomSafeError"
import { createErrorToaster } from "~/lib/error-parser"
import { useInboxList } from "~/queries/inboxes"
import { inboxActions, useInboxById } from "~/store/inbox"
import { subscriptionActions, useInboxSubscriptionCount } from "~/store/subscription"
import { subscriptionActions } from "~/store/subscription"

import { useActivationModal } from "../activation"
import { InboxForm } from "./inbox-form"

const useCanCreateMoreInboxAndNotify = () => {
const role = useUserRole()
const currentInboxCount = useInboxSubscriptionCount()
const presentActivationModal = useActivationModal()

return useEventCallback(() => {
if (role === UserRole.Trial) {
const can = currentInboxCount < MAX_TRIAL_USER_INBOX_SUBSCRIPTION
const can = false
if (!can) {
presentActivationModal()

throw new CustomSafeError(
`Trial user cannot create more inboxes, limit: ${MAX_TRIAL_USER_INBOX_SUBSCRIPTION}, current: ${currentInboxCount}`,
true,
)
throw new CustomSafeError(`Trial user cannot create more inboxes`, true)
}
return can
} else {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5081,6 +5081,8 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
IS_RSS3_TESTNET: boolean;
PRODUCT_HUNT_VOTE_URL: string;
ANNOUNCEMENT: string;
MAX_TRIAL_USER_FEED_SUBSCRIPTION: number;
MAX_TRIAL_USER_LIST_SUBSCRIPTION: number;
};
};
outputFormat: "json" | "text";
Expand Down

0 comments on commit eee2bf8

Please sign in to comment.