share-link.tsx 669 B

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