feat: useIsPaymentEnabled
This commit is contained in:
parent
53e3578af2
commit
48b2ea39ae
|
|
@ -37,3 +37,15 @@ export const getIsInMASReview = () => {
|
|||
serverConfigs?.MAS_IN_REVIEW_VERSION === PKG.version
|
||||
)
|
||||
}
|
||||
|
||||
export const useIsPaymentEnabled = () => {
|
||||
const serverConfigs = useServerConfigs()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
return !isInMASReview && serverConfigs?.PAYMENT_ENABLED
|
||||
}
|
||||
|
||||
export const getIsPaymentEnabled = () => {
|
||||
const serverConfigs = getServerConfigs()
|
||||
const isInMASReview = getIsInMASReview()
|
||||
return !isInMASReview && serverConfigs?.PAYMENT_ENABLED
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { isNeedUpgradeError } from "@follow-app/client-sdk"
|
|||
import type { ReactNode } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useIsPaymentEnabled } from "~/atoms/server-configs"
|
||||
import { CopyButton } from "~/components/ui/button/CopyButton"
|
||||
import { Markdown } from "~/components/ui/markdown/Markdown"
|
||||
import { useFeature } from "~/hooks/biz/useFeature"
|
||||
|
|
@ -78,12 +78,12 @@ export const AISummaryCardBase: React.FC<AISummaryCardBaseProps> = ({
|
|||
}) => {
|
||||
const { t } = useTranslation("app")
|
||||
const aiEnabled = useFeature("ai")
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
|
||||
const hasContent = !isLoading && content
|
||||
const normalizedErrorCode = typeof errorCode === "number" ? errorCode : undefined
|
||||
const shouldSuggestUpgrade =
|
||||
normalizedErrorCode !== undefined && !isInMASReview && isNeedUpgradeError(normalizedErrorCode)
|
||||
normalizedErrorCode !== undefined && isPaymentEnabled && isNeedUpgradeError(normalizedErrorCode)
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { createElement } from "react"
|
|||
import type { ExternalToast } from "sonner"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { getIsInMASReview } from "~/atoms/server-configs"
|
||||
import { getIsPaymentEnabled } from "~/atoms/server-configs"
|
||||
import { CopyButton } from "~/components/ui/button/CopyButton"
|
||||
import { Markdown } from "~/components/ui/markdown/Markdown"
|
||||
import { DebugRegistry } from "~/modules/debug/registry"
|
||||
|
|
@ -123,8 +123,8 @@ export const toastFetchError = (
|
|||
if (!_reason) {
|
||||
const title = _title || message || "Unknown error occurred"
|
||||
toastOptions.description = _title ? message : ""
|
||||
const isInMASReview = getIsInMASReview()
|
||||
const needUpgradeError = code && !isInMASReview ? isNeedUpgradeError(code) : false
|
||||
const isPaymentEnabled = getIsPaymentEnabled()
|
||||
const needUpgradeError = code && isPaymentEnabled ? isNeedUpgradeError(code) : false
|
||||
if (needUpgradeError) {
|
||||
toastOptions.description = "Please upgrade your plan."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import { useTranslation } from "react-i18next"
|
|||
import { toast } from "sonner"
|
||||
import { z } from "zod"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useIsPaymentEnabled } from "~/atoms/server-configs"
|
||||
import { Autocomplete } from "~/components/ui/auto-completion"
|
||||
import { useCurrentModal, useIsInModal } from "~/components/ui/modal/stacked/hooks"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
|
|
@ -61,7 +61,7 @@ export type FeedFormDataValuesType = z.infer<typeof formSchema>
|
|||
export const PaidBadge = () => {
|
||||
const { t } = useTranslation("settings")
|
||||
const settingModalPresent = useSettingModal()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
|
||||
const handleClick = useCallback(
|
||||
(e) => {
|
||||
|
|
@ -71,7 +71,7 @@ export const PaidBadge = () => {
|
|||
[settingModalPresent],
|
||||
)
|
||||
|
||||
if (isInMASReview) {
|
||||
if (!isPaymentEnabled) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
@ -336,8 +336,8 @@ const FeedInnerForm = ({
|
|||
}, [feed.title, form])
|
||||
|
||||
const role = useUserRole()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const disabledForRole = role === UserRole.Free && !isInMASReview
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
const disabledForRole = role === UserRole.Free && isPaymentEnabled
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col gap-y-4">
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import { useCallback, useId, useState } from "react"
|
|||
import { useTranslation } from "react-i18next"
|
||||
import { titleCase } from "title-case"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useIsPaymentEnabled } from "~/atoms/server-configs"
|
||||
|
||||
import { SettingPaidLevels } from "./helper/setting-builder"
|
||||
import { useSetSettingTab } from "./modal/context"
|
||||
|
|
@ -26,7 +26,7 @@ export const PaidBadge: Component<{
|
|||
}> = ({ paidLevel }) => {
|
||||
const { t } = useTranslation("settings")
|
||||
const setTab = useSetSettingTab()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
|
||||
const handleClick = useCallback(
|
||||
(e) => {
|
||||
|
|
@ -36,7 +36,7 @@ export const PaidBadge: Component<{
|
|||
[setTab],
|
||||
)
|
||||
|
||||
if (isInMASReview) {
|
||||
if (!isPaymentEnabled) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import { useTranslation } from "react-i18next"
|
|||
import { currentSupportedLanguages } from "~/@types/constants"
|
||||
import { defaultResources } from "~/@types/default-resource"
|
||||
import { langLoadingLockMapAtom } from "~/atoms/lang"
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { useIsPaymentEnabled } from "~/atoms/server-configs"
|
||||
import {
|
||||
DEFAULT_ACTION_LANGUAGE,
|
||||
setGeneralSetting,
|
||||
|
|
@ -296,8 +296,8 @@ const TranslationModeSelector = () => {
|
|||
const { t } = useTranslation("settings")
|
||||
const translationMode = useGeneralSettingKey("translationMode")
|
||||
const role = useUserRole()
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const disabledForRole = role === UserRole.Free && !isInMASReview
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
const disabledForRole = role === UserRole.Free && isPaymentEnabled
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { useTranslation } from "react-i18next"
|
|||
import { toast } from "sonner"
|
||||
|
||||
import type { PaymentFeature, PaymentPlan } from "~/atoms/server-configs"
|
||||
import { useIsInMASReview, useServerConfigs } from "~/atoms/server-configs"
|
||||
import { useIsPaymentEnabled, useServerConfigs } from "~/atoms/server-configs"
|
||||
import { subscription } from "~/lib/auth"
|
||||
|
||||
const formatFeatureValue = (
|
||||
|
|
@ -104,7 +104,7 @@ const useCancelPlan = () => {
|
|||
}
|
||||
|
||||
export function SettingPlan() {
|
||||
const isInMASReview = useIsInMASReview()
|
||||
const isPaymentEnabled = useIsPaymentEnabled()
|
||||
const role = useUserRole()
|
||||
const roleEndDate = useRoleEndAt()
|
||||
const [billingPeriod, setBillingPeriod] = useState<"monthly" | "yearly">("yearly")
|
||||
|
|
@ -129,7 +129,7 @@ export function SettingPlan() {
|
|||
return acc + savings
|
||||
}, 0) / plans.filter((plan) => plan.priceInDollars > 0).length,
|
||||
)
|
||||
if (isInMASReview) {
|
||||
if (!isPaymentEnabled) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue