feat: referral (#3761)
Co-authored-by: DIYgod <i@diygod.me> Co-authored-by: Innei <tukon479@gmail.com>
This commit is contained in:
co-authored by
DIYgod
Innei
parent
79c9b05246
commit
30bb37c7b9
@@ -9,6 +9,7 @@ import { Alert, Text, TouchableOpacity, View } from "react-native"
|
||||
import { KeyboardController } from "react-native-keyboard-controller"
|
||||
import { z } from "zod"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import { SubmitButton } from "@/src/components/common/SubmitButton"
|
||||
import { PlainTextField } from "@/src/components/ui/form/TextField"
|
||||
import { signIn, signUp } from "@/src/lib/auth"
|
||||
@@ -20,6 +21,8 @@ import { ForgetPasswordScreen } from "@/src/screens/(modal)/ForgetPasswordScreen
|
||||
import { TwoFactorAuthScreen } from "@/src/screens/(modal)/TwoFactorAuthScreen"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
import { ReferralForm } from "./referral"
|
||||
|
||||
const formSchema = z.object({
|
||||
email: z.string().email(),
|
||||
password: z.string().min(8).max(128),
|
||||
@@ -170,6 +173,7 @@ function SignupInput({
|
||||
}
|
||||
|
||||
export function EmailSignUp() {
|
||||
const serverConfigs = useServerConfigs()
|
||||
const { control, handleSubmit, formState } = useForm<SignupFormValue>({
|
||||
resolver: zodResolver(signupFormSchema),
|
||||
defaultValues: {
|
||||
@@ -261,6 +265,12 @@ export function EmailSignUp() {
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
{serverConfigs?.REFERRAL_ENABLED && (
|
||||
<>
|
||||
<View className="border-b-opaque-separator border-b-hairline" />
|
||||
<ReferralForm />
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
<SubmitButton
|
||||
disabled={submitMutation.isPending || !formState.isValid}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useState } from "react"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { Text, TouchableOpacity, TouchableWithoutFeedback, View } from "react-native"
|
||||
import { KeyboardController } from "react-native-keyboard-controller"
|
||||
import { KeyboardAvoidingView, KeyboardController } from "react-native-keyboard-controller"
|
||||
import Animated, { useAnimatedStyle, useSharedValue } from "react-native-reanimated"
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import * as ContextMenu from "zeego/context-menu"
|
||||
@@ -30,63 +30,65 @@ export function Login() {
|
||||
|
||||
return (
|
||||
<View className="pb-safe-or-2 flex-1 justify-between" style={{ paddingTop: insets.top + 56 }}>
|
||||
<TouchableWithoutFeedback
|
||||
onPress={() => {
|
||||
KeyboardController.dismiss()
|
||||
}}
|
||||
accessible={false}
|
||||
>
|
||||
<View
|
||||
className="items-center"
|
||||
style={{
|
||||
gap: gapSize,
|
||||
<KeyboardAvoidingView behavior={"position"}>
|
||||
<TouchableWithoutFeedback
|
||||
onPress={() => {
|
||||
KeyboardController.dismiss()
|
||||
}}
|
||||
accessible={false}
|
||||
>
|
||||
<Logo style={{ width: logoSize, height: logoSize }} />
|
||||
<Text
|
||||
className="text-label"
|
||||
<View
|
||||
className="items-center"
|
||||
style={{
|
||||
fontSize,
|
||||
lineHeight,
|
||||
gap: gapSize,
|
||||
}}
|
||||
>
|
||||
<Text className="font-semibold">{`${isRegister ? t("signin.sign_up_to") : t("signin.sign_in_to")} `}</Text>
|
||||
<Text className="font-bold">Folo</Text>
|
||||
</Text>
|
||||
{isEmail ? (
|
||||
isRegister ? (
|
||||
<EmailSignUp />
|
||||
<Logo style={{ width: logoSize, height: logoSize }} />
|
||||
<Text
|
||||
className="text-label"
|
||||
style={{
|
||||
fontSize,
|
||||
lineHeight,
|
||||
}}
|
||||
>
|
||||
<Text className="font-semibold">{`${isRegister ? t("signin.sign_up_to") : t("signin.sign_in_to")} `}</Text>
|
||||
<Text className="font-bold">Folo</Text>
|
||||
</Text>
|
||||
{isEmail ? (
|
||||
isRegister ? (
|
||||
<EmailSignUp />
|
||||
) : (
|
||||
<EmailLogin />
|
||||
)
|
||||
) : (
|
||||
<EmailLogin />
|
||||
)
|
||||
<SocialLogin onPressEmail={() => setIsEmail(true)} isRegister={isRegister} />
|
||||
)}
|
||||
</View>
|
||||
</TouchableWithoutFeedback>
|
||||
<TermsCheckBox />
|
||||
<View className="mt-14">
|
||||
{isEmail ? (
|
||||
<Text
|
||||
className="text-label pb-2 text-center text-lg font-medium"
|
||||
onPress={() => setIsEmail(false)}
|
||||
>
|
||||
{t("login.back")}
|
||||
</Text>
|
||||
) : (
|
||||
<SocialLogin onPressEmail={() => setIsEmail(true)} />
|
||||
<TouchableOpacity onPress={() => setIsRegister(!isRegister)}>
|
||||
<Text className="text-label pb-2 text-center text-lg font-medium">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={isRegister ? "login.have_account" : "login.no_account"}
|
||||
components={{
|
||||
strong: <Text className="text-accent" />,
|
||||
}}
|
||||
/>
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
</TouchableWithoutFeedback>
|
||||
<TermsCheckBox />
|
||||
<View className="mt-14">
|
||||
{isEmail ? (
|
||||
<Text
|
||||
className="text-label pb-2 text-center text-lg font-medium"
|
||||
onPress={() => setIsEmail(false)}
|
||||
>
|
||||
{t("login.back")}
|
||||
</Text>
|
||||
) : (
|
||||
<TouchableOpacity onPress={() => setIsRegister(!isRegister)}>
|
||||
<Text className="text-label pb-2 text-center text-lg font-medium">
|
||||
<Trans
|
||||
t={t}
|
||||
i18nKey={isRegister ? "login.have_account" : "login.no_account"}
|
||||
components={{
|
||||
strong: <Text className="text-accent" />,
|
||||
}}
|
||||
/>
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useAtom } from "jotai"
|
||||
import { atomWithStorage } from "jotai/utils"
|
||||
import { View } from "react-native"
|
||||
|
||||
import { PlainTextField } from "@/src/components/ui/form/TextField"
|
||||
import { JotaiPersistSyncStorage } from "@/src/lib/jotai"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
const referralCodeAtom = atomWithStorage("referral-code", "", JotaiPersistSyncStorage, {
|
||||
getOnInit: true,
|
||||
})
|
||||
|
||||
export function ReferralForm() {
|
||||
const [referralCode, setReferralCode] = useAtom(referralCodeAtom)
|
||||
|
||||
return (
|
||||
<View className="flex-row">
|
||||
<PlainTextField
|
||||
value={referralCode}
|
||||
onChangeText={(text) => {
|
||||
setReferralCode(text)
|
||||
}}
|
||||
selectionColor={accentColor}
|
||||
hitSlop={20}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
placeholder="Referral Code (optional)"
|
||||
className="text-text flex-1"
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -4,11 +4,21 @@ import { useColorScheme } from "nativewind"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Text, TouchableOpacity, View } from "react-native"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import { Image } from "@/src/components/ui/image/Image"
|
||||
import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator"
|
||||
import { signIn, useAuthProviders } from "@/src/lib/auth"
|
||||
|
||||
export function SocialLogin({ onPressEmail }: { onPressEmail: () => void }) {
|
||||
import { ReferralForm } from "./referral"
|
||||
|
||||
export function SocialLogin({
|
||||
onPressEmail,
|
||||
isRegister,
|
||||
}: {
|
||||
isRegister: boolean
|
||||
onPressEmail: () => void
|
||||
}) {
|
||||
const serverConfigs = useServerConfigs()
|
||||
const { data: authProviders, isLoading } = useAuthProviders()
|
||||
const { colorScheme } = useColorScheme()
|
||||
const providers = Object.entries(authProviders || [])
|
||||
@@ -87,6 +97,11 @@ export function SocialLogin({ onPressEmail }: { onPressEmail: () => void }) {
|
||||
</TouchableOpacity>
|
||||
)
|
||||
})}
|
||||
{isRegister && serverConfigs?.REFERRAL_ENABLED && (
|
||||
<View className="border-opaque-separator border-hairline w-full rounded-xl px-6 py-4">
|
||||
<ReferralForm />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import { LoveCuteFiIcon } from "@/src/icons/love_cute_fi"
|
||||
import { Magic2CuteFiIcon } from "@/src/icons/magic_2_cute_fi"
|
||||
import { NotificationCuteReIcon } from "@/src/icons/notification_cute_re"
|
||||
import { PaletteCuteFiIcon } from "@/src/icons/palette_cute_fi"
|
||||
import { PowerOutlineIcon } from "@/src/icons/power_outline"
|
||||
import { RadaCuteFiIcon } from "@/src/icons/rada_cute_fi"
|
||||
import { SafeLockFilledIcon } from "@/src/icons/safe_lock_filled"
|
||||
import { Settings1CuteFiIcon } from "@/src/icons/settings_1_cute_fi"
|
||||
@@ -29,6 +30,7 @@ import { signOut } from "@/src/lib/auth"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import type { Navigation } from "@/src/lib/navigation/Navigation"
|
||||
import { InvitationScreen } from "@/src/screens/(modal)/InvitationScreen"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
import { AboutScreen } from "./routes/About"
|
||||
import { AccountScreen } from "./routes/Account"
|
||||
@@ -40,7 +42,9 @@ import { GeneralScreen } from "./routes/General"
|
||||
import { InvitationsScreen } from "./routes/Invitations"
|
||||
import { ListsScreen } from "./routes/Lists"
|
||||
import { NotificationsScreen } from "./routes/Notifications"
|
||||
import { PlanScreen } from "./routes/Plan"
|
||||
import { PrivacyScreen } from "./routes/Privacy"
|
||||
import { ReferralScreen } from "./routes/Referral"
|
||||
|
||||
interface GroupNavigationLink {
|
||||
label: Extract<ParseKeys<"settings">, `titles.${string}`>
|
||||
@@ -113,6 +117,29 @@ const BetaGroupNavigationLinks: GroupNavigationLink[] = [
|
||||
},
|
||||
]
|
||||
|
||||
const ReferralGroupNavigationLinks: GroupNavigationLink[] = [
|
||||
{
|
||||
label: "titles.plan.short",
|
||||
icon: PowerOutlineIcon,
|
||||
onPress: ({ navigation }) => {
|
||||
navigation.pushControllerView(PlanScreen)
|
||||
},
|
||||
iconBackgroundColor: accentColor,
|
||||
anonymous: false,
|
||||
hideIf: (serverConfigs) => !serverConfigs?.REFERRAL_ENABLED,
|
||||
},
|
||||
{
|
||||
label: "titles.referral.short",
|
||||
icon: LoveCuteFiIcon,
|
||||
onPress: ({ navigation }) => {
|
||||
navigation.pushControllerView(ReferralScreen)
|
||||
},
|
||||
iconBackgroundColor: "#EC4899",
|
||||
anonymous: false,
|
||||
hideIf: (serverConfigs) => !serverConfigs?.REFERRAL_ENABLED,
|
||||
},
|
||||
]
|
||||
|
||||
const DataGroupNavigationLinks: GroupNavigationLink[] = [
|
||||
{
|
||||
label: "titles.actions",
|
||||
@@ -210,7 +237,7 @@ const NavigationLinkGroup: FC<{
|
||||
</GroupedInsetListNavigationLinkIcon>
|
||||
}
|
||||
onPress={() => {
|
||||
if (link.trialNotAllowed && role === UserRole.Trial) {
|
||||
if (link.trialNotAllowed && (role === UserRole.Free || role === UserRole.Trial)) {
|
||||
navigation.presentControllerView(InvitationScreen)
|
||||
} else {
|
||||
link.onPress({ navigation })
|
||||
@@ -226,6 +253,7 @@ const NavigationLinkGroup: FC<{
|
||||
const navigationGroups = [
|
||||
SettingGroupNavigationLinks,
|
||||
DataGroupNavigationLinks,
|
||||
ReferralGroupNavigationLinks,
|
||||
BetaGroupNavigationLinks,
|
||||
PrivacyGroupNavigationLinks,
|
||||
ActionGroupNavigationLinks,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { UserRole, UserRoleName } from "@follow/constants"
|
||||
import { useImageColors } from "@follow/store/image/hooks"
|
||||
import { useUserById } from "@follow/store/user/hooks"
|
||||
import { useUserById, useUserRole } from "@follow/store/user/hooks"
|
||||
import { cn, getLuminance } from "@follow/utils"
|
||||
import { LinearGradient } from "expo-linear-gradient"
|
||||
import type { FC } from "react"
|
||||
@@ -10,18 +11,21 @@ import ReAnimated, { FadeIn, FadeOut, interpolate, useAnimatedStyle } from "reac
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
||||
import { useColor } from "react-native-uikit-colors"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar"
|
||||
import { DiscordCuteFiIcon } from "@/src/icons/discord_cute_fi"
|
||||
import { FacebookCuteFiIcon } from "@/src/icons/facebook_cute_fi"
|
||||
import { GithubCuteFiIcon } from "@/src/icons/github_cute_fi"
|
||||
import { InstagramCuteFiIcon } from "@/src/icons/instagram_cute_fi"
|
||||
import { LinkCuteReIcon } from "@/src/icons/link_cute_re"
|
||||
import { PowerIcon } from "@/src/icons/power"
|
||||
import { TwitterCuteFiIcon } from "@/src/icons/twitter_cute_fi"
|
||||
import { WebCuteReIcon } from "@/src/icons/web_cute_re"
|
||||
import { YoutubeCuteFiIcon } from "@/src/icons/youtube_cute_fi"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import { LoginScreen } from "@/src/screens/(modal)/LoginScreen"
|
||||
import { usePrefetchImageColors } from "@/src/store/image/hooks"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
const defaultGradientColors = ["#000", "#100", "#200"]
|
||||
|
||||
@@ -40,14 +44,19 @@ const PlatformInfoMap: Record<
|
||||
export const UserHeaderBanner = ({
|
||||
scrollY,
|
||||
userId,
|
||||
showRoleBadge,
|
||||
}: {
|
||||
scrollY: SharedValue<number>
|
||||
userId?: string
|
||||
showRoleBadge?: boolean
|
||||
}) => {
|
||||
const serverConfigs = useServerConfigs()
|
||||
const bgColor = useColor("systemGroupedBackground")
|
||||
const avatarIconColor = useColor("secondaryLabel")
|
||||
|
||||
const user = useUserById(userId)
|
||||
const role = useUserRole()
|
||||
|
||||
usePrefetchImageColors(user?.image)
|
||||
const insets = useSafeAreaInsets()
|
||||
|
||||
@@ -146,13 +155,11 @@ export const UserHeaderBanner = ({
|
||||
)}
|
||||
</ReAnimated.View>
|
||||
<View className="items-center px-4 pb-[24px]" style={{ paddingTop: insets.top }}>
|
||||
<ReAnimated.View
|
||||
style={avatarStyles}
|
||||
className="bg-system-background overflow-hidden rounded-full"
|
||||
>
|
||||
<ReAnimated.View style={avatarStyles} className="bg-system-background rounded-full">
|
||||
<UserAvatar
|
||||
image={user?.image}
|
||||
name={user?.name}
|
||||
role={showRoleBadge && serverConfigs?.REFERRAL_ENABLED ? role : undefined}
|
||||
size={60}
|
||||
className={!user?.name ? "bg-system-grouped-background" : ""}
|
||||
color={avatarIconColor}
|
||||
@@ -174,6 +181,34 @@ export const UserHeaderBanner = ({
|
||||
<Text className="text-text text-2xl font-bold">Folo Account</Text>
|
||||
)}
|
||||
|
||||
{!!role && serverConfigs?.REFERRAL_ENABLED && (
|
||||
<View className="my-1 flex flex-row items-center gap-2">
|
||||
<PowerIcon
|
||||
color={
|
||||
role === UserRole.Trial || role === UserRole.Free
|
||||
? gradientLight
|
||||
? "rgba(0,0,0,0.7)"
|
||||
: "rgba(255,255,255,0.7)"
|
||||
: accentColor
|
||||
}
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
<Text
|
||||
className={cn(
|
||||
role === UserRole.Trial || role === UserRole.Free
|
||||
? gradientLight
|
||||
? "text-black/70"
|
||||
: "text-white/70"
|
||||
: "text-accent",
|
||||
"font-semibold",
|
||||
)}
|
||||
>
|
||||
{UserRoleName[role]}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{user?.handle ? (
|
||||
<Text className={cn(gradientLight ? "text-black/70" : "text-white/70")}>
|
||||
@{user.handle}
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
import { UserRole, UserRoleName } from "@follow/constants"
|
||||
import { useRoleEndAt, useUserRole } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import dayjs from "dayjs"
|
||||
import type { ProductPurchase } from "expo-iap"
|
||||
import { useIAP } from "expo-iap"
|
||||
import { openURL } from "expo-linking"
|
||||
import { useEffect } from "react"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { Linking, Pressable, ScrollView, Text, View } from "react-native"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import {
|
||||
NavigationBlurEffectHeaderView,
|
||||
SafeNavigationScrollView,
|
||||
} from "@/src/components/layouts/views/SafeNavigationScrollView"
|
||||
import {
|
||||
GroupedInformationCell,
|
||||
GroupedInsetListCard,
|
||||
} from "@/src/components/ui/grouped/GroupedList"
|
||||
import { CheckLineIcon } from "@/src/icons/check_line"
|
||||
import { PowerOutlineIcon } from "@/src/icons/power_outline"
|
||||
import { TimeCuteReIcon } from "@/src/icons/time_cute_re"
|
||||
import { apiClient } from "@/src/lib/api-fetch"
|
||||
import { authClient } from "@/src/lib/auth"
|
||||
import { useNavigation } from "@/src/lib/navigation/hooks"
|
||||
import type { NavigationControllerView } from "@/src/lib/navigation/types"
|
||||
import { isIOS } from "@/src/lib/platform"
|
||||
import { proxyEnv } from "@/src/lib/proxy-env"
|
||||
import { accentColor } from "@/src/theme/colors"
|
||||
|
||||
import { ReferralScreen } from "./Referral"
|
||||
|
||||
// Plan configuration types
|
||||
interface Plan {
|
||||
id: string
|
||||
title: string
|
||||
price: string
|
||||
period: string
|
||||
features: string[]
|
||||
isPopular?: boolean
|
||||
role: UserRole
|
||||
isComingSoon?: boolean
|
||||
tier: number // Add tier for hierarchy comparison
|
||||
}
|
||||
|
||||
// Plan hierarchy: Free (1) < Pro Preview (2) < Pro (3)
|
||||
const PLAN_TIER_MAP: Record<UserRole, number> = {
|
||||
[UserRole.Admin]: 4, // Admin has highest tier
|
||||
[UserRole.Free]: 1,
|
||||
[UserRole.Trial]: 1, // Same as Free (deprecated)
|
||||
[UserRole.PreProTrial]: 2, // Same tier as PrePro
|
||||
[UserRole.PrePro]: 2,
|
||||
[UserRole.Pro]: 3,
|
||||
}
|
||||
|
||||
// Plan configurations
|
||||
const PLAN_CONFIGS: Plan[] = [
|
||||
{
|
||||
id: "free",
|
||||
title: UserRoleName[UserRole.Free],
|
||||
price: "$0",
|
||||
period: "",
|
||||
features: ["50 feeds", "10 lists"],
|
||||
isPopular: false,
|
||||
role: UserRole.Free,
|
||||
tier: PLAN_TIER_MAP[UserRole.Free],
|
||||
},
|
||||
{
|
||||
id: "pro-preview",
|
||||
title: UserRoleName[UserRole.PrePro],
|
||||
price: "$1 or 3 invitations",
|
||||
period: "",
|
||||
features: ["1000 feeds and lists", "10 inboxes", "10 actions", "100 webhooks"],
|
||||
isPopular: false,
|
||||
role: UserRole.PrePro,
|
||||
tier: PLAN_TIER_MAP[UserRole.PrePro],
|
||||
},
|
||||
{
|
||||
id: "pro",
|
||||
title: UserRoleName[UserRole.Pro],
|
||||
price: "Coming soon",
|
||||
period: "",
|
||||
features: [`Everything in ${UserRoleName[UserRole.PrePro]}`, "Advanced AI features"],
|
||||
isPopular: false,
|
||||
role: UserRole.Pro,
|
||||
isComingSoon: true,
|
||||
tier: PLAN_TIER_MAP[UserRole.Pro],
|
||||
},
|
||||
]
|
||||
|
||||
const useReferralInfoQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: ["referral", "info"],
|
||||
queryFn: () => apiClient.referrals.$get().then((res) => res.data),
|
||||
})
|
||||
}
|
||||
|
||||
export const PlanScreen: NavigationControllerView = () => {
|
||||
const { connected, getProducts, requestPurchase, validateReceipt } = useIAP({
|
||||
onPurchaseSuccess: (purchase) => {
|
||||
validatePurchase(purchase)
|
||||
},
|
||||
onPurchaseError: (error) => {
|
||||
console.error("Purchase failed:", error)
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (connected) {
|
||||
getProducts(["is.follow.propreview"])
|
||||
}
|
||||
}, [connected])
|
||||
|
||||
const validatePurchase = async (purchase: ProductPurchase) => {
|
||||
if (!purchase.transactionId) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const result = await validateReceipt(purchase.transactionId)
|
||||
if (result.isValid) {
|
||||
apiClient.referrals["verify-receipt"].$post({ json: { appReceipt: result.receiptData } })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Validation failed:", error)
|
||||
}
|
||||
}
|
||||
|
||||
const navigation = useNavigation()
|
||||
const { t } = useTranslation("settings")
|
||||
const serverConfigs = useServerConfigs()
|
||||
const ruleLink = serverConfigs?.REFERRAL_RULE_LINK
|
||||
const requiredInvitationsAmount = serverConfigs?.REFERRAL_REQUIRED_INVITATIONS || 3
|
||||
|
||||
const { data: referralInfo } = useReferralInfoQuery()
|
||||
const validInvitationsAmount = referralInfo?.invitations.filter((i) => i.usedAt).length || 0
|
||||
|
||||
const role = useUserRole()
|
||||
const roleEndDate = useRoleEndAt()
|
||||
const daysLeft = roleEndDate
|
||||
? Math.ceil((roleEndDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24))
|
||||
: null
|
||||
const progress = (validInvitationsAmount / requiredInvitationsAmount) * 100
|
||||
return (
|
||||
<SafeNavigationScrollView
|
||||
className="bg-system-grouped-background"
|
||||
Header={<NavigationBlurEffectHeaderView title={t("titles.plan.long")} />}
|
||||
>
|
||||
<View className="mt-6">
|
||||
<GroupedInsetListCard>
|
||||
<GroupedInformationCell
|
||||
title={t("titles.plan.short")}
|
||||
icon={<PowerOutlineIcon height={40} width={40} color="#fff" />}
|
||||
iconBackgroundColor={accentColor}
|
||||
>
|
||||
<Trans
|
||||
ns="settings"
|
||||
i18nKey="plan.description"
|
||||
parent={({ children }: { children: React.ReactNode }) => (
|
||||
<Text className="text-label mt-3 text-left text-base leading-tight">
|
||||
{children}
|
||||
</Text>
|
||||
)}
|
||||
components={{
|
||||
Link: (
|
||||
<Text
|
||||
className="text-accent"
|
||||
onPress={() => {
|
||||
if (ruleLink) {
|
||||
Linking.openURL(ruleLink)
|
||||
}
|
||||
}}
|
||||
>
|
||||
Learn more
|
||||
</Text>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</GroupedInformationCell>
|
||||
</GroupedInsetListCard>
|
||||
</View>
|
||||
|
||||
<ScrollView horizontal className="m-4 py-4">
|
||||
{PLAN_CONFIGS.map((plan) => (
|
||||
<PlanCard
|
||||
key={plan.id}
|
||||
plan={plan}
|
||||
currentUserRole={role || null}
|
||||
daysLeft={daysLeft}
|
||||
isCurrentPlan={
|
||||
role === plan.role || (plan.role === UserRole.PrePro && role === UserRole.PreProTrial)
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</ScrollView>
|
||||
|
||||
<View className="bg-secondary-system-grouped-background mx-4 rounded-lg p-4">
|
||||
<View className="mb-4 flex-row items-center gap-2">
|
||||
<View className="bg-accent rounded-full p-2">
|
||||
<TimeCuteReIcon color="#fff" width={16} height={16} />
|
||||
</View>
|
||||
<View>
|
||||
<Text className="text-label font-medium">Current Status</Text>
|
||||
<Text className="text-label text-sm">
|
||||
{role === UserRole.PrePro
|
||||
? "You have an active Pro Preview plan"
|
||||
: role === UserRole.PreProTrial
|
||||
? `Pro Preview trial expires ${dayjs(roleEndDate).format("MMMM D, YYYY")} (${daysLeft} days left)`
|
||||
: "Start your journey with our referral program"}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="mb-4 flex-row items-center justify-between">
|
||||
<Text className="text-label font-medium">Referral Progress</Text>
|
||||
<Text className="text-label">
|
||||
{validInvitationsAmount} / {requiredInvitationsAmount}
|
||||
</Text>
|
||||
</View>
|
||||
<View className="bg-label h-2 w-full rounded-full">
|
||||
<View
|
||||
className="bg-accent h-2 rounded-full"
|
||||
style={{
|
||||
width: `${progress}%`,
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{role !== UserRole.PrePro && (
|
||||
<View className="mt-4 flex-row items-center gap-2 self-end">
|
||||
<Pressable
|
||||
className="bg-accent rounded-lg p-2"
|
||||
onPress={() => {
|
||||
navigation.pushControllerView(ReferralScreen)
|
||||
}}
|
||||
>
|
||||
<Text className="text-white">{`Invite ${serverConfigs?.REFERRAL_REQUIRED_INVITATIONS || 3} friends`}</Text>
|
||||
</Pressable>
|
||||
<Text className="text-label">or</Text>
|
||||
<Pressable
|
||||
className="bg-accent rounded-lg p-2"
|
||||
onPress={async () => {
|
||||
if (isIOS) {
|
||||
requestPurchase({ request: { sku: "is.follow.propreview" } })
|
||||
} else {
|
||||
const res = await authClient.subscription.upgrade({
|
||||
plan: "folo pro preview",
|
||||
successUrl: proxyEnv.WEB_URL,
|
||||
cancelUrl: proxyEnv.WEB_URL,
|
||||
disableRedirect: true,
|
||||
})
|
||||
if (res.data?.url) {
|
||||
openURL(res.data.url)
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Text className="text-white">{`Pay $${serverConfigs?.REFERRAL_PRO_PREVIEW_STRIPE_PRICE_IN_DOLLAR || 1}`}</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</SafeNavigationScrollView>
|
||||
)
|
||||
}
|
||||
|
||||
interface PlanCardProps {
|
||||
plan: Plan
|
||||
currentUserRole: UserRole | null
|
||||
isCurrentPlan: boolean
|
||||
daysLeft: number | null
|
||||
}
|
||||
|
||||
function PlanCard({ plan, isCurrentPlan, daysLeft }: PlanCardProps) {
|
||||
return (
|
||||
<View
|
||||
className={cn(
|
||||
"bg-secondary-system-grouped-background mr-4 min-w-[160px] rounded-lg p-4 shadow-md",
|
||||
isCurrentPlan && "border-accent border-2",
|
||||
plan.isComingSoon && "opacity-75",
|
||||
)}
|
||||
>
|
||||
<Text className="text-label text-lg font-bold">{plan.title}</Text>
|
||||
<Text className="text-label mb-4 text-lg font-bold">{plan.price}</Text>
|
||||
|
||||
{plan.features.map((feature, index) => (
|
||||
<View key={index} className="mb-2 flex-row items-center gap-2">
|
||||
<View className="bg-green/10 rounded-full p-[2px]">
|
||||
<CheckLineIcon width={16} height={16} color="rgb(40, 205, 65)" />
|
||||
</View>
|
||||
<Text className="text-label text-sm">{feature}</Text>
|
||||
</View>
|
||||
))}
|
||||
|
||||
{plan.isComingSoon ? (
|
||||
<Text className="text-label border-opaque-separator mt-2 rounded-lg border p-2 text-center text-sm text-gray-500">
|
||||
Coming soon
|
||||
</Text>
|
||||
) : isCurrentPlan && daysLeft !== null ? (
|
||||
<Text className="text-label border-opaque-separator mt-2 rounded-lg border p-2 text-center text-sm text-gray-500">
|
||||
{`In Trial (${daysLeft} days left)`}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
import { UserRole, UserRoleName } from "@follow/constants"
|
||||
import { env } from "@follow/shared/env.rn"
|
||||
import { useWhoami } from "@follow/store/user/hooks"
|
||||
import { cn } from "@follow/utils"
|
||||
import { useQuery } from "@tanstack/react-query"
|
||||
import dayjs from "dayjs"
|
||||
import { setStringAsync } from "expo-clipboard"
|
||||
import { Trans, useTranslation } from "react-i18next"
|
||||
import { Linking, Pressable, Share, Text, View } from "react-native"
|
||||
|
||||
import { useServerConfigs } from "@/src/atoms/server-configs"
|
||||
import {
|
||||
NavigationBlurEffectHeaderView,
|
||||
SafeNavigationScrollView,
|
||||
} from "@/src/components/layouts/views/SafeNavigationScrollView"
|
||||
import { UserAvatar } from "@/src/components/ui/avatar/UserAvatar"
|
||||
import { ContextMenu } from "@/src/components/ui/context-menu"
|
||||
import {
|
||||
GroupedInformationCell,
|
||||
GroupedInsetActivityIndicatorCell,
|
||||
GroupedInsetListBaseCell,
|
||||
GroupedInsetListCard,
|
||||
GroupedInsetListSectionHeader,
|
||||
} from "@/src/components/ui/grouped/GroupedList"
|
||||
import { MonoText } from "@/src/components/ui/typography/MonoText"
|
||||
import { LoveCuteFiIcon } from "@/src/icons/love_cute_fi"
|
||||
import { apiClient } from "@/src/lib/api-fetch"
|
||||
import type { NavigationControllerView } from "@/src/lib/navigation/types"
|
||||
import { toast } from "@/src/lib/toast"
|
||||
import { useColor } from "@/src/theme/colors"
|
||||
|
||||
const useReferralInfoQuery = () => {
|
||||
return useQuery({
|
||||
queryKey: ["referral", "info"],
|
||||
queryFn: () => apiClient.referrals.$get().then((res) => res.data),
|
||||
})
|
||||
}
|
||||
|
||||
export const ReferralScreen: NavigationControllerView = () => {
|
||||
const { t } = useTranslation("settings")
|
||||
const serverConfigs = useServerConfigs()
|
||||
const ruleLink = serverConfigs?.REFERRAL_RULE_LINK
|
||||
const requiredInvitationsAmount = serverConfigs?.REFERRAL_REQUIRED_INVITATIONS || 3
|
||||
|
||||
const { data: referralInfo, isLoading } = useReferralInfoQuery()
|
||||
const invitations = referralInfo?.invitations
|
||||
const validInvitationsAmount = referralInfo?.invitations.filter((i) => i.usedAt).length || 0
|
||||
const user = useWhoami()
|
||||
const referralLink = `${env.WEB_URL}/register?referral=${user?.handle || user?.id}`
|
||||
|
||||
const secondaryLabelColor = useColor("secondaryLabel")
|
||||
|
||||
const progress = (validInvitationsAmount / requiredInvitationsAmount) * 100
|
||||
return (
|
||||
<SafeNavigationScrollView
|
||||
className="bg-system-grouped-background"
|
||||
Header={<NavigationBlurEffectHeaderView title={t("titles.referral.long")} />}
|
||||
>
|
||||
<View className="mt-6">
|
||||
<GroupedInsetListCard>
|
||||
<GroupedInformationCell
|
||||
title={t("titles.referral.short")}
|
||||
icon={<LoveCuteFiIcon height={40} width={40} color="#fff" />}
|
||||
iconBackgroundColor={"#EC4899"}
|
||||
>
|
||||
<Trans
|
||||
ns="settings"
|
||||
i18nKey="referral.description"
|
||||
values={{
|
||||
day: referralInfo?.referralCycleDays || 45,
|
||||
}}
|
||||
parent={({ children }: { children: React.ReactNode }) => (
|
||||
<Text className="text-label mt-3 text-left text-base leading-tight">
|
||||
{children}
|
||||
</Text>
|
||||
)}
|
||||
components={{
|
||||
Link: (
|
||||
<Text
|
||||
className="text-accent"
|
||||
onPress={() => {
|
||||
if (ruleLink) {
|
||||
Linking.openURL(ruleLink)
|
||||
}
|
||||
}}
|
||||
>
|
||||
Learn more
|
||||
</Text>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</GroupedInformationCell>
|
||||
</GroupedInsetListCard>
|
||||
</View>
|
||||
|
||||
<GroupedInsetListSectionHeader label={t("referral.link")} />
|
||||
<GroupedInsetListCard>
|
||||
<ContextMenu.Root>
|
||||
<ContextMenu.Trigger>
|
||||
<GroupedInsetListBaseCell>
|
||||
<Pressable
|
||||
onPress={() => {
|
||||
Share.share({ url: referralLink })
|
||||
}}
|
||||
>
|
||||
<MonoText className="text-label">{referralLink}</MonoText>
|
||||
</Pressable>
|
||||
</GroupedInsetListBaseCell>
|
||||
</ContextMenu.Trigger>
|
||||
<ContextMenu.Content>
|
||||
<ContextMenu.Item
|
||||
key="copy"
|
||||
onSelect={() => {
|
||||
setStringAsync(referralLink)
|
||||
toast.success("Referral link copied to clipboard")
|
||||
}}
|
||||
>
|
||||
<ContextMenu.ItemTitle>Copy</ContextMenu.ItemTitle>
|
||||
</ContextMenu.Item>
|
||||
</ContextMenu.Content>
|
||||
</ContextMenu.Root>
|
||||
</GroupedInsetListCard>
|
||||
|
||||
<GroupedInsetListSectionHeader
|
||||
label={`Referral Progress for the Free ${UserRoleName[UserRole.PrePro]} ${validInvitationsAmount}/${requiredInvitationsAmount}:`}
|
||||
/>
|
||||
<GroupedInsetListCard>
|
||||
<GroupedInsetListBaseCell>
|
||||
<View className="bg-label h-2 w-full rounded-full">
|
||||
<View
|
||||
className="bg-accent h-2 rounded-full"
|
||||
style={{
|
||||
width: `${progress}%`,
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
</GroupedInsetListBaseCell>
|
||||
</GroupedInsetListCard>
|
||||
|
||||
<GroupedInsetListSectionHeader label={"Your Invited Friends"} />
|
||||
<GroupedInsetListCard>
|
||||
{isLoading && <GroupedInsetActivityIndicatorCell />}
|
||||
{invitations?.map((invitation) => (
|
||||
<GroupedInsetListBaseCell
|
||||
key={invitation.code}
|
||||
className="bg-secondary-system-grouped-background flex-1"
|
||||
>
|
||||
<View className="mr-2 shrink flex-row items-center gap-4">
|
||||
<UserAvatar
|
||||
size={26}
|
||||
image={invitation.user?.image}
|
||||
preview={false}
|
||||
color={secondaryLabelColor}
|
||||
/>
|
||||
<View className="min-w-0 shrink">
|
||||
<Text
|
||||
className={cn("text-label", !invitation.user && "text-secondary-label")}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{invitation.user?.name || (!invitation.user ? t("invitation.notUsed") : "")}
|
||||
</Text>
|
||||
<Text className="text-secondary-label text-sm">
|
||||
{t("invitation.created_at")} {dayjs(invitation.createdAt).format("YYYY/MM/DD")}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
<Text className="text-label">
|
||||
{invitation.usedAt
|
||||
? t("referral.invited_friend_status.valid")
|
||||
: t("referral.invited_friend_status.pending")}
|
||||
</Text>
|
||||
</GroupedInsetListBaseCell>
|
||||
))}
|
||||
</GroupedInsetListCard>
|
||||
</SafeNavigationScrollView>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user