-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from ReseauEntourage/epic/EN-7374-Messagerie
WIP - Epic/messagerie
- Loading branch information
Showing
73 changed files
with
1,835 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ice/dashboard/DashboardMessagingConversation/ConversationItem/ConversationItem.styles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import styled from 'styled-components'; | ||
import { COLORS } from 'src/constants/styles'; | ||
|
||
export const StyledContainer = styled.div` | ||
display: flex; | ||
background: ${COLORS.hoverBlue}; | ||
padding: 18px 20px; | ||
gap: 15px; | ||
flex: 1; | ||
cursor: pointer; | ||
`; | ||
|
||
export const StyledConversationParticipants = styled.div` | ||
display: flex; | ||
gap: 10px; | ||
align-items: center; | ||
font-weight: bold; | ||
width: 275px; | ||
`; | ||
|
||
export const StyledMessagePreview = styled.div<{ hasSeen: boolean }>` | ||
display: flex; | ||
align-items: center; | ||
flex: auto; | ||
${({ hasSeen }) => !hasSeen && `font-weight: 700;`} | ||
`; | ||
|
||
export const StyledMessageDate = styled.div` | ||
display: flex; | ||
align-items: center; | ||
`; |
51 changes: 51 additions & 0 deletions
51
...backoffice/dashboard/DashboardMessagingConversation/ConversationItem/ConversationItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import moment from 'moment'; | ||
import { useRouter } from 'next/router'; | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { Conversation, User } from 'src/api/types'; | ||
import { ImgProfile } from 'src/components/utils'; | ||
import { selectCurrentUserId } from 'src/use-cases/current-user'; | ||
import { | ||
StyledContainer, | ||
StyledConversationParticipants, | ||
StyledMessageDate, | ||
StyledMessagePreview, | ||
} from './ConversationItem.styles'; | ||
|
||
export interface ConversationItemProps { | ||
conversation: Conversation; | ||
} | ||
|
||
export const ConversationItem = ({ conversation }: ConversationItemProps) => { | ||
const router = useRouter(); | ||
const currentUserId = useSelector(selectCurrentUserId); | ||
const addresee = conversation.participants.find( | ||
(participant) => participant.id !== currentUserId | ||
) as User; | ||
const userParticipantConversation = conversation.participants.find( | ||
(participant) => participant.id === currentUserId | ||
); | ||
const lastMessage = conversation.messages[conversation.messages.length - 1]; | ||
const seenAt = userParticipantConversation?.ConversationParticipant.seenAt; | ||
const userHasSeenConversation = | ||
seenAt && moment(seenAt).isSameOrAfter(lastMessage.createdAt); | ||
|
||
const openConversation = () => { | ||
router.push(`/backoffice/messaging?userId=${addresee.id}`); | ||
}; | ||
|
||
return ( | ||
<StyledContainer onClick={openConversation}> | ||
<StyledConversationParticipants> | ||
<ImgProfile user={addresee} size={25} /> | ||
{`${addresee.firstName} ${addresee.lastName}`} | ||
</StyledConversationParticipants> | ||
<StyledMessagePreview hasSeen={userHasSeenConversation}> | ||
{conversation.messages[0].content} | ||
</StyledMessagePreview> | ||
<StyledMessageDate> | ||
{moment(conversation.messages[0].createdAt).format('DD/MM/YYYY')} | ||
</StyledMessageDate> | ||
</StyledContainer> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
...office/dashboard/DashboardMessagingConversation/DashboardMessagingConversation.styles.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const CardContent = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 20px; | ||
`; | ||
|
||
export const ConversationList = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
`; |
42 changes: 42 additions & 0 deletions
42
...ts/backoffice/dashboard/DashboardMessagingConversation/DashboardMessagingConversation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useRouter } from 'next/router'; | ||
import React, { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { Button, Card } from 'src/components/utils'; | ||
import { messagingActions, selectConversations } from 'src/use-cases/messaging'; | ||
import { ConversationItem } from './ConversationItem/ConversationItem'; | ||
import { | ||
CardContent, | ||
ConversationList, | ||
} from './DashboardMessagingConversation.styles'; | ||
|
||
export const DashboardMessagingConversation = () => { | ||
const router = useRouter(); | ||
const dispatch = useDispatch(); | ||
const conversations = useSelector(selectConversations); | ||
|
||
useEffect(() => { | ||
dispatch(messagingActions.getConversationsRequested()); | ||
}, [dispatch]); | ||
|
||
if (!conversations || conversations.length === 0) { | ||
return null; | ||
} | ||
|
||
const openMessaging = () => { | ||
router.push('/backoffice/messaging'); | ||
}; | ||
|
||
return ( | ||
<Card title="Mes derniers messages"> | ||
<CardContent> | ||
<ConversationList> | ||
{conversations && | ||
conversations.slice(0, 3).map((conversation) => { | ||
return <ConversationItem conversation={conversation} />; | ||
})} | ||
</ConversationList> | ||
<Button onClick={openMessaging}>Accéder à la messagerie</Button> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/components/backoffice/dashboard/DashboardMessagingConversation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DashboardMessagingConversation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.