use-user-setting-request.tsx


Overview

use-user-setting-request.tsx is a React hooks module providing a comprehensive set of custom hooks to interact with user settings, tenant management, system tokens, and Langfuse configuration in a web application. These hooks encapsulate API calls related to user and tenant information, system tokens management, tenant user administration, system status/version retrieval, and Langfuse configuration management.

The file leverages React Query (@tanstack/react-query) for data fetching, caching, and mutations, Ant Design (antd) for UI modal dialogs, and i18next for internationalization. It integrates with a centralized userService that abstracts API endpoints. The hooks provide an idiomatic React interface to perform CRUD and fetch operations, handle loading states, and present user feedback via messages and modals.


Detailed Explanation of Exports

Enum: UserSettingApiAction

Defines string constants representing API action keys used in React Query hooks for query/mutation keys.

Action Name

Description

UserInfo

Fetch current user information

TenantInfo

Fetch current tenant information

SaveSetting

Save user settings

FetchManualSystemTokenList

Fetch system tokens (manual)

FetchSystemTokenList

Fetch system tokens (query)

RemoveSystemToken

Remove a system token

CreateSystemToken

Create a new system token

ListTenantUser

List users in a tenant

AddTenantUser

Add a user to a tenant

DeleteTenantUser

Delete a user from a tenant

ListTenant

List tenants

AgreeTenant

Approve a tenant

SetLangfuseConfig

Set Langfuse configuration

DeleteLangfuseConfig

Delete Langfuse configuration

FetchLangfuseConfig

Fetch Langfuse configuration


Hook: useFetchUserInfo

Fetches the current user's information.

const { data: userInfo, loading } = useFetchUserInfo();

if (!loading) {
  console.log(userInfo.name);
}

Hook: useFetchTenantInfo(showEmptyModelWarn?: boolean)

Fetches tenant information.

const { data: tenantInfo, loading } = useFetchTenantInfo(true);

Hook: useSelectParserList

Derives a list of parser options for UI selects from tenant information.


Hook: useSaveSetting

Mutates (saves) user settings.

const { saveSetting, loading } = useSaveSetting();

await saveSetting({ new_password: 'newpass123' });

Hook: useFetchSystemVersion

Fetches the current system version.


Hook: useFetchSystemStatus

Fetches the current system status.


Hook: useFetchManualSystemTokenList

Fetches a list of system tokens using mutation (manual fetch).


Hook: useFetchSystemTokenList

Fetches a list of system tokens via query (auto fetching).


Hook: useRemoveSystemToken

Removes a system token.


Hook: useCreateSystemToken

Creates a new system token.


Hook: useListTenantUser

Lists users in the current tenant.


Hook: useAddTenantUser

Adds a user to the current tenant.


Hook: useDeleteTenantUser

Deletes a user from a tenant.


Hook: useListTenant

Lists tenants.


Hook: useAgreeTenant

Approves a tenant by tenant ID.


Hook: useSetLangfuseConfig

Sets Langfuse configuration.


Hook: useDeleteLangfuseConfig

Deletes Langfuse configuration.


Hook: useFetchLangfuseConfig

Fetches Langfuse configuration.


Important Implementation Details


Interaction with Other Parts of the System


Usage Example Summary

Typical usage involves importing the desired hook and using it within React components:

import { useFetchUserInfo, useSaveSetting } from '@/hooks/use-user-setting-request';

function ProfileSettings() {
  const { data: userInfo, loading } = useFetchUserInfo();
  const { saveSetting, loading: saving } = useSaveSetting();

  const onChangePassword = async (newPassword: string) => {
    await saveSetting({ new_password: newPassword });
  };

  if (loading) return <div>Loading...</div>;

  return <div>Welcome, {userInfo.name}</div>;
}

Mermaid Diagram: Component Interaction Diagram

classDiagram
    class useFetchUserInfo {
        +data: IUserInfo
        +loading: boolean
    }
    class useFetchTenantInfo {
        +data: ITenantInfo
        +loading: boolean
    }
    class useSaveSetting {
        +saveSetting(userInfo)
        +loading: boolean
    }
    class useFetchSystemVersion {
        +fetchSystemVersion()
        +version: string
        +loading: boolean
    }
    class useFetchSystemStatus {
        +fetchSystemStatus()
        +systemStatus: ISystemStatus
        +loading: boolean
    }
    class useFetchSystemTokenList {
        +data: IToken[]
        +loading: boolean
        +refetch()
    }
    class useRemoveSystemToken {
        +removeToken(token)
        +loading: boolean
    }
    class useCreateSystemToken {
        +createToken(params)
        +loading: boolean
    }
    class useListTenantUser {
        +data: ITenantUser[]
        +loading: boolean
        +refetch()
    }
    class useAddTenantUser {
        +addTenantUser(email)
        +loading: boolean
    }
    class useDeleteTenantUser {
        +deleteTenantUser(params)
        +loading: boolean
    }
    class useListTenant {
        +data: ITenant[]
        +loading: boolean
        +refetch()
    }
    class useAgreeTenant {
        +agreeTenant(tenantId)
        +loading: boolean
    }
    class useSetLangfuseConfig {
        +setLangfuseConfig(params)
        +loading: boolean
    }
    class useDeleteLangfuseConfig {
        +deleteLangfuseConfig()
        +loading: boolean
    }
    class useFetchLangfuseConfig {
        +data: ILangfuseConfig
        +loading: boolean
    }

    useSaveSetting ..> useFetchUserInfo : invalidates
    useRemoveSystemToken ..> useFetchSystemTokenList : invalidates
    useCreateSystemToken ..> useFetchSystemTokenList : invalidates
    useAddTenantUser ..> useListTenantUser : invalidates
    useDeleteTenantUser ..> useListTenantUser : invalidates
    useDeleteTenantUser ..> useListTenant : invalidates
    useAgreeTenant ..> useListTenant : invalidates
    useListTenantUser --> useFetchTenantInfo : depends on tenantId
    useAddTenantUser --> useFetchTenantInfo : depends on tenantId
    useDeleteTenantUser --> useFetchTenantInfo : depends on tenantId
    useListTenant --> useFetchTenantInfo : depends on tenantId

Summary

use-user-setting-request.tsx is a critical integration layer that abstracts and manages all data operations and mutations related to user settings, tenant management, system tokens, and Langfuse configuration. It provides a clean, reactive interface for components to interact with backend APIs while ensuring data consistency, feedback, and user experience through internationalization and UI messaging.

This modular design promotes separation of concerns, reusability, and maintainability in a complex multi-tenant user management system.