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

Enable remindAll button even after event start. #2532

Open
wants to merge 1 commit into
base: main
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
66 changes: 16 additions & 50 deletions src/features/events/components/ParticipantSummaryCard.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import {
Box,
Button,
CircularProgress,
ClickAwayListener,
Paper,
Popper,
TextField,
Tooltip,
Typography,
} from '@mui/material';
import { Check, PriorityHigh, Settings } from '@mui/icons-material';
import { Check, Settings } from '@mui/icons-material';
import { FC, useState } from 'react';

import messageIds from 'features/events/l10n/messageIds';
import { removeOffset } from 'utils/dateUtils';
import { useAppSelector } from 'core/hooks';
import useEvent from '../hooks/useEvent';
import useEventParticipants from '../hooks/useEventParticipants';
import useEventParticipantsMutations from '../hooks/useEventParticipantsMutations';
import useParticipantStatus from '../hooks/useParticipantsStatus';
import ZUICard from 'zui/ZUICard';
import ZUINumberChip from 'zui/ZUINumberChip';
import { Msg, useMessages } from 'core/i18n';
import RemindAllToolbox from './RemindAllBox';

type ParticipantSummaryCardProps = {
eventId: number;
Expand Down Expand Up @@ -67,10 +65,6 @@ const ParticipantSummaryCard: FC<ParticipantSummaryCardProps> = ({
null | (EventTarget & SVGSVGElement)
>(null);

const isRemindingParticipants = useAppSelector(
(state) => state.events.remindingByEventId[eventId]
);

if (!event) {
return null;
}
Expand Down Expand Up @@ -186,48 +180,12 @@ const ParticipantSummaryCard: FC<ParticipantSummaryCardProps> = ({
</Typography>
<Box alignItems="center" display="flex">
<Typography variant="h4">{`${numRemindedParticipants}/${numAvailParticipants}`}</Typography>
<Tooltip
arrow
placement="top-start"
title={
contactPerson == null
? messages.participantSummaryCard.remindButtondisabledTooltip()
: ''
}
>
<Box>
<Button
disabled={
contactPerson == null ||
isRemindingParticipants ||
numRemindedParticipants >= numAvailParticipants
}
onClick={() => {
sendReminders(eventId);
}}
size="small"
startIcon={
contactPerson ? (
isRemindingParticipants ? (
<CircularProgress size={20} />
) : (
<Check />
)
) : (
<PriorityHigh />
)
}
sx={{
marginLeft: 2,
}}
variant="outlined"
>
<Msg
id={messageIds.participantSummaryCard.remindButton}
/>
</Button>
</Box>
</Tooltip>
<RemindAllToolbox
contactPerson={contactPerson}
eventId={eventId}
orgId={orgId}
sendReminders={sendReminders}
/>
</Box>
</Box>
) : (
Expand All @@ -249,6 +207,14 @@ const ParticipantSummaryCard: FC<ParticipantSummaryCardProps> = ({
})}
</Typography>
)}
{new Date(removeOffset(event.end_time)) > new Date() && (
<RemindAllToolbox
contactPerson={contactPerson}
eventId={eventId}
orgId={orgId}
sendReminders={sendReminders}
/>
)}
{!hasRecordedAttendance && (
<Box ml={2}>
<Button
Expand Down
75 changes: 75 additions & 0 deletions src/features/events/components/RemindAllBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { FC } from 'react';
import { Check, PriorityHigh } from '@mui/icons-material';
import { Box, Button, CircularProgress, Tooltip } from '@mui/material';

import { Msg, useMessages } from 'core/i18n';
import { useAppSelector } from 'core/hooks';
import messageIds from 'features/events/l10n/messageIds';
import useEventParticipants from '../hooks/useEventParticipants';

interface RemindAllToolboxProps {
contactPerson?: null | { id: number; name: string };
eventId: number;
orgId: number;
sendReminders: (eventId: number) => void;
}

const RemindAllToolbox: FC<RemindAllToolboxProps> = ({
contactPerson,
eventId,
orgId,
sendReminders,
}) => {
const isRemindingParticipants = useAppSelector(
(state) => state.events.remindingByEventId[eventId]
);

const { numAvailParticipants, numRemindedParticipants } =
useEventParticipants(orgId, eventId);

const messages = useMessages(messageIds);

return (
<Tooltip
arrow
placement="top-start"
title={
contactPerson == null
? messages.participantSummaryCard.remindButtondisabledTooltip()
: ''
}
>
<Box>
<Button
disabled={
contactPerson == null ||
isRemindingParticipants ||
numRemindedParticipants >= numAvailParticipants
}
onClick={() => {
sendReminders(eventId);
}}
size="small"
startIcon={
contactPerson ? (
isRemindingParticipants ? (
<CircularProgress size={20} />
) : (
<Check />
)
) : (
<PriorityHigh />
)
}
sx={{
marginLeft: 2,
}}
variant="outlined"
>
<Msg id={messageIds.participantSummaryCard.remindButton} />
</Button>
</Box>
</Tooltip>
);
};
export default RemindAllToolbox;
Loading