Skip to content

Commit 05ae92c

Browse files
authored
Merge pull request #2665 from objectcomputing/bugfix-2660/volunteer-tracking
Moved permission checking out of the VolunteerTables
2 parents 8063be0 + 48803b3 commit 05ae92c

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

web-ui/src/components/volunteer/VolunteerEvents.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import DatePickerField from '../date-picker-field/DatePickerField';
1919
import ConfirmationDialog from '../dialogs/ConfirmationDialog';
2020
import OrganizationDialog from '../dialogs/OrganizationDialog'; // Include OrganizationDialog
2121
import { AppContext } from '../../context/AppContext';
22-
import { selectCsrfToken, selectCurrentUser, selectProfileMap } from '../../context/selectors';
22+
import {
23+
selectCsrfToken,
24+
selectCurrentUser,
25+
selectProfileMap,
26+
selectHasVolunteeringEventsPermission,
27+
} from '../../context/selectors';
2328
import { formatDate } from '../../helpers/datetime';
2429

2530
const eventBaseUrl = '/services/volunteer/event';
@@ -322,6 +327,9 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
322327
<td>{event.hours}</td>
323328
<td>{event.notes}</td>
324329
<td>
330+
{(member.id == currentUser.id ||
331+
selectHasVolunteeringEventsPermission(state)) &&
332+
<>
325333
<Tooltip title="Edit">
326334
<IconButton aria-label="Edit" onClick={() => editEvent(event)}>
327335
<Edit />
@@ -332,6 +340,7 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
332340
<Delete />
333341
</IconButton>
334342
</Tooltip>
343+
</>}
335344
</td>
336345
</tr>
337346
);
@@ -362,9 +371,10 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
362371
</thead>
363372
<tbody>{events.map(eventRow)}</tbody>
364373
</table>
374+
{(onlyMe || selectHasVolunteeringEventsPermission(state)) &&
365375
<IconButton aria-label="Add Volunteer Event" classes={{ root: 'add-button' }} onClick={addEvent}>
366376
<AddCircleOutline />
367-
</IconButton>
377+
</IconButton>}
368378
</div>
369379
);
370380
}, [events, organizationMap, profileMap, relationshipMap, sortAscending, sortColumn]);
@@ -536,4 +546,4 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
536546

537547
VolunteerEvents.propTypes = propTypes;
538548

539-
export default VolunteerEvents;
549+
export default VolunteerEvents;

web-ui/src/components/volunteer/VolunteerRelationships.jsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import DatePickerField from '../date-picker-field/DatePickerField';
1919
import ConfirmationDialog from '../dialogs/ConfirmationDialog';
2020
import OrganizationDialog from '../dialogs/OrganizationDialog';
2121
import { AppContext } from '../../context/AppContext';
22-
import { selectCsrfToken, selectCurrentUser, selectProfileMap } from '../../context/selectors';
22+
import {
23+
selectCsrfToken,
24+
selectCurrentUser,
25+
selectProfileMap,
26+
selectHasVolunteeringRelationshipsPermission,
27+
selectHasVolunteeringOrganizationsPermission,
28+
} from '../../context/selectors';
2329
import { formatDate } from '../../helpers/datetime';
2430
import { showError } from '../../helpers/toast';
2531

@@ -279,6 +285,11 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
279285
[sortAscending, sortColumn]
280286
);
281287

288+
const organizationOptions = Object.keys(organizationMap);
289+
if (selectHasVolunteeringOrganizationsPermission(state)) {
290+
organizationOptions.unshift('new');
291+
}
292+
282293
return (
283294
<div id="volunteer-relationships">
284295
{/* Table for showing relationships */}
@@ -311,6 +322,9 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
311322
<td>{relationship.startDate}</td>
312323
<td>{relationship.endDate}</td>
313324
<td>
325+
{(relationship.memberId == currentUser.id ||
326+
selectHasVolunteeringRelationshipsPermission(state)) &&
327+
<>
314328
<Tooltip title="Edit">
315329
<IconButton
316330
aria-label="Edit"
@@ -330,17 +344,19 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
330344
<Delete />
331345
</IconButton>
332346
</Tooltip>
347+
</>}
333348
</td>
334349
</tr>
335350
))}
336351
</tbody>
337352
</table>
353+
{(onlyMe || selectHasVolunteeringRelationshipsPermission(state)) &&
338354
<IconButton
339355
aria-label="Add Volunteer Relationship"
340356
onClick={addRelationship}
341357
>
342358
<AddCircleOutline />
343-
</IconButton>
359+
</IconButton>}
344360
</div>
345361

