feat: add attendee detail and stats features
- Implemented API endpoints to fetch attendee details and statistics. - Created new route for fetching attendee by ID and their attendance stats. - Added schemas for attendee statistics. - Developed frontend components to display attendee details and attendance statistics. - Integrated attendee detail provider to manage state and data fetching. - Added tests for attendee retrieval and statistics calculation.
This commit is contained in:
@@ -24,9 +24,9 @@ import {
|
||||
getGroupWaitlist,
|
||||
getInviteToken,
|
||||
promoteGroupWaitlistEntry,
|
||||
removeGroupAttendee,
|
||||
removeGroupWaitlistEntry,
|
||||
} from '../../../lib/api'
|
||||
import { useRemoveAttendee } from './useRemoveAttendee'
|
||||
|
||||
export type BulkAttendeeRow = {
|
||||
firstName: string
|
||||
@@ -68,8 +68,6 @@ type GroupDetailContextValue = {
|
||||
isAddAttendeeModalOpen: boolean
|
||||
openAddAttendeeModal: () => void
|
||||
closeAddAttendeeModal: () => void
|
||||
selectedAttendee: AttendeeDto | null
|
||||
setSelectedAttendee: (attendee: AttendeeDto | null) => void
|
||||
attendeeToRemove: AttendeeDto | null
|
||||
requestRemoveAttendee: (attendee: AttendeeDto) => void
|
||||
cancelRemoveAttendee: () => void
|
||||
@@ -111,7 +109,6 @@ type GroupDetailContextValue = {
|
||||
copyInviteLink: () => Promise<void>
|
||||
copyWhatsappMessage: () => Promise<void>
|
||||
openWhatsapp: () => Promise<void>
|
||||
copyAbsenceNotifyUrl: (url: string) => void
|
||||
}
|
||||
|
||||
const GroupDetailContext = createContext<GroupDetailContextValue | null>(null)
|
||||
@@ -122,7 +119,6 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
|
||||
const [isInviteModalOpen, setIsInviteModalOpen] = useState(false)
|
||||
const [isAddAttendeeModalOpen, setIsAddAttendeeModalOpen] = useState(false)
|
||||
const [selectedAttendee, setSelectedAttendee] = useState<AttendeeDto | null>(null)
|
||||
const [activeTab, setActiveTab] = useState<AddAttendeeTab>('quick')
|
||||
const [listSection, setListSection] = useState<ListSection>('members')
|
||||
const [attendeeToRemove, setAttendeeToRemove] = useState<AttendeeDto | null>(null)
|
||||
@@ -290,30 +286,9 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
},
|
||||
})
|
||||
|
||||
const removeAttendeeMutation = useMutation({
|
||||
mutationFn: (payload: { attendeeId: string; promoteFromWaitlist: boolean }) =>
|
||||
removeGroupAttendee(groupId, payload.attendeeId, { promoteFromWaitlist: payload.promoteFromWaitlist }),
|
||||
onSuccess: (result, payload) => {
|
||||
const removedName = attendees.find((a) => a.id === payload.attendeeId)?.fullName ?? 'El miembro'
|
||||
if (result.promoted) {
|
||||
toast.success(
|
||||
`${removedName} fue quitado del grupo y ${result.promoted.fullName} pasó de la lista de espera al grupo.`,
|
||||
)
|
||||
} else {
|
||||
toast.success(`${removedName} fue quitado del grupo.`)
|
||||
}
|
||||
invalidateGroupQueries()
|
||||
setSelectedAttendee(null)
|
||||
setAttendeeToRemove(null)
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
if (err instanceof ApiError && err.problem?.code === 'attendee_has_payments') {
|
||||
toast.error(err.problem.detail ?? 'Este miembro tiene cobros asociados.')
|
||||
} else {
|
||||
toast.error(err.message || 'Error al quitar al miembro del grupo.')
|
||||
}
|
||||
setAttendeeToRemove(null)
|
||||
},
|
||||
const removeAttendeeMutation = useRemoveAttendee({
|
||||
groupId,
|
||||
onRemoved: () => setAttendeeToRemove(null),
|
||||
})
|
||||
|
||||
const promoteWaitlistMutation = useMutation({
|
||||
@@ -384,12 +359,6 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
window.open(whatsappShareUrl, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
|
||||
const copyAbsenceNotifyUrl = (url: string) => {
|
||||
void navigator.clipboard.writeText(url).then(() => {
|
||||
toast.success('Link copiado al portapapeles.')
|
||||
})
|
||||
}
|
||||
|
||||
const validRows: BulkAttendeeRow[] = useMemo(
|
||||
() =>
|
||||
parsedContacts
|
||||
@@ -453,17 +422,12 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
isAddAttendeeModalOpen,
|
||||
openAddAttendeeModal: () => setIsAddAttendeeModalOpen(true),
|
||||
closeAddAttendeeModal: () => setIsAddAttendeeModalOpen(false),
|
||||
selectedAttendee,
|
||||
setSelectedAttendee,
|
||||
attendeeToRemove,
|
||||
requestRemoveAttendee: (attendee) => setAttendeeToRemove(attendee),
|
||||
cancelRemoveAttendee: () => setAttendeeToRemove(null),
|
||||
confirmRemoveAttendee: (promoteFromWaitlist) => {
|
||||
if (!attendeeToRemove) return
|
||||
removeAttendeeMutation.mutate({
|
||||
attendeeId: attendeeToRemove.id,
|
||||
promoteFromWaitlist,
|
||||
})
|
||||
removeAttendeeMutation.removeAttendee({ attendee: attendeeToRemove, promoteFromWaitlist })
|
||||
},
|
||||
selectedWaitlistEntry,
|
||||
setSelectedWaitlistEntry,
|
||||
@@ -490,7 +454,7 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
isSubmittingForcedAttendee: createAttendeeForceMutation.isPending,
|
||||
isSubmittingWaitlistEntry: addToWaitlistMutation.isPending,
|
||||
isSubmittingBulkImport: bulkImportMutation.isPending,
|
||||
isSubmittingRemoval: removeAttendeeMutation.isPending,
|
||||
isSubmittingRemoval: removeAttendeeMutation.isRemovingAttendee,
|
||||
isSubmittingPromotion: promoteWaitlistMutation.isPending,
|
||||
isSubmittingWaitlistRemoval: removeWaitlistEntryMutation.isPending,
|
||||
isRegeneratingInvite: regenerateTokenMutation.isPending,
|
||||
@@ -522,7 +486,6 @@ export function GroupDetailProvider({ groupId, children }: { groupId: string; ch
|
||||
copyInviteLink,
|
||||
copyWhatsappMessage,
|
||||
openWhatsapp,
|
||||
copyAbsenceNotifyUrl,
|
||||
}
|
||||
|
||||
return <GroupDetailContext.Provider value={value}>{children}</GroupDetailContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user