Add trust center files
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import { useIsAuthenticated } from "/hooks/useIsAuthenticated.ts";
|
||||
type Props = PropsWithChildren<{
|
||||
documentId?: string;
|
||||
reportId?: string;
|
||||
trustCenterFileId?: string;
|
||||
onSuccess?: () => void;
|
||||
}>;
|
||||
|
||||
@@ -33,6 +34,7 @@ export function RequestAccessDialog({
|
||||
children,
|
||||
documentId,
|
||||
reportId,
|
||||
trustCenterFileId,
|
||||
onSuccess,
|
||||
}: Props) {
|
||||
const trustCenter = useTrustCenter();
|
||||
@@ -46,7 +48,7 @@ export function RequestAccessDialog({
|
||||
});
|
||||
const isAuthenticated = useIsAuthenticated();
|
||||
const dialogRef = useDialogRef();
|
||||
const [commitMutation, isMutating] = useMutation({ documentId, reportId });
|
||||
const [commitMutation, isMutating] = useMutation({ documentId, reportId, trustCenterFileId });
|
||||
|
||||
const submitCallback = (data: z.infer<typeof schema> | null) => {
|
||||
commitMutation(data)
|
||||
@@ -155,13 +157,26 @@ const requestReportAccessMutation = graphql`
|
||||
}
|
||||
`;
|
||||
|
||||
const requestTrustCenterFileAccessMutation = graphql`
|
||||
mutation RequestAccessDialogTrustCenterFileMutation(
|
||||
$input: RequestTrustCenterFileAccessInput!
|
||||
) {
|
||||
requestTrustCenterFileAccess(input: $input) {
|
||||
trustCenterAccess {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* Use the correct mutation using the shape
|
||||
*/
|
||||
function useMutation({
|
||||
documentId,
|
||||
reportId,
|
||||
}: Pick<Props, "documentId" | "reportId">): [
|
||||
trustCenterFileId,
|
||||
}: Pick<Props, "documentId" | "reportId" | "trustCenterFileId">): [
|
||||
(data: z.infer<typeof schema> | null) => Promise<unknown>,
|
||||
boolean,
|
||||
] {
|
||||
@@ -173,8 +188,25 @@ function useMutation({
|
||||
useMutationWithToasts(requestDocumentAccessMutation);
|
||||
const [commitRequestReportAccess, isRequestingReportAccess] =
|
||||
useMutationWithToasts(requestReportAccessMutation);
|
||||
const [commitRequestTrustCenterFileAccess, isRequestingTrustCenterFileAccess] =
|
||||
useMutationWithToasts(requestTrustCenterFileAccessMutation);
|
||||
|
||||
if (reportId) {
|
||||
if (trustCenterFileId) {
|
||||
return [
|
||||
(data) => {
|
||||
return commitRequestTrustCenterFileAccess({
|
||||
variables: {
|
||||
input: {
|
||||
trustCenterId: trustCenter.id,
|
||||
trustCenterFileId: trustCenterFileId,
|
||||
...data,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
isRequestingTrustCenterFileAccess,
|
||||
];
|
||||
} else if (reportId) {
|
||||
return [
|
||||
(data) => {
|
||||
return commitRequestReportAccess({
|
||||
|
||||
88
apps/trust/src/components/TrustCenterFileRow.tsx
Normal file
88
apps/trust/src/components/TrustCenterFileRow.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import { graphql } from "relay-runtime";
|
||||
import type { TrustCenterFileRowFragment$key } from "./__generated__/TrustCenterFileRowFragment.graphql";
|
||||
import { useFragment } from "react-relay";
|
||||
import {
|
||||
Button,
|
||||
IconArrowInbox,
|
||||
IconLock,
|
||||
IconPageTextLine,
|
||||
Spinner,
|
||||
} from "@probo/ui";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import type { TrustCenterFileRowDownloadMutation } from "./__generated__/TrustCenterFileRowDownloadMutation.graphql";
|
||||
import { useMutationWithToasts } from "/hooks/useMutationWithToast";
|
||||
import { downloadFile } from "@probo/helpers";
|
||||
import { RequestAccessDialog } from "/components/RequestAccessDialog.tsx";
|
||||
import { useState } from "react";
|
||||
|
||||
const downloadMutation = graphql`
|
||||
mutation TrustCenterFileRowDownloadMutation($input: ExportTrustCenterFileInput!) {
|
||||
exportTrustCenterFile(input: $input) {
|
||||
data
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const trustCenterFileRowFragment = graphql`
|
||||
fragment TrustCenterFileRowFragment on TrustCenterFile {
|
||||
id
|
||||
name
|
||||
isUserAuthorized
|
||||
hasUserRequestedAccess
|
||||
}
|
||||
`;
|
||||
|
||||
export function TrustCenterFileRow(props: { file: TrustCenterFileRowFragment$key }) {
|
||||
const file = useFragment(trustCenterFileRowFragment, props.file);
|
||||
const { __ } = useTranslate();
|
||||
const [commitDownload, downloading] =
|
||||
useMutationWithToasts<TrustCenterFileRowDownloadMutation>(downloadMutation);
|
||||
const handleDownload = () => {
|
||||
commitDownload({
|
||||
variables: {
|
||||
input: {
|
||||
trustCenterFileId: file.id,
|
||||
},
|
||||
},
|
||||
onSuccess(response) {
|
||||
downloadFile(response.exportTrustCenterFile.data, file.name);
|
||||
},
|
||||
});
|
||||
};
|
||||
const [hasRequested, setHasRequested] = useState(
|
||||
file.hasUserRequestedAccess,
|
||||
);
|
||||
return (
|
||||
<div className="text-sm border-1 border-border-solid -mt-[1px] flex gap-3 flex-col md:flex-row md:justify-between px-6 py-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<IconPageTextLine size={16} className=" flex-none text-txt-tertiary" />
|
||||
{file.name}
|
||||
</div>
|
||||
{file.isUserAuthorized ? (
|
||||
<Button
|
||||
className="w-full md:w-max"
|
||||
variant="secondary"
|
||||
disabled={downloading}
|
||||
icon={downloading ? Spinner : IconArrowInbox}
|
||||
onClick={handleDownload}
|
||||
>
|
||||
{__("Download")}
|
||||
</Button>
|
||||
) : (
|
||||
<RequestAccessDialog
|
||||
trustCenterFileId={file.id}
|
||||
onSuccess={() => setHasRequested(true)}
|
||||
>
|
||||
<Button
|
||||
disabled={hasRequested}
|
||||
className="w-full md:w-max"
|
||||
variant="secondary"
|
||||
icon={IconLock}
|
||||
>
|
||||
{hasRequested ? __("Access requested") : __("Request access")}
|
||||
</Button>
|
||||
</RequestAccessDialog>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
108
apps/trust/src/components/__generated__/RequestAccessDialogTrustCenterFileMutation.graphql.ts
generated
Normal file
108
apps/trust/src/components/__generated__/RequestAccessDialogTrustCenterFileMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* @generated SignedSource<<4c07d5c8e345a8e3015f512403927890>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type RequestTrustCenterFileAccessInput = {
|
||||
email?: string | null | undefined;
|
||||
name?: string | null | undefined;
|
||||
trustCenterFileId: string;
|
||||
trustCenterId: string;
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation$variables = {
|
||||
input: RequestTrustCenterFileAccessInput;
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation$data = {
|
||||
readonly requestTrustCenterFileAccess: {
|
||||
readonly trustCenterAccess: {
|
||||
readonly id: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
export type RequestAccessDialogTrustCenterFileMutation = {
|
||||
response: RequestAccessDialogTrustCenterFileMutation$data;
|
||||
variables: RequestAccessDialogTrustCenterFileMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "RequestAccessesPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "requestTrustCenterFileAccess",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "TrustCenterAccess",
|
||||
"kind": "LinkedField",
|
||||
"name": "trustCenterAccess",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "73b3007ef1a45f6dc6d31be0c627e482",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "RequestAccessDialogTrustCenterFileMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation RequestAccessDialogTrustCenterFileMutation(\n $input: RequestTrustCenterFileAccessInput!\n) {\n requestTrustCenterFileAccess(input: $input) {\n trustCenterAccess {\n id\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "a97eb6c4ec94c79a293d1cc51bf18e66";
|
||||
|
||||
export default node;
|
||||
92
apps/trust/src/components/__generated__/TrustCenterFileRowDownloadMutation.graphql.ts
generated
Normal file
92
apps/trust/src/components/__generated__/TrustCenterFileRowDownloadMutation.graphql.ts
generated
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* @generated SignedSource<<8d608da0bcff489887f71f6e69f1bfe3>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from 'relay-runtime';
|
||||
export type ExportTrustCenterFileInput = {
|
||||
trustCenterFileId: string;
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation$variables = {
|
||||
input: ExportTrustCenterFileInput;
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation$data = {
|
||||
readonly exportTrustCenterFile: {
|
||||
readonly data: string;
|
||||
};
|
||||
};
|
||||
export type TrustCenterFileRowDownloadMutation = {
|
||||
response: TrustCenterFileRowDownloadMutation$data;
|
||||
variables: TrustCenterFileRowDownloadMutation$variables;
|
||||
};
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = [
|
||||
{
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
v1 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "input",
|
||||
"variableName": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "ExportTrustCenterFilePayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "exportTrustCenterFile",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "data",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"selections": (v1/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": (v0/*: any*/),
|
||||
"kind": "Operation",
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"selections": (v1/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "8a97b9e7ac44deea6da6e79f1d0c662f",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterFileRowDownloadMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation TrustCenterFileRowDownloadMutation(\n $input: ExportTrustCenterFileInput!\n) {\n exportTrustCenterFile(input: $input) {\n data\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "e6d74e96e929cf1aa79711b8315a8b85";
|
||||
|
||||
export default node;
|
||||
66
apps/trust/src/components/__generated__/TrustCenterFileRowFragment.graphql.ts
generated
Normal file
66
apps/trust/src/components/__generated__/TrustCenterFileRowFragment.graphql.ts
generated
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @generated SignedSource<<0261adc72d21035b906b6156ea9d0b40>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ReaderFragment } from 'relay-runtime';
|
||||
import { FragmentRefs } from "relay-runtime";
|
||||
export type TrustCenterFileRowFragment$data = {
|
||||
readonly hasUserRequestedAccess: boolean;
|
||||
readonly id: string;
|
||||
readonly isUserAuthorized: boolean;
|
||||
readonly name: string;
|
||||
readonly " $fragmentType": "TrustCenterFileRowFragment";
|
||||
};
|
||||
export type TrustCenterFileRowFragment$key = {
|
||||
readonly " $data"?: TrustCenterFileRowFragment$data;
|
||||
readonly " $fragmentSpreads": FragmentRefs<"TrustCenterFileRowFragment">;
|
||||
};
|
||||
|
||||
const node: ReaderFragment = {
|
||||
"argumentDefinitions": [],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "TrustCenterFileRowFragment",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "isUserAuthorized",
|
||||
"storageKey": null
|
||||
},
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "hasUserRequestedAccess",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "TrustCenterFile",
|
||||
"abstractKey": null
|
||||
};
|
||||
|
||||
(node as any).hash = "4ff11c14e65566f0dfe3a77ea73903e8";
|
||||
|
||||
export default node;
|
||||
Reference in New Issue
Block a user