Skip to content

Commit

Permalink
Revert "Prevent to reserve seats or signup is enrolment is not open"
Browse files Browse the repository at this point in the history
This reverts commit adeed9b.
  • Loading branch information
jorilindell committed Jun 14, 2023
1 parent adeed9b commit 0168338
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 340 deletions.
1 change: 0 additions & 1 deletion public/locales/en/enrolment.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"titleNotifications": "Event notifications",
"titleRegistration": "Registration",
"warnings": {
"allSeatsReserved": "All seats in the event are currently booked. Please try again later.",
"capacityInWaitingList": "Registration for this event is still possible, but there are only {{count}} seat left in the queue.",
"capacityInWaitingList_other": "Registration for this event is still possible, but there are only {{count}} seats left in the queue.",
"capacityInWaitingListNoLimit": "Registration for this event is still possible, but there are only seats left in the queue.",
Expand Down
1 change: 0 additions & 1 deletion public/locales/fi/enrolment.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"titleNotifications": "Tapahtumaa koskevat ilmoitukset",
"titleRegistration": "Ilmoittautuminen",
"warnings": {
"allSeatsReserved": "Tapahtuman kaikki paikat ovat tällä hetkellä varatut. Kokeile myöhemmin uudelleen.",
"capacityInWaitingList": "Ilmoittautuminen tähän tapahtumaan on vielä mahdollista, mutta jonopaikkoja on jäljellä vain {{count}} kpl.",
"capacityInWaitingList_other": "Ilmoittautuminen tähän tapahtumaan on vielä mahdollista, mutta jonopaikkoja on jäljellä vain {{count}} kpl.",
"capacityInWaitingListNoLimit": "Ilmoittautuminen tähän tapahtumaan on vielä mahdollista, mutta vain jonopaikkoja on jäljellä.",
Expand Down
1 change: 0 additions & 1 deletion public/locales/sv/enrolment.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"titleNotifications": "Evenemangmeddelanden",
"titleRegistration": "Registrering",
"warnings": {
"allSeatsReserved": "Alla platser i evenemanget är för närvarande bokade. Vänligen försök igen senare.",
"capacityInWaitingList": "Registrering för detta evenemang är fortfarande möjligt, men det är bara {{count}} plats kvar i kön.",
"capacityInWaitingList_other": "Registrering för detta evenemang är fortfarande möjligt, men det är bara {{count}} platser kvar i kön.",
"capacityInWaitingListNoLimit": "Registrering till detta evenemang är fortfarande möjlig, men det finns endast platser kvar i kön.",
Expand Down
16 changes: 4 additions & 12 deletions src/domain/enrolment/enrolmentForm/EnrolmentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IconCross, SingleSelectProps } from 'hds-react';
import pick from 'lodash/pick';
import { useTranslation } from 'next-i18next';
import { useRouter } from 'next/router';
import React, { useMemo } from 'react';
import React from 'react';
import { ValidationError } from 'yup';
import 'react-toastify/dist/ReactToastify.css';

Expand Down Expand Up @@ -92,19 +92,11 @@ const EnrolmentForm: React.FC<Props> = ({
useEnrolmentPageContext();

const notificationOptions = useNotificationOptions();
const formDisabled = !isRegistrationPossible(registration);
const locale = useLocale();
const router = useRouter();
const { query } = router;

const formDisabled = useMemo(() => {
const data = getSeatsReservationData(registration.id as string);
if (data && !isSeatsReservationExpired(data)) {
return false;
}

return !isRegistrationPossible(registration);
}, [registration]);

const { serverErrorItems, setServerErrorItems, showServerErrors } =
useEnrolmentServerErrorsContext();

Expand Down Expand Up @@ -206,7 +198,7 @@ const EnrolmentForm: React.FC<Props> = ({
<ServerErrorSummary errors={serverErrorItems} />
<RegistrationWarning registration={registration} />

{isRegistrationPossible(registration) && !readOnly && (
{!readOnly && (
<>
<Divider />
<ReservationTimer
Expand All @@ -215,7 +207,7 @@ const EnrolmentForm: React.FC<Props> = ({
reservationTimerCallbacksDisabled.current
}
disableCallbacks={disableReservationTimerCallbacks}
initReservationData={true}
initReservationData={!enrolment}
registration={registration}
setAttendees={setAttendees}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { useTranslation } from 'next-i18next';
import { FC, useMemo } from 'react';
import { FC } from 'react';

import { Registration } from '../../../registration/types';
import {
getFreeAttendeeCapacity,
getFreeWaitingListCapacity,
isAttendeeCapacityUsed,
} from '../../../registration/utils';
import {
getSeatsReservationData,
isSeatsReservationExpired,
} from '../../../reserveSeats/utils';

type Props = {
registration: Registration;
Expand All @@ -22,22 +18,17 @@ const AvailableSeatsText: FC<Props> = ({ registration }) => {
const attendeeCapacityUsed = isAttendeeCapacityUsed(registration);
const freeWaitingListCapacity = getFreeWaitingListCapacity(registration);

const reservedSeats = useMemo(() => {
const data = getSeatsReservationData(registration.id as string);
return data && !isSeatsReservationExpired(data) ? data.seats : 0;
}, [registration.id]);
return (
<>
{typeof freeAttendeeCapacity === 'number' && !attendeeCapacityUsed && (
<p>
{t('freeAttendeeCapacity')}{' '}
<strong>{freeAttendeeCapacity + reservedSeats}</strong>
{t('freeAttendeeCapacity')} <strong>{freeAttendeeCapacity}</strong>
</p>
)}
{attendeeCapacityUsed && typeof freeWaitingListCapacity === 'number' && (
<p>
{t('freeWaitingListCapacity')}{' '}
<strong>{freeWaitingListCapacity + reservedSeats}</strong>
<strong>{freeWaitingListCapacity}</strong>
</p>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
import React from 'react';

import { RESERVATION_NAMES } from '../../../../../constants';
import {
fakeRegistration,
getMockedSeatsReservationData,
} from '../../../../../utils/mockDataUtils';
import { fakeRegistration } from '../../../../../utils/mockDataUtils';
import { configure, render, screen } from '../../../../../utils/testUtils';
import { TEST_REGISTRATION_ID } from '../../../../registration/constants';
import { Registration } from '../../../../registration/types';
import { SeatsReservation } from '../../../../reserveSeats/types';
import AvailableSeatsText from '../AvailableSeatsText';

configure({ defaultHidden: true });

const renderComponent = (registration: Registration) =>
render(<AvailableSeatsText registration={registration} />);

const setSessionStorageValues = (reservation: SeatsReservation) => {
jest.spyOn(sessionStorage, 'getItem').mockImplementation((key: string) => {
switch (key) {
case `${RESERVATION_NAMES.ENROLMENT_RESERVATION}-${TEST_REGISTRATION_ID}`:
return reservation ? JSON.stringify(reservation) : '';
default:
return '';
}
});
};

test('should show amount of free seats', () => {
test('should show amount of free seats ', () => {
renderComponent(
fakeRegistration({
maximum_attendee_capacity: 10,
Expand All @@ -40,7 +23,7 @@ test('should show amount of free seats', () => {
screen.getByText('7');
});

test('should show amount of remaining seats', () => {
test('should show amount of remaining seats ', () => {
renderComponent(
fakeRegistration({
maximum_attendee_capacity: 10,
Expand All @@ -53,22 +36,6 @@ test('should show amount of remaining seats', () => {
screen.getByText('0');
});

test('should show amount of remaining seats if there ia reservation stored to session storage', () => {
const reservation = getMockedSeatsReservationData(1000);
setSessionStorageValues(reservation);
renderComponent(
fakeRegistration({
id: TEST_REGISTRATION_ID,
maximum_attendee_capacity: 10,
current_attendee_count: 3,
remaining_attendee_capacity: 0,
})
);

screen.getByText('Saatavilla olevia paikkoja');
screen.getByText(reservation.seats);
});

test('should show amount of free waiting list seats', () => {
renderComponent(
fakeRegistration({
Expand Down Expand Up @@ -100,22 +67,3 @@ test('should show amount of remaining waiting list seats ', () => {
screen.getByText('Saatavilla olevia jonopaikkoja');
screen.getByText('0');
});

test('should show amount of remaining waiting list seats if there ia reservation stored to session storage', () => {
const reservation = getMockedSeatsReservationData(1000);
setSessionStorageValues(reservation);
renderComponent(
fakeRegistration({
id: TEST_REGISTRATION_ID,
maximum_attendee_capacity: 10,
current_attendee_count: 10,
current_waiting_list_count: 3,
remaining_attendee_capacity: 0,
remaining_waiting_list_capacity: 0,
waiting_list_capacity: 10,
})
);

screen.getByText('Saatavilla olevia jonopaikkoja');
screen.getByText(reservation.seats);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useField } from 'formik';
import { useTranslation } from 'next-i18next';
import React, { useMemo, useState } from 'react';
import React, { useState } from 'react';

import Button from '../../../common/components/button/Button';
import NumberInput from '../../../common/components/numberInput/NumberInput';
Expand All @@ -9,10 +9,7 @@ import {
getAttendeeCapacityError,
getFreeAttendeeOrWaitingListCapacity,
} from '../../registration/utils';
import {
getSeatsReservationData,
isSeatsReservationExpired,
} from '../../reserveSeats/utils';
import { getSeatsReservationData } from '../../reserveSeats/utils';
import { ENROLMENT_FIELDS, ENROLMENT_MODALS } from '../constants';
import { useEnrolmentPageContext } from '../enrolmentPageContext/hooks/useEnrolmentPageContext';
import { useEnrolmentServerErrorsContext } from '../enrolmentServerErrorsContext/hooks/useEnrolmentServerErrorsContext';
Expand Down Expand Up @@ -58,17 +55,7 @@ const ParticipantAmountSelector: React.FC<Props> = ({
t
);

const reservedSeats = useMemo(() => {
const data = getSeatsReservationData(registration.id as string);
return data && !isSeatsReservationExpired(data) ? data.seats : 0;
}, [registration.id]);

const maxSeatAmount = useMemo(() => {
const freeCapacity = getFreeAttendeeOrWaitingListCapacity(registration);
return freeCapacity !== undefined
? freeCapacity + reservedSeats
: /* istanbul ignore next */ undefined;
}, [registration, reservedSeats]);
const maxSeatAmount = getFreeAttendeeOrWaitingListCapacity(registration);

const { saving, updateSeatsReservation } = useSeatsReservationActions({
attendees,
Expand Down
13 changes: 2 additions & 11 deletions src/domain/enrolment/registrationWarning/RegistrationWarning.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Notification } from 'hds-react';
import { useTranslation } from 'next-i18next';
import React, { useMemo } from 'react';
import React from 'react';

import { Registration } from '../../registration/types';
import { getRegistrationWarning } from '../../registration/utils';
import {
getSeatsReservationData,
isSeatsReservationExpired,
} from '../../reserveSeats/utils';
import styles from './registrationWarning.module.scss';

type Props = {
Expand All @@ -18,12 +14,7 @@ const RegistrationWarning: React.FC<Props> = ({ registration }) => {
const { t } = useTranslation(['enrolment']);
const registrationWarning = getRegistrationWarning(registration, t);

const hasReservation = useMemo(() => {
const data = getSeatsReservationData(registration.id as string);
return Boolean(data && !isSeatsReservationExpired(data));
}, [registration.id]);

return registrationWarning && !hasReservation ? (
return registrationWarning ? (
<Notification className={styles.warning}>
{registrationWarning}
</Notification>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,30 @@ import addDays from 'date-fns/addDays';
import subDays from 'date-fns/subDays';
import React from 'react';

import { RESERVATION_NAMES } from '../../../../constants';
import {
fakeRegistration,
getMockedSeatsReservationData,
} from '../../../../utils/mockDataUtils';
import { fakeRegistration } from '../../../../utils/mockDataUtils';
import { render, screen } from '../../../../utils/testUtils';
import { TEST_REGISTRATION_ID } from '../../../registration/constants';
import { Registration } from '../../../registration/types';
import { SeatsReservation } from '../../../reserveSeats/types';
import RegistrationWarning from '../RegistrationWarning';

const renderComponent = (registration: Registration) =>
render(<RegistrationWarning registration={registration} />);

const now = new Date();
const enrolment_start_time = subDays(now, 1).toISOString();
const enrolment_end_time = addDays(now, 1).toISOString();
const registration = fakeRegistration({
current_attendee_count: 10,
current_waiting_list_count: 5,
enrolment_end_time,
enrolment_start_time,
id: TEST_REGISTRATION_ID,
maximum_attendee_capacity: 10,
waiting_list_capacity: 5,
});

const setSessionStorageValues = (reservation: SeatsReservation) => {
jest.spyOn(sessionStorage, 'getItem').mockImplementation((key: string) => {
switch (key) {
case `${RESERVATION_NAMES.ENROLMENT_RESERVATION}-${TEST_REGISTRATION_ID}`:
return reservation ? JSON.stringify(reservation) : '';
default:
return '';
}
test('should show warning if registration is full', async () => {
const now = new Date();
const enrolment_start_time = subDays(now, 1).toISOString();
const enrolment_end_time = addDays(now, 1).toISOString();
const registration = fakeRegistration({
current_attendee_count: 10,
current_waiting_list_count: 5,
enrolment_end_time,
enrolment_start_time,
maximum_attendee_capacity: 10,
waiting_list_capacity: 5,
});
};

test('should show warning if registration is full', async () => {
renderComponent(registration);

await screen.getByText(
'Tapahtuman kaikki paikat ovat tällä hetkellä varatut. Kokeile myöhemmin uudelleen.'
screen.getByText(
'Ilmoittautuminen tähän tapahtumaan on tällä hetkellä suljettu. Kokeile myöhemmin uudelleen.'
);
});

test('should not show warning if registration is full but user has reservation', async () => {
const reservation = getMockedSeatsReservationData(1000);
setSessionStorageValues(reservation);
renderComponent(registration);

expect(
screen.queryByText(
'Tapahtuman kaikki paikat ovat tällä hetkellä varatut. Kokeile myöhemmin uudelleen.'
)
).not.toBeInTheDocument();
});
Loading

0 comments on commit 0168338

Please sign in to comment.