Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
import {useMutation, useQueryClient} from '@tanstack/react-query';
import {publicCheckInClient} from "../api/check-in.client";
import {GET_CHECK_IN_LIST_ATTENDEES_PUBLIC_QUERY_KEY} from "../queries/useGetCheckInListAttendeesPublic.ts";
import {GET_CHECK_IN_LIST_PUBLIC_QUERY_KEY} from "../queries/useGetCheckInListPublic.ts";
import {GET_CHECK_IN_LIST_STATS_PUBLIC_QUERY_KEY} from "../queries/useGetCheckInListStatsPublic.ts";
import {GET_CHECK_IN_LIST_ATTENDEE_DETAIL_PUBLIC_QUERY_KEY} from "../queries/useGetCheckInListAttendeeDetailPublic.ts";
import {IdParam, QueryFilters} from "../types.ts";
export const useCreateCheckInPublic = (pagination: QueryFilters) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({checkInListShortId, attendeePublicId, action}: {
checkInListShortId: IdParam,
attendeePublicId: IdParam,
action: 'check-in' | 'check-in-and-mark-order-as-paid'
}) =>
publicCheckInClient.createCheckIn(checkInListShortId, attendeePublicId, action),
onSuccess: (data, {checkInListShortId, action}) => {
const markedAsPaid = action === 'check-in-and-mark-order-as-paid';
queryClient.setQueryData(
[GET_CHECK_IN_LIST_ATTENDEES_PUBLIC_QUERY_KEY, checkInListShortId, pagination],
(oldData: any) => {
if (!oldData?.data) return oldData;
const updatedAttendee = data?.data?.find((checkIn: any) => checkIn.attendee_id);
if (!updatedAttendee) return oldData;
const updatedOrderId = updatedAttendee.order_id;
const newAttendees = oldData.data.map((attendee: any) => {
const attendeeCheckIn = data?.data?.find(
(checkIn: any) => checkIn.attendee_id === attendee.id
);
const hasError = data.errors && Object.keys(data.errors).some(
(key) => key === attendee.public_id
);
if (attendeeCheckIn) {
return {
...attendee,
check_in: attendeeCheckIn,
status: markedAsPaid && !hasError ? 'ACTIVE' : attendee.status,
};
}
// Mark all attendees with the same order_id as ACTIVE if markedAsPaid
if (markedAsPaid && attendee.order_id === updatedOrderId) {
return {
...attendee,
status: 'ACTIVE',
};
}
return attendee;
});
return {
...oldData,
data: newAttendees,
};
}
);
queryClient.invalidateQueries({
queryKey: [GET_CHECK_IN_LIST_PUBLIC_QUERY_KEY, checkInListShortId],
});
queryClient.invalidateQueries({
queryKey: [GET_CHECK_IN_LIST_STATS_PUBLIC_QUERY_KEY, checkInListShortId],
});
queryClient.invalidateQueries({
queryKey: [GET_CHECK_IN_LIST_ATTENDEE_DETAIL_PUBLIC_QUERY_KEY, checkInListShortId],
});
}
});
};