2022-01-01 20:42:25 +01:00
|
|
|
import Image from 'next/image'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import date from 'date-and-time'
|
|
|
|
|
|
|
|
import { MessageWithMember } from '../../../../models/Message'
|
2022-01-07 21:21:38 +01:00
|
|
|
import { MessageText } from './MessageText'
|
|
|
|
import { Loader } from '../../../design/Loader'
|
|
|
|
import { MessageFile } from './MessageFile'
|
2022-01-01 20:42:25 +01:00
|
|
|
|
|
|
|
export interface MessageProps {
|
|
|
|
message: MessageWithMember
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Message: React.FC<MessageProps> = (props) => {
|
|
|
|
const { message } = props
|
|
|
|
|
|
|
|
return (
|
2022-01-07 21:21:38 +01:00
|
|
|
<div
|
2022-02-19 23:20:33 +01:00
|
|
|
className='flex p-4 transition hover:bg-gray-200 dark:hover:bg-gray-900'
|
2022-01-07 21:21:38 +01:00
|
|
|
data-cy={`message-${message.id}`}
|
|
|
|
>
|
2022-01-01 20:42:25 +01:00
|
|
|
<Link href={`/application/users/${message.member.user.id}`}>
|
|
|
|
<a>
|
2022-02-19 23:20:33 +01:00
|
|
|
<div className='mr-4 flex h-12 w-12 flex-shrink-0 items-center justify-center'>
|
|
|
|
<div className='h-10 w-10 drop-shadow-md'>
|
2022-01-01 20:42:25 +01:00
|
|
|
<Image
|
2022-04-07 16:54:05 +02:00
|
|
|
quality={100}
|
2022-01-01 20:42:25 +01:00
|
|
|
className='rounded-full'
|
|
|
|
src={
|
|
|
|
message.member.user.logo == null
|
|
|
|
? '/images/data/user-default.png'
|
2022-04-08 20:59:04 +02:00
|
|
|
: message.member.user.logo
|
2022-01-01 20:42:25 +01:00
|
|
|
}
|
|
|
|
alt={"Users's profil picture"}
|
|
|
|
width={50}
|
|
|
|
height={50}
|
|
|
|
draggable={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
<div className='w-full'>
|
2022-02-19 23:20:33 +01:00
|
|
|
<div className='flex w-max items-center'>
|
2022-01-01 20:42:25 +01:00
|
|
|
<Link href={`/application/users/${message.member.user.id}`}>
|
|
|
|
<a>
|
|
|
|
<span
|
|
|
|
data-cy='message-member-user-name'
|
|
|
|
className='font-bold text-gray-900 dark:text-gray-200'
|
|
|
|
>
|
|
|
|
{message.member.user.name}
|
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
<span
|
|
|
|
data-cy='message-date'
|
2022-02-19 23:20:33 +01:00
|
|
|
className='ml-4 select-none text-xs text-gray-500 dark:text-gray-200'
|
2022-01-01 20:42:25 +01:00
|
|
|
>
|
|
|
|
{date.format(new Date(message.createdAt), 'DD/MM/YYYY - HH:mm:ss')}
|
|
|
|
</span>
|
|
|
|
</div>
|
2022-01-07 21:21:38 +01:00
|
|
|
{message.type === 'text' ? (
|
|
|
|
<MessageText message={message} />
|
|
|
|
) : message.type === 'file' ? (
|
|
|
|
<MessageFile message={message} />
|
|
|
|
) : (
|
|
|
|
<Loader />
|
|
|
|
)}
|
2022-01-01 20:42:25 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|