Skip to content

Commit

Permalink
Merge pull request #8744 from CitizenLabDotCo/TAN-2515-event-confirma…
Browse files Browse the repository at this point in the history
…tion

TAN-2515 Only open modal for event references in success action
  • Loading branch information
luucvanderzee authored Aug 22, 2024
2 parents ad18b08 + a5c318c commit 7a6fc28
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
14 changes: 8 additions & 6 deletions front/app/components/EventAttendanceButton/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@ import React from 'react';

import { Box, Title, Text } from '@citizenlab/cl2-component-library';

import { IEventData } from 'api/events/types';
import useAuthUser from 'api/me/useAuthUser';

import useLocalize from 'hooks/useLocalize';

import EventSharingButtons from 'containers/EventsShowPage/components/EventSharingButtons';

import { AddEventToCalendarButton } from 'components/AddEventToCalendarButton';
import Modal from 'components/UI/Modal';

import { EventModalConfetti } from './EventModalConfetti';
import messages from './messages';

import useAuthUser from 'api/me/useAuthUser';
import { useIntl } from 'utils/cl-intl';
import { IEventData } from 'api/events/types';
import useLocalize from 'hooks/useLocalize';
import { getEventDateString } from 'utils/dateUtils';

import { EventModalConfetti } from './EventModalConfetti';
import messages from './messages';

interface Props {
opened: boolean;
event: IEventData;
Expand Down
13 changes: 10 additions & 3 deletions front/app/components/EventAttendanceButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ const EventAttendanceButton = ({ event }: EventAttendanceButtonProps) => {
const { data: phases } = usePhases(project?.data.id);
const currentPhase = getCurrentPhase(phases?.data);

const handleEventAttendanceEvent = useCallback(() => {
setConfirmationModalVisible(true);
}, []);
const handleEventAttendanceEvent = useCallback(
(eventEmitterEvent) => {
const eventId = eventEmitterEvent.eventValue;

if (eventId === event.id) {
setConfirmationModalVisible(true);
}
},
[event.id]
);

useObserveEvent('eventAttendance', handleEventAttendanceEvent);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { IEventData } from 'api/events/types';
import { IUserData } from 'api/users/types';

import { addEventAttendance } from 'api/event_attendance/useAddEventAttendance';
import eventsKeys from 'api/events/keys';
import { IEventData } from 'api/events/types';
import { addFollower } from 'api/follow_unfollow/useAddFollower';
import eventEmitter from 'utils/eventEmitter';
import { queryClient } from 'utils/cl-react-query/queryClient';

import projectsKeys from 'api/projects/keys';
import { IUserData } from 'api/users/types';

import eventsKeys from 'api/events/keys';
import { queryClient } from 'utils/cl-react-query/queryClient';
import eventEmitter from 'utils/eventEmitter';

export interface AttendEventParams {
event: IEventData;
Expand All @@ -35,6 +33,6 @@ export const attendEvent = ({ event }: AttendEventParams) => {
queryKey: eventsKeys.list({ attendeeId }),
});

eventEmitter.emit('eventAttendance');
eventEmitter.emit('eventAttendance', event.id);
};
};
11 changes: 7 additions & 4 deletions front/app/hooks/useObserveEvent.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { useEffect } from 'react';

import eventEmitter from 'utils/eventEmitter';
import eventEmitter, { IEventEmitterEvent } from 'utils/eventEmitter';

// Hook
export default (eventName: string | undefined, callBack: () => void) => {
export default (
eventName: string | undefined,
callBack: (event: IEventEmitterEvent<unknown>) => void
) => {
useEffect(() => {
if (eventName) {
const subscription = eventEmitter
.observeEvent(eventName)
.subscribe(() => {
callBack();
.subscribe((event) => {
callBack(event);
});

return () => subscription.unsubscribe();
Expand Down

0 comments on commit 7a6fc28

Please sign in to comment.