mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
Moved code into src folder. Added build for component library.
This commit is contained in:
parent
7a7233ead4
commit
ede658771e
490 changed files with 749 additions and 442 deletions
28
src/components/hooks/useShareToken.js
Normal file
28
src/components/hooks/useShareToken.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { useEffect } from 'react';
|
||||
import useStore, { setShareToken } from 'store/app';
|
||||
import useApi from './useApi';
|
||||
|
||||
const selector = state => state.shareToken;
|
||||
|
||||
export function useShareToken(shareId) {
|
||||
const shareToken = useStore(selector);
|
||||
const { get } = useApi();
|
||||
|
||||
async function loadToken(id) {
|
||||
const data = await get(`/share/${id}`);
|
||||
|
||||
if (data) {
|
||||
setShareToken(data);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (shareId) {
|
||||
loadToken(shareId);
|
||||
}
|
||||
}, [shareId]);
|
||||
|
||||
return shareToken;
|
||||
}
|
||||
|
||||
export default useShareToken;
|
||||
Loading…
Add table
Add a link
Reference in a new issue