share-link.tsx 710 B

12345678910111213141516171819202122
  1. import type { Nullable } from '@growi/core';
  2. import type { SWRResponse } from 'swr';
  3. import useSWR from 'swr';
  4. import { apiv3Get } from '~/client/util/apiv3-client';
  5. import type { IResShareLinkList } from '~/interfaces/share-link';
  6. const fetchShareLinks = async (endpoint, pageId) => {
  7. const res = await apiv3Get<IResShareLinkList>(endpoint, {
  8. relatedPage: pageId,
  9. });
  10. return res.data.shareLinksResult;
  11. };
  12. export const useSWRxSharelink = (
  13. currentPageId: Nullable<string>,
  14. ): SWRResponse<IResShareLinkList['shareLinksResult'], Error> => {
  15. return useSWR(
  16. currentPageId == null ? null : ['/share-links/', currentPageId],
  17. ([endpoint]) => fetchShareLinks(endpoint, currentPageId),
  18. );
  19. };