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:
@@ -36,9 +36,9 @@ import { z } from "zod";
|
||||
|
||||
import type { CompliancePageReferenceListItemFragment$data } from "#/__generated__/core/CompliancePageReferenceListItemFragment.graphql";
|
||||
import {
|
||||
useCreateTrustCenterReferenceMutation,
|
||||
useUpdateTrustCenterReferenceMutation,
|
||||
} from "#/hooks/graph/TrustCenterReferenceGraph";
|
||||
useCreateCompliancePageReferenceMutation,
|
||||
useUpdateCompliancePageReferenceMutation,
|
||||
} from "#/hooks/graph/CompliancePageReferenceGraph";
|
||||
import { useFormWithSchema } from "#/hooks/useFormWithSchema";
|
||||
|
||||
const referenceSchema = z.object({
|
||||
@@ -50,23 +50,23 @@ const referenceSchema = z.object({
|
||||
|
||||
type ReferenceFormData = z.infer<typeof referenceSchema>;
|
||||
|
||||
export type TrustCenterReferenceDialogRef = {
|
||||
openCreate: (trustCenterId: string, connectionId: string) => void;
|
||||
export type CompliancePageReferenceDialogRef = {
|
||||
openCreate: (compliancePageId: string, connectionId: string) => void;
|
||||
openEdit: (reference: CompliancePageReferenceListItemFragment$data, rank: number) => void;
|
||||
};
|
||||
|
||||
export const TrustCenterReferenceDialog = forwardRef<TrustCenterReferenceDialogRef, { children?: ReactNode }>(
|
||||
function TrustCenterReferenceDialog({ children }, ref) {
|
||||
export const CompliancePageReferenceDialog = forwardRef<CompliancePageReferenceDialogRef, { children?: ReactNode }>(
|
||||
function CompliancePageReferenceDialog({ children }, ref) {
|
||||
const { __ } = useTranslate();
|
||||
const dialogRef = useDialogRef();
|
||||
const [mode, setMode] = useState<"create" | "edit">("create");
|
||||
const [trustCenterId, setTrustCenterId] = useState<string>("");
|
||||
const [compliancePageId, setCompliancePageId] = useState<string>("");
|
||||
const [connectionId, setConnectionId] = useState<string>("");
|
||||
const [editReference, setEditReference] = useState<CompliancePageReferenceListItemFragment$data | null>(null);
|
||||
const [uploadedFile, setUploadedFile] = useState<File | null>(null);
|
||||
|
||||
const [createReference, isCreating] = useCreateTrustCenterReferenceMutation();
|
||||
const [updateReference, isUpdating] = useUpdateTrustCenterReferenceMutation();
|
||||
const [createReference, isCreating] = useCreateCompliancePageReferenceMutation();
|
||||
const [updateReference, isUpdating] = useUpdateCompliancePageReferenceMutation();
|
||||
|
||||
const { register, handleSubmit, formState: { errors }, reset } = useFormWithSchema(
|
||||
referenceSchema,
|
||||
@@ -80,9 +80,9 @@ export const TrustCenterReferenceDialog = forwardRef<TrustCenterReferenceDialogR
|
||||
);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
openCreate: (tId: string, cId: string) => {
|
||||
openCreate: (pageId: string, cId: string) => {
|
||||
setMode("create");
|
||||
setTrustCenterId(tId);
|
||||
setCompliancePageId(pageId);
|
||||
setConnectionId(cId);
|
||||
setEditReference(null);
|
||||
setUploadedFile(null);
|
||||
@@ -123,7 +123,7 @@ export const TrustCenterReferenceDialog = forwardRef<TrustCenterReferenceDialogR
|
||||
await createReference({
|
||||
variables: {
|
||||
input: {
|
||||
trustCenterId,
|
||||
trustCenterId: compliancePageId,
|
||||
name: data.name,
|
||||
description: data.description || null,
|
||||
websiteUrl: data.websiteUrl,
|
||||
@@ -134,12 +134,11 @@ export const TrustCenterReferenceDialog = forwardRef<TrustCenterReferenceDialogR
|
||||
uploadables: {
|
||||
"input.logoFile": uploadedFile,
|
||||
},
|
||||
onSuccess: () => {
|
||||
reset();
|
||||
setUploadedFile(null);
|
||||
dialogRef.current?.close();
|
||||
},
|
||||
});
|
||||
|
||||
reset();
|
||||
setUploadedFile(null);
|
||||
dialogRef.current?.close();
|
||||
} else if (editReference) {
|
||||
const input: {
|
||||
id: string;
|
||||
@@ -169,12 +168,11 @@ export const TrustCenterReferenceDialog = forwardRef<TrustCenterReferenceDialogR
|
||||
await updateReference({
|
||||
variables: { input },
|
||||
uploadables: Object.keys(uploadables).length > 0 ? uploadables : undefined,
|
||||
onSuccess: () => {
|
||||
reset();
|
||||
setUploadedFile(null);
|
||||
dialogRef.current?.close();
|
||||
},
|
||||
});
|
||||
|
||||
reset();
|
||||
setUploadedFile(null);
|
||||
dialogRef.current?.close();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -30,8 +30,9 @@ import {
|
||||
useDialogRef,
|
||||
} from "@probo/ui";
|
||||
|
||||
import { deleteTrustCenterReferenceMutation } from "#/hooks/graph/TrustCenterReferenceGraph";
|
||||
import { useMutationWithToasts } from "#/hooks/useMutationWithToasts";
|
||||
import type { CompliancePageReferenceGraphDeleteMutation } from "#/__generated__/core/CompliancePageReferenceGraphDeleteMutation.graphql";
|
||||
import { deleteCompliancePageReferenceMutation } from "#/hooks/graph/CompliancePageReferenceGraph";
|
||||
import { useMutation } from "#/lib/relay/useMutation";
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode;
|
||||
@@ -41,7 +42,7 @@ type Props = {
|
||||
onSuccess?: () => void;
|
||||
};
|
||||
|
||||
export function DeleteTrustCenterReferenceDialog({
|
||||
export function DeleteCompliancePageReferenceDialog({
|
||||
children,
|
||||
referenceId,
|
||||
referenceName,
|
||||
@@ -51,10 +52,13 @@ export function DeleteTrustCenterReferenceDialog({
|
||||
const { __ } = useTranslate();
|
||||
const ref = useDialogRef();
|
||||
|
||||
const [mutate, isDeleting] = useMutationWithToasts(deleteTrustCenterReferenceMutation, {
|
||||
successMessage: __("Reference deleted successfully"),
|
||||
errorMessage: __("Failed to delete reference"),
|
||||
});
|
||||
const [mutate, isDeleting] = useMutation<CompliancePageReferenceGraphDeleteMutation>(
|
||||
deleteCompliancePageReferenceMutation,
|
||||
{
|
||||
successMessage: __("Reference deleted successfully"),
|
||||
errorToast: __("Failed to delete reference"),
|
||||
},
|
||||
);
|
||||
|
||||
const handleDelete = async () => {
|
||||
await mutate({
|
||||
Reference in New Issue
Block a user