import React from 'react'; import { usePage, router } from '@inertiajs/react'; import { useTranslation } from 'react-i18next'; import MarketingLayout from '@/layouts/mainWebsite'; import { Loader, CheckCircle } from 'lucide-react'; import { useLocalizedRoutes } from '@/hooks/useLocalizedRoutes'; import { useLocale } from '@/hooks/useLocale'; import { ADMIN_HOME_PATH } from '@/admin/constants'; import { Button } from '@/components/ui/button'; import { fetchGiftVoucherByCheckout, type GiftVoucherLookupResponse } from '@/lib/giftVouchers'; type SuccessProps = { type?: string; }; const GiftSuccess: React.FC = () => { const { t } = useTranslation('marketing'); const { localizedPath } = useLocalizedRoutes(); const locale = useLocale(); const [voucher, setVoucher] = React.useState(null); const [loading, setLoading] = React.useState(true); const [error, setError] = React.useState(null); const [copied, setCopied] = React.useState(false); React.useEffect(() => { const params = new URLSearchParams(window.location.search); const checkoutId = params.get('checkout_id') || sessionStorage.getItem('gift_checkout_id'); const transactionId = params.get('transaction_id'); fetchGiftVoucherByCheckout(checkoutId || undefined, transactionId || undefined) .then((data) => { if (data) { setVoucher(data); } else { setError(t('success.gift_lookup_failed')); } }) .catch(() => setError(t('success.gift_lookup_failed'))) .finally(() => setLoading(false)); }, [t]); const onCopy = async () => { if (!voucher?.code) return; try { await navigator.clipboard.writeText(voucher.code); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (e) { setError(t('success.gift_copy_failed')); } }; const onShare = async () => { if (!voucher?.code) return; const text = t('success.gift_share_text', { code: voucher.code, amount: voucher.amount.toFixed(2), currency: voucher.currency, }); if (navigator.share) { try { await navigator.share({ title: t('success.gift_title'), text }); return; } catch (e) { // fall back to copy } } await onCopy(); }; return (

{t('success.gift_title')}

{t('success.gift_description')}

{t('success.gift_code_title')}

{loading &&

{t('success.gift_loading')}

} {error &&

{error}

} {voucher && (

{t('success.gift_code_label')}

{voucher.code}

{t('success.gift_value', { amount: voucher.amount.toFixed(2), currency: voucher.currency, })}

{voucher.expires_at && (

{t('success.gift_expires', { date: new Date(voucher.expires_at).toLocaleDateString(locale || undefined), })}

)}
)}

{t('success.gift_bullets_title')}

  • {t('success.gift_bullet_email')}
  • {t('success.gift_bullet_validity')}
  • {t('success.gift_bullet_redeem')}
); }; const AuthRedirectSuccess: React.FC<{ emailVerified?: boolean | null }> = ({ emailVerified }) => { const { t } = useTranslation('success'); const { localizedPath } = useLocalizedRoutes(); if (emailVerified) { router.visit(ADMIN_HOME_PATH, { preserveState: false }); return (

{t('redirecting')}

); } return (

{t('complete_purchase')}

{t('login_to_continue')}

{t('login')}
); }; const Success: React.FC = () => { const { auth } = usePage<{ auth: { user?: { email_verified_at?: string | null } } }>().props; const searchParams = typeof window !== 'undefined' ? new URLSearchParams(window.location.search) : new URLSearchParams(); const type = searchParams.get('type'); if (type === 'gift') { return ; } return ; }; Success.layout = (page: React.ReactNode) => page; export default Success;