import { FC, useEffect, useState } from 'react' import { Helmet } from 'react-helmet-async' import { useTranslation } from 'react-i18next' import SidebarHint from './components/SidebarHint' import SupportImage from '../../assets/images/support.png' import Button from '../../components/Button' import { CloseCircle, Document, Element3, TickCircle } from 'iconsax-react' import Tabs from '../../components/Tabs' import { useBuySupportPlan, useGetSupportPlans } from './hooks/useSupportData' import { NumberFormat } from '../../config/func' import { PlanItemType, featureItemType } from './types/SupportTypes' import SupportSkeleton from './components/SupportSkeleton' import SupportIcon from './components/SupportIcon' import { SupportPlanFeatureKey } from './enum/SupportEnum' import { toast } from '../../components/Toast' import { ErrorType } from '../../helpers/types' import { useNavigate } from 'react-router-dom' import { Pages } from '../../config/Pages' const Support: FC = () => { const { data, isLoading } = useGetSupportPlans() const { t } = useTranslation('global') const [activeTab, setActiveTab] = useState('') const [loadingPlanId, setLoadingPlanId] = useState('') const { mutate: buySupportPlan } = useBuySupportPlan() const navigate = useNavigate() useEffect(() => { if (data?.data?.supportPlans?.length > 0 && !activeTab) { setActiveTab(data.data.supportPlans[0].id) } }, [data, activeTab]) const handleBuy = (planId: string) => { setLoadingPlanId(planId) buySupportPlan(planId, { onSuccess: (data) => { toast(data?.data?.message, 'success') navigate(Pages.receipts.detail + data?.data?.invoice?.id) setLoadingPlanId('') }, onError: (error: ErrorType) => { toast(error?.response?.data?.error.message[0], 'error') setLoadingPlanId('') } }) } if (isLoading || !data?.data) { return } return (
داناک | {t('support.title')}
{t('support.title')}
({ icon: , label: plan.name, value: plan.id }))} active={activeTab} onChange={setActiveTab} />
support
{ data?.data?.supportPlans?.map((item: PlanItemType) => { return (
{item.name}
ماهیانه
{NumberFormat(item.price)}
تومان
) }) }
{ data?.data?.supportPlans?.[0]?.features.map((row: featureItemType) => (
{t(`support.${row.featureKey}`)}
)) }
{ data?.data?.supportPlans?.map((item: PlanItemType) => (
{ item.features.map((row) => (
{ row.featureType === 'boolean' ? row.featureValue === 'true' ? : :
{row.featureValue}
}
)) }
)) }
{/* Mobile View */}
{ data?.data?.supportPlans?.map((plan: PlanItemType) => ( activeTab === plan.id && (
support
{plan.name}
ماهیانه
{NumberFormat(plan.price)}
تومان
{ plan.features.map((row: featureItemType) => (
{t(`support.${row.featureKey}`)}
{ row.featureType === 'boolean' ? row.featureValue === 'true' ? : :
{row.featureValue}
}
)) }
) )) }
) } export default Support