teableio/teable

View on GitHub
apps/nextjs-app/src/features/app/blocks/base/duplicate/useTemplateMonitor.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { useRouter } from 'next/router';
import { useMount } from 'react-use';
import { useTemplateCreateBaseStore } from './useTemplateCreateBaseStore';

export const useTemplateMonitor = () => {
  const router = useRouter();
  const { tid, action } = router.query as { tid: string; action: string };
  const { openModal } = useTemplateCreateBaseStore();
  useMount(() => {
    if (action === 'createFromTemplate' && tid) {
      openModal(tid);
      router.push(router.pathname, undefined, { shallow: true });
    }
  });
};