Skip to content

Commit

Permalink
Merge pull request #704 from dotkom/feat/confirmation-before-attendin…
Browse files Browse the repository at this point in the history
…g-events-after-unattend-expiry

Add confirmation before attending events you cannot unnattend
  • Loading branch information
jotjern authored Nov 10, 2023
2 parents a4808ae + 384e87e commit d26e409
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/events/components/Attendance/AttendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import { Button } from '@dotkomonline/design-system';
import { useToast } from 'core/utils/toast/useToast';
import { unwrapResult } from '@reduxjs/toolkit';
import style from './attendance.less';
import { ConfirmModal } from '../../../common/components/Modal';

interface IAttendButtonProps {
eventId: number;
isEventFull: boolean;
cannotUnattend?: boolean;
}

const AttendButton: FC<IAttendButtonProps> = (props: IAttendButtonProps) => {
const dispatch = useDispatch();
const { eventId, isEventFull } = props;
const [showModal, setShowModal] = useState<boolean>(false);
const [showConfirmModal, setShowConfirmModal] = useState<boolean>(false);
const [addToast] = useToast({ type: 'success', duration: 5000 });

const signUp = async (token: string | null) => {
Expand All @@ -31,10 +34,33 @@ const AttendButton: FC<IAttendButtonProps> = (props: IAttendButtonProps) => {
};
const toggleModal = () => setShowModal(!showModal);
const modal = <CaptchaModal showModal={showModal} toggleModal={toggleModal} setRecaptcha={signUp} />;
const onConfirmModalClose = (retValue: boolean) => {
setShowConfirmModal(false);

if (retValue) {
toggleModal();
}
};

return (
<>
<Button color={isEventFull ? 'secondary' : 'success'} onClick={toggleModal} className={style.button}>
<ConfirmModal
message="Avmeldingsfristen er utløpt så du vil ikke kunne melde deg av igjen."
title="Bekreft påmelding"
open={showConfirmModal}
onClose={onConfirmModalClose}
></ConfirmModal>
<Button
color={isEventFull ? 'secondary' : 'success'}
onClick={() => {
if (props.cannotUnattend) {
setShowConfirmModal(true);
} else {
toggleModal();
}
}}
className={style.button}
>
Meld meg på {isEventFull ? 'venteliste' : null}
</Button>
{modal}
Expand Down
8 changes: 7 additions & 1 deletion src/events/components/Attendance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ const Attendance: FC<IAttendButtonProps> = (props: IAttendButtonProps) => {
if (!canAttend.status) return <p>{canAttend.message}</p>;

// Base-case: The user is logged in and can attend!
return <AttendButton eventId={id} isEventFull={max_capacity <= number_of_seats_taken} />;
return (
<AttendButton
eventId={id}
isEventFull={max_capacity <= number_of_seats_taken}
cannotUnattend={unattendDeadline < currentTime}
/>
);
};

export default Attendance;

1 comment on commit d26e409

@vercel
Copy link

@vercel vercel bot commented on d26e409 Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.