Files
plume/src/app/pricing/page.tsx
streaper2 12de3a8328 mie a jour de la des mots du jour,
optimisation de la latence des pages
ajout d'option  clique droit plus paragraphe
2026-03-14 20:45:59 +01:00

58 lines
1.7 KiB
TypeScript

'use client';
import React, { useState, useEffect } from 'react';
import Pricing from '@/components/Pricing';
import { useRouter } from 'next/navigation';
import { useAuthContext } from '@/providers/AuthProvider';
export default function PricingPage() {
const router = useRouter();
const { user } = useAuthContext();
const [plans, setPlans] = useState([]);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
fetch('/api/plans', { cache: 'no-store' })
.then(res => res.json())
.then(data => {
setPlans(data);
setIsLoading(false);
})
.catch(err => {
console.error(err);
setIsLoading(false);
});
}, []);
return (
<Pricing
plans={plans}
isLoading={isLoading}
currentPlan={user?.planId || 'free'}
onBack={() => router.push(user ? '/dashboard' : '/')}
onSelectPlan={async (id) => {
if (!user) {
router.push('/login');
return;
}
try {
const response = await fetch('/api/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ planId: id })
});
const data = await response.json();
if (data.url) {
window.location.href = data.url;
}
} catch (err) {
console.error('Checkout error:', err);
}
}}
/>
);
}