Plug trust center part 1

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-09 19:14:17 +01:00
committed by Bryan Frimin
parent 663400c4f6
commit 7322201dab
41 changed files with 1959 additions and 1033 deletions

View File

@@ -1,11 +1,11 @@
import { useTranslate } from "@probo/i18n";
import { Button, Card, IconBlock, IconLock, IconMedal } from "@probo/ui";
import type { TrustGraphQuery$data } from "/queries/__generated__/TrustGraphQuery.graphql";
import type { PropsWithChildren } from "react";
import { use, type PropsWithChildren } from "react";
import { domain } from "@probo/helpers";
import { AuditRowAvatar } from "./AuditRow";
import { RequestAccessDialog } from "./RequestAccessDialog";
import { useIsAuthenticated } from "/hooks/useIsAuthenticated";
import { Viewer } from "/providers/Viewer";
export function OrganizationSidebar({
trustCenter,
@@ -13,7 +13,7 @@ export function OrganizationSidebar({
trustCenter: TrustGraphQuery$data["trustCenterBySlug"];
}) {
const { __ } = useTranslate();
const isAuthenticated = useIsAuthenticated();
const isAuthenticated = !!use(Viewer);
if (!trustCenter) {
return null;

View File

@@ -15,9 +15,9 @@ import { useFormWithSchema } from "/hooks/useFormWithSchema";
import { graphql } from "relay-runtime";
import { useMutationWithToasts } from "/hooks/useMutationWithToast";
import { useTrustCenter } from "/hooks/useTrustCenter";
import { type FormEventHandler, type PropsWithChildren } from "react";
import { useIsAuthenticated } from "/hooks/useIsAuthenticated.ts";
import { use, type FormEventHandler, type PropsWithChildren } from "react";
import { InvalidError } from "/providers/RelayProviders";
import { Viewer } from "/providers/Viewer";
type Props = PropsWithChildren<{
documentId?: string;
@@ -27,7 +27,7 @@ type Props = PropsWithChildren<{
}>;
const schema = z.object({
name: z.string(),
fullName: z.string(),
email: z.string().email(),
});
@@ -41,18 +41,28 @@ export function RequestAccessDialog({
const trustCenter = useTrustCenter();
const { toast } = useToast();
const { __ } = useTranslate();
const { handleSubmit, register, setError, formState } = useFormWithSchema(schema, {
defaultValues: {
name: "",
email: "",
const viewer = use(Viewer);
const { handleSubmit, register, setError, formState } = useFormWithSchema(
schema,
{
defaultValues: {
fullName: "",
email: "",
},
},
});
const isAuthenticated = useIsAuthenticated();
);
const dialogRef = useDialogRef();
const [commitMutation, isMutating] = useMutation({ documentId, reportId, trustCenterFileId });
const [commitMutation, isMutating] = useMutation({
documentId,
reportId,
trustCenterFileId,
});
const submitCallback = (data: z.infer<typeof schema> | null) => {
commitMutation(data)
commitMutation({
email: data?.email ?? viewer?.email ?? "",
fullName: data?.fullName ?? viewer?.fullName ?? "",
})
.then(() => {
onSuccess?.();
toast({
@@ -65,7 +75,7 @@ export function RequestAccessDialog({
.catch((error) => {
if (error instanceof InvalidError) {
if (error.field === "email") {
setError(error.field, {message: error.message})
setError(error.field, { message: error.message });
}
return;
}
@@ -77,7 +87,7 @@ export function RequestAccessDialog({
});
};
const onSubmit: FormEventHandler<HTMLFormElement> = isAuthenticated
const onSubmit: FormEventHandler<HTMLFormElement> = viewer
? (e) => {
e.preventDefault();
submitCallback(null);
@@ -102,12 +112,12 @@ export function RequestAccessDialog({
trustCenter.organization.name,
)}
</p>
{!isAuthenticated && (
{!viewer && (
<div className="space-y-4">
<Field
label={__("Full name")}
placeholder="John Doe"
{...register("name")}
{...register("fullName")}
type="text"
/>
<Field
@@ -195,8 +205,10 @@ function useMutation({
useMutationWithToasts(requestDocumentAccessMutation);
const [commitRequestReportAccess, isRequestingReportAccess] =
useMutationWithToasts(requestReportAccessMutation);
const [commitRequestTrustCenterFileAccess, isRequestingTrustCenterFileAccess] =
useMutationWithToasts(requestTrustCenterFileAccessMutation);
const [
commitRequestTrustCenterFileAccess,
isRequestingTrustCenterFileAccess,
] = useMutationWithToasts(requestTrustCenterFileAccessMutation);
if (trustCenterFileId) {
return [

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<5344ac5d6a506485d45e399361b92299>>
* @generated SignedSource<<5113feef2c7f7b13a2d6348202086916>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -11,8 +11,8 @@
import { ConcreteRequest } from 'relay-runtime';
export type RequestDocumentAccessInput = {
documentId: string;
email?: any | null | undefined;
name?: string | null | undefined;
email: any;
fullName: string;
trustCenterId: string;
};
export type RequestAccessDialogDocumentMutation$variables = {

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<19ada29ea9b8f557b4fcc39f57bc3aec>>
* @generated SignedSource<<294b6a25a178cf3bd9269591ef61381f>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -10,8 +10,8 @@
import { ConcreteRequest } from 'relay-runtime';
export type RequestAllAccessesInput = {
email?: any | null | undefined;
name?: string | null | undefined;
email: any;
fullName: string;
trustCenterId: string;
};
export type RequestAccessDialogMutation$variables = {

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<858effd78b88a123430edcf6fcb100ed>>
* @generated SignedSource<<d3209530c326da3c7db6535cef428ded>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -10,8 +10,8 @@
import { ConcreteRequest } from 'relay-runtime';
export type RequestReportAccessInput = {
email?: any | null | undefined;
name?: string | null | undefined;
email: any;
fullName: string;
reportId: string;
trustCenterId: string;
};

View File

@@ -1,5 +1,5 @@
/**
* @generated SignedSource<<32242c5e0b4dc9c9368c0e2f4034d95e>>
* @generated SignedSource<<1e744bd11b2d5dd4d982bf1ce8b2a721>>
* @lightSyntaxTransform
* @nogrep
*/
@@ -10,8 +10,8 @@
import { ConcreteRequest } from 'relay-runtime';
export type RequestTrustCenterFileAccessInput = {
email?: any | null | undefined;
name?: string | null | undefined;
email: any;
fullName: string;
trustCenterFileId: string;
trustCenterId: string;
};