Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved permission checking out of the VolunteerTables #2665

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions web-ui/src/components/volunteer/VolunteerEvents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import DatePickerField from '../date-picker-field/DatePickerField';
import ConfirmationDialog from '../dialogs/ConfirmationDialog';
import OrganizationDialog from '../dialogs/OrganizationDialog'; // Include OrganizationDialog
import { AppContext } from '../../context/AppContext';
import { selectCsrfToken, selectCurrentUser, selectProfileMap } from '../../context/selectors';
import {
selectCsrfToken,
selectCurrentUser,
selectProfileMap,
selectHasVolunteeringEventsPermission,
} from '../../context/selectors';
import { formatDate } from '../../helpers/datetime';

const eventBaseUrl = '/services/volunteer/event';
Expand Down Expand Up @@ -322,6 +327,9 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
<td>{event.hours}</td>
<td>{event.notes}</td>
<td>
{(member.id == currentUser.id ||
selectHasVolunteeringEventsPermission(state)) &&
<>
<Tooltip title="Edit">
<IconButton aria-label="Edit" onClick={() => editEvent(event)}>
<Edit />
Expand All @@ -332,6 +340,7 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
<Delete />
</IconButton>
</Tooltip>
</>}
</td>
</tr>
);
Expand Down Expand Up @@ -362,9 +371,10 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {
</thead>
<tbody>{events.map(eventRow)}</tbody>
</table>
{(onlyMe || selectHasVolunteeringEventsPermission(state)) &&
<IconButton aria-label="Add Volunteer Event" classes={{ root: 'add-button' }} onClick={addEvent}>
<AddCircleOutline />
</IconButton>
</IconButton>}
</div>
);
}, [events, organizationMap, profileMap, relationshipMap, sortAscending, sortColumn]);
Expand Down Expand Up @@ -536,4 +546,4 @@ const VolunteerEvents = ({ forceUpdate = () => {}, onlyMe = false }) => {

VolunteerEvents.propTypes = propTypes;

export default VolunteerEvents;
export default VolunteerEvents;
22 changes: 19 additions & 3 deletions web-ui/src/components/volunteer/VolunteerRelationships.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import DatePickerField from '../date-picker-field/DatePickerField';
import ConfirmationDialog from '../dialogs/ConfirmationDialog';
import OrganizationDialog from '../dialogs/OrganizationDialog';
import { AppContext } from '../../context/AppContext';
import { selectCsrfToken, selectCurrentUser, selectProfileMap } from '../../context/selectors';
import {
selectCsrfToken,
selectCurrentUser,
selectProfileMap,
selectHasVolunteeringRelationshipsPermission,
selectHasVolunteeringOrganizationsPermission,
} from '../../context/selectors';
import { formatDate } from '../../helpers/datetime';
import { showError } from '../../helpers/toast';

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

const organizationOptions = Object.keys(organizationMap);
if (selectHasVolunteeringOrganizationsPermission(state)) {
organizationOptions.unshift('new');
}

return (
<div id="volunteer-relationships">
{/* Table for showing relationships */}
Expand Down Expand Up @@ -311,6 +322,9 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
<td>{relationship.startDate}</td>
<td>{relationship.endDate}</td>
<td>
{(relationship.memberId == currentUser.id ||
selectHasVolunteeringRelationshipsPermission(state)) &&
<>
<Tooltip title="Edit">
<IconButton
aria-label="Edit"
Expand All @@ -330,17 +344,19 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
<Delete />
</IconButton>
</Tooltip>
</>}
</td>
</tr>
))}
</tbody>
</table>
{(onlyMe || selectHasVolunteeringRelationshipsPermission(state)) &&
<IconButton
aria-label="Add Volunteer Relationship"
onClick={addRelationship}
>
<AddCircleOutline />
</IconButton>
</IconButton>}
</div>

{/* Message below the table */}
Expand All @@ -357,7 +373,7 @@ const VolunteerRelationships = ({ forceUpdate = () => {}, onlyMe = false }) => {
getOptionLabel={(option) =>
option === 'new' ? 'Create a New Organization' : organizationMap[option]?.name || option
}
options={['new', ...Object.keys(organizationMap)]}
options={organizationOptions}
onChange={(event, value) => {
if (value === 'new') {
setRelationshipDialogOpen(false); // Close the relationship dialog
Expand Down
36 changes: 11 additions & 25 deletions web-ui/src/components/volunteer/VolunteerTables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import PropTypes from 'prop-types';
import React, { useContext, useReducer, useState } from 'react';
import { Box, Tab, Tabs, Typography, Card, CardHeader, CardContent, Avatar } from '@mui/material';

import {
selectHasVolunteeringEventsPermission,
selectHasVolunteeringRelationshipsPermission,
noPermission,
} from '../../context/selectors';
import { AppContext } from '../../context/AppContext';

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

// React requires that tabs be sequentially numbered. Use these to ensure
// that each tab coinsides with the correct tab content based on the
// individual permissions.
let tabCount = 0;
let tabContent = 0;

return (selectHasVolunteeringEventsPermission(state) ||
selectHasVolunteeringRelationshipsPermission(state)) ? (
return (
<Card className="volunteer-activities-card">
<CardContent className="volunteer-tables">
<Tabs
Expand All @@ -67,7 +55,7 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
value={tabIndex}
variant="fullWidth"
>
{selectHasVolunteeringRelationshipsPermission(state) && <Tab
<Tab
label={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Avatar sx={{ mr: 1 }}>
Expand All @@ -76,13 +64,13 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
<Typography textTransform="none" variant='h5' component='h2'>Volunteer Orgs</Typography>
</Box>
}
{...a11yProps(tabCount++)}
{...a11yProps(0)}
sx={{
minWidth: '150px',
whiteSpace: 'nowrap'
}}
/>}
{selectHasVolunteeringEventsPermission(state) && <Tab
/>
<Tab
label={
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Avatar sx={{ mr: 1 }}>
Expand All @@ -91,31 +79,29 @@ const VolunteerReportPage = ({ onlyMe = false }) => {
<Typography textTransform="none" variant='h5' component='h2'>Events</Typography>
</Box>
}
{...a11yProps(tabCount++)}
{...a11yProps(1)}
sx={{
minWidth: '150px',
whiteSpace: 'nowrap'
}}
/>}
/>
</Tabs>
{selectHasVolunteeringRelationshipsPermission(state) && <TabPanel index={tabContent++} value={tabIndex}>
<TabPanel index={0} value={tabIndex}>
<VolunteerRelationships
forceUpdate={forceUpdate}
key={'vr' + n}
onlyMe={onlyMe}
/>
</TabPanel>}
{selectHasVolunteeringEventsPermission(state) && <TabPanel index={tabContent++} value={tabIndex}>
</TabPanel>
<TabPanel index={1} value={tabIndex}>
<VolunteerEvents
forceUpdate={forceUpdate}
key={'vh' + n}
onlyMe={onlyMe}
/>
</TabPanel>}
</TabPanel>
</CardContent>
</Card>
) : (
<h3>{noPermission}</h3>
);
};

Expand Down
Loading