feat: ensure handler session id only once in credit package
This commit is contained in:
parent
c7a1ec69bb
commit
367965e41f
@ -18,7 +18,7 @@ import { Routes } from '@/routes';
|
|||||||
import { CircleCheckBigIcon, CoinsIcon, Loader2Icon } from 'lucide-react';
|
import { CircleCheckBigIcon, CoinsIcon, Loader2Icon } from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useSearchParams } from 'next/navigation';
|
import { useSearchParams } from 'next/navigation';
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { CreditCheckoutButton } from './credit-checkout-button';
|
import { CreditCheckoutButton } from './credit-checkout-button';
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ export function CreditPackages() {
|
|||||||
const t = useTranslations('Dashboard.settings.credits.packages');
|
const t = useTranslations('Dashboard.settings.credits.packages');
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const localeRouter = useLocaleRouter();
|
const localeRouter = useLocaleRouter();
|
||||||
|
const hasHandledSession = useRef(false);
|
||||||
|
|
||||||
// Use the new useCredits hook
|
// Use the new useCredits hook
|
||||||
const { balance, isLoading, refresh } = useCredits();
|
const { balance, isLoading, refresh } = useCredits();
|
||||||
@ -45,7 +46,8 @@ export function CreditPackages() {
|
|||||||
// Check for payment success and show success message
|
// Check for payment success and show success message
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const sessionId = searchParams.get('session_id');
|
const sessionId = searchParams.get('session_id');
|
||||||
if (sessionId) {
|
if (sessionId && !hasHandledSession.current) {
|
||||||
|
hasHandledSession.current = true;
|
||||||
// Show success toast (delayed to avoid React lifecycle conflicts)
|
// Show success toast (delayed to avoid React lifecycle conflicts)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
toast.success(t('creditsAdded'));
|
toast.success(t('creditsAdded'));
|
||||||
|
@ -153,7 +153,13 @@ export const useCreditsStore = create<CreditsState>((set, get) => ({
|
|||||||
* @param user Current user from auth session
|
* @param user Current user from auth session
|
||||||
*/
|
*/
|
||||||
refreshCredits: async (user) => {
|
refreshCredits: async (user) => {
|
||||||
if (!user) return;
|
if (!user) {
|
||||||
|
set({
|
||||||
|
error: 'No user found',
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
set({
|
set({
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user