diff --git a/src/components/eRACommons.js b/src/components/eRACommons.js index b43a0e918..58319d934 100644 --- a/src/components/eRACommons.js +++ b/src/components/eRACommons.js @@ -15,8 +15,7 @@ export const eRACommons = hh(class eRACommons extends React.Component { expirationCount: 0, eraCommonsId: '', nihError: false, - isHovered: false, - isCurrentUser: true + isHovered: false }; componentDidMount = async () => { @@ -49,31 +48,40 @@ export const eRACommons = hh(class eRACommons extends React.Component { }; getUserInfo = async () => { - let response = await User.getMe(); - if (this.props.researcher !== undefined) { - const givenUser = this.props.researcher; - if (givenUser.userId != response.userId) { - this.setState(prev => { - prev.isCurrentUser = false; - return prev; - }); - } - response = givenUser; + if (this.props.researcherProfile === undefined) { + const response = await User.getMe(); + const props = response.researcherProperties; + const authProp = find({'propertyKey':'eraAuthorized'})(props); + const expProp = find({'propertyKey':'eraExpiration'})(props); + const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp); + const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp)); + const nihValid = isAuthorized && expirationCount > 0; + const eraCommonsId = response.eraCommonsId; + this.props.onNihStatusUpdate(nihValid); + this.setState(prev => { + prev.isAuthorized = isAuthorized; + prev.expirationCount = expirationCount; + prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId; + return prev; + }); + } + else { + const response = this.props.researcherProfile; + const props = response.researcherProperties; + const authProp = find({'propertyKey':'eraAuthorized'})(props); + const expProp = find({'propertyKey':'eraExpiration'})(props); + const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp); + const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp)); + const nihValid = isAuthorized && expirationCount > 0; + const eraCommonsId = response.eraCommonsId; + this.props.onNihStatusUpdate(nihValid); + this.setState(prev => { + prev.isAuthorized = isAuthorized; + prev.expirationCount = expirationCount; + prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId; + return prev; + }); } - const props = response.researcherProperties; - const authProp = find({'propertyKey':'eraAuthorized'})(props); - const expProp = find({'propertyKey':'eraExpiration'})(props); - const isAuthorized = isNil(authProp) ? false : getOr(false,'propertyValue')(authProp); - const expirationCount = isNil(expProp) ? 0 : AuthenticateNIH.expirationCount(getOr(0,'propertyValue')(expProp)); - const nihValid = isAuthorized && expirationCount > 0; - const eraCommonsId = response.eraCommonsId; - this.props.onNihStatusUpdate(nihValid); - this.setState(prev => { - prev.isAuthorized = isAuthorized; - prev.expirationCount = expirationCount; - prev.eraCommonsId = isNil(eraCommonsId) ? '' : eraCommonsId; - return prev; - }); }; verifyToken = async (parsedToken) => { @@ -202,10 +210,10 @@ export const eRACommons = hh(class eRACommons extends React.Component { className: 'col-lg-12 col-md-12 col-sm-6 col-xs-12 no-padding' }, [ div({ isRendered: this.state.expirationCount >= 0, className: 'fadein' }, ['Your NIH authentication will expire in ' + this.state.expirationCount + ' days']), - div({ isRendered: this.state.expirationCount < 0, className: 'fadein' }, [this.state.isCurrentUser ? 'Your NIH authentication has expired' : `This user's NIH authentication has expired`]) + div({ isRendered: this.state.expirationCount < 0, className: 'fadein' }, [(this.props.researcherProfile === undefined) ? 'Your NIH authentication has expired' : `This user's NIH authentication has expired`]) ]) ]) ]) ); } -}); +}); \ No newline at end of file diff --git a/src/libs/ajax.js b/src/libs/ajax.js index 3d88b5807..0d1d4a92e 100644 --- a/src/libs/ajax.js +++ b/src/libs/ajax.js @@ -626,12 +626,6 @@ export const User = { return res.json(); }, - // getSOsForGivenUser: async (userId) => { - // const url = `${await getApiUrl()}/api/user/signing-officials/${userId}`; - // const res = await fetchOk(url, fp.mergeAll([Config.authOpts(), { method: 'GET' }])); - // return res.json(); - // }, - getUnassignedUsers: async () => { const url = `${await getApiUrl()}/api/user/institution/unassigned`; const res = await axios.get(url, Config.authOpts()); diff --git a/src/pages/dar_application/DataAccessRequest.js b/src/pages/dar_application/DataAccessRequest.js index 762f92dd4..b8f1f7ad3 100644 --- a/src/pages/dar_application/DataAccessRequest.js +++ b/src/pages/dar_application/DataAccessRequest.js @@ -413,4 +413,4 @@ export default function DataAccessRequest(props) { ]), ]) ); -} +} \ No newline at end of file diff --git a/src/pages/dar_application/DataAccessRequestApplication.js b/src/pages/dar_application/DataAccessRequestApplication.js index 000771491..326664f0e 100644 --- a/src/pages/dar_application/DataAccessRequestApplication.js +++ b/src/pages/dar_application/DataAccessRequestApplication.js @@ -28,8 +28,7 @@ import UsgOmbText from '../../components/UsgOmbText'; const ApplicationTabs = [ { name: 'Researcher Information' }, { name: 'Data Access Request' }, - { name: 'Research Purpose Statement' }, - { name: 'Data Use Agreement' } + { name: 'Research Purpose Statement' } ]; const fetchAllDatasets = async (dsIds) => { @@ -125,6 +124,9 @@ const DataAccessRequestApplication = (props) => { const [isLoading, setIsLoading] = useState(true); const [isAttested, setIsAttested] = useState(false); + if (!props.readOnlyMode) { + ApplicationTabs.push({ name: 'Data Use Agreement' }); + } const [applicationTabs, setApplicationTabs] = useState(ApplicationTabs); //helper function to coordinate local state changes as well as updates to form data on the parent @@ -227,19 +229,11 @@ const DataAccessRequestApplication = (props) => { const init = useCallback(async () => { const { dataRequestId, collectionId } = props.match.params; let formData = {}; - if (props.researcher === undefined) { - const researcher = await User.getMe(); - const signingOfficials = await User.getSOsForCurrentUser(); - setResearcher(researcher); - setAllSigningOfficials(signingOfficials); - } - else { - const researcher = props.researcher; - // const signingOfficials = await User.getSOsForGivenUser(props.researcher.userId); - setResearcher(researcher); - setAllSigningOfficials(['Hello']); - } + const researcher = await User.getMe(); + const signingOfficials = await User.getSOsForCurrentUser(); + setResearcher(researcher); + setAllSigningOfficials(signingOfficials); setIsLoading(false); if (!isNil(collectionId)) { @@ -267,7 +261,7 @@ const DataAccessRequestApplication = (props) => { batchFormFieldChange(formData); window.addEventListener('scroll', onScroll); // eslint-disable-line -- codacy says event listeners are dangerous - }, [onScroll, props.match.params, props.researcher, researcher]); + }, [onScroll, props.match.params]); useEffect(() => { init(); @@ -538,6 +532,7 @@ const DataAccessRequestApplication = (props) => { { nihValid={nihValid} onNihStatusUpdate={setNihValid} showNihValidationError={showNihValidationError} - researcher={(props.researcher === undefined) ? researcher : props.researcher} + researcher={researcher} allSigningOfficials={allSigningOfficials} setLabCollaboratorsCompleted={setLabCollaboratorsCompleted} setInternalCollaboratorsCompleted={setInternalCollaboratorsCompleted} @@ -587,15 +582,16 @@ const DataAccessRequestApplication = (props) => { /> -
- {!props.readOnlyMode ? setIsAttested(false)} - isAttested={isAttested} - attest={attemptSubmit} - save={() => setShowDialogSave(true)} - /> :
} -
+ {!props.readOnlyMode ? +
+ setIsAttested(false)} + isAttested={isAttested} + attest={attemptSubmit} + save={() => setShowDialogSave(true)} + /> +
:
} {isAttested &&
diff --git a/src/pages/dar_application/ResearcherInfo.js b/src/pages/dar_application/ResearcherInfo.js index ea3d79baa..16a42ce4e 100644 --- a/src/pages/dar_application/ResearcherInfo.js +++ b/src/pages/dar_application/ResearcherInfo.js @@ -19,6 +19,7 @@ export default function ResearcherInfo(props) { const { allSigningOfficials, readOnlyMode, + researcherProfile, includeInstructions, completed, darCode, @@ -78,7 +79,7 @@ export default function ResearcherInfo(props) { title: '1.1 Researcher', validators: [FormValidators.REQUIRED], ariaLevel: ariaLevel + 1, - defaultValue: researcher.displayName, + defaultValue: (researcherProfile === undefined) ? researcher.displayName : researcherProfile.displayName, disabled: true }), ]), @@ -97,7 +98,7 @@ export default function ResearcherInfo(props) { location: location, validationError: showNihValidationError, readOnly: readOnlyMode, - researcher: props.researcher, + researcherProfile: researcherProfile, header: true, required: formData.checkCollaborator !== true, }) @@ -200,7 +201,7 @@ export default function ResearcherInfo(props) { }), ]), - div({className: 'dar-application-row'}, [ + !props.readOnlyMode && div({className: 'dar-application-row'}, [ h(FormField, { id: 'signingOfficial', type: FormFieldTypes.SELECT, @@ -392,4 +393,4 @@ export default function ResearcherInfo(props) { ]), ]) ); -} +} \ No newline at end of file diff --git a/src/pages/dar_application/collaborator/CollaboratorList.js b/src/pages/dar_application/collaborator/CollaboratorList.js index be4855d73..c18fd217d 100644 --- a/src/pages/dar_application/collaborator/CollaboratorList.js +++ b/src/pages/dar_application/collaborator/CollaboratorList.js @@ -123,4 +123,4 @@ export default function CollaboratorList(props) { ListItems ]) ); -} +} \ No newline at end of file diff --git a/src/pages/dar_collection_review/DarCollectionReview.js b/src/pages/dar_collection_review/DarCollectionReview.js index cfe6c9531..d017c295c 100644 --- a/src/pages/dar_collection_review/DarCollectionReview.js +++ b/src/pages/dar_collection_review/DarCollectionReview.js @@ -205,8 +205,8 @@ export default function DarCollectionReview(props) { }), h(DataAccessRequestApplication, { isRendered: selectedTab === tabs.fullDAR, - researcher: researcherProfile, readOnlyMode: true, + researcherProfile: researcherProfile, ...props }), h(MultiDatasetVotingTab, { @@ -232,4 +232,4 @@ export default function DarCollectionReview(props) { ] ), ]); -} +} \ No newline at end of file