From 63b070d6839514e3ff2a1e6058444cf16c60fb04 Mon Sep 17 00:00:00 2001 From: 1orzero Date: Wed, 3 Apr 2024 19:20:58 +0800 Subject: [PATCH 1/4] Remove the referral check for downgrading user plans --- utils/server/supabase.ts | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/utils/server/supabase.ts b/utils/server/supabase.ts index e627f7ea67..e487f1934a 100644 --- a/utils/server/supabase.ts +++ b/utils/server/supabase.ts @@ -552,7 +552,7 @@ export const updateProAccountsPlan = async (): Promise => { const { error: updateError } = await supabase .from('profiles') .update({ plan: 'free' }) - .eq('plan', 'pro') + .in('plan', ['ultra', 'pro']) .lte('pro_plan_expiration_date', nowMinusOneDay); if (updateError) { @@ -568,7 +568,7 @@ export const getTrialExpiredUserProfiles = async (): Promise => { const { data: users, error: fetchError } = await supabase .from('profiles') .select('id') - .eq('plan', 'pro') + .in('plan', ['ultra', 'pro']) .lte('pro_plan_expiration_date', nowMinusOneDay); if (fetchError) { @@ -580,24 +580,5 @@ export const getTrialExpiredUserProfiles = async (): Promise => { return []; } - const trialUserIds: string[] = []; - - for (const userId of userIds) { - // Check if user has any referral record in the past 7 days - const { data: referralRows, error: referralError } = await supabase - .from('referral') - .select('referee_id') - .eq('referee_id', userId) - .gte('referral_date', endReferralDay); - - if (referralError) { - throw referralError; - } - - if (referralRows?.length > 0) { - trialUserIds.push(userId); - } - } - - return trialUserIds; + return userIds; }; From 45dbcf84207f11f922c0537d059857218b7513f3 Mon Sep 17 00:00:00 2001 From: 1orzero Date: Wed, 3 Apr 2024 19:21:07 +0800 Subject: [PATCH 2/4] Fix referral code regeneration button --- components/User/ReferralModel.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/User/ReferralModel.tsx b/components/User/ReferralModel.tsx index 563787fc42..6486833320 100644 --- a/components/User/ReferralModel.tsx +++ b/components/User/ReferralModel.tsx @@ -65,7 +65,7 @@ const ReferralModel = memo(({ onClose }: Props) => { }; const { - isLoading: isRegenerating, + isFetching: isRegenerating, isError, error: queryError, refetch: queryReferralCodeRefetch, @@ -177,6 +177,7 @@ const ReferralModel = memo(({ onClose }: Props) => { ) : ( )} +
{t('Regenerate code')}
From c6a008eb891e4b691682415b9ca117dcd1de98e3 Mon Sep 17 00:00:00 2001 From: 1orzero Date: Mon, 24 Jun 2024 18:47:37 +0800 Subject: [PATCH 3/4] feat(supabase): update plan and teacher status for expired pro accounts --- utils/server/supabase.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/server/supabase.ts b/utils/server/supabase.ts index 633d3806b7..92e4029a71 100644 --- a/utils/server/supabase.ts +++ b/utils/server/supabase.ts @@ -553,8 +553,8 @@ export const userProfileQuery = async ({ const associatedTeacherId = isTempUser ? userProfile.temporary_account_profiles[0].teacher_profile_id : isTeacherAccount - ? userProfile.id - : undefined; + ? userProfile.id + : undefined; const tempUserUniqueId = isTempUser ? userProfile.temporary_account_profiles[0].uniqueId : undefined; @@ -588,7 +588,7 @@ export const updateProAccountsPlan = async (): Promise => { const { error: updateError } = await supabase .from('profiles') - .update({ plan: 'free' }) + .update({ plan: 'free', is_teacher_account: false }) .in('plan', ['ultra', 'pro']) .lte('pro_plan_expiration_date', nowMinusOneDay); From d2d53009aaf6835cd97490ddad297d5934e0b9d0 Mon Sep 17 00:00:00 2001 From: 1orzero Date: Mon, 24 Jun 2024 18:54:10 +0800 Subject: [PATCH 4/4] refactor(supabase): improve trial user identification logic --- utils/server/supabase.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/utils/server/supabase.ts b/utils/server/supabase.ts index 92e4029a71..515781434d 100644 --- a/utils/server/supabase.ts +++ b/utils/server/supabase.ts @@ -617,5 +617,25 @@ export const getTrialExpiredUserProfiles = async (): Promise => { return []; } - return userIds; + const trialUserIds: string[] = []; + + // NOTE: only the user has referral record is considered as trial user + for (const userId of userIds) { + // Check if user has any referral record in the past 7 days + const { data: referralRows, error: referralError } = await supabase + .from('referral') + .select('referee_id') + .eq('referee_id', userId) + .gte('referral_date', endReferralDay); + + if (referralError) { + throw referralError; + } + + if (referralRows?.length > 0) { + trialUserIds.push(userId); + } + } + + return trialUserIds; };