-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly call the /variable endpoint after the user is authenti…
…cated (#4276) fix: correctly call the /variable endpoint after the user is authenticated (#4267) * ✨ (authContext.tsx): Add functionality to fetch global variables on authentication 🔧 (api.tsx): Replace universal-cookie import with react-cookie for consistency 🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency 🔧 (use-get-global-variables.ts): Add check to only fetch global variables if user is authenticated ✨ (use-get-mutation-global-variables.ts): Add mutation function to fetch and update global variables 🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency * ✨ (use-get-folders.ts): add authentication check before fetching folders data to ensure only authenticated users can access the data
- Loading branch information
1 parent
6d7cce6
commit a4af411
Showing
6 changed files
with
63 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/frontend/src/controllers/API/queries/variables/use-get-mutation-global-variables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useGlobalVariablesStore } from "@/stores/globalVariablesStore/globalVariables"; | ||
import getUnavailableFields from "@/stores/globalVariablesStore/utils/get-unavailable-fields"; | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { GlobalVariable } from "@/types/global_variables"; | ||
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
export const useGetGlobalVariablesMutation: useMutationFunctionType< | ||
undefined | ||
> = (options?) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const setGlobalVariablesEntries = useGlobalVariablesStore( | ||
(state) => state.setGlobalVariablesEntries, | ||
); | ||
const setUnavailableFields = useGlobalVariablesStore( | ||
(state) => state.setUnavailableFields, | ||
); | ||
|
||
const getGlobalVariablesFn = async (): Promise<GlobalVariable[]> => { | ||
const res = await api.get(`${getURL("VARIABLES")}/`); | ||
setGlobalVariablesEntries(res.data.map((entry) => entry.name)); | ||
setUnavailableFields(getUnavailableFields(res.data)); | ||
return res.data; | ||
}; | ||
|
||
const mutation: UseMutationResult<undefined, Error, GlobalVariable[]> = | ||
mutate(["useGetGlobalVariables"], getGlobalVariablesFn, options); | ||
|
||
return mutation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters