Add console useMutation and rename compliance graphs
Introduce the app-bound useMutation primitive and rename the trust center graph and reference hooks to compliance page, moving the shared reference dialogs alongside them. Sweep the compliance page subpages onto the new mutation hook and the compliance-portal permission strings, and strip the profile fields from the organization settings form. Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
53
apps/console/src/lib/relay/useMutation.ts
Normal file
53
apps/console/src/lib/relay/useMutation.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import { formatError } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { createUseMutation, type MutationNotifier } from "@probo/relay";
|
||||
import { useToast } from "@probo/ui";
|
||||
import { useMemo } from "react";
|
||||
|
||||
/**
|
||||
* Binds the shared awaitable useMutation (`@probo/relay`) to this app's
|
||||
* feedback stack: `@probo/ui` toasts, i18n titles, and `formatError`
|
||||
* descriptions. This is the only place those opinions are wired.
|
||||
*
|
||||
* Always import useMutation from `#/lib/relay/useMutation` — never useMutation
|
||||
* from react-relay.
|
||||
*/
|
||||
function useMutationNotifier(): MutationNotifier {
|
||||
const { toast } = useToast();
|
||||
const { __ } = useTranslate();
|
||||
|
||||
return useMemo<MutationNotifier>(
|
||||
() => ({
|
||||
notifySuccess: (title) => {
|
||||
toast({ title, description: "", variant: "success" });
|
||||
},
|
||||
notifyError: (error, title) => {
|
||||
const finalTitle = title ?? __("Error");
|
||||
toast({
|
||||
title: finalTitle,
|
||||
description: formatError(finalTitle, error),
|
||||
variant: "error",
|
||||
});
|
||||
},
|
||||
}),
|
||||
[toast, __],
|
||||
);
|
||||
}
|
||||
|
||||
export type { MutationFeedback } from "@probo/relay";
|
||||
|
||||
export const useMutation = createUseMutation(useMutationNotifier);
|
||||
Reference in New Issue
Block a user