-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate out ManageUsersDropdown
- Loading branch information
1 parent
633566f
commit 1b1c1d7
Showing
3 changed files
with
84 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/pages/signing_official_console/ManageUsersDropdown.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<ul className="dropdown-menu" role="menu" style={{ padding: '20px', textTransform:'none'}}> | ||
<th id="link_signOut" style={{display:'flex', padding: '5px', textAlign: 'left'}}> | ||
<strong>Agreement Actions</strong> | ||
</th> | ||
<form> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<label style={{fontWeight: 'normal', whiteSpace: 'nowrap'}}> | ||
<input type="radio" name="users" value="apply" checked={applyAll} onChange={handleApplyAllChange}/> | ||
Apply all agreements to this user | ||
</label> | ||
</li> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<label style={{fontWeight: 'normal', whiteSpace: 'nowrap' }}> | ||
<input type="radio" name="users" value="remove" checked={removeAll} onChange={handleRemoveAllChange}/> | ||
Remove all agreements from this user | ||
</label> | ||
</li> | ||
</form> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<Button style={{ | ||
fontSize: '15px', | ||
fontWeight: 'normal', | ||
fontFamily: 'Montserrat', | ||
border: '1px solid #0948B7', | ||
borderRadius: '5px', | ||
height: '40px', | ||
marginRight: '1em', | ||
cursor: 'pointer', | ||
color: '#0948B7', | ||
padding: '10px 20px', | ||
textTransform: 'none' | ||
}} onClick={() => handleApplyAll()}>Apply</Button> | ||
</li> | ||
</ul> | ||
); | ||
} |