@@ -94,7 +94,7 @@ export function TrustCenterAuditsCard<Params>(props: Props<Params>) {
|
||||
{audits.map((audit, index) => (
|
||||
<AuditRow
|
||||
key={index}
|
||||
audit={audit}
|
||||
auditFragmentRef={audit}
|
||||
onChangeVisibility={onChangeVisibility}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
@@ -116,23 +116,24 @@ export function TrustCenterAuditsCard<Params>(props: Props<Params>) {
|
||||
}
|
||||
|
||||
function AuditRow(props: {
|
||||
audit: TrustCenterAuditsCardFragment$key;
|
||||
auditFragmentRef: TrustCenterAuditsCardFragment$key;
|
||||
onChangeVisibility: (auditId: string, trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC") => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const audit = useFragment(trustCenterAuditFragment, props.audit);
|
||||
const { auditFragmentRef, onChangeVisibility, disabled } = props;
|
||||
const audit = useFragment(trustCenterAuditFragment, auditFragmentRef);
|
||||
const organizationId = useOrganizationId();
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = organizationId ? isAuthorized("TrustCenter", "updateTrustCenter") : false;
|
||||
|
||||
const handleValueChange = useCallback((value: string | {}) => {
|
||||
const handleValueChange = useCallback((value: string) => {
|
||||
const stringValue = typeof value === 'string' ? value : '';
|
||||
const typedValue = stringValue as "NONE" | "PRIVATE" | "PUBLIC";
|
||||
setOptimisticValue(typedValue);
|
||||
props.onChangeVisibility(audit.id, typedValue);
|
||||
}, [audit.id, props.onChangeVisibility]);
|
||||
onChangeVisibility(audit.id, typedValue);
|
||||
}, [audit.id, onChangeVisibility]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optimisticValue && audit.trustCenterVisibility === optimisticValue) {
|
||||
@@ -167,7 +168,7 @@ function AuditRow(props: {
|
||||
type="select"
|
||||
value={currentValue}
|
||||
onValueChange={handleValueChange}
|
||||
disabled={props.disabled || !canUpdate}
|
||||
disabled={disabled || !canUpdate}
|
||||
className="w-[105px]"
|
||||
>
|
||||
{visibilityOptions.map((option) => (
|
||||
|
||||
@@ -98,7 +98,7 @@ export function TrustCenterDocumentsCard<Params>(props: Props<Params>) {
|
||||
{documents.map((document, index) => (
|
||||
<DocumentRow
|
||||
key={index}
|
||||
document={document}
|
||||
documentFragmentRef={document}
|
||||
onChangeVisibility={onChangeVisibility}
|
||||
disabled={props.disabled}
|
||||
/>
|
||||
@@ -121,23 +121,24 @@ export function TrustCenterDocumentsCard<Params>(props: Props<Params>) {
|
||||
}
|
||||
|
||||
function DocumentRow(props: {
|
||||
document: TrustCenterDocumentsCardFragment$key;
|
||||
documentFragmentRef: TrustCenterDocumentsCardFragment$key;
|
||||
onChangeVisibility: (documentId: string, trustCenterVisibility: "NONE" | "PRIVATE" | "PUBLIC") => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const document = useFragment(trustCenterDocumentFragment, props.document);
|
||||
const { documentFragmentRef, onChangeVisibility, disabled } = props;
|
||||
const document = useFragment(trustCenterDocumentFragment, documentFragmentRef);
|
||||
const organizationId = useOrganizationId();
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = isAuthorized("TrustCenter", "updateTrustCenter");
|
||||
|
||||
const handleValueChange = useCallback((value: string | {}) => {
|
||||
const handleValueChange = useCallback((value: string) => {
|
||||
const stringValue = typeof value === 'string' ? value : '';
|
||||
const typedValue = stringValue as "NONE" | "PRIVATE" | "PUBLIC";
|
||||
setOptimisticValue(typedValue);
|
||||
props.onChangeVisibility(document.id, typedValue);
|
||||
}, [document.id, props.onChangeVisibility]);
|
||||
onChangeVisibility(document.id, typedValue);
|
||||
}, [document.id, onChangeVisibility]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optimisticValue && document.trustCenterVisibility === optimisticValue) {
|
||||
@@ -167,7 +168,7 @@ function DocumentRow(props: {
|
||||
type="select"
|
||||
value={currentValue}
|
||||
onValueChange={handleValueChange}
|
||||
disabled={props.disabled || !canUpdate}
|
||||
disabled={disabled || !canUpdate}
|
||||
className="w-[105px]"
|
||||
>
|
||||
{visibilityOptions.map((option) => (
|
||||
|
||||
@@ -145,18 +145,18 @@ function FileRow(props: {
|
||||
onDelete: (id: string) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
const file = props.file;
|
||||
const { file, onChangeVisibility, onEdit, onDelete, disabled } = props;
|
||||
const { __ } = useTranslate();
|
||||
const [optimisticValue, setOptimisticValue] = useState<string | null>(null);
|
||||
const { isAuthorized } = use(PermissionsContext);
|
||||
const canUpdate = isAuthorized("TrustCenter", "updateTrustCenter");
|
||||
|
||||
const handleValueChange = useCallback((value: string | {}) => {
|
||||
const handleValueChange = useCallback((value: string) => {
|
||||
const stringValue = typeof value === 'string' ? value : '';
|
||||
const typedValue = stringValue as "NONE" | "PRIVATE" | "PUBLIC";
|
||||
setOptimisticValue(typedValue);
|
||||
props.onChangeVisibility(file.id, typedValue);
|
||||
}, [file.id, props.onChangeVisibility]);
|
||||
onChangeVisibility(file.id, typedValue);
|
||||
}, [file.id, onChangeVisibility]);
|
||||
|
||||
useEffect(() => {
|
||||
if (optimisticValue && file.trustCenterVisibility === optimisticValue) {
|
||||
@@ -182,7 +182,7 @@ function FileRow(props: {
|
||||
type="select"
|
||||
value={currentValue}
|
||||
onValueChange={handleValueChange}
|
||||
disabled={props.disabled || !canUpdate}
|
||||
disabled={disabled || !canUpdate}
|
||||
className="w-[105px]"
|
||||
>
|
||||
{visibilityOptions.map((option) => (
|
||||
@@ -208,8 +208,8 @@ function FileRow(props: {
|
||||
<Button
|
||||
variant="secondary"
|
||||
icon={IconPencil}
|
||||
onClick={() => props.onEdit({ id: file.id, name: file.name, category: file.category })}
|
||||
disabled={props.disabled}
|
||||
onClick={() => onEdit({ id: file.id, name: file.name, category: file.category })}
|
||||
disabled={disabled}
|
||||
title={__("Edit")}
|
||||
/>
|
||||
)}
|
||||
@@ -217,8 +217,8 @@ function FileRow(props: {
|
||||
<Button
|
||||
variant="danger"
|
||||
icon={IconTrashCan}
|
||||
onClick={() => props.onDelete(file.id)}
|
||||
disabled={props.disabled}
|
||||
onClick={() => onDelete(file.id)}
|
||||
disabled={disabled}
|
||||
title={__("Delete")}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user