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

refacto: condition hasMessage in Messaging #356

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
17 changes: 12 additions & 5 deletions src/components/backoffice/messaging/Messaging.desktop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { StyledBackofficeBackground } from '../Backoffice.styles';
import { Section } from 'src/components/utils';
Expand All @@ -21,6 +21,16 @@ export const MessagingDesktop = () => {
const conversations = useSelector(selectConversations);
const query = useSelector(selectQuery);
const selectedConversationId = useSelector(selectSelectedConversationId);
const [hasMessage, setHasMessage] = React.useState(false);

guillobits marked this conversation as resolved.
Show resolved Hide resolved
useEffect(() => {
setHasMessage(
conversations === null ||
conversations.length > 0 ||
query !== '' ||
selectedConversationId !== null
);
}, [conversations, query, selectedConversationId]);

return (
<>
Expand All @@ -31,10 +41,7 @@ export const MessagingDesktop = () => {
</Section>
</StyledBackofficeBackground>
<Section>
{conversations !== null &&
conversations.length <= 0 &&
query === '' &&
selectedConversationId === null ? (
{!hasMessage ? (
<MessagingEmptyState
title="Aucun message dans votre messagerie"
subtitle="Contactez les membres de la communauté à partir du réseau d’entraide"
Expand Down
15 changes: 11 additions & 4 deletions src/components/backoffice/messaging/Messaging.mobile.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { StyledBackofficeBackground } from '../Backoffice.styles';
import { Section } from 'src/components/utils';
Expand All @@ -19,12 +19,19 @@ import { MessagingEmptyState } from './MessagingEmptyState';
export const MessagingMobile = () => {
const selectedConversationId = useSelector(selectSelectedConversationId);
const conversations = useSelector(selectConversations);
const [hasMessage, setHasMessage] = React.useState(false);

useEffect(() => {
setHasMessage(
conversations === null ||
conversations.length > 0 ||
selectedConversationId !== null
);
}, [conversations, selectedConversationId]);

return (
<>
{conversations !== null &&
conversations.length <= 0 &&
!selectedConversationId ? (
{!hasMessage ? (
<MessagingEmptyStateContainerMobile>
<MessagingEmptyState
title="Aucun message dans votre messagerie"
Expand Down
Loading