mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Teams context settings.
This commit is contained in:
parent
4429198397
commit
8f853ddb97
77 changed files with 317 additions and 272 deletions
|
|
@ -25,5 +25,6 @@ export * from './useLocale';
|
|||
export * from './useMessages';
|
||||
export * from './useNavigation';
|
||||
export * from './useSticky';
|
||||
export * from './useTeamContext';
|
||||
export * from './useTheme';
|
||||
export * from './useTimezone';
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import useStore, { setUser } from 'store/app';
|
||||
import useApi from './useApi';
|
||||
import { UseQueryResult } from '@tanstack/react-query';
|
||||
|
||||
const selector = (state: { user: any }) => state.user;
|
||||
|
||||
export function useLogin() {
|
||||
export function useLogin(): {
|
||||
user: any;
|
||||
setUser: (data: any) => void;
|
||||
} & UseQueryResult {
|
||||
const { get, useQuery } = useApi();
|
||||
const user = useStore(selector);
|
||||
|
||||
|
|
@ -19,7 +23,7 @@ export function useLogin() {
|
|||
enabled: !user,
|
||||
});
|
||||
|
||||
return { user, ...query };
|
||||
return { user, setUser, ...query };
|
||||
}
|
||||
|
||||
export default useLogin;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,18 @@ import useApi from './useApi';
|
|||
import useFilterQuery from './useFilterQuery';
|
||||
import useCache from 'store/cache';
|
||||
|
||||
export function useWebsites({ userId, teamId }: { userId?: string; teamId?: string }) {
|
||||
export function useWebsites(
|
||||
{ userId, teamId }: { userId?: string; teamId?: string },
|
||||
params?: { [key: string]: string | number },
|
||||
) {
|
||||
const { get } = useApi();
|
||||
const modified = useCache((state: any) => state?.websites);
|
||||
|
||||
return useFilterQuery({
|
||||
queryKey: ['websites', { userId, teamId, modified }],
|
||||
queryFn: (params: any) => {
|
||||
queryKey: ['websites', { userId, teamId, modified, ...params }],
|
||||
queryFn: (data: any) => {
|
||||
return get(teamId ? `/teams/${teamId}/websites` : `/users/${userId}/websites`, {
|
||||
...data,
|
||||
...params,
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,13 +7,10 @@ export function useNavigation(): {
|
|||
query: { [key: string]: string };
|
||||
router: any;
|
||||
renderUrl: (params: any, reset?: boolean) => string;
|
||||
renderTeamUrl: (url: string) => string;
|
||||
teamId?: string;
|
||||
} {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const params = useSearchParams();
|
||||
const [, teamId] = pathname.match(/^\/teams\/([a-f0-9-]+)/) || [];
|
||||
|
||||
const query = useMemo(() => {
|
||||
const obj = {};
|
||||
|
|
@ -29,11 +26,7 @@ export function useNavigation(): {
|
|||
return reset ? pathname : buildUrl(pathname, { ...query, ...params });
|
||||
}
|
||||
|
||||
function renderTeamUrl(url: string) {
|
||||
return teamId ? `/teams/${teamId}${url}` : url;
|
||||
}
|
||||
|
||||
return { pathname, query, router, renderUrl, renderTeamUrl, teamId };
|
||||
return { pathname, query, router, renderUrl };
|
||||
}
|
||||
|
||||
export default useNavigation;
|
||||
|
|
|
|||
17
src/components/hooks/useTeamContext.ts
Normal file
17
src/components/hooks/useTeamContext.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { usePathname } from 'next/navigation';
|
||||
|
||||
export function useTeamContext(): {
|
||||
teamId?: string;
|
||||
renderTeamUrl: (url: string) => string;
|
||||
} {
|
||||
const pathname = usePathname();
|
||||
const [, teamId] = pathname.match(/^\/teams\/([a-f0-9-]+)/) || [];
|
||||
|
||||
function renderTeamUrl(url: string) {
|
||||
return teamId ? `/teams/${teamId}${url}` : url;
|
||||
}
|
||||
|
||||
return { teamId, renderTeamUrl };
|
||||
}
|
||||
|
||||
export default useTeamContext;
|
||||
Loading…
Add table
Add a link
Reference in a new issue