mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 21:57:16 +01:00
Added teams pages. Refactored hooks.
This commit is contained in:
parent
a2c202fa36
commit
9448aa3ab5
136 changed files with 387 additions and 287 deletions
|
|
@ -1,5 +1,14 @@
|
|||
export * from './useApi';
|
||||
export * from './useConfig';
|
||||
export * from './queries/useApi';
|
||||
export * from './queries/useConfig';
|
||||
export * from './queries/useFilterQuery';
|
||||
export * from './queries/useLogin';
|
||||
export * from './queries/useReport';
|
||||
export * from './queries/useReports';
|
||||
export * from './queries/useShareToken';
|
||||
export * from './queries/useTeam';
|
||||
export * from './queries/useTeamWebsites';
|
||||
export * from './queries/useUser';
|
||||
export * from './queries/useWebsite';
|
||||
export * from './useCountryNames';
|
||||
export * from './useDateRange';
|
||||
export * from './useDocumentClick';
|
||||
|
|
@ -11,12 +20,6 @@ export * from './useLanguageNames';
|
|||
export * from './useLocale';
|
||||
export * from './useMessages';
|
||||
export * from './useNavigation';
|
||||
export * from './useReport';
|
||||
export * from './useReports';
|
||||
export * from './useLogin';
|
||||
export * from './useShareToken';
|
||||
export * from './useSticky';
|
||||
export * from './useTheme';
|
||||
export * from './useTimezone';
|
||||
export * from './useUser';
|
||||
export * from './useWebsite';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { getClientAuthToken } from 'lib/client';
|
|||
import { SHARE_TOKEN_HEADER } from 'lib/constants';
|
||||
import useStore from 'store/app';
|
||||
|
||||
const selector = state => state.shareToken;
|
||||
const selector = (state: { shareToken: { token?: string } }) => state.shareToken;
|
||||
|
||||
export function useApi() {
|
||||
const shareToken = useStore(selector);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { useEffect } from 'react';
|
||||
import useStore, { setConfig } from 'store/app';
|
||||
import useApi from 'components/hooks/useApi';
|
||||
import { useApi } from './useApi';
|
||||
|
||||
let loading = false;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { UseQueryOptions } from '@tanstack/react-query';
|
||||
import { useState, Dispatch, SetStateAction } from 'react';
|
||||
import { useApi } from 'components/hooks/useApi';
|
||||
import { useApi } from './useApi';
|
||||
import { FilterResult, SearchFilter } from 'lib/types';
|
||||
|
||||
export interface FilterQueryResult<T> {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import useApi from 'components/hooks/useApi';
|
||||
import useUser from 'components/hooks/useUser';
|
||||
import useApi from './useApi';
|
||||
import useUser from './useUser';
|
||||
|
||||
export function useLogin() {
|
||||
const { get, useQuery } = useApi();
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { produce } from 'immer';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useTimezone } from './useTimezone';
|
||||
import useApi from './useApi';
|
||||
import useMessages from './useMessages';
|
||||
import { useApi } from './useApi';
|
||||
import { useTimezone } from '../useTimezone';
|
||||
import { useMessages } from '../useMessages';
|
||||
|
||||
export function useReport(reportId: string, defaultParameters: { [key: string]: any }) {
|
||||
const [report, setReport] = useState(null);
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState } from 'react';
|
||||
import useApi from './useApi';
|
||||
import useFilterQuery from 'components/hooks/useFilterQuery';
|
||||
import useFilterQuery from './useFilterQuery';
|
||||
|
||||
export function useReports(websiteId?: string) {
|
||||
const [modified, setModified] = useState(Date.now());
|
||||
12
src/components/hooks/queries/useTeam.ts
Normal file
12
src/components/hooks/queries/useTeam.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import useApi from './useApi';
|
||||
|
||||
export function useTeam(teamId: string) {
|
||||
const { get, useQuery } = useApi();
|
||||
return useQuery({
|
||||
queryKey: ['teams', teamId],
|
||||
queryFn: () => get(`/teams/${teamId}`),
|
||||
enabled: !!teamId,
|
||||
});
|
||||
}
|
||||
|
||||
export default useTeam;
|
||||
15
src/components/hooks/queries/useTeamWebsites.ts
Normal file
15
src/components/hooks/queries/useTeamWebsites.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import useApi from './useApi';
|
||||
import useFilterQuery from './useFilterQuery';
|
||||
|
||||
export function useTeamWebsites(teamId: string) {
|
||||
const { get } = useApi();
|
||||
|
||||
return useFilterQuery({
|
||||
queryKey: ['teams:websites', { teamId }],
|
||||
queryFn: (params: any) => {
|
||||
return get(`/teams/${teamId}/websites`, params);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default useTeamWebsites;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import useStore, { setUser } from 'store/app';
|
||||
|
||||
const selector = state => state.user;
|
||||
const selector = (state: { user: any }) => state.user;
|
||||
|
||||
export function useUser() {
|
||||
const user = useStore(selector);
|
||||
20
src/components/hooks/queries/useWebsites.ts
Normal file
20
src/components/hooks/queries/useWebsites.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import useApi from './useApi';
|
||||
import useFilterQuery from './useFilterQuery';
|
||||
import useCache from 'store/cache';
|
||||
|
||||
export function useWebsites({ userId, teamId }: { userId?: string; teamId?: string }) {
|
||||
const { get } = useApi();
|
||||
const modified = useCache((state: any) => state?.websites);
|
||||
|
||||
return useFilterQuery({
|
||||
queryKey: ['websites', { userId, teamId, modified }],
|
||||
queryFn: (params: any) => {
|
||||
return get(teamId ? `/teams/${teamId}/websites` : '/websites', {
|
||||
...params,
|
||||
});
|
||||
},
|
||||
enabled: !!(userId || teamId),
|
||||
});
|
||||
}
|
||||
|
||||
export default useWebsites;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { httpGet } from 'next-basics';
|
||||
import enUS from 'public/intl/country/en-US.json';
|
||||
import enUS from '../../../public/intl/country/en-US.json';
|
||||
|
||||
const countryNames = {
|
||||
'en-US': enUS,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import websiteStore, { setWebsiteDateRange } from 'store/websites';
|
|||
import appStore, { setDateRange } from 'store/app';
|
||||
import { DateRange } from 'lib/types';
|
||||
import useLocale from './useLocale';
|
||||
import useApi from './useApi';
|
||||
import { useApi } from 'components/hooks';
|
||||
|
||||
export function useDateRange(websiteId?: string) {
|
||||
const { get } = useApi();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { httpGet } from 'next-basics';
|
||||
import enUS from 'public/intl/language/en-US.json';
|
||||
import enUS from '../../../public/intl/language/en-US.json';
|
||||
|
||||
const languageNames = {
|
||||
'en-US': enUS,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import { httpGet, setItem } from 'next-basics';
|
|||
import { LOCALE_CONFIG } from 'lib/constants';
|
||||
import { getDateLocale, getTextDirection } from 'lib/lang';
|
||||
import useStore, { setLocale } from 'store/app';
|
||||
import useForceUpdate from 'components/hooks/useForceUpdate';
|
||||
import enUS from 'public/intl/country/en-US.json';
|
||||
import { useForceUpdate } from 'components/hooks';
|
||||
import enUS from '../../../public/intl/country/en-US.json';
|
||||
|
||||
const messages = {
|
||||
'en-US': enUS,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export function useTimezone() {
|
|||
const [timezone, setTimezone] = useState(getItem(TIMEZONE_CONFIG) || getTimezone());
|
||||
|
||||
const saveTimezone = useCallback(
|
||||
value => {
|
||||
(value: string) => {
|
||||
setItem(TIMEZONE_CONFIG, value);
|
||||
setTimezone(value);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue