Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import 'server-only';

import { setPaymentReturnUrl } from '@/lib/payment-return-url';

export async function setReturnUrlAndRedirect(
returnUrl: string,
creditsUrl: string
): Promise<string> {
export async function setReturnUrlAndRedirect(returnUrl: string): Promise<void> {
await setPaymentReturnUrl(returnUrl);
return creditsUrl;
}
11 changes: 7 additions & 4 deletions apps/web/src/components/shared/InsufficientBalanceBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AlertTriangle, Info, type LucideIcon } from 'lucide-react';
import { Button } from '@/components/Button';
import { cn } from '@/lib/utils';
import { setReturnUrlAndRedirect } from './InsufficientBalanceBanner.actions';
import { usePathname } from 'next/navigation';
import { usePathname, useRouter } from 'next/navigation';

/** Minimum balance required to use features that require credits (in dollars) */
export const MIN_BALANCE_DOLLARS_DEFAULT = 1;
Expand Down Expand Up @@ -84,12 +84,15 @@ export function InsufficientBalanceBanner({
content,
}: InsufficientBalanceBannerProps) {
const pathname = usePathname();
const creditsUrl = organizationId ? `/organizations/${organizationId}` : '/credits';
const router = useRouter();
const creditsUrl = organizationId
? `/organizations/${encodeURIComponent(organizationId)}`
: '/credits';

const handleAddCreditsClick = async () => {
// Set the return URL cookie before redirecting
const redirectUrl = await setReturnUrlAndRedirect(pathname, creditsUrl);
window.location.href = redirectUrl;
await setReturnUrlAndRedirect(pathname);
router.push(creditsUrl);
};

const formattedBalance = balance.toLocaleString('en-US', {
Expand Down