Skip to content

Commit

Permalink
fix(last-mails-sent): sort mails
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Oct 29, 2024
1 parent 8481376 commit 0c15c99
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 67 deletions.
137 changes: 71 additions & 66 deletions client/src/pages/last-mails-sent/components/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,82 +17,87 @@ const LastMailsSentItem: React.FC<LastMailsSentProps> = ({ data }) => {

return (
<>
{data.emails.map((email, index) => {
const link = generateLink(
email.collectionName,
email.fromApplication,
email.contributionId
);
{data.emails
.slice()
.sort(
(a, b) => new Date(b.sentAt).getTime() - new Date(a.sentAt).getTime()
)
.map((email, index) => {
const link = generateLink(
email.collectionName,
email.fromApplication,
email.contributionId
);

const sentDate = new Date(email.sentAt);
const formattedDate = sentDate.toLocaleDateString("fr-FR");
const formattedTime = sentDate.toLocaleTimeString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
});
const sentDate = new Date(email.sentAt);
const formattedDate = sentDate.toLocaleDateString("fr-FR");
const formattedTime = sentDate.toLocaleTimeString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
});

return (
<Col key={index} className="email-item fr-mb-2w">
<div className="badges">
<Badge
size="sm"
color="green-menthe"
className="fr-mr-1w fr-mb-1w"
>
{collectionNameMapping[email.collectionName]}
</Badge>

{email.fromApplication && (
return (
<Col key={index} className="email-item fr-mb-2w">
<div className="badges">
<Badge
size="sm"
color="blue-ecume"
color="green-menthe"
className="fr-mr-1w fr-mb-1w"
>
{email.fromApplication}
{collectionNameMapping[email.collectionName]}
</Badge>
)}
</div>

<div className="email-content">
<Text className="fr-mb-0">
Réponse de{" "}
<strong>
<i>{email.selectedProfile}</i>
</strong>{" "}
à{" "}
<strong>
{email.fromApplication && (
<Badge
size="sm"
color="blue-ecume"
className="fr-mr-1w fr-mb-1w"
>
{email.fromApplication}
</Badge>
)}
</div>

<div className="email-content">
<Text className="fr-mb-0">
Réponse de{" "}
<strong>
<i>{email.selectedProfile}</i>
</strong>{" "}
à{" "}
<strong>
<i>
{email?.name} ({email?.to})
</i>
</strong>
</Text>
<Text size="sm">
<Link href={link} rel="noopener noreferrer">
Voir la contribution <i>{email?.contributionId}</i>
</Link>
<button
className={`copy-button ${
copiedId === email.contributionId ? "copied" : ""
}`}
onClick={() => copyToClipboard(email.contributionId)}
title="Copier l'ID"
>
{copiedId === email.contributionId && (
<span className="copied-text">Copié</span>
)}
<FaCopy size={14} color="#2196f3" className="copy-icon" />
</button>
</Text>
<Text size="sm">
<i>
{email?.name} ({email?.to})
Envoyé le {formattedDate} à {formattedTime}
</i>
</strong>
</Text>
<Text size="sm">
<Link href={link} rel="noopener noreferrer">
Voir la contribution <i>{email?.contributionId}</i>
</Link>
<button
className={`copy-button ${
copiedId === email.contributionId ? "copied" : ""
}`}
onClick={() => copyToClipboard(email.contributionId)}
title="Copier l'ID"
>
{copiedId === email.contributionId && (
<span className="copied-text">Copié</span>
)}
<FaCopy size={14} color="#2196f3" className="copy-icon" />
</button>
</Text>
<Text size="sm">
<i>
Envoyé le {formattedDate} à {formattedTime}
</i>
</Text>
<Text>{email.userResponse}</Text>
</div>
</Col>
);
})}
</Text>
<Text>{email.userResponse}</Text>
</div>
</Col>
);
})}
</>
);
};
Expand Down
1 change: 0 additions & 1 deletion client/src/pages/last-mails-sent/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const collectionNameMapping: { [key: string]: string } = {
};

export default collectionNameMapping;
// utils/generateLink.ts
export function generateLink(
collectionName: string,
fromApplication?: string,
Expand Down

0 comments on commit 0c15c99

Please sign in to comment.