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

fix/#117 add time and date in messages #130

Merged
merged 2 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"language": "en,es",
"words": [
"Aceptar",
"Enviado",
"azordev",
"Empecemos",
"Codacy",
Expand Down
14 changes: 13 additions & 1 deletion src/pages/Chat/Chat.styled.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const MessageRow = styled.div`
export const MessageBox = styled.div`
${[ p({ all: '10px' }), rounded({ all: '15px' }), size({ width: '40vw' }), text.base, text.gray09, bg.gray ]}
display: inline-block;
width: max-content;
width: auto;
min-width: 80px;
max-width: 100%;
overflow-wrap: break-word;
Expand All @@ -140,6 +140,18 @@ export const MessageBox = styled.div`
}
`

export const MessageBoxDate = styled.div`
font-size: 0.8rem;
margin-top: 10px;
color: var(--light-gray-11);
`

export const MessageAndUpdatedBox = styled.div`
display: flex;
flex-direction: column;
align-items: ${ props => props.client ? 'end' : 'start'};;
`

export const Avatar = styled.img`
width: 40px;
height: auto;
Expand Down
18 changes: 15 additions & 3 deletions src/pages/Chat/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useParams, useHistory } from 'react-router-dom'
import deliveryManWhite from '../../assets/delivery-chat-user.png'
import userIcon from '../../assets/user_icon.png'
import { FooterChatInput, MessageBox, Avatar, MessageRow } from './Chat.styled'
import { FooterChatInput, MessageBox, MessageAndUpdatedBox, MessageBoxDate, Avatar, MessageRow } from './Chat.styled'
import { useLatestMessages, InsertClientMessage } from '../../hooks'
import { Input } from '../../components'
import sendChat from '../../assets/image_send_chat.png'
Expand All @@ -16,6 +16,12 @@ const Chat = () => {
if (!id) {
history.push('/check')
}

const formatDate = (dateString) => {
const options = {hour: '2-digit', minute: '2-digit'}
return `Enviado ${new Date(dateString).toLocaleTimeString("es-CO", options)}`
}

const { LatestMessages = { chats: [] } } = useLatestMessages(id)
const { loading, insertClientMessage } = InsertClientMessage()
const [ message, setMessage ] = useState('')
Expand All @@ -30,15 +36,21 @@ const Chat = () => {
<MessageRow client key={`chat-message-${packageId}`}>
{/* @ts-ignore */}
<Avatar src={userIcon} type={'client'} />
<MessageBox>{msg.last_client_message}</MessageBox>
<MessageAndUpdatedBox client>
<MessageBox>{msg.last_client_message}</MessageBox>
<MessageBoxDate>{formatDate(msg.updated_at)}</MessageBoxDate>
</MessageAndUpdatedBox>
</MessageRow>
)
} else {
return (
<MessageRow key={`chat-message-${packageId}`}>
{/* @ts-ignore */}
<Avatar src={deliveryManWhite} type={'dasher'} />
<MessageBox>{msg.last_dasher_message}</MessageBox>
<MessageAndUpdatedBox>
<MessageBox>{msg.last_dasher_message}</MessageBox>
<MessageBoxDate>{formatDate(msg.updated_at)}</MessageBoxDate>
</MessageAndUpdatedBox>
</MessageRow>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/styles/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const colors = {
yellow07: '#FDC12A',
yellow06: '#FFCC00',
yellow05: '#FFD119',
gray11: '#8F8B8B',
gray10: '#000000',
gray09: '#334A5E',
gray08: '#40596B',
Expand Down
1 change: 1 addition & 0 deletions src/styles/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Theme = ({ children }) => (
--light-gray-0: ${theme.colors.gray00};
--light-gray-1: ${theme.colors.gray01};
--light-gray-2: ${theme.colors.gray04};
--light-gray-11: ${theme.colors.gray11};
--light-red-1: ${theme.colors.red01};
--white: white;
--danger: ${theme.colors.gray09};
Expand Down