From a95e2f49c2ad5bec86e579b785bfe978961b9b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Sibiril?= <81782+aureliensibiril@users.noreply.github.com> Date: Fri, 10 Apr 2026 10:13:01 +0200 Subject: [PATCH] Replace deprecated useMutationWithToasts hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Switch to useMutation + useToast with onCompleted and onError callbacks, matching the pattern used across the rest of the console app. Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com> --- .../_components/GoogleWorkspaceConnector.tsx | 75 +++++++++++++++---- 1 file changed, 61 insertions(+), 14 deletions(-) diff --git a/apps/console/src/pages/iam/organizations/settings/_components/GoogleWorkspaceConnector.tsx b/apps/console/src/pages/iam/organizations/settings/_components/GoogleWorkspaceConnector.tsx index daf6ebf7d..d5945f545 100644 --- a/apps/console/src/pages/iam/organizations/settings/_components/GoogleWorkspaceConnector.tsx +++ b/apps/console/src/pages/iam/organizations/settings/_components/GoogleWorkspaceConnector.tsx @@ -12,7 +12,7 @@ // OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -import { sprintf } from "@probo/helpers"; +import { formatError, type GraphQLError, sprintf } from "@probo/helpers"; import { useTranslate } from "@probo/i18n"; import { Badge, @@ -25,14 +25,14 @@ import { IconSettingsGear2, Input, useDialogRef, + useToast, } from "@probo/ui"; import { useState } from "react"; -import { graphql, useFragment } from "react-relay"; +import { graphql, useFragment, useMutation } from "react-relay"; import type { GoogleWorkspaceConnectorDeleteMutation } from "#/__generated__/iam/GoogleWorkspaceConnectorDeleteMutation.graphql"; import type { GoogleWorkspaceConnectorFragment$key } from "#/__generated__/iam/GoogleWorkspaceConnectorFragment.graphql"; import type { GoogleWorkspaceConnectorUpdateSCIMBridgeMutation } from "#/__generated__/iam/GoogleWorkspaceConnectorUpdateSCIMBridgeMutation.graphql"; -import { useMutationWithToasts } from "#/hooks/useMutationWithToasts"; import { useOrganizationId } from "#/hooks/useOrganizationId"; const googleWorkspaceConnectorFragment = graphql` @@ -85,27 +85,20 @@ export function GoogleWorkspaceConnector(props: { const organizationId = useOrganizationId(); const { __, dateTimeFormat } = useTranslate(); + const { toast } = useToast(); const dialogRef = useDialogRef(); const excludedUserNamesDialogRef = useDialogRef(); const [newUser, setNewUser] = useState(""); const [deleteSCIMConfiguration, isDeleting] - = useMutationWithToasts( + = useMutation( deleteSCIMConfigurationMutation, - { - successMessage: __("Google Workspace disconnected successfully"), - errorMessage: __("Failed to disconnect Google Workspace"), - }, ); const [updateSCIMBridge, isUpdating] - = useMutationWithToasts( + = useMutation( updateSCIMBridgeMutation, - { - successMessage: __("Excluded user names updated successfully"), - errorMessage: __("Failed to update excluded user names"), - }, ); const handleConnect = () => { @@ -131,9 +124,35 @@ export function GoogleWorkspaceConnector(props: { scimConfigurationId: scimConfigurationId, }, }, - onCompleted: () => { + onCompleted(_, errors) { + if (errors?.length) { + toast({ + title: __("Error"), + description: formatError( + __("Failed to disconnect Google Workspace"), + errors as GraphQLError[], + ), + variant: "error", + }); + return; + } + toast({ + title: __("Success"), + description: __("Google Workspace disconnected successfully"), + variant: "success", + }); dialogRef.current?.close(); }, + onError(error) { + toast({ + title: __("Error"), + description: formatError( + __("Failed to disconnect Google Workspace"), + error as GraphQLError, + ), + variant: "error", + }); + }, updater: (store) => { const organizationRecord = store.get(organizationId); if (organizationRecord) { @@ -156,6 +175,34 @@ export function GoogleWorkspaceConnector(props: { excludedUserNames: newList, }, }, + onCompleted(_, errors) { + if (errors?.length) { + toast({ + title: __("Error"), + description: formatError( + __("Failed to update excluded user names"), + errors as GraphQLError[], + ), + variant: "error", + }); + return; + } + toast({ + title: __("Success"), + description: __("Excluded user names updated successfully"), + variant: "success", + }); + }, + onError(error) { + toast({ + title: __("Error"), + description: formatError( + __("Failed to update excluded user names"), + error as GraphQLError, + ), + variant: "error", + }); + }, }); };