share-link.tsx 697 B

123456789101112131415161718
  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, { relatedPage: pageId });
  8. return res.data.shareLinksResult;
  9. };
  10. export const useSWRxSharelink = (currentPageId: Nullable<string>): SWRResponse<IResShareLinkList['shareLinksResult'], Error> => {
  11. return useSWR(
  12. currentPageId == null ? null : ['/share-links/', currentPageId],
  13. ([endpoint]) => fetchShareLinks(endpoint, currentPageId),
  14. );
  15. };