Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.6 KB
Raw Blame
import { t } from 'i18next';
import { RefreshCcw } from 'lucide-react';
import { useRef, useState } from 'react';
import { ErrorBoundary } from 'react-error-boundary';

import { Button } from '@/components/ui/button';

const DynamicPropertiesErrorBoundary = ({
  children,
}: {
  children: React.ReactNode;
}) => {
  const [key, setKey] = useState(Date.now());
  const triedRerenderingRef = useRef(false);
  return (
    <ErrorBoundary
      key={key}
      fallback={
        !triedRerenderingRef.current ? (
          <div className="text-sm text-danger-11 italic flex justify-between items-center">
            {t('Unexpected error, please retry')}
            <Button
              size="icon"
              variant="outline"
              onClick={() => {
                setKey(Date.now());
                triedRerenderingRef.current = true;
              }}
            >
              {<RefreshCcw className="w-4 h-4 text-gray-12!"></RefreshCcw>}{' '}
            </Button>
          </div>
        ) : (
          <div className="text-sm text-danger-11 italic flex justify-between items-center">
            {t('Unexpected error, please refresh the page or contact support')}
            <Button
              size="icon"
              variant="outline"
              onClick={() => {
                window.location.reload();
              }}
            >
              {<RefreshCcw className="w-4 h-4 text-gray-12!"></RefreshCcw>}{' '}
            </Button>
          </div>
        )
      }
    >
      {children}
    </ErrorBoundary>
  );
};
DynamicPropertiesErrorBoundary.displayName = 'DynamicPropertiesErrorBoundary';
export { DynamicPropertiesErrorBoundary };