2022-09-30 14:20:58 -07:00
import classNames from 'clsx' ;
2022-09-08 14:25:02 -07:00
import React from 'react' ;
import { defineMessages , FormattedMessage , useIntl } from 'react-intl' ;
2022-09-06 06:13:28 -07:00
2022-09-08 14:25:02 -07:00
import EventActionButton from 'soapbox/features/event/components/event-action-button' ;
import EventDate from 'soapbox/features/event/components/event-date' ;
import { useAppSelector } from 'soapbox/hooks' ;
2022-09-06 06:13:28 -07:00
import Icon from './icon' ;
import { Button , HStack , Stack , Text } from './ui' ;
import VerificationBadge from './verification_badge' ;
import type { Account as AccountEntity , Status as StatusEntity } from 'soapbox/types/entities' ;
2022-09-07 11:03:26 -07:00
const messages = defineMessages ( {
2022-09-08 14:25:02 -07:00
bannerHeader : { id : 'event.banner' , defaultMessage : 'Event banner' } ,
2022-09-07 11:03:26 -07:00
leaveConfirm : { id : 'confirmations.leave_event.confirm' , defaultMessage : 'Leave event' } ,
leaveMessage : { id : 'confirmations.leave_event.message' , defaultMessage : 'If you want to rejoin the event, the request will be manually reviewed again. Are you sure you want to proceed?' } ,
} ) ;
2022-09-06 06:13:28 -07:00
interface IEventPreview {
2022-09-30 14:20:58 -07:00
status : StatusEntity ,
className? : string ,
2022-10-05 15:01:26 -07:00
hideAction? : boolean ;
2022-09-06 06:13:28 -07:00
}
2022-10-05 15:01:26 -07:00
const EventPreview : React.FC < IEventPreview > = ( { status , className , hideAction } ) = > {
2022-09-07 11:03:26 -07:00
const intl = useIntl ( ) ;
2022-09-06 06:13:28 -07:00
const me = useAppSelector ( ( state ) = > state . me ) ;
const account = status . account as AccountEntity ;
const event = status . event ! ;
const banner = status . media_attachments ? . find ( ( { description } ) = > description === 'Banner' ) ;
return (
2022-09-30 14:20:58 -07:00
< div className = { classNames ( 'rounded-lg bg-gray-100 dark:bg-primary-800 relative overflow-hidden' , className ) } >
2022-09-06 06:13:28 -07:00
< div className = 'absolute top-28 right-3' >
2022-10-05 15:01:26 -07:00
{ ! hideAction && ( account . id === me ? (
2022-09-06 06:13:28 -07:00
< Button
size = 'sm'
theme = 'secondary'
to = { ` /@ ${ account . acct } /events/ ${ status . id } ` }
>
< FormattedMessage id = 'event.manage' defaultMessage = 'Manage' / >
< / Button >
2022-10-05 15:01:26 -07:00
) : < EventActionButton status = { status } / > ) }
2022-09-06 06:13:28 -07:00
< / div >
< div className = 'bg-primary-200 dark:bg-gray-600 h-40' >
2022-09-08 14:25:02 -07:00
{ banner && < img className = 'h-full w-full object-cover' src = { banner . url } alt = { intl . formatMessage ( messages . bannerHeader ) } / > }
2022-09-06 06:13:28 -07:00
< / div >
< Stack className = 'p-2.5' space = { 2 } >
< Text weight = 'semibold' > { event . name } < / Text >
< div className = 'flex gap-y-1 gap-x-2 flex-wrap text-gray-700 dark:text-gray-600' >
2022-09-08 14:25:02 -07:00
< HStack alignItems = 'center' space = { 2 } >
2022-09-06 06:13:28 -07:00
< Icon src = { require ( '@tabler/icons/user.svg' ) } / >
< span >
< span dangerouslySetInnerHTML = { { __html : account.display_name_html } } / >
{ account . verified && < VerificationBadge / > }
< / span >
< / HStack >
2022-09-08 14:25:02 -07:00
< EventDate status = { status } / >
2022-09-06 06:13:28 -07:00
{ event . location && (
2022-09-08 14:25:02 -07:00
< HStack alignItems = 'center' space = { 2 } >
2022-09-06 06:13:28 -07:00
< Icon src = { require ( '@tabler/icons/map-pin.svg' ) } / >
< span >
{ event . location . get ( 'name' ) }
< / span >
< / HStack >
) }
< / div >
< / Stack >
< / div >
) ;
} ;
export default EventPreview ;