Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create queryKey factory #1580

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { deleteInformationPage, getInformationPages } from '~/api';
import { useCustomNavigate, useTitle } from '~/hooks';
import { KEY } from '~/i18n/constants';
import { reverse } from '~/named-urls';
import { infoPageKeys } from '~/queryKeys';
import { ROUTES } from '~/routes';
import { dbT, lowerCapitalize } from '~/utils';
import { AdminPageLayout } from '../AdminPageLayout/AdminPageLayout';
Expand All @@ -18,7 +19,7 @@ export function InformationAdminPage() {

// TODO: add permissions on render
const { data, isLoading } = useQuery({
queryKey: ['informationpages'],
queryKey: infoPageKeys.all,
queryFn: getInformationPages,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { MultiSelect } from '~/Components/MultiSelect';
import { createRole, editRole, getPermissions } from '~/api';
import type { RoleDto } from '~/dto';
import { KEY } from '~/i18n/constants';
import { permissionKeys } from '~/queryKeys';
import { ROLE_CONTENT_TYPE, ROLE_NAME } from '~/schema/role';
import styles from './RoleForm.module.scss';

Expand All @@ -47,7 +48,7 @@ export function RoleForm({ role }: Props) {
isLoading,
isError,
} = useQuery({
queryKey: ['permissions'],
queryKey: permissionKeys.all,
queryFn: getPermissions,
});

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/PagesAdmin/RolesAdminPage/RolesAdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getRoles } from '~/api';
import { useTitle } from '~/hooks';
import { KEY } from '~/i18n/constants';
import { reverse } from '~/named-urls';
import { roleKeys } from '~/queryKeys';
import { ROUTES } from '~/routes';
import { lowerCapitalize } from '~/utils';

Expand All @@ -19,7 +20,7 @@ export function RolesAdminPage() {
useTitle(title);

const { data: roles, isLoading } = useQuery({
queryKey: ['roles'],
queryKey: roleKeys.all,
queryFn: getRoles,
});

Expand Down
23 changes: 23 additions & 0 deletions frontend/src/queryKeys.ts
robines marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const roleKeys = {
all: ['roles'] as const,
lists: () => [...roleKeys.all, 'list'] as const,
list: (filters: unknown[]) => [...roleKeys.lists(), { filters }] as const,
details: () => [...roleKeys.all, 'detail'] as const,
detail: (id: number) => [...roleKeys.details(), id] as const,
};

export const infoPageKeys = {
all: ['infopages'] as const,
lists: () => [...infoPageKeys.all, 'list'] as const,
list: (filters: unknown[]) => [...infoPageKeys.lists(), { filters }] as const,
details: () => [...infoPageKeys.all, 'detail'] as const,
detail: (slug: string) => [...infoPageKeys.details(), slug] as const,
};

export const permissionKeys = {
all: ['permissions'] as const,
lists: () => [...permissionKeys.all, 'list'] as const,
list: (filters: unknown[]) => [...permissionKeys.lists(), { filters }] as const,
details: () => [...permissionKeys.all, 'detail'] as const,
detail: (id: number) => [...permissionKeys.details(), id] as const,
};
Loading