Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render image in dashboard #962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 87 additions & 55 deletions assets/src/components/conversations/ChatMessageBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {Box, Flex} from 'theme-ui';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import {MarkdownRenderer, Text} from '../common';
import {colors, MarkdownRenderer, Text} from '../common';
import {Attachment, Message, MessageSource} from '../../types';
import {PaperClipOutlined} from '../icons';

Expand Down Expand Up @@ -36,20 +36,42 @@ const ChatMessageAttachment = ({
color?: string;
}) => {
const {id, filename, file_url: fileUrl} = attachment;
const isImage =
filename.includes('.png') ||
filename.includes('jpeg') ||
filename.includes('.jpg');

return (
<Box key={id}>
<PaperClipOutlined />{' '}
<a
href={fileUrl}
style={{
color,
textDecoration: 'underline',
}}
>
{filename}
</a>
</Box>
<Flex
sx={{
flexDirection: 'column',
backgroundColor: '#F5F5F5',
borderRadius: 3,
}}
>
{isImage && (
<img
src={fileUrl}
alt="display image"
style={{height: '100%', borderRadius: 3}}
/>
)}
<Box>
<Flex pb={2} pt={2} pr={3}>
<a
href={fileUrl}
style={{
textDecoration: 'underline',
color: colors.primary,
backgroundColor: '#F5F5F5',
border: 'none',
}}
>
<PaperClipOutlined style={{color: '#7E7E7E'}} /> {filename}
</a>
</Flex>
</Box>
</Flex>
);
};

Expand Down Expand Up @@ -87,17 +109,60 @@ const ChatMessageBox = ({
});

return (
<Box sx={parsedSx}>
{subject && (
<Box pb={1} mb={2} sx={{borderBottom: '1px solid rgba(0,0,0,.06)'}}>
<Text className={className} type="secondary" style={{fontSize: 12}}>
{subject}
</Text>
</Box>
)}
<Box>
{body && (
<Box sx={parsedSx}>
{subject && (
<Box pb={1} mb={2} sx={{borderBottom: '1px solid rgba(0,0,0,.06)'}}>
<Text
className={className}
type="secondary"
style={{fontSize: 12}}
>
{subject}
</Text>
</Box>
)}
<MarkdownRenderer className={className} source={body} />

<MarkdownRenderer className={className} source={body} />
{formattedSource && (
<Flex
pt={1}
mt={2}
sx={{
borderTop: '1px solid rgba(0,0,0,.06)',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text
className={className}
type="secondary"
style={{fontSize: 12, marginRight: 32}}
>
{createdAt}
</Text>

<Flex sx={{alignItems: 'center'}}>
{sourceIcon && (
<img
src={sourceIcon}
alt={source}
style={{height: 12, marginRight: 4}}
/>
)}
<Text
className={className}
type="secondary"
style={{fontSize: 12}}
>
Sent via {formattedSource}
</Text>
</Flex>
</Flex>
)}
</Box>
)}
{attachments && attachments.length > 0 && (
<Box mt={2} className={className}>
{attachments.map((attachment) => {
Expand All @@ -111,39 +176,6 @@ const ChatMessageBox = ({
})}
</Box>
)}

{formattedSource && (
<Flex
pt={1}
mt={2}
sx={{
borderTop: '1px solid rgba(0,0,0,.06)',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text
className={className}
type="secondary"
style={{fontSize: 12, marginRight: 32}}
>
{createdAt}
</Text>

<Flex sx={{alignItems: 'center'}}>
{sourceIcon && (
<img
src={sourceIcon}
alt={source}
style={{height: 12, marginRight: 4}}
/>
)}
<Text className={className} type="secondary" style={{fontSize: 12}}>
Sent via {formattedSource}
</Text>
</Flex>
</Flex>
)}
</Box>
);
};
Expand Down