346362
{/* Message below the table */}
@@ -357,7 +373,7 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
357373
getOptionLabel={(option) =>
358374
option === 'new' ? 'Create a New Organization' : organizationMap[option]?.name || option
359375
}
360-
options={['new', ...Object.keys(organizationMap)]}
376+
options={organizationOptions}
361377
onChange={(event, value) => {
362378
if (value === 'new') {
363379
setRelationshipDialogOpen(false); // Close the relationship dialog

web-ui/src/components/volunteer/VolunteerTables.jsx

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import PropTypes from 'prop-types';
22
import React, { useContext, useReducer, useState } from 'react';
33
import { Box, Tab, Tabs, Typography, Card, CardHeader, CardContent, Avatar } from '@mui/material';
44

5-
import {
6-
selectHasVolunteeringEventsPermission,
7-
selectHasVolunteeringRelationshipsPermission,
8-
noPermission,
9-
} from '../../context/selectors';
105
import { AppContext } from '../../context/AppContext';
116

127
import Organizations from './Organizations';
@@ -50,14 +45,7 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
5045
const [n, forceUpdate] = useReducer(n => n + 1, 0);
5146
const [tabIndex, setTabIndex] = useState(0);
5247

53-
// React requires that tabs be sequentially numbered. Use these to ensure
54-
// that each tab coinsides with the correct tab content based on the
55-
// individual permissions.
56-
let tabCount = 0;
57-
let tabContent = 0;
58-
59-
return (selectHasVolunteeringEventsPermission(state) ||
60-
selectHasVolunteeringRelationshipsPermission(state)) ? (
48+
return (
6149
<Card className="volunteer-activities-card">
6250
<CardContent className="volunteer-tables">
6351
<Tabs
@@ -67,7 +55,7 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
6755
value={tabIndex}
6856
variant="fullWidth"
6957
>
70-
{selectHasVolunteeringRelationshipsPermission(state) && <Tab
58+
<Tab
7159
label={
7260
<Box sx={{ display: 'flex', alignItems: 'center' }}>
7361
<Avatar sx={{ mr: 1 }}>
@@ -76,13 +64,13 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
7664
<Typography textTransform="none" variant='h5' component='h2'>Volunteer Orgs</Typography>
7765
</Box>
7866
}
79-
{...a11yProps(tabCount++)}
67+
{...a11yProps(0)}
8068
sx={{
8169
minWidth: '150px',
8270
whiteSpace: 'nowrap'
8371
}}
84-
/>}
85-
{selectHasVolunteeringEventsPermission(state) && <Tab
72+
/>
73+
<Tab
8674
label={
8775
<Box sx={{ display: 'flex', alignItems: 'center' }}>
8876
<Avatar sx={{ mr: 1 }}>
@@ -91,31 +79,29 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
9179
<Typography textTransform="none" variant='h5' component='h2'>Events</Typography>
9280
</Box>
9381
}
94-
{...a11yProps(tabCount++)}
82+
{...a11yProps(1)}
9583
sx={{
9684
minWidth: '150px',
9785
whiteSpace: 'nowrap'
9886
}}
99-
/>}
87+
/>
10088
</Tabs>
101-
{selectHasVolunteeringRelationshipsPermission(state) && <TabPanel index={tabContent++} value={tabIndex}>
89+
<TabPanel index={0} value={tabIndex}>
10290
<VolunteerRelationships
10391
forceUpdate={forceUpdate}
10492
key={'vr' + n}
10593
onlyMe={onlyMe}
10694
/>
107-
</TabPanel>}
108-
{selectHasVolunteeringEventsPermission(state) && <TabPanel index={tabContent++} value={tabIndex}>
95+
</TabPanel>
96+
<TabPanel index={1} value={tabIndex}>
10997
<VolunteerEvents
11098
forceUpdate={forceUpdate}
11199
key={'vh' + n}
112100
onlyMe={onlyMe}
113101
/>
114-
</TabPanel>}
102+
</TabPanel>
115103
</CardContent>
116104
</Card>
117-
) : (
118-
<h3>{noPermission}</h3>
119105
);
120106
};
121107

0 commit comments

Comments
 (0)