ExternalLinkPage.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { useParams } from 'react-router-dom';
  2. import { useQuery } from '@tanstack/react-query';
  3. import { Loader2, AlertTriangle } from 'lucide-react';
  4. import { useTranslation } from 'react-i18next';
  5. import { api } from '../api/client';
  6. import { useTheme } from '../contexts/ThemeContext';
  7. export function ExternalLinkPage() {
  8. const { t } = useTranslation();
  9. const { id } = useParams<{ id: string }>();
  10. const { mode } = useTheme();
  11. const { data: link, isLoading, error } = useQuery({
  12. queryKey: ['external-link', id],
  13. queryFn: () => api.getExternalLink(Number(id)),
  14. enabled: !!id,
  15. });
  16. if (isLoading) {
  17. return (
  18. <div className="flex items-center justify-center h-full">
  19. <Loader2 className="w-8 h-8 text-bambu-green animate-spin" />
  20. </div>
  21. );
  22. }
  23. if (error || !link) {
  24. return (
  25. <div className="flex flex-col items-center justify-center h-full gap-4 text-bambu-gray">
  26. <AlertTriangle className="w-12 h-12" />
  27. <p>{t('common.linkNotFound')}</p>
  28. </div>
  29. );
  30. }
  31. return (
  32. <iframe
  33. src={link.url}
  34. className="h-full w-full border-0"
  35. style={{ colorScheme: mode }}
  36. title={link.name}
  37. sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
  38. />
  39. );
  40. }