payments card and separated /support url

This commit is contained in:
2025-05-22 16:08:40 +03:00
parent 6963fdb17a
commit 29d3af2ea1
16 changed files with 481 additions and 31 deletions

View File

@@ -7,8 +7,7 @@ import Loader from '@/components/ui/Loader'
import { RiUser3Line } from 'react-icons/ri'
import { FaRoute } from 'react-icons/fa'
import { GoPackageDependents, GoPackageDependencies } from 'react-icons/go'
import { MdOutlinePayments } from 'react-icons/md'
import { CgNotes } from 'react-icons/cg'
import { MdOutlinePayments, MdOutlineContactSupport } from 'react-icons/md'
import useUserStore from '@/app/store/userStore'
export default function AccountLayout({ children }: { children: React.ReactNode }) {
@@ -47,6 +46,7 @@ export default function AccountLayout({ children }: { children: React.ReactNode
icon: GoPackageDependencies,
},
{ name: 'Тарифы', href: '/account/payments', icon: MdOutlinePayments },
{ name: 'Поддержка', href: '/account/support', icon: MdOutlineContactSupport },
]
return (

View File

@@ -5,7 +5,7 @@ import { useForm } from '@/app/hooks/useForm'
import Button from '@/components/ui/Button'
import showToast from '@/components/ui/Toast'
import useUserStore from '@/app/store/userStore'
import ContactUs from '@/components/ContactUs'
import TextInput from '@/components/ui/TextInput'
import PhoneInput from '@/components/ui/PhoneInput'
@@ -126,7 +126,6 @@ const AccountPage = () => {
</div>
</div>
</div>
<ContactUs />
</div>
)
}

View File

@@ -0,0 +1,113 @@
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<PricingCardProps> = ({
plan,
price,
features,
isPopular,
isActive,
onPlanChange,
}) => {
const [isLoading, setIsLoading] = useState(false)
const { user, setUser } = useUserStore()
const handlePlanChange = async () => {
try {
setIsLoading(true)
console.log('Changing plan to:', plan)
// const response = await changePlan(plan) -- тут обработка данных запроса на смену плана
// обновляем данные в сторе
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 (
<div
className={`flex h-full translate-y-5 animate-[fadeIn_0.8s_ease-out_forwards] flex-col rounded-xl p-6 shadow-lg ${
isPopular ? 'border-orange border-2' : 'border border-gray-200'
} transition-all duration-300 hover:translate-y-[-8px]`}
>
<div className="flex-1">
{isPopular && (
<div className="bg-orange mb-2 inline-block rounded-2xl px-2 py-1 text-xs text-white">
Популярный выбор
</div>
)}
{isActive && (
<div className="mb-2 inline-block rounded-2xl bg-blue-500 px-2 py-1 text-xs text-white">
Активный план
</div>
)}
<h3 className="mb-2 text-xl font-bold capitalize">{plan}</h3>
<div className="mb-4">
<span className="text-3xl font-bold">{price}</span>
{price > 0 && <span className="text-gray-600"> / месяц</span>}
</div>
<ul className="space-y-2">
{features.map((feature, index) => (
<li key={index} className="flex items-start gap-2">
<svg
className="mt-1 h-[16px] w-[16px] flex-shrink-0 text-green-500"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M5 13l4 4L19 7"
/>
</svg>
<span className="leading-6">{feature}</span>
</li>
))}
</ul>
</div>
<div className="mt-6">
<Button
className={`flex w-full items-center justify-center rounded-2xl px-4 py-2 ${
isPopular
? 'bg-orange hover:bg-orange/80 text-white'
: 'bg-gray-100 hover:bg-blue-500 hover:text-white'
} ${isActive ? 'hidden' : ''} ${isLoading ? 'cursor-not-allowed opacity-50' : ''}`}
text={isLoading ? 'Обновление...' : 'Выбрать план'}
onClick={handlePlanChange}
disabled={isLoading}
/>
</div>
</div>
)
}
export default PricingCard

View File

@@ -1,7 +1,58 @@
import React from 'react'
'use client'
const PaymentsPage = () => {
return <div>page</div>
import React, { useEffect, useState } from 'react'
import PricingCard from './PricingCard'
import { PricingCardProps } from '@/app/types'
import useUserStore from '@/app/store/userStore'
import Loader from '@/components/ui/Loader'
const AdminPayments = () => {
const { user } = useUserStore()
const [plans, setPlans] = useState<PricingCardProps[]>([])
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
const fetchPlans = async () => {
try {
const response = await fetch('/api/account/get-plans')
if (!response.ok) {
throw new Error('Failed to fetch plans')
}
const data = await response.json()
setPlans(data)
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load pricing plans')
} finally {
setIsLoading(false)
}
}
fetchPlans()
}, [])
if (isLoading) {
return <Loader />
}
if (error) {
return <div className="p-8 text-center text-red-500">{error}</div>
}
return (
<div className="container mx-auto translate-y-5 animate-[fadeIn_1.1s_ease-out_forwards] space-y-6">
<h2 className="mb-6 text-center text-3xl font-bold">Тарифные планы</h2>
<div className="grid grid-cols-1 gap-8 rounded-lg bg-white p-8 md:grid-cols-3">
{plans.map(plan => (
<PricingCard
key={plan.plan}
{...plan}
isActive={user?.account_type?.toLowerCase() === plan.plan.toLowerCase()}
/>
))}
</div>
</div>
)
}
export default PaymentsPage
export default AdminPayments

View File

@@ -0,0 +1,8 @@
import React from 'react'
import ContactUs from '@/components/ContactUs'
const SupportPage = () => {
return <ContactUs />
}
export default SupportPage

View File

@@ -0,0 +1,26 @@
import { NextRequest } from 'next/server'
export async function GET(req: NextRequest) {
try {
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/plans/`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
if (!response.ok) {
const error = await response.json()
console.error('API error:', error)
return new Response(JSON.stringify(error), { status: response.status })
}
const result = await response.json()
return new Response(JSON.stringify(result), { status: 200 })
} catch (error) {
console.error('Route handler error:', error)
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
status: 500,
})
}
}

View File

@@ -24,6 +24,7 @@ export interface ButtonProps {
leftIcon?: React.ReactNode
rightIcon?: React.ReactNode
type?: 'button' | 'submit' | 'reset'
disabled?: boolean
}
export interface SearchCardProps {
@@ -215,3 +216,12 @@ export interface CheckboxProps {
disabledText: string
enabledText: string
}
export interface PricingCardProps {
plan: 'free' | 'pro' | 'premium'
price: number
features: string[]
isPopular?: boolean
isActive?: boolean
onPlanChange?: () => void
}