Files
ColdBreeze-chat-web/src/hooks/useConfig.ts
T
Will Sheng c8199da34e 增加VoceSpace视频会议功能 (#275)
* vocespace video conf page

[feat]: get and update vocespace config

[feat]: get and update vocespace config

[feat]: vocespace setting box in home page

remove zip

send vocespace link

[feat]: vocespace license upgrade

* docs(readme): add Chinese readme and update package mananger to pnpm

* docs: Remove outdated contact information and completed feature requests (#272)

* feat: 增加passkey支持 (#270)

* chore: add .pnpm-store to .gitignore

* feat: implement passkey authentication and management features

- Added passkey login and registration endpoints to the auth service.
- Introduced PasskeyManagement component for user passkey management.
- Updated localization files to include passkey-related strings in English and Chinese.
- Created utility functions for handling passkey operations in WebAuthn.
- Adjusted login page to support passkey login flow.
- Modified configuration for local development server.

* feat: enhance passkey management with modal input and localization updates

- Added a modal for entering passkey names during registration in the PasskeyManagement component.
- Updated English and Chinese localization files to include new strings for passkey name input.
- Improved user experience by validating passkey name input before registration.

* feat: enhance passkey login experience with localization updates

- Added new localization strings for passkey authentication errors and status messages in English and Chinese.
- Updated the login page to utilize localized strings for improved user feedback during passkey login attempts.

* feat: add name field to UserPasskey interface for enhanced user identification

* feat: integrate passkey support across login and settings

- Added passkey option to login configuration and updated related components to conditionally render passkey login button.
- Enhanced MyAccount and Logins components to manage passkey settings and display passkey management options based on configuration.
- Updated English and Chinese localization files to include new strings for passkey functionality.

* feat: added server version check for passkey

* chore: update version to 0.9.30 in package.json

* chore: update version to 0.9.31 in package.json and add magic link authentication strings in English and Chinese

* i18n

[feat]: undeploy or vocespace.com

[fix]: theme fit for ui

[feat]: ip or alert

version v0.9.32

[fix]: use version compare for feat

[fix]: api hook inner useEffect

---------

Co-authored-by: haorwen <haorwen@qq.com>
2025-12-18 23:33:24 +08:00

154 lines
4.4 KiB
TypeScript

import { useEffect, useState } from "react";
import toast from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { isEqual } from "lodash";
import {
useGetAgoraConfigQuery,
useGetFirebaseConfigQuery,
useGetLoginConfigQuery,
useGetSMTPConfigQuery,
useGetVocespaceConfigQuery,
useUpdateAgoraConfigMutation,
useUpdateFirebaseConfigMutation,
useUpdateLoginConfigMutation,
useUpdateSMTPConfigMutation,
useUpdateVocespaceConfigMutation,
} from "@/app/services/server";
import {
AgoraConfig,
FirebaseConfig,
LoginConfig,
SMTPConfig,
VocespaceConfig,
} from "@/types/server";
// config: smtp agora login firebase
type ConfigType = "smtp" | "agora" | "login" | "firebase" | "vocespace";
type ConfigMap = Record<
ConfigType,
AgoraConfig | FirebaseConfig | LoginConfig | SMTPConfig | VocespaceConfig
>;
type valuesOf<T> = T[keyof T];
let originalValue: valuesOf<ConfigMap> | undefined = undefined;
// type valueOf<T,config as ConfigType> = T[config];
export default function useConfig(config: keyof ConfigMap = "smtp") {
const { t: ct } = useTranslation();
const [changed, setChanged] = useState(false);
const [values, setValues] = useState<valuesOf<ConfigMap> | undefined>(undefined);
const [updateLoginConfig, { isSuccess: LoginUpdated, isLoading: LoginUpdating }] =
useUpdateLoginConfigMutation();
const [updateSMTPConfig, { isSuccess: SMTPUpdated, isLoading: SMTPUpdating }] =
useUpdateSMTPConfigMutation();
const [updateAgoraConfig, { isSuccess: AgoraUpdated, isLoading: AgoraUpdating }] =
useUpdateAgoraConfigMutation();
const [updateVocespaceConfig, { isSuccess: VocespaceUpdated, isLoading: VocespaceUpdating }] =
useUpdateVocespaceConfigMutation();
const [updateFirebaseConfig, { isSuccess: FirebaseUpdated, isLoading: FirebaseUpdating }] =
useUpdateFirebaseConfigMutation();
const { refetch: getAgoraConfig, data: agoraConfig } = useGetAgoraConfigQuery(undefined, {
skip: config !== "agora",
});
const { refetch: getVocespaceConfig, data: vocespaceConfig } = useGetVocespaceConfigQuery(
undefined,
{
skip: config !== "vocespace",
}
);
const { refetch: getLoginConfig, data: loginConfig } = useGetLoginConfigQuery(undefined, {
skip: config !== "login",
});
const { refetch: getSMTPConfig, data: smtpConfig } = useGetSMTPConfigQuery(undefined, {
skip: config !== "smtp",
});
const { refetch: getFirebaseConfig, data: firebaseConfig } = useGetFirebaseConfigQuery(
undefined,
{
skip: config !== "firebase",
}
);
const updateFns = {
login: updateLoginConfig,
smtp: updateSMTPConfig,
agora: updateAgoraConfig,
firebase: updateFirebaseConfig,
vocespace: updateVocespaceConfig,
};
const requests = {
smtp: getSMTPConfig,
agora: getAgoraConfig,
firebase: getFirebaseConfig,
login: getLoginConfig,
vocespace: getVocespaceConfig,
};
const updates = {
login: LoginUpdated,
smtp: SMTPUpdated,
agora: AgoraUpdated,
firebase: FirebaseUpdated,
vocespace: VocespaceUpdated,
};
const updatings = {
login: LoginUpdating,
smtp: SMTPUpdating,
agora: AgoraUpdating,
firebase: FirebaseUpdating,
vocespace: VocespaceUpdating,
};
const updateConfig = updateFns[config];
const refetch = requests[config];
const updated = updates[config];
const updating = updatings[config];
const reset = () => {
setValues(undefined);
};
const toggleEnable = () => {
setValues((prev) => {
if (prev && "enabled" in prev) {
return { ...prev, enabled: !prev.enabled };
}
return prev;
});
};
useEffect(() => {
if (updated) {
toast.success(ct("tip.update"));
// setChanged(false);
refetch();
}
}, [updated]);
useEffect(() => {
const _config = smtpConfig || firebaseConfig || loginConfig || agoraConfig || vocespaceConfig;
if (_config) {
originalValue = _config;
setValues(_config);
}
}, [smtpConfig, firebaseConfig, loginConfig, agoraConfig, vocespaceConfig]);
useEffect(() => {
// 空对象
if (!values || Object.keys(values).length == 0) return;
if (!isEqual(originalValue, values)) {
setChanged(true);
} else {
setChanged(false);
}
}, [values]);
return {
originalValues: originalValue,
updating,
updated,
reset,
changed,
updateConfig,
agoraConfig,
values,
setValues,
toggleEnable,
refetch,
};
}