general-error.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { useNavigate, useRouter } from '@tanstack/react-router'
  2. import { useTranslation } from 'react-i18next'
  3. import { cn } from '@/lib/utils'
  4. import { Button } from '@/components/ui/button'
  5. const FEEDBACK_URL = 'https://github.com/QuantumNous/new-api/issues'
  6. type GeneralErrorProps = React.HTMLAttributes<HTMLDivElement> & {
  7. minimal?: boolean
  8. }
  9. export function GeneralError({
  10. className,
  11. minimal = false,
  12. }: GeneralErrorProps) {
  13. const { t } = useTranslation()
  14. const navigate = useNavigate()
  15. const { history } = useRouter()
  16. return (
  17. <div className={cn('h-svh w-full', className)}>
  18. <div className='m-auto flex h-full w-full flex-col items-center justify-center gap-2'>
  19. {!minimal && (
  20. <h1 className='text-[7rem] leading-tight font-bold'>500</h1>
  21. )}
  22. <span className='font-medium'>
  23. {t('Oops! Something went wrong')} {`:')`}
  24. </span>
  25. <p className='text-muted-foreground text-center'>
  26. {t('We apologize for the inconvenience.')} <br />{' '}
  27. {t('Please try again later.')}
  28. </p>
  29. {!minimal && (
  30. <p className='text-muted-foreground text-center text-sm'>
  31. {t('If this keeps happening, please report it on GitHub Issues.')}
  32. </p>
  33. )}
  34. {!minimal && (
  35. <div className='mt-6 flex flex-wrap justify-center gap-4'>
  36. <Button variant='outline' onClick={() => history.go(-1)}>
  37. {t('Go Back')}
  38. </Button>
  39. <Button
  40. variant='outline'
  41. render={
  42. <a
  43. href={FEEDBACK_URL}
  44. target='_blank'
  45. rel='noopener noreferrer'
  46. />
  47. }
  48. >
  49. {t('Report an issue')}
  50. </Button>
  51. <Button onClick={() => navigate({ to: '/' })}>
  52. {t('Back to Home')}
  53. </Button>
  54. </div>
  55. )}
  56. </div>
  57. </div>
  58. )
  59. }