Replace deprecated useMutationWithToasts hook
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>
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
// PERFORMANCE OF THIS SOFTWARE.
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
import { sprintf } from "@probo/helpers";
|
import { formatError, type GraphQLError, sprintf } from "@probo/helpers";
|
||||||
import { useTranslate } from "@probo/i18n";
|
import { useTranslate } from "@probo/i18n";
|
||||||
import {
|
import {
|
||||||
Badge,
|
Badge,
|
||||||
@@ -25,14 +25,14 @@ import {
|
|||||||
IconSettingsGear2,
|
IconSettingsGear2,
|
||||||
Input,
|
Input,
|
||||||
useDialogRef,
|
useDialogRef,
|
||||||
|
useToast,
|
||||||
} from "@probo/ui";
|
} from "@probo/ui";
|
||||||
import { useState } from "react";
|
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 { GoogleWorkspaceConnectorDeleteMutation } from "#/__generated__/iam/GoogleWorkspaceConnectorDeleteMutation.graphql";
|
||||||
import type { GoogleWorkspaceConnectorFragment$key } from "#/__generated__/iam/GoogleWorkspaceConnectorFragment.graphql";
|
import type { GoogleWorkspaceConnectorFragment$key } from "#/__generated__/iam/GoogleWorkspaceConnectorFragment.graphql";
|
||||||
import type { GoogleWorkspaceConnectorUpdateSCIMBridgeMutation } from "#/__generated__/iam/GoogleWorkspaceConnectorUpdateSCIMBridgeMutation.graphql";
|
import type { GoogleWorkspaceConnectorUpdateSCIMBridgeMutation } from "#/__generated__/iam/GoogleWorkspaceConnectorUpdateSCIMBridgeMutation.graphql";
|
||||||
import { useMutationWithToasts } from "#/hooks/useMutationWithToasts";
|
|
||||||
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
import { useOrganizationId } from "#/hooks/useOrganizationId";
|
||||||
|
|
||||||
const googleWorkspaceConnectorFragment = graphql`
|
const googleWorkspaceConnectorFragment = graphql`
|
||||||
@@ -85,27 +85,20 @@ export function GoogleWorkspaceConnector(props: {
|
|||||||
|
|
||||||
const organizationId = useOrganizationId();
|
const organizationId = useOrganizationId();
|
||||||
const { __, dateTimeFormat } = useTranslate();
|
const { __, dateTimeFormat } = useTranslate();
|
||||||
|
const { toast } = useToast();
|
||||||
const dialogRef = useDialogRef();
|
const dialogRef = useDialogRef();
|
||||||
const excludedUserNamesDialogRef = useDialogRef();
|
const excludedUserNamesDialogRef = useDialogRef();
|
||||||
|
|
||||||
const [newUser, setNewUser] = useState("");
|
const [newUser, setNewUser] = useState("");
|
||||||
|
|
||||||
const [deleteSCIMConfiguration, isDeleting]
|
const [deleteSCIMConfiguration, isDeleting]
|
||||||
= useMutationWithToasts<GoogleWorkspaceConnectorDeleteMutation>(
|
= useMutation<GoogleWorkspaceConnectorDeleteMutation>(
|
||||||
deleteSCIMConfigurationMutation,
|
deleteSCIMConfigurationMutation,
|
||||||
{
|
|
||||||
successMessage: __("Google Workspace disconnected successfully"),
|
|
||||||
errorMessage: __("Failed to disconnect Google Workspace"),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const [updateSCIMBridge, isUpdating]
|
const [updateSCIMBridge, isUpdating]
|
||||||
= useMutationWithToasts<GoogleWorkspaceConnectorUpdateSCIMBridgeMutation>(
|
= useMutation<GoogleWorkspaceConnectorUpdateSCIMBridgeMutation>(
|
||||||
updateSCIMBridgeMutation,
|
updateSCIMBridgeMutation,
|
||||||
{
|
|
||||||
successMessage: __("Excluded user names updated successfully"),
|
|
||||||
errorMessage: __("Failed to update excluded user names"),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleConnect = () => {
|
const handleConnect = () => {
|
||||||
@@ -131,9 +124,35 @@ export function GoogleWorkspaceConnector(props: {
|
|||||||
scimConfigurationId: scimConfigurationId,
|
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();
|
dialogRef.current?.close();
|
||||||
},
|
},
|
||||||
|
onError(error) {
|
||||||
|
toast({
|
||||||
|
title: __("Error"),
|
||||||
|
description: formatError(
|
||||||
|
__("Failed to disconnect Google Workspace"),
|
||||||
|
error as GraphQLError,
|
||||||
|
),
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
},
|
||||||
updater: (store) => {
|
updater: (store) => {
|
||||||
const organizationRecord = store.get(organizationId);
|
const organizationRecord = store.get(organizationId);
|
||||||
if (organizationRecord) {
|
if (organizationRecord) {
|
||||||
@@ -156,6 +175,34 @@ export function GoogleWorkspaceConnector(props: {
|
|||||||
excludedUserNames: newList,
|
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",
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user