AlertSiteUrlUndefined.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { useTranslation } from 'next-i18next';
  2. import { useSiteUrl } from '~/stores/context';
  3. const isValidUrl = (str: string): boolean => {
  4. try {
  5. // eslint-disable-next-line no-new
  6. new URL(str);
  7. return true;
  8. }
  9. catch {
  10. return false;
  11. }
  12. };
  13. export const AlertSiteUrlUndefined = (): JSX.Element => {
  14. const { t } = useTranslation('commons');
  15. const { data: siteUrl, error: errorSiteUrl } = useSiteUrl();
  16. const isLoadingSiteUrl = siteUrl === undefined && errorSiteUrl === undefined;
  17. if (isLoadingSiteUrl) {
  18. return <></>;
  19. }
  20. if (typeof siteUrl === 'string' && isValidUrl(siteUrl)) {
  21. return <></>;
  22. }
  23. return (
  24. <div className="alert alert-danger rounded-0 d-edit-none mb-0 px-4 py-2">
  25. <span className="material-symbols-outlined">error</span>
  26. {
  27. t('alert.siteUrl_is_not_set', { link: t('headers.app_settings') })
  28. } &gt;&gt; <a href="/admin/app">{t('headers.app_settings')}<span className="material-symbols-outlined">login</span></a>
  29. </div>
  30. );
  31. };
  32. AlertSiteUrlUndefined.displayName = 'AlertSiteUrlUndefined';