import React from 'react'; import { Link, useParams } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { Loader2 } from 'lucide-react'; import { Page } from './_util'; import { useLocale } from '../i18n/LocaleContext'; import { useTranslation } from '../i18n/useTranslation'; import { getHelpArticle, type HelpArticleDetail } from '../services/helpApi'; import PullToRefresh from '../components/PullToRefresh'; export default function HelpArticlePage() { const params = useParams<{ token?: string; slug: string }>(); const slug = params.slug; const { locale } = useLocale(); const { t } = useTranslation(); const [article, setArticle] = React.useState(null); const [state, setState] = React.useState<'loading' | 'ready' | 'error'>('loading'); const basePath = params.token ? `/e/${encodeURIComponent(params.token)}/help` : '/help'; const loadArticle = React.useCallback(async () => { if (!slug) { setState('error'); return; } setState('loading'); try { const result = await getHelpArticle(slug, locale); setArticle(result.article); setState('ready'); } catch (error) { console.error('[HelpArticle] Failed to load article', error); setState('error'); } }, [slug, locale]); React.useEffect(() => { loadArticle(); }, [loadArticle]); const title = article?.title ?? t('help.article.unavailable'); return (
{state === 'loading' && (
{t('common.actions.loading')}
)} {state === 'error' && (

{t('help.article.unavailable')}

)} {state === 'ready' && article && (
{article.updated_at && (
{t('help.article.updated', { date: formatDate(article.updated_at, locale) })}
)}
{article.related && article.related.length > 0 && (

{t('help.article.relatedTitle')}

{article.related.map((rel) => ( ))}
)}
)}
); } function formatDate(value: string, locale: string): string { try { return new Date(value).toLocaleDateString(locale, { day: '2-digit', month: 'short', year: 'numeric', }); } catch { return value; } }