Fix merge and handle display of unpersisted trusct center document access status
Signed-off-by: Émile Ré <nemile.re@gmail.com>
This commit is contained in:
@@ -110,6 +110,7 @@ export const loadTrustCenterAccessDocumentAccessesQuery = graphql`
|
||||
availableDocumentAccesses(first: 100, orderBy: { field: CREATED_AT, direction: DESC }) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
active
|
||||
requested
|
||||
status
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* @generated SignedSource<<bf1055f4f2fe5eb7a428afdd30f4f672>>
|
||||
* @generated SignedSource<<3d9ccb3632d0373c627c87f6e6585673>>
|
||||
* @lightSyntaxTransform
|
||||
* @nogrep
|
||||
*/
|
||||
@@ -25,6 +25,7 @@ export type TrustCenterAccessGraphLoadDocumentAccessesQuery$data = {
|
||||
readonly id: string;
|
||||
readonly title: string;
|
||||
} | null | undefined;
|
||||
readonly id: string;
|
||||
readonly report: {
|
||||
readonly audit: {
|
||||
readonly framework: {
|
||||
@@ -214,6 +215,7 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/),
|
||||
@@ -325,6 +327,7 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v2/*: any*/),
|
||||
(v4/*: any*/),
|
||||
(v5/*: any*/),
|
||||
(v6/*: any*/),
|
||||
@@ -387,16 +390,16 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "a764b27e48509dfdf4a7a03c5f00ea59",
|
||||
"cacheID": "a590c829b3c88e4fa4fe146771c723b9",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "TrustCenterAccessGraphLoadDocumentAccessesQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query TrustCenterAccessGraphLoadDocumentAccessesQuery(\n $accessId: ID!\n) {\n node(id: $accessId) {\n __typename\n ... on TrustCenterAccess {\n id\n availableDocumentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n active\n requested\n status\n document {\n id\n title\n documentType\n }\n report {\n id\n filename\n audit {\n id\n framework {\n name\n id\n }\n }\n }\n trustCenterFile {\n id\n name\n category\n }\n }\n }\n }\n }\n id\n }\n}\n"
|
||||
"text": "query TrustCenterAccessGraphLoadDocumentAccessesQuery(\n $accessId: ID!\n) {\n node(id: $accessId) {\n __typename\n ... on TrustCenterAccess {\n id\n availableDocumentAccesses(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {\n edges {\n node {\n id\n active\n requested\n status\n document {\n id\n title\n documentType\n }\n report {\n id\n filename\n audit {\n id\n framework {\n name\n id\n }\n }\n }\n trustCenterFile {\n id\n name\n category\n }\n }\n }\n }\n }\n id\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
(node as any).hash = "f40dbb607d0bd5adb85b0a8377b96b32";
|
||||
(node as any).hash = "1145528ffc9c1576b8e5dd6d58e64a9c";
|
||||
|
||||
export default node;
|
||||
|
||||
@@ -85,7 +85,9 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
||||
setDocumentAccesses((prev) => prev.map(element => ({...element, status: "GRANTED"})))
|
||||
}, [])
|
||||
const handleRejectOrRevokeAllDocumentAccess = useCallback(() => {
|
||||
setDocumentAccesses((prev) => prev.map(element => ({...element, status: initialStatusByID[element.id] === "GRANTED" ? "REVOKED" : "REJECTED"})))
|
||||
setDocumentAccesses((prev) => prev
|
||||
.map(element => ({...element, status: initialStatusByID[element.id] === "GRANTED" ? "REVOKED" : "REJECTED"}))
|
||||
)
|
||||
}, [initialStatusByID])
|
||||
|
||||
const editSchema = z.object({
|
||||
@@ -102,21 +104,23 @@ export function TrustCenterAccessEditForm(props: TrustCenterAccessEditFormProps)
|
||||
});
|
||||
|
||||
const handleSubmit = editForm.handleSubmit(async (data) => {
|
||||
const documents: {id: string, status: TrustCenterDocumentAccessStatus}[] = []
|
||||
const reports: {id: string, status: TrustCenterDocumentAccessStatus}[] = []
|
||||
const trustCenterFiles: {id: string, status: TrustCenterDocumentAccessStatus}[] = [];
|
||||
const documents: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
const reports: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
const trustCenterFiles: { id: string, status: TrustCenterDocumentAccessStatus }[] = []
|
||||
|
||||
for (const docAccess of documentAccesses) {
|
||||
switch (docAccess.type) {
|
||||
case "document":
|
||||
documents.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "report":
|
||||
reports.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "file":
|
||||
trustCenterFiles.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
if (docAccess.persisted || docAccess.status !== "REQUESTED") {
|
||||
switch (docAccess.type) {
|
||||
case "document":
|
||||
documents.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "report":
|
||||
reports.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
case "file":
|
||||
trustCenterFiles.push({id: docAccess.id, status: docAccess.status});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { TrustCenterDocumentAccessStatus } from "@probo/coredata";
|
||||
import { getTrustCenterDocumentAccessStatusBadgeVariant, type TrustCenterDocumentAccessInfo } from "@probo/helpers";
|
||||
import { getTrustCenterDocumentAccessStatusBadgeVariant, getTrustCenterDocumentAccessStatusLabel, type TrustCenterDocumentAccessInfo } from "@probo/helpers";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Badge, Button, Table, Tbody, Td, Th, Thead, Tr } from "@probo/ui";
|
||||
|
||||
@@ -25,7 +25,7 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
<h4 className="font-medium text-txt-primary">
|
||||
{__("Document Access Permissions")}
|
||||
</h4>
|
||||
<div className="ml-auto flex items-center gap-4">
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
{showGrantCTA &&
|
||||
<Button
|
||||
type="button"
|
||||
@@ -83,11 +83,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
</div>
|
||||
</Td>
|
||||
<Td>
|
||||
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
||||
{docAccess.status}
|
||||
</Badge>
|
||||
{(docAccess.persisted || docAccess.status !== "REQUESTED") &&
|
||||
<Badge variant={getTrustCenterDocumentAccessStatusBadgeVariant(docAccess.status)}>
|
||||
{getTrustCenterDocumentAccessStatusLabel(docAccess.status, __)}
|
||||
</Badge>
|
||||
}
|
||||
</Td>
|
||||
<Td className="flex justify-end">
|
||||
<Td className="flex justify-end gap-2">
|
||||
{docAccess.status !== "GRANTED" &&
|
||||
<Button
|
||||
type="button"
|
||||
@@ -102,10 +104,13 @@ export function TrustCenterDocumentAccessList(props: TrustCenterDocumentAccessLi
|
||||
<Button
|
||||
type="button"
|
||||
variant="danger"
|
||||
onClick={() => onUpdateStatus(docAccess, initialStatusByID[docAccess.id] === "GRANTED" ? "REVOKED" : "REJECTED")}
|
||||
onClick={() => onUpdateStatus(
|
||||
docAccess,
|
||||
docAccess.id && initialStatusByID[docAccess.id] === "GRANTED" ? "REVOKED" : "REJECTED"
|
||||
)}
|
||||
className="text-xs h-7 min-h-7"
|
||||
>
|
||||
{initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
||||
{docAccess.id && initialStatusByID[docAccess.id] === "GRANTED" ? __("Revoke") : __("Reject")}
|
||||
</Button>
|
||||
}
|
||||
</Td>
|
||||
|
||||
Reference in New Issue
Block a user