import React, { useState } from 'react' import { PricingCardProps } from '@/app/types' import Button from '@/components/ui/Button' import showToast from '@/components/ui/Toast' import useUserStore from '@/app/store/userStore' const PricingCard: React.FC = ({ plan, price, features, isPopular, isActive, onPlanChange, }) => { const [isLoading, setIsLoading] = useState(false) const { user, setUser } = useUserStore() const handlePlanChange = async () => { try { setIsLoading(true) const requestData = { plan: plan, } const response = await fetch('/api/account/membership', { method: 'PATCH', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(requestData), }) if (!response.ok) { const error = await response.json() console.error('PricingCard - Server error:', error) throw new Error(error.error || 'Ошибка при создании маршрута') } // обновляем данные в сторе if (user) { setUser({ ...user, account_type: plan, }) } // обновляем данные на странице if (onPlanChange) { onPlanChange() } showToast({ type: 'success', duration: 1000, message: `Тариф успешно изменен на ${plan.toUpperCase()}!`, }) } catch (error) { console.error('Error changing plan:', error) showToast({ type: 'error', message: 'Не удалось изменить тариф. Попробуйте позже.', }) } finally { setIsLoading(false) } } return (
{isPopular && (
Популярный выбор
)} {isActive && (
Активный план
)}

{plan}

{price}₸ {price > 0 && / месяц}
    {features.map((feature, index) => (
  • {feature}
  • ))}
) } export default PricingCard