2022-09-21 14:27:53 -07:00
import React , { useEffect } from 'react' ;
import { FormattedMessage } from 'react-intl' ;
import { fetchEventParticipations } from 'soapbox/actions/events' ;
2023-01-07 03:24:18 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
import { Modal , Spinner } from 'soapbox/components/ui' ;
2022-11-26 11:25:48 -08:00
import AccountContainer from 'soapbox/containers/account-container' ;
2022-09-21 14:27:53 -07:00
import { useAppDispatch , useAppSelector } from 'soapbox/hooks' ;
interface IEventParticipantsModal {
2023-02-15 13:26:27 -08:00
onClose : ( type : string ) = > void
statusId : string
2022-09-21 14:27:53 -07:00
}
const EventParticipantsModal : React.FC < IEventParticipantsModal > = ( { onClose , statusId } ) = > {
const dispatch = useAppDispatch ( ) ;
const accountIds = useAppSelector ( ( state ) = > state . user_lists . event_participations . get ( statusId ) ? . items ) ;
const fetchData = ( ) = > {
dispatch ( fetchEventParticipations ( statusId ) ) ;
} ;
useEffect ( ( ) = > {
fetchData ( ) ;
} , [ ] ) ;
const onClickClose = ( ) = > {
onClose ( 'EVENT_PARTICIPANTS' ) ;
} ;
let body ;
if ( ! accountIds ) {
body = < Spinner / > ;
} else {
2023-01-07 03:24:18 -08:00
const emptyMessage = < FormattedMessage id = 'empty_column.event_participants' defaultMessage = 'No one joined this event yet. When someone does, they will show up here.' / > ;
2022-09-21 14:27:53 -07:00
body = (
2023-01-07 03:24:18 -08:00
< ScrollableList
scrollKey = 'event_participations'
emptyMessage = { emptyMessage }
className = 'max-w-full'
itemClassName = 'pb-3'
>
{ accountIds . map ( id = >
< AccountContainer key = { id } id = { id } / > ,
2022-09-21 14:27:53 -07:00
) }
2023-01-07 03:24:18 -08:00
< / ScrollableList >
2022-09-21 14:27:53 -07:00
) ;
}
return (
< Modal
title = { < FormattedMessage id = 'column.event_participants' defaultMessage = 'Event participants' / > }
onClose = { onClickClose }
>
{ body }
< / Modal >
) ;
} ;
export default EventParticipantsModal ;