Merge remote-tracking branch 'origin/main' into cloudflare
This commit is contained in:
commit
d7cc9b956d
@ -9,6 +9,7 @@ import {
|
|||||||
CardTitle,
|
CardTitle,
|
||||||
} from '@/components/ui/card';
|
} from '@/components/ui/card';
|
||||||
import { useCurrentUser } from '@/hooks/use-current-user';
|
import { useCurrentUser } from '@/hooks/use-current-user';
|
||||||
|
import { useMounted } from '@/hooks/use-mounted';
|
||||||
import { useLocalePathname } from '@/i18n/navigation';
|
import { useLocalePathname } from '@/i18n/navigation';
|
||||||
import { formatPrice } from '@/lib/formatter';
|
import { formatPrice } from '@/lib/formatter';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@ -79,6 +80,7 @@ export function PricingCard({
|
|||||||
const price = getPriceForPlan(plan, interval, paymentType);
|
const price = getPriceForPlan(plan, interval, paymentType);
|
||||||
const currentUser = useCurrentUser();
|
const currentUser = useCurrentUser();
|
||||||
const currentPath = useLocalePathname();
|
const currentPath = useLocalePathname();
|
||||||
|
const mounted = useMounted();
|
||||||
// console.log('pricing card, currentPath', currentPath);
|
// console.log('pricing card, currentPath', currentPath);
|
||||||
|
|
||||||
// generate formatted price and price label
|
// generate formatted price and price label
|
||||||
@ -152,7 +154,7 @@ export function PricingCard({
|
|||||||
|
|
||||||
{/* show action buttons based on plans */}
|
{/* show action buttons based on plans */}
|
||||||
{plan.isFree ? (
|
{plan.isFree ? (
|
||||||
currentUser ? (
|
mounted && currentUser ? (
|
||||||
<Button variant="outline" className="mt-4 w-full disabled">
|
<Button variant="outline" className="mt-4 w-full disabled">
|
||||||
{t('getStartedForFree')}
|
{t('getStartedForFree')}
|
||||||
</Button>
|
</Button>
|
||||||
@ -172,7 +174,7 @@ export function PricingCard({
|
|||||||
{t('yourCurrentPlan')}
|
{t('yourCurrentPlan')}
|
||||||
</Button>
|
</Button>
|
||||||
) : isPaidPlan ? (
|
) : isPaidPlan ? (
|
||||||
currentUser ? (
|
mounted && currentUser ? (
|
||||||
<CheckoutButton
|
<CheckoutButton
|
||||||
userId={currentUser.id}
|
userId={currentUser.id}
|
||||||
planId={plan.id}
|
planId={plan.id}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
import { authClient } from '@/lib/auth-client';
|
import { authClient } from '@/lib/auth-client';
|
||||||
import { useCreditsStore } from '@/stores/credits-store';
|
import { useCreditsStore } from '@/stores/credits-store';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
@ -7,8 +8,21 @@ import { useCallback, useEffect } from 'react';
|
|||||||
*
|
*
|
||||||
* This hook provides access to the credits state and methods to manage it.
|
* This hook provides access to the credits state and methods to manage it.
|
||||||
* It also automatically fetches credits information when the user changes.
|
* It also automatically fetches credits information when the user changes.
|
||||||
|
* Only works when credits are enabled in the website configuration.
|
||||||
*/
|
*/
|
||||||
export function useCredits() {
|
export function useCredits() {
|
||||||
|
// Return default values if credits are disabled
|
||||||
|
if (!websiteConfig.credits.enableCredits) {
|
||||||
|
return {
|
||||||
|
balance: 0,
|
||||||
|
isLoading: false,
|
||||||
|
error: null,
|
||||||
|
fetchCredits: () => Promise.resolve(),
|
||||||
|
consumeCredits: () => Promise.resolve(false),
|
||||||
|
hasEnoughCredits: () => false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
balance,
|
balance,
|
||||||
isLoading,
|
isLoading,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { websiteConfig } from '@/config/website';
|
||||||
import { authClient } from '@/lib/auth-client';
|
import { authClient } from '@/lib/auth-client';
|
||||||
import { useCreditsStore } from '@/stores/credits-store';
|
import { useCreditsStore } from '@/stores/credits-store';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
@ -9,8 +10,14 @@ import { useEffect } from 'react';
|
|||||||
*
|
*
|
||||||
* This component initializes the credits store when the user is authenticated
|
* This component initializes the credits store when the user is authenticated
|
||||||
* and handles cleanup when the user logs out.
|
* and handles cleanup when the user logs out.
|
||||||
|
* Only renders when credits are enabled in the website configuration.
|
||||||
*/
|
*/
|
||||||
export function CreditsProvider({ children }: { children: React.ReactNode }) {
|
export function CreditsProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
// Only initialize credits store if credits are enabled
|
||||||
|
if (!websiteConfig.credits.enableCredits) {
|
||||||
|
return <>{children}</>;
|
||||||
|
}
|
||||||
|
|
||||||
const { fetchCredits } = useCreditsStore();
|
const { fetchCredits } = useCreditsStore();
|
||||||
const { data: session } = authClient.useSession();
|
const { data: session } = authClient.useSession();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user