diff --git a/api/src/setting/controllers/setting.controller.ts b/api/src/setting/controllers/setting.controller.ts index bc616284..3cca9167 100644 --- a/api/src/setting/controllers/setting.controller.ts +++ b/api/src/setting/controllers/setting.controller.ts @@ -58,16 +58,6 @@ export class SettingController { return await this.settingService.find(filters, sort); } - /** - * Loads all settings available in the system. - * - * @returns A list of all settings. - */ - @Get('load') - async load() { - return await this.settingService.load(); - } - /** * Updates a setting by its ID. If the setting does not exist, throws a `NotFoundException`. * diff --git a/frontend/src/hooks/entities/auth-hooks.ts b/frontend/src/hooks/entities/auth-hooks.ts index ba46c767..a7f7b661 100755 --- a/frontend/src/hooks/entities/auth-hooks.ts +++ b/frontend/src/hooks/entities/auth-hooks.ts @@ -10,12 +10,12 @@ import { useEffect } from "react"; import { useMutation, useQuery } from "react-query"; -import { Format, TMutationOptions } from "@/services/types"; +import { EntityType, TMutationOptions } from "@/services/types"; import { ILoginAttributes } from "@/types/auth/login.types"; import { IUserPermissions } from "@/types/auth/permission.types"; -import { ISetting } from "@/types/setting.types"; import { IUser, IUserAttributes, IUserStub } from "@/types/user.types"; +import { useFind } from "../crud/useFind"; import { useApiClient } from "../useApiClient"; import { useAuth } from "../useAuth"; import { useLocalStorageState } from "../useLocalStorageState"; @@ -128,26 +128,31 @@ export const useConfirmAccount = ( }); }; -export const SETTINGS_STORAGE_KEY = "settings"; export const useLoadSettings = () => { - const { apiClient } = useApiClient(); const { isAuthenticated } = useAuth(); - const { persist, value } = useLocalStorageState(SETTINGS_STORAGE_KEY); - const storedSettings = value - ? (JSON.parse(value || JSON.stringify({})) as { [key: string]: ISetting[] }) - : undefined; + const { data: settings, ...rest } = useFind( + { entity: EntityType.SETTING }, + { + hasCount: false, + initialSortState: [{ field: "weight", sort: "desc" }], + }, + { + enabled: isAuthenticated, + }, + ); - return useQuery({ - enabled: isAuthenticated, - queryKey: [SETTINGS_STORAGE_KEY, Format.BASIC], - async queryFn() { - return await apiClient.getSettings(); - }, - onSuccess(data) { - persist(JSON.stringify(data)); - }, - initialData: storedSettings || ({} as { [key: string]: ISetting[] }), - }); + return { + ...rest, + data: + settings?.reduce((acc, curr) => { + const group = acc[curr.group] || []; + + group.push(curr); + acc[curr.group] = group; + + return acc; + }, {}) || {}, + }; }; export const useUpdateProfile = ( diff --git a/frontend/src/services/api.class.ts b/frontend/src/services/api.class.ts index 1e1a2caf..c5bdd76e 100644 --- a/frontend/src/services/api.class.ts +++ b/frontend/src/services/api.class.ts @@ -16,7 +16,6 @@ import { ICsrf } from "@/types/csrf.types"; import { IInvitation, IInvitationAttributes } from "@/types/invitation.types"; import { INlpDatasetSampleAttributes } from "@/types/nlp-sample.types"; import { IResetPayload, IResetRequest } from "@/types/reset.types"; -import { ISetting } from "@/types/setting.types"; import { IUser, IUserAttributes, IUserStub } from "@/types/user.types"; import { EntityType, Format, TCount, TypeByFormat } from "./types"; @@ -34,7 +33,6 @@ export const ROUTES = { CSRF: "/csrftoken", BOTSTATS: "/botstats", REFRESH_TRANSLATIONS: "/translation/refresh", - LOAD_SETTINGS: "/setting/load", RESET: "/user/reset", NLP_SAMPLE_IMPORT: "/nlpsample/import", NLP_SAMPLE_PREDICT: "/nlpsample/message", @@ -191,14 +189,6 @@ export class ApiClient { return data; } - async getSettings() { - const { data } = await this.request.get<{ - [key: string]: ISetting[]; - }>(ROUTES.LOAD_SETTINGS); - - return data; - } - async reset(token: string, payload: IResetPayload) { const { data } = await this.request.post< IResetPayload,