diff --git a/client/src/data-provider/Location/index.ts b/client/src/data-provider/Location/index.ts new file mode 100644 index 0000000000..3cf1ef310b --- /dev/null +++ b/client/src/data-provider/Location/index.ts @@ -0,0 +1 @@ +export * from './queries'; diff --git a/client/src/data-provider/Location/queries.ts b/client/src/data-provider/Location/queries.ts new file mode 100644 index 0000000000..cba201e314 --- /dev/null +++ b/client/src/data-provider/Location/queries.ts @@ -0,0 +1,23 @@ +import { useQueryClient, useMutation } from '@tanstack/react-query'; +import { QueryKeys, MutationKeys, dataService } from 'librechat-data-provider'; +import type { UseMutationOptions } from '@tanstack/react-query'; +import type { TUserLocation } from 'librechat-data-provider'; + +export type UpdateUserLocationResponse = { updated: boolean; location?: TUserLocation }; + +export const useUpdateUserLocationMutation = ( + options?: UseMutationOptions, +) => { + const queryClient = useQueryClient(); + return useMutation( + [MutationKeys.updateUserLocation], + (location: TUserLocation) => dataService.updateUserLocation(location), + { + ...options, + onSuccess: (...params) => { + queryClient.invalidateQueries([QueryKeys.user]); + options?.onSuccess?.(...params); + }, + }, + ); +}; diff --git a/client/src/data-provider/index.ts b/client/src/data-provider/index.ts index e4be6aee0b..3d238ad07e 100644 --- a/client/src/data-provider/index.ts +++ b/client/src/data-provider/index.ts @@ -3,6 +3,8 @@ export * from './Agents'; export * from './Endpoints'; export * from './Skills'; export * from './Files'; +/* Location */ +export * from './Location'; /* Memories */ export * from './Memories'; export * from './Messages'; diff --git a/packages/data-provider/src/api-endpoints.ts b/packages/data-provider/src/api-endpoints.ts index 09864bea43..117cdc4b1e 100644 --- a/packages/data-provider/src/api-endpoints.ts +++ b/packages/data-provider/src/api-endpoints.ts @@ -473,6 +473,9 @@ export const disableTwoFactor = () => `${BASE_URL}/api/auth/2fa/disable`; export const regenerateBackupCodes = () => `${BASE_URL}/api/auth/2fa/backup/regenerate`; export const verifyTwoFactorTemp = () => `${BASE_URL}/api/auth/2fa/verify-temp`; +/* User location */ +export const userLocation = () => `${BASE_URL}/api/user/settings/location`; + /* Memories */ export const memories = () => `${BASE_URL}/api/memories`; export const memory = (key: string) => `${memories()}/${encodeURIComponent(key)}`; diff --git a/packages/data-provider/src/data-service.ts b/packages/data-provider/src/data-service.ts index e008e8c514..ee87bb114f 100644 --- a/packages/data-provider/src/data-service.ts +++ b/packages/data-provider/src/data-service.ts @@ -1277,6 +1277,12 @@ export const updateMemoryPreferences = (preferences: { return request.patch(endpoints.memoryPreferences(), preferences); }; +export const updateUserLocation = ( + location: t.TUserLocation, +): Promise<{ updated: boolean; location?: t.TUserLocation }> => { + return request.patch(endpoints.userLocation(), location); +}; + export const createMemory = (data: { key: string; value: string; diff --git a/packages/data-provider/src/keys.ts b/packages/data-provider/src/keys.ts index 04a65beb51..253d06bc70 100644 --- a/packages/data-provider/src/keys.ts +++ b/packages/data-provider/src/keys.ts @@ -116,6 +116,7 @@ export enum MutationKeys { enableTwoFactor = 'enableTwoFactor', verifyTwoFactor = 'verifyTwoFactor', updateMemoryPreferences = 'updateMemoryPreferences', + updateUserLocation = 'updateUserLocation', createProject = 'createProject', updateProject = 'updateProject', deleteProject = 'deleteProject',