mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Created share token hook.
This commit is contained in:
parent
4119e80a9a
commit
5a73c224b7
22 changed files with 90 additions and 49 deletions
25
hooks/useShareToken.js
Normal file
25
hooks/useShareToken.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { get } from 'lib/web';
|
||||
import { setShareToken } from 'redux/actions/app';
|
||||
|
||||
export default function useShareToken(shareId) {
|
||||
const dispatch = useDispatch();
|
||||
const shareToken = useSelector(state => state.app.shareToken);
|
||||
|
||||
async function loadToken(id) {
|
||||
const { data } = await get(`/api/share/${id}`);
|
||||
|
||||
if (data) {
|
||||
dispatch(setShareToken(data));
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (shareId) {
|
||||
loadToken(shareId);
|
||||
}
|
||||
}, [shareId]);
|
||||
|
||||
return shareToken;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue