Skip to content

Commit

Permalink
fix(improvements): full rework of message preview, add sideMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Jun 14, 2024
1 parent addc0e2 commit f844596
Show file tree
Hide file tree
Showing 11 changed files with 414 additions and 355 deletions.
4 changes: 2 additions & 2 deletions src/api/send-mail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function EmailSender({
? "https://api.brevo.com/v3/smtp/email"
: "/email/";
const scanRUrl = isDevelopment
? `https://scanr-api.dataesr.ovh/${basePath}/${contribution._id}`
? `https://scanr-api.dataesr.ovh/${basePath}/${contribution?._id}`
: `/api/${basePath}/${contribution._id}`;
const [selectedProfile, setSelectedProfile] = useState("");

Expand Down Expand Up @@ -107,7 +107,7 @@ function EmailSender({
onClick={sendEmail}
size="sm"
>
{contribution.mailSent ? "Renvoyer un mail" : "Répondre"}
{contribution?.mailSent ? "Renvoyer un mail" : "Répondre"}
</Button>
</Col>
</Row>
Expand Down
6 changes: 3 additions & 3 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const EditModal: React.FC<EditModalProps> = ({
}
const isDevelopment = import.meta.env.VITE_HEADER_TAG === "Development";
const url = isDevelopment
? `https://scanr-api.dataesr.ovh/${basePath}/${data._id}`
: `${window.location.origin}/api/${basePath}/${data._id}`;
? `https://scanr-api.dataesr.ovh/${basePath}/${data?._id}`
: `${window.location.origin}/api/${basePath}/${data?._id}`;
const [inputs, setInputs] = useState<Inputs>({
team: [user],
status: "treated",
Expand Down Expand Up @@ -199,7 +199,7 @@ const EditModal: React.FC<EditModalProps> = ({
<Col>
<TextArea
label={
data.comment
data?.comment
? "Mettre à jour le commentaire pour l'équipe"
: "Ajouter un commentaire pour l'équipe"
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/highlighted-message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ const HighlightedMessage = ({

const lowerCaseMessage = message?.toLowerCase();
const lowerCaseQuery = highlightedQuery?.toLowerCase();
const index = lowerCaseMessage.indexOf(lowerCaseQuery);
const index = lowerCaseMessage?.indexOf(lowerCaseQuery);
if (index === -1) return message;

const prefix = message.substring(0, index);
const highlight = message.substring(index, index + highlightedQuery.length);
const suffix = message.substring(index + highlightedQuery.length);
const prefix = message?.substring(0, index);
const highlight = message?.substring(
index,
index + highlightedQuery.length
);
const suffix = message?.substring(index + highlightedQuery.length);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const MessagePreview = ({
data={data}
/>
<Row className="contributorProductionSideInfo">
{data.id && (
{data?.id && (
<Text
size="sm"
style={{ cursor: "pointer" }}
Expand Down
122 changes: 0 additions & 122 deletions src/pages/contribution-page/contribution-card.tsx

This file was deleted.

85 changes: 85 additions & 0 deletions src/pages/contribution-page/contribution-item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React from "react";
import {
Badge,
Col,
Container,
Row,
Text,
Notice,
Title,
} from "@dataesr/dsfr-plus";
import ContributorInfo from "./contributor-info";
import StaffActions from "./staff-action";
import { Contribution } from "../../types";
import { BadgeColor } from "./utils";
import "./styles.scss";

interface ContributionItemProps {
data: Contribution;
highlightedQuery: string;
refetch: () => void;
}
const ContributionItem: React.FC<ContributionItemProps> = ({
data,
highlightedQuery,
refetch,
}) => {
return (
<Container fluid>
<div>
{data?.tags?.length > 0 && (
<Badge size="sm" color="purple-glycine" className="fr-mr-1w fr-mb-1w">
{data.tags.join(", ")}
</Badge>
)}
<Badge size="sm" color="purple-glycine" className="fr-mr-1w fr-mb-1w">
{data?.status}
</Badge>
{data?.responseFrom && (
<Badge size="sm" color="blue-ecume" className="fr-mr-1w fr-mb-1w">
{`Réponse envoyée par ${data.responseFrom}`}
</Badge>
)}
{data?.comment && data?.team?.length > 0 && (
<Badge size="sm" color="green-emeraude" className="fr-mr-1w fr-mb-1w">
{`Commenté par ${data.team[0]}`}
</Badge>
)}
{data?.type && (
<Badge
size="sm"
color={BadgeColor({ type: data.type })}
className="fr-mr-1w fr-mb-1w"
>
{data.type}
</Badge>
)}
</div>
<Row>
<Col md="12">
<Title look="h5">{data?.name}</Title>
{!data?.comment && (
<Notice type="info" closeMode="disallow" className="fr-mb-2w">
Aucune réponse apportée à ce message pour l'instant
</Notice>
)}
</Col>
<Text size="sm" bold>
<i>Reçu le {new Date(data?.created_at).toLocaleDateString()}</i>
</Text>
</Row>
<Row>
<Col>
<ContributorInfo
data={data}
highlightedQuery={highlightedQuery}
refetch={refetch}
/>
<StaffActions refetch={refetch} data={data} />
</Col>
</Row>
</Container>
);
};

export default ContributionItem;
58 changes: 58 additions & 0 deletions src/pages/contribution-page/contributor-summary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from "react";
import { Badge, SideMenu, SideMenuItem, Text } from "@dataesr/dsfr-plus";
import { Contribution } from "../../types";

interface ContributorSummaryProps {
contributions: Contribution[];
onSelectContribution: (id: string) => void;
}

const ContributorSummary: React.FC<ContributorSummaryProps> = ({
contributions,
onSelectContribution,
}) => {
const handleClick = (id: string) => {
onSelectContribution(id);
window.scrollTo({ top: 200, behavior: "smooth" });
};

return (
<SideMenu title="Contributeurs" sticky fullHeight>
{contributions.map((contribution) => (
<SideMenuItem
key={contribution.id}
title={
<div>
{contribution?.status && (
<Badge
size="sm"
color="purple-glycine"
className="fr-mr-1w fr-mb-1w"
>
{contribution.status}
</Badge>
)}
{contribution?.tags?.length > 0 && (
<Badge
size="sm"
color="purple-glycine"
className="fr-mr-1w fr-mb-1w"
>
{contribution.tags.join(", ")}
</Badge>
)}
<Text size="sm">{contribution.name}</Text>
<Text size="sm" className="fr-text--italic">
{new Date(contribution.created_at).toLocaleDateString()}
</Text>
</div>
}
defaultExpanded={false}
onClick={() => handleClick(contribution._id)}
/>
))}
</SideMenu>
);
};

export default ContributorSummary;
Loading

0 comments on commit f844596

Please sign in to comment.