synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
274 lines (273 loc) • 10.3 kB
JavaScript
import { jsx as t, jsxs as n, Fragment as S } from "react/jsx-runtime";
import "../../synapse-client/SynapseClient.js";
import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode";
import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse";
import "@sage-bionetworks/synapse-client/util/SynapseClientError";
import { FileHandleAssociateType as O } from "@sage-bionetworks/synapse-types";
import "../../utils/functions/EntityTypeUtils.js";
import { DAY_IN_MS as C } from "../../utils/SynapseConstants.js";
import "lodash-es";
import "@sage-bionetworks/synapse-client/util/synapseClientFetch";
import "@tanstack/react-query";
import "../../utils/PermissionLevelToAccessType.js";
import { forwardRef as _, useEffect as k, useState as u, useMemo as B, useImperativeHandle as M } from "react";
import "../../utils/context/SynapseContext.js";
import "use-deep-compare-effect";
import { Alert as R, Box as f, Typography as v, FormControlLabel as a, Checkbox as l, TextField as $ } from "@mui/material";
import "../../utils/hooks/useCookiePreferences.js";
import "../../utils/hooks/useSourceAppConfigs.js";
import "universal-cookie";
import "../../utils/AppUtils/session/ApplicationSessionContext.js";
import "../../utils/context/FullContextProvider.js";
import "../../utils/context/DocumentMetadataContext.js";
import { SynapseSpinner as j } from "../LoadingScreen/LoadingScreen.js";
import "@tanstack/query-core";
import "lodash-es/isEmpty";
import "lodash-es/isEqual";
import "lodash-es/xorWith";
import "react-router";
import "@sage-bionetworks/synapse-client";
import "../../utils/types/IsType.js";
import { useGetAccessRequirements as L, useUpdateAccessRequirement as w } from "../../synapse-queries/dataaccess/useAccessRequirements.js";
import { UploadDocumentField as N } from "../AccessRequirementList/ManagedACTAccessRequirementRequestFlow/UploadDocumentField.js";
import { SynapseErrorBoundary as W } from "../error/ErrorBanner.js";
import { AccessRequirementWikiInstructions as V } from "../SetBasicAccessRequirementFields/AccessRequirementWikiInstructions.js";
import { AccessorRequirements as G } from "../SetBasicAccessRequirementFields/AccessorRequirements.js";
import "../SetBasicAccessRequirementFields/SetBasicAccessRequirementFields.js";
const Y = "There was an error uploading the DUC template. ", E = (s) => {
if (s === "") return 0;
const d = "Please enter a valid expiration period (in days): ";
if (/^[-]?\d+$/.test(s)) {
const c = Number(s);
return c < 0 ? `${d}If expiration period is set, then it must be greater than 0.` : c * C;
}
return `${d}For input string: "${s}"`;
}, Pe = _(
function(d, c) {
const { accessRequirementId: y, onSave: P, onError: h } = d, { data: p, error: x } = L(
y,
{ staleTime: 1 / 0 }
);
k(() => {
p && (o(p), I(
(p.expirationPeriod / C).toString()
));
}, [p]);
const [q, A] = u(null), [b, g] = u(null), [e, o] = u(null), [m, I] = u(""), U = B(() => {
if (e?.ducTemplateFileHandleId)
return {
fileHandleId: e.ducTemplateFileHandleId,
associateObjectType: O.AccessRequirementAttachment,
associateObjectId: e.id.toString()
};
}, [e?.ducTemplateFileHandleId, e?.id]), F = (r) => {
if (r.resp && r.success && e) {
A(null);
const i = r.resp;
o({
...e,
ducTemplateFileHandleId: i.fileHandleId
});
} else !r.success && r.error && A(
`${Y} ${r.error.reason}`
);
}, {
mutate: D,
isPending: H,
error: T
} = w({
onSuccess: () => P(),
onError: () => h()
});
return M(
c,
() => ({
save() {
if (e) {
const r = E(m);
typeof r == "string" ? (g(r), h()) : D({
...e,
expirationPeriod: r
});
}
}
}),
[m, e, D, h]
), e ? /* @__PURE__ */ n(S, { children: [
/* @__PURE__ */ t(V, { accessRequirement: e }),
/* @__PURE__ */ n(f, { children: [
/* @__PURE__ */ t(
v,
{
sx: {
bgcolor: "#f5f5f5",
borderBottom: "1px solid #ddd",
color: "#333",
px: 2,
py: 1
},
children: "Data Access Request Parameters"
}
),
/* @__PURE__ */ n(
f,
{
sx: {
mt: 2,
mb: 4
},
children: [
/* @__PURE__ */ t(
G,
{
accessRequirement: e,
onChange: (r) => o(r)
}
),
/* @__PURE__ */ n(
f,
{
sx: {
mb: 2
},
children: [
/* @__PURE__ */ t(
v,
{
variant: "body1",
sx: {
fontWeight: 700
},
children: "DUC"
}
),
/* @__PURE__ */ t(
a,
{
control: /* @__PURE__ */ t(l, {}),
label: "DUC is required.",
checked: e.isDUCRequired,
onChange: (r, i) => o({
...e,
isDUCRequired: i
})
}
),
/* @__PURE__ */ n(W, { children: [
/* @__PURE__ */ t(
N,
{
id: "duc",
isLoading: H,
uploadCallback: (r) => F(r),
documentName: "Template DUC",
fileHandleAssociations: U ? [U] : void 0,
isMultiFileUpload: !1,
uploadBtnVariant: "contained"
}
),
q && /* @__PURE__ */ t(R, { severity: "error", sx: { marginTop: 2 }, children: q })
] }),
/* @__PURE__ */ t(
a,
{
label: "IRB approval is required.",
checked: e.isIRBApprovalRequired,
control: /* @__PURE__ */ t(l, {}),
onChange: (r, i) => o({
...e,
isIRBApprovalRequired: i
}),
sx: { ml: 0 }
}
),
/* @__PURE__ */ t(
a,
{
control: /* @__PURE__ */ t(l, {}),
label: "Other documents are required.",
checked: e.areOtherAttachmentsRequired,
onChange: (r, i) => o({
...e,
areOtherAttachmentsRequired: i
})
}
),
/* @__PURE__ */ t(
$,
{
id: "expirationPeriod",
name: "expirationPeriod",
label: "Expiration period (days)",
value: m,
error: !!b,
helperText: b,
sx: { mt: 1 },
fullWidth: !0,
onChange: (r) => {
g(null), I(r.target.value);
},
onBlur: () => {
const r = E(m);
typeof r == "string" && g(r);
}
}
),
/* @__PURE__ */ n(
f,
{
sx: {
mt: 1
},
children: [
/* @__PURE__ */ t(
a,
{
control: /* @__PURE__ */ t(l, {}),
label: "Intended Data Use statement is required.",
checked: e.isIDURequired,
onChange: (r, i) => {
o(i ? {
...e,
isIDURequired: !0
} : {
...e,
isIDURequired: !1,
isIDUPublic: !1
});
}
}
),
/* @__PURE__ */ t(
a,
{
control: /* @__PURE__ */ t(l, {}),
label: "Intended Data Use statements will be publicly available.",
checked: e.isIDUPublic,
disabled: !e.isIDURequired,
onChange: (r, i) => o({
...e,
isIDUPublic: i
})
}
)
]
}
)
]
}
)
]
}
)
] }),
T && /* @__PURE__ */ t(R, { severity: "error", sx: { marginTop: 2 }, children: T.reason })
] }) : x ? /* @__PURE__ */ t(R, { severity: "error", children: x.reason }) : /* @__PURE__ */ t(j, {});
}
);
export {
Y as DUC_TEMPLATE_UPLOAD_ERROR,
Pe as SetManagedAccessRequirementFields,
E as getValidExpirationPeriodOrErrorMessage
};
//# sourceMappingURL=SetManagedAccessRequirementFields.js.map