UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

349 lines (348 loc) 14.4 kB
import { jsxs as r, Fragment as d, jsx as t } from "react/jsx-runtime"; import { NewReleasesOutlined as ee } from "@mui/icons-material"; import { DialogTitle as te, Stack as se, Box as C, IconButton as ie, DialogContent as re, Typography as a, Divider as D, Alert as ae, DialogActions as oe, Button as U, Link as ne } from "@mui/material"; import { deepEquals as ce } from "@rjsf/utils"; import { AccessType as P, FileHandleAssociateType as A } from "@sage-bionetworks/synapse-types"; import { useState as b, useEffect as G } from "react"; 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 "../../../../utils/functions/EntityTypeUtils.js"; import "../../../../utils/SynapseConstants.js"; import "lodash-es"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "@tanstack/react-query"; import "../../../../utils/PermissionLevelToAccessType.js"; import { useSynapseContext as le } from "../../../../utils/context/SynapseContext.js"; import "use-deep-compare-effect"; 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 '../../../../style/components/_spinner.css';/* empty css */ 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 { useSubmitDataAccessRequest as de } from "../../../../synapse-queries/dataaccess/useDataAccessSubmission.js"; import { useGetDataAccessRequestForUpdate as ue, useUpdateDataAccessRequest as me } from "../../../../synapse-queries/dataaccess/useAccessRequirements.js"; import { useGetCurrentUserProfile as pe } from "../../../../synapse-queries/user/useUserBundle.js"; import { SynapseErrorBoundary as v } from "../../../error/ErrorBanner.js"; import he from "../../../IconSvg/IconSvg.js"; import fe from "../DataAccessRequestAccessorsEditor.js"; import ge from "../DocumentTemplate.js"; import Ae from "../ManagedACTAccessRequirementFormWikiWrapper.js"; import { UploadDocumentField as x } from "../UploadDocumentField.js"; function be(p) { const { managedACTAccessRequirement: o } = p; let i = "", c = ""; return o.isCertifiedUserRequired && o.isValidatedProfileRequired ? (i = "https://help.synapse.org/docs/User-Types.2007072795.html", c = "All data requesters must be certified users and have a validated user profile.") : o.isCertifiedUserRequired ? (i = "https://help.synapse.org/docs/User-Types.2007072795.html#UserAccountTiers-CertifiedUsers", c = "All data requesters must be a certified user.") : o.isValidatedProfileRequired && (i = "https://help.synapse.org/docs/User-Types.2007072795.html#UserAccountTiers-ValidatedUsers", c = "All data requesters must have a validated user profile."), /* @__PURE__ */ r(d, { children: [ o.isDUCRequired ? /* @__PURE__ */ r(C, { sx: { display: "flex", gap: 2, alignItems: "center", py: 1 }, children: [ /* @__PURE__ */ t(ee, { sx: { color: "error.main" } }), /* @__PURE__ */ t("div", { children: "You must list the Synapse user names of all collaborators listed in your Data Use Certificate (DUC)." }) ] }) : "", c, " ", i && /* @__PURE__ */ t(ne, { href: i, target: "_blank", rel: "noreferrer", children: "Learn more" }) ] }); } function ot(p) { const { onSubmissionCreated: o, managedACTAccessRequirement: i, subjectId: c, subjectType: L, researchProjectId: S, onCancel: N, onBackClicked: W } = p, { isAuthenticated: T } = le(), { data: h } = pe({ enabled: T }), [y, w] = b(), [f, H] = b(), [F, M] = b(), [k, V] = b(), { data: e, isLoading: Y } = ue(String(i.id), { enabled: T, // Infinite staleTime ensures this won't get re-fetched unless explicitly invalidated by the mutation staleTime: 1 / 0, // This call should never fail, so if we run into an error, throwing to an error boundary is acceptable throwOnError: !0 }), u = e?.concreteType === "org.sagebionetworks.repo.model.dataaccess.Renewal"; function O(s) { console.log("RequestDataAccessStep2: Error updating form", s), w({ key: "error", message: B(s.reason) }); } const { mutate: _, isPending: q } = de({ onSuccess: (s) => { o(s.submissionId); }, onError: O }), { mutateAsync: l, isPending: z } = me({ onError: O }), R = Y || z || q; G(() => { if (e && h) { let s = !1; e.researchProjectId || (e.researchProjectId = S, s = !0); const n = { userId: h.ownerId, type: u ? P.RENEW_ACCESS : P.GAIN_ACCESS }; (!e.accessorChanges || !e.accessorChanges.find( (g) => ce(g, n) )) && (e.accessorChanges = [ n, ...e.accessorChanges || [] ], s = !0); const m = /* @__PURE__ */ new Set(), E = e.accessorChanges.filter( (g) => m.has(g.userId) ? !1 : m.add(g.userId) ); E.length !== e.accessorChanges.length && (e.accessorChanges = E, s = !0), s && l(e); } }, [ e, u, S, l, h ]), G(() => { e && (e.accessorChanges && f == null && H(e.accessorChanges), u && e.publication && k == null && V(e.publication), u && e.summaryOfUse && F == null && M(e.summaryOfUse)); }, [e]); function j() { return { ...e, // append local state to the request accessorChanges: f, publication: k, summaryOfUse: F }; } async function J() { if (e) { const s = await l( j() ); _({ request: { requestId: s.id, requestEtag: s.etag, subjectId: c, subjectType: L }, accessRequirementId: String(i.id) }); } } const B = (s = "") => /* @__PURE__ */ r(d, { children: [ /* @__PURE__ */ t("strong", { children: "Sorry, there is an error in submitting your request." }), /* @__PURE__ */ t("br", {}), s ] }), K = (s) => { H([...s(f || [])]); }, Q = (s) => { l({ ...e, attachments: e.attachments?.filter((n) => n !== s) }); }, I = (s, n) => { if (s.resp && s.success) { const m = s.resp; l(n === "attachments" ? { ...e, attachments: [ ...e.attachments || [], m.fileHandleId ] } : { ...e, [n]: m.fileHandleId }); } else !s.success && s.error && (console.log( "RequestDataAccessStep2: Error uploading the file", s.error ), w({ key: "error", message: B(s.error.reason) })); }, X = e?.ducFileHandleId ? [ { fileHandleId: e?.ducFileHandleId, associateObjectType: A.DataAccessRequestAttachment, associateObjectId: String(e.id) } ] : [], Z = e?.irbFileHandleId ? [ { fileHandleId: e.irbFileHandleId, associateObjectType: A.DataAccessRequestAttachment, associateObjectId: String(e.id) } ] : [], $ = (e?.attachments || []).map((s) => ({ fileHandleId: s, associateObjectType: A.DataAccessRequestAttachment, associateObjectId: String(e.id) })) ?? []; return /* @__PURE__ */ r(d, { children: [ /* @__PURE__ */ t(te, { children: /* @__PURE__ */ r( se, { direction: "row", sx: { alignItems: "center", gap: "5px" }, children: [ "Request Access", /* @__PURE__ */ t(C, { sx: { flexGrow: 1 } }), /* @__PURE__ */ t(ie, { onClick: p.onHide, children: /* @__PURE__ */ t(he, { icon: "close", wrap: !1, sx: { color: "grey.700" } }) }) ] } ) }), /* @__PURE__ */ r(re, { children: [ /* @__PURE__ */ t( Ae, { managedACTAccessRequirementId: String(i.id), children: /* @__PURE__ */ r( C, { component: "form", sx: { // Must set a minHeight to ensure the user picker in the DataAccessRequestAccessorsEditor doesn't get cut off minHeight: "475px" }, onSubmit: (s) => s.preventDefault(), children: [ /* @__PURE__ */ t(a, { variant: "body1", sx: { mb: 2 }, children: "Please provide the information below to submit the request for access." }), e && h && /* @__PURE__ */ t( fe, { accessorChanges: f || [], onChange: K, isRenewal: u, helpText: /* @__PURE__ */ t( be, { managedACTAccessRequirement: i } ) } ), (i?.isDUCRequired || i?.isIRBApprovalRequired || i?.areOtherAttachmentsRequired) && /* @__PURE__ */ t(D, { sx: { my: 4 } }), i?.isDUCRequired && /* @__PURE__ */ r(d, { children: [ i?.ducTemplateFileHandleId && /* @__PURE__ */ t( ge, { title: "Download DUC Template", description: "As a first step, you will need to download the most current version of the Data Use Certificate.", fileHandleAssociation: { fileHandleId: i.ducTemplateFileHandleId, associateObjectType: A.AccessRequirementAttachment, associateObjectId: String(i.id) }, downloadButtonText: "Download DUC Template" } ), /* @__PURE__ */ t(a, { variant: "headline3", sx: { mt: 4, mb: 2 }, children: "Fill out and upload a Data Use Certificate" }), /* @__PURE__ */ t(a, { variant: "body1", sx: { my: 2 }, children: "You must download and fill out a Data Use Certificate (DUC). Be sure to upload the completed DUC below once you've completed it." }), /* @__PURE__ */ r(a, { variant: "body1", component: "ol", children: [ /* @__PURE__ */ t("li", { children: "Download the DUC template file." }), /* @__PURE__ */ t("li", { children: "Fill out the DUC template, following the instructions in the file." }), /* @__PURE__ */ t("li", { children: "Upload the completed certificate using the button below:" }) ] }), /* @__PURE__ */ t(v, { children: /* @__PURE__ */ t( x, { id: "duc", isLoading: R, uploadCallback: (s) => I(s, "ducFileHandleId"), documentName: "Data Use Certificate", fileHandleAssociations: X } ) }), (i?.isIRBApprovalRequired || i?.areOtherAttachmentsRequired) && /* @__PURE__ */ t(D, { sx: { my: 4 } }) ] }), i?.isIRBApprovalRequired && /* @__PURE__ */ r(d, { children: [ /* @__PURE__ */ t(a, { variant: "headline3", sx: { my: 2 }, children: "IRB Approval" }), /* @__PURE__ */ t(a, { variant: "body1", sx: { my: 2 }, children: "Upload a signed IRB letter on institutional letterhead. The letter must include the names of all the datasets requested, as well as the names of the data requesters above. Use the button below to upload the document." }), /* @__PURE__ */ t(v, { children: /* @__PURE__ */ t( x, { id: "irb", isLoading: R, documentName: "IRB Approval Letter", uploadCallback: (s) => I(s, "irbFileHandleId"), fileHandleAssociations: Z } ) }), i?.areOtherAttachmentsRequired && /* @__PURE__ */ t(D, { sx: { my: 4 } }) ] }), /* Attachments */ i?.areOtherAttachmentsRequired && /* @__PURE__ */ r(d, { children: [ /* @__PURE__ */ t(a, { variant: "headline3", sx: { my: 2 }, children: "Upload other required documents" }), /* @__PURE__ */ t(a, { variant: "body1", sx: { my: 2 }, children: "You must upload other required documents. Please review the instructions to gain data access to determine which documents must also be uploaded." }), /* @__PURE__ */ t(v, { children: /* @__PURE__ */ t( x, { id: "file-attachment", isLoading: R, documentName: "Attachment", uploadCallback: (s) => I(s, "attachments"), isMultiFileUpload: !0, fileHandleAssociations: $, onClearAttachment: Q } ) }) ] }) ] } ) } ), y && /* @__PURE__ */ t(ae, { severity: y.key, children: y.message }) ] }), /* @__PURE__ */ r(oe, { children: [ /* @__PURE__ */ t( U, { variant: "outlined", onClick: () => { W(); }, children: "Back" } ), /* @__PURE__ */ t(C, { sx: { flexGrow: 1 } }), /* @__PURE__ */ t( U, { variant: "outlined", disabled: q, onClick: () => { e && N(j()); }, children: "Cancel" } ), /* @__PURE__ */ t( U, { variant: "contained", disabled: q, onClick: () => { J(); }, children: "Submit" } ) ] }) ] }); } export { ot as default }; //# sourceMappingURL=DataAccessRequestAccessorsFilesForm.js.map