diff --git a/src/libs/ajax/DAA.js b/src/libs/ajax/DAA.js index e212bd33f..2ff91ba81 100644 --- a/src/libs/ajax/DAA.js +++ b/src/libs/ajax/DAA.js @@ -1,6 +1,5 @@ -import * as fp from 'lodash/fp'; import fileDownload from 'js-file-download'; -import { getApiUrl, fetchOk } from '../ajax'; +import { getApiUrl } from '../ajax'; import { Config } from '../config'; import axios from 'axios'; @@ -52,7 +51,7 @@ export const DAA = { const url = `${await getApiUrl()}/api/daa/bulk/user/${userId}`; const res = await axios.delete(url, { ...Config.authOpts(), data: daaList }); return res.data; - }, + }, getDaaFileById: async (daaId, daaFileName) => { const authOpts = Object.assign(Config.authOpts(), { responseType: 'blob' }); diff --git a/src/pages/signing_official_console/ManageResearcherDAAsTable.jsx b/src/pages/signing_official_console/ManageResearcherDAAsTable.jsx index 910cc0bd8..c49ac140a 100644 --- a/src/pages/signing_official_console/ManageResearcherDAAsTable.jsx +++ b/src/pages/signing_official_console/ManageResearcherDAAsTable.jsx @@ -15,7 +15,7 @@ import { import { DAA } from '../../libs/ajax/DAA'; import {User} from '../../libs/ajax/User'; import { USER_ROLES } from '../../libs/utils'; -import { Button } from '@mui/material'; +import ManageUsersDropdown from './ManageUsersDropdown'; //Styles specific to this table const styles = { @@ -111,68 +111,7 @@ const DAACell = ( }; }; -const dropdown = (applyAll, removeAll, handleApplyAllChange, handleRemoveAllChange, handleApplyAll, actionsTitle, option1, option2, download) => { - const name = download ? 'users' : 'daa'; - return ( - - ); -}; - -const displayNameCell = (displayName, email, id, daas, handleApplyAllDaaChange, handleRemoveAllDaaChange, applyAllDaa, removeAllDaa, setResearchers) => { - const handleApplyAllDaa = async () => { - const daaList = { 'daaList': daas.map(daa => daa.daaId) }; - if (applyAllDaa) { - try { - await DAA.bulkAddDaasToUser(id, daaList); - Notifications.showSuccess({text: `Approved access to request data from all DACs to user: ${displayName}`}); - refreshResearchers(setResearchers); - } catch(error) { - Notifications.showError({text: `Error approving access to request data from all DACs to user: ${displayName}`}); - } - } else if (removeAllDaa) { - try { - await DAA.bulkRemoveDaasFromUser(id, daaList); - Notifications.showSuccess({text: `Removed approval of access to request data from all DACs from user: ${displayName}`}); - refreshResearchers(setResearchers); - } catch(error) { - Notifications.showError({text: `Error removing approval of access to request data from all DACs from user: ${displayName}`}); - } - } - }; - +const displayNameCell = (displayName, email, id, daas, setResearchers) => { return { data: ( <> @@ -184,7 +123,7 @@ const displayNameCell = (displayName, email, id, daas, handleApplyAllDaaChange, {email || '- -'} - {dropdown(applyAllDaa, removeAllDaa, handleApplyAllDaaChange, handleRemoveAllDaaChange, handleApplyAllDaa, 'Agreement Actions', 'Apply all agreements to this user', 'Remove all agreements from this user', false, false)} + ), @@ -203,8 +142,6 @@ export default function ManageResearcherDAAsTable(props) { const [filteredResearchers, setFilteredResearchers] = useState([]); const [visibleResearchers, setVisibleResearchers] = useState([]); const searchRef = useRef(''); - const [applyAllDaa, setApplyAllDaa] = useState(false); - const [removeAllDaa, setRemoveAllDaa] = useState(false); const { signingOfficial, isLoading, dacs, daas } = props; const headers = (dacs) => { @@ -230,16 +167,6 @@ export default function ManageResearcherDAAsTable(props) { ); }, [researchers]); - const handleApplyAllDaaChange = (event) => { - setApplyAllDaa(event.target.checked); - setRemoveAllDaa(!event.target.checked); - }; - - const handleRemoveAllDaaChange = (event) => { - setRemoveAllDaa(event.target.checked); - setApplyAllDaa(!event.target.checked); - }; - //init hook useEffect(() => { const init = async() => { @@ -299,7 +226,7 @@ export default function ManageResearcherDAAsTable(props) { const email = researcher.email || libraryCard.userEmail; const id = researcher.userId || email; return [ - displayNameCell(displayName, email, id, daas, handleApplyAllDaaChange, handleRemoveAllDaaChange, applyAllDaa, removeAllDaa, setResearchers), + displayNameCell(displayName, email, id, daas, setResearchers), ...dacs.map(dac => DAACell(dac, researcher, signingOfficial.institutionId, daas, refreshResearchers, setResearchers)) ]; }); diff --git a/src/pages/signing_official_console/ManageUsersDropdown.jsx b/src/pages/signing_official_console/ManageUsersDropdown.jsx new file mode 100644 index 000000000..4d73180ef --- /dev/null +++ b/src/pages/signing_official_console/ManageUsersDropdown.jsx @@ -0,0 +1,78 @@ +import React, { useState } from 'react'; +import { Button } from '@mui/material'; +import { DAA } from '../../libs/ajax/DAA'; +import { Notifications } from '../../libs/utils'; + +export default function ManageUsersDropdown(props) { + const [applyAll, setApplyAll] = useState(false); + const [removeAll, setRemoveAll] = useState(false); + const {daas, refreshResearchers, setResearchers, moreData} = props; + + const handleApplyAllChange = (event) => { + setApplyAll(event.target.checked); + setRemoveAll(!event.target.checked); + }; + + const handleRemoveAllChange = (event) => { + setRemoveAll(event.target.checked); + setApplyAll(!event.target.checked); + }; + + const handleApplyAll = async () => { + const daaList = { 'daaList': daas.map(daa => daa.daaId) }; + if (applyAll) { + try { + await DAA.bulkAddDaasToUser(moreData.id, daaList); + Notifications.showSuccess({text: `Approved access to request data from all DACs to user: ${moreData.name}`}); + refreshResearchers(setResearchers); + } catch(error) { + Notifications.showError({text: `Error approving access to request data from all DACs to user: ${moreData.name}`}); + } + } else if (removeAll) { + try { + await DAA.bulkRemoveDaasFromUser(moreData.id, daaList); + Notifications.showSuccess({text: `Removed approval of access to request data from all DACs from user: ${moreData.name}`}); + refreshResearchers(setResearchers); + } catch(error) { + Notifications.showError({text: `Error removing approval of access to request data from all DACs from user: ${moreData.name}`}); + } + } + }; + + return ( + + ); +} \ No newline at end of file