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

FIX the handling logic of pro expiration date #254

Open
wants to merge 3 commits into
base: chat-everywhere
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/User/ReferralModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ReferralModel = memo(({ onClose }: Props) => {
};

const {
isLoading: isRegenerating,
isFetching: isRegenerating,
isError,
error: queryError,
refetch: queryReferralCodeRefetch,
Expand Down Expand Up @@ -177,6 +177,7 @@ const ReferralModel = memo(({ onClose }: Props) => {
) : (
<IconRefresh />
)}

<div>{t('Regenerate code')}</div>
</button>
<ReferralProgramData />
Expand Down
25 changes: 3 additions & 22 deletions utils/server/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ export const updateProAccountsPlan = async (): Promise<void> => {
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) {
Expand All @@ -568,7 +568,7 @@ export const getTrialExpiredUserProfiles = async (): Promise<String[]> => {
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) {
Expand All @@ -580,24 +580,5 @@ export const getTrialExpiredUserProfiles = async (): Promise<String[]> => {
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;
};