From 19ae57f0199ac1dc5cb66d96f5891284afb4d4ae Mon Sep 17 00:00:00 2001 From: hexastack Date: Mon, 17 Feb 2025 19:27:40 +0100 Subject: [PATCH] feat: replace mutateasync with mutate --- .../app-components/attachment/AttachmentUploader.tsx | 2 +- frontend/src/app-components/auth/Login.tsx | 11 ++++++----- .../src/components/context-vars/ContextVarForm.tsx | 4 ++-- frontend/src/components/inbox/components/Chat.tsx | 2 +- frontend/src/components/languages/index.tsx | 7 ++++--- frontend/src/components/nlp/components/NlpSample.tsx | 6 +++--- frontend/src/components/nlp/index.tsx | 2 +- frontend/src/components/profile/profile.tsx | 4 ++-- frontend/src/components/settings/index.tsx | 5 +++-- .../src/components/visual-editor/BlockEditForm.tsx | 4 ++-- .../visual-editor/hooks/useVisualEditor.tsx | 9 +++++---- frontend/src/types/visual-editor.types.ts | 9 +++++---- 12 files changed, 35 insertions(+), 30 deletions(-) diff --git a/frontend/src/app-components/attachment/AttachmentUploader.tsx b/frontend/src/app-components/attachment/AttachmentUploader.tsx index b50cc21d..da373ff2 100644 --- a/frontend/src/app-components/attachment/AttachmentUploader.tsx +++ b/frontend/src/app-components/attachment/AttachmentUploader.tsx @@ -84,7 +84,7 @@ const AttachmentUploader: FC = ({ const dialogs = useDialogs(); const [isDragOver, setIsDragOver] = useState(false); const { toast } = useToast(); - const { mutateAsync: uploadAttachment } = useUpload(EntityType.ATTACHMENT, { + const { mutate: uploadAttachment } = useUpload(EntityType.ATTACHMENT, { onError: () => { toast.error(t("message.upload_failed")); }, diff --git a/frontend/src/app-components/auth/Login.tsx b/frontend/src/app-components/auth/Login.tsx index 78bbd138..f4760d35 100755 --- a/frontend/src/app-components/auth/Login.tsx +++ b/frontend/src/app-components/auth/Login.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import EmailIcon from "@mui/icons-material/Email"; import KeyIcon from "@mui/icons-material/Key"; import KeyboardArrowRightIcon from "@mui/icons-material/KeyboardArrowRight"; @@ -38,7 +39,7 @@ export const Login = () => { const { toast } = useToast(); const router = useRouter(); const { authenticate } = useAuth(); - const { mutateAsync: login, isLoading } = useLogin({ + const { mutate: login, isLoading } = useLogin({ onSuccess: (data) => { if (data.state) authenticate(data); else { @@ -49,7 +50,7 @@ export const Login = () => { toast.error(t("message.login_failure")); }, }); - const { mutateAsync: confirmAccount } = useConfirmAccount({ + const { mutate: confirmAccount } = useConfirmAccount({ onSuccess: () => { toast.success(t("message.reset_confirm_success")); }, @@ -76,8 +77,8 @@ export const Login = () => { required: t("message.password_is_required"), }, }; - const onSubmitForm = async (data: ILoginAttributes) => { - await login(data); + const onSubmitForm = (data: ILoginAttributes) => { + login(data); }; useEffect(() => { diff --git a/frontend/src/components/context-vars/ContextVarForm.tsx b/frontend/src/components/context-vars/ContextVarForm.tsx index f42bac64..8a31e945 100644 --- a/frontend/src/components/context-vars/ContextVarForm.tsx +++ b/frontend/src/components/context-vars/ContextVarForm.tsx @@ -39,11 +39,11 @@ export const ContextVarForm: FC> = ({ toast.success(t("message.success_save")); }, }; - const { mutateAsync: createContextVar } = useCreate( + const { mutate: createContextVar } = useCreate( EntityType.CONTEXT_VAR, options, ); - const { mutateAsync: updateContextVar } = useUpdate( + const { mutate: updateContextVar } = useUpdate( EntityType.CONTEXT_VAR, options, ); diff --git a/frontend/src/components/inbox/components/Chat.tsx b/frontend/src/components/inbox/components/Chat.tsx index edcf7611..b6c50f22 100644 --- a/frontend/src/components/inbox/components/Chat.tsx +++ b/frontend/src/components/inbox/components/Chat.tsx @@ -39,7 +39,7 @@ export function Chat() { const { t, i18n } = useTranslate(); const { subscriber } = useChat(); const { user } = useAuth(); - const { mutateAsync: createMessage } = useCreate(EntityType.MESSAGE); + const { mutate: createMessage } = useCreate(EntityType.MESSAGE); const { replyTo, messages, fetchNextPage, hasNextPage, isFetching } = useInfinitedLiveMessages(); diff --git a/frontend/src/components/languages/index.tsx b/frontend/src/components/languages/index.tsx index 1d914634..f9028f3c 100644 --- a/frontend/src/components/languages/index.tsx +++ b/frontend/src/components/languages/index.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { Flag } from "@mui/icons-material"; import AddIcon from "@mui/icons-material/Add"; import { Button, Grid, Paper, Switch } from "@mui/material"; @@ -52,7 +53,7 @@ export const Languages = () => { params: searchPayload, }, ); - const { mutateAsync: updateLanguage } = useUpdate(EntityType.LANGUAGE, { + const { mutate: updateLanguage } = useUpdate(EntityType.LANGUAGE, { onError: () => { toast.error(t("message.internal_server_error")); }, @@ -61,7 +62,7 @@ export const Languages = () => { toast.success(t("message.success_save")); }, }); - const { mutateAsync: deleteLanguage } = useDelete(EntityType.LANGUAGE, { + const { mutate: deleteLanguage } = useDelete(EntityType.LANGUAGE, { onError: () => { toast.error(t("message.internal_server_error")); }, diff --git a/frontend/src/components/nlp/components/NlpSample.tsx b/frontend/src/components/nlp/components/NlpSample.tsx index da28d1a3..ce409cbd 100644 --- a/frontend/src/components/nlp/components/NlpSample.tsx +++ b/frontend/src/components/nlp/components/NlpSample.tsx @@ -110,7 +110,7 @@ export default function NlpSample() { toast.success(t("message.item_delete_success")); }, }); - const { mutateAsync: importDataset, isLoading } = useImport( + const { mutate: importDataset, isLoading } = useImport( EntityType.NLP_SAMPLE, { onError: () => { @@ -297,8 +297,8 @@ export default function NlpSample() { const handleSelectionChange = (selection: GridRowSelectionModel) => { setSelectedNlpSamples(selection as string[]); }; - const handleImportChange = async (file: File) => { - await importDataset(file); + const handleImportChange = (file: File) => { + importDataset(file); }; return ( diff --git a/frontend/src/components/nlp/index.tsx b/frontend/src/components/nlp/index.tsx index fbf4b5fe..a53ab4c7 100644 --- a/frontend/src/components/nlp/index.tsx +++ b/frontend/src/components/nlp/index.tsx @@ -62,7 +62,7 @@ export const Nlp = ({ }; const { t } = useTranslate(); const { toast } = useToast(); - const { mutateAsync: createSample } = useCreate< + const { mutate: createSample } = useCreate< EntityType.NLP_SAMPLE, INlpDatasetSampleAttributes, INlpSample, diff --git a/frontend/src/components/profile/profile.tsx b/frontend/src/components/profile/profile.tsx index 5967ef12..8dabf41d 100644 --- a/frontend/src/components/profile/profile.tsx +++ b/frontend/src/components/profile/profile.tsx @@ -34,7 +34,7 @@ export const ProfileForm: FC = ({ user }) => { const { t } = useTranslate(); const queryClient = useQueryClient(); const { toast } = useToast(); - const { mutateAsync: updateProfile, isLoading } = useUpdateProfile({ + const { mutate: updateProfile, isLoading } = useUpdateProfile({ onError: () => { toast.error(t("message.internal_server_error")); }, @@ -84,7 +84,7 @@ export const ProfileForm: FC = ({ user }) => { password2: _password2, ...rest }: IProfileAttributes) => { - await updateProfile({ + updateProfile({ ...rest, password: password || undefined, }); diff --git a/frontend/src/components/settings/index.tsx b/frontend/src/components/settings/index.tsx index ece950b2..e6a54a3a 100644 --- a/frontend/src/components/settings/index.tsx +++ b/frontend/src/components/settings/index.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { faCogs } from "@fortawesome/free-solid-svg-icons"; import { debounce, @@ -85,7 +86,7 @@ export const Settings = () => { initialSortState: [{ field: "weight", sort: "asc" }], }, ); - const { mutateAsync: updateSetting } = useUpdate(EntityType.SETTING, { + const { mutate: updateSetting } = useUpdate(EntityType.SETTING, { onError: () => { toast.error(t("message.internal_server_error")); }, diff --git a/frontend/src/components/visual-editor/BlockEditForm.tsx b/frontend/src/components/visual-editor/BlockEditForm.tsx index 3d657e31..9630288b 100644 --- a/frontend/src/components/visual-editor/BlockEditForm.tsx +++ b/frontend/src/components/visual-editor/BlockEditForm.tsx @@ -46,7 +46,7 @@ export const BlockEditForm: FC> = ({ setSelectedTab(newValue); }; const { toast } = useToast(); - const { mutateAsync: updateBlock } = useUpdate(EntityType.BLOCK, { + const { mutate: updateBlock } = useUpdate(EntityType.BLOCK, { onError: () => { rest.onError?.(); toast.error(t("message.internal_server_error")); @@ -94,7 +94,7 @@ export const BlockEditForm: FC> = ({ required: t("message.name_is_required"), }, }; - const onSubmitForm = async (params: IBlockAttributes) => { + const onSubmitForm = (params: IBlockAttributes) => { if (block) { updateBlock({ id: block.id, params }); } diff --git a/frontend/src/components/visual-editor/hooks/useVisualEditor.tsx b/frontend/src/components/visual-editor/hooks/useVisualEditor.tsx index f9ed3488..fcf93709 100644 --- a/frontend/src/components/visual-editor/hooks/useVisualEditor.tsx +++ b/frontend/src/components/visual-editor/hooks/useVisualEditor.tsx @@ -1,11 +1,12 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { debounce } from "@mui/material"; import createEngine, { DiagramModel } from "@projectstorm/react-diagrams"; import * as React from "react"; @@ -252,12 +253,12 @@ const VisualEditorProvider: React.FC = ({ children, }) => { const [selectedCategoryId, setSelectedCategoryId] = React.useState(""); - const { mutateAsync: createBlock } = useCreate(EntityType.BLOCK); - const createNode = async (payload: any) => { + const { mutate: createBlock } = useCreate(EntityType.BLOCK); + const createNode = (payload: any) => { payload.position = payload.position || getCentroid(); payload.category = payload.category || selectedCategoryId; - return await createBlock(payload, { + return createBlock(payload, { onSuccess({ id }) { addNode({ ...payload, diff --git a/frontend/src/types/visual-editor.types.ts b/frontend/src/types/visual-editor.types.ts index 31dcb433..8d9ce51d 100644 --- a/frontend/src/types/visual-editor.types.ts +++ b/frontend/src/types/visual-editor.types.ts @@ -1,16 +1,17 @@ /* - * Copyright © 2024 Hexastack. All rights reserved. + * Copyright © 2025 Hexastack. All rights reserved. * * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ + import { - NodeModel, - DiagramModel, DiagramEngine, + DiagramModel, DiagramModelGenerics, + NodeModel, } from "@projectstorm/react-diagrams"; import { ReactNode } from "react"; @@ -38,7 +39,7 @@ export interface IVisualEditor { } export interface IVisualEditorContext { addNode: (payload: any) => NodeModel; - createNode: (payload: any) => Promise; + createNode; buildDiagram: (props: IVisualEditor) => { model: DiagramModel; engine: DiagramEngine;