2023-02-06 10:01:03 -08:00
import clsx 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' ;
2022-11-26 11:25:48 -08:00
import VerificationBadge from './verification-badge' ;
2022-09-06 06:13:28 -07:00
import type { Account as AccountEntity , Status as StatusEntity } from 'soapbox/types/entities' ;
2022-09-07 11:03:26 -07:00
const messages = defineMessages ( {
2022-12-15 14:51:30 -08:00
eventBanner : { 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-11-27 14:29:45 -08:00
status : StatusEntity
className? : string
hideAction? : boolean
floatingAction? : boolean
2022-09-06 06:13:28 -07:00
}
2022-11-27 14:29:45 -08:00
const EventPreview : React.FC < IEventPreview > = ( { status , className , hideAction , floatingAction = true } ) = > {
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 ! ;
2022-11-27 14:29:45 -08:00
const banner = event . banner ;
const action = ! hideAction && ( account . id === me ? (
< Button
size = 'sm'
theme = { floatingAction ? 'secondary' : 'primary' }
to = { ` /@ ${ account . acct } /events/ ${ status . id } ` }
>
< FormattedMessage id = 'event.manage' defaultMessage = 'Manage' / >
< / Button >
) : (
< EventActionButton
status = { status }
theme = { floatingAction ? 'secondary' : 'primary' }
/ >
) ) ;
2022-09-06 06:13:28 -07:00
return (
2023-02-06 10:06:44 -08:00
< div className = { clsx ( 'relative w-full overflow-hidden rounded-lg bg-gray-100 dark:bg-primary-800' , className ) } >
2023-04-01 11:37:34 -07:00
< div className = 'absolute right-3 top-28' >
2022-11-27 14:29:45 -08:00
{ floatingAction && action }
2022-09-06 06:13:28 -07:00
< / div >
2023-02-01 14:13:42 -08:00
< div className = 'h-40 bg-primary-200 dark:bg-gray-600' >
2022-12-15 14:51:30 -08:00
{ banner && < img className = 'h-full w-full object-cover' src = { banner . url } alt = { intl . formatMessage ( messages . eventBanner ) } / > }
2022-09-06 06:13:28 -07:00
< / div >
< Stack className = 'p-2.5' space = { 2 } >
2022-11-27 14:29:45 -08:00
< HStack space = { 2 } alignItems = 'center' justifyContent = 'between' >
< Text weight = 'semibold' truncate > { event . name } < / Text >
{ ! floatingAction && action }
< / HStack >
2022-09-06 06:13:28 -07:00
2023-04-01 11:37:34 -07:00
< div className = 'flex flex-wrap gap-x-2 gap-y-1 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' ) } / >
2022-11-27 15:28:15 -08:00
< HStack space = { 1 } alignItems = 'center' grow >
2022-09-06 06:13:28 -07:00
< span dangerouslySetInnerHTML = { { __html : account.display_name_html } } / >
{ account . verified && < VerificationBadge / > }
2022-11-27 15:28:15 -08:00
< / HStack >
2022-09-06 06:13:28 -07:00
< / 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 ;