Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.0 KB
Raw Blame
'use client';

import { FluentEmoji, Result, Text } from '@lobehub/ui';
import React, { memo, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSearchParams } from 'react-router';

import { resultStyles } from '../resultStyles';

const SuccessPage = memo(() => {
  const { t } = useTranslation('oauth');
  const [searchParams] = useSearchParams();
  const [countdown, setCountdown] = useState(3);

  useEffect(() => {
    // Check if this is a LobeHub Skill OAuth callback
    const provider = searchParams.get('provider');

    if (provider && window.opener) {
      // Notify parent window about successful OAuth
      window.opener.postMessage(
        {
          provider,
          type: 'LOBEHUB_SKILL_AUTH_SUCCESS',
        },
        window.location.origin,
      );

      // Start countdown and close window after 3 seconds
      let timeLeft = 3;
      setCountdown(timeLeft);

      const countdownTimer = setInterval(() => {
        timeLeft -= 1;
        setCountdown(timeLeft);

        if (timeLeft <= 0) {
          clearInterval(countdownTimer);
          window.close();
        }
      }, 1000);

      return () => clearInterval(countdownTimer);
    }
  }, [searchParams]);

  const provider = searchParams.get('provider');

  return (
    <Result
      className={resultStyles.fullWidthSubTitle}
      icon={<FluentEmoji emoji={'✅'} size={96} type={'anim'} />}
      status="success"
      subTitle={
        <Text align="center" as="span" fontSize={16} style={{ display: 'block' }} type="secondary">
          {provider
            ? t('success.subTitleWithCountdown', {
                countdown,
                defaultValue: `You may close this page. Auto-closing in ${countdown}s...`,
              })
            : t('success.subTitle')}
        </Text>
      }
      title={
        <Text fontSize={32} weight={'bold'}>
          {t('success.title')}
        </Text>
      }
    />
  );
});

SuccessPage.displayName = 'SuccessPage';

export default SuccessPage;