Skip to content

Commit

Permalink
chore(client): clean code, and add filters on last sent mails page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Nov 12, 2024
1 parent a7fdd22 commit 5b4b2d3
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 35 deletions.
1 change: 0 additions & 1 deletion client/src/api/contribution-api/getSentMails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const useSentEmails = () => {
["sentEmails"],
fetchSentEmails
);
console.log(data);
return { data, isLoading, isError, refetch };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import StaffProductionActions from "./staff-production-action";
import { useState } from "react";
import { FaCopy } from "react-icons/fa";
import { Contribute_Production } from "../../../types";
import { BadgeStatus, StatusLabel } from "../../../components/items/utils";
import {
BadgeStatus,
StatusLabel,
} from "../../contact-contributionbyobject-page/components/utils";

const ContributionProductionItem = ({
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const ExcelExportButton: React.FC<ExcelExportButtonProps> = ({ refetch }) => {
};

const handleExportClick = async () => {
console.log(dataList);
const dataToExport = dataList
.filter((item) => item.export === true)
.map((item) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const ContributionPage: React.FC<ContributionPageProps> = () => {
status={status}
setSort={setSort}
setStatus={setStatus}
searchInMessage={""}
searchInMessage={true}
setSearchInMessage={""}
/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import { Badge, Col, Row, Text, Notice, Title } from "@dataesr/dsfr-plus";
import ContributorInfo from "./contributor-info";
import StaffActions from "./staff-action";
import { ContributionItemProps } from "../../types";
import { ContributionItemProps } from "../../../types";
import {
BadgeColor,
BadgeStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contribution } from "../../types";
import { Contribution } from "../../../types";
import MessagePreview from "./message-preview";

const ContributorInfo = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SideMenuItem,
Text,
} from "@dataesr/dsfr-plus";
import { ContributorSummaryProps } from "../../types";
import { ContributorSummaryProps } from "../../../types";
import {
BadgeColor,
BadgeStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button, Col, Container, Link, Row, Text } from "@dataesr/dsfr-plus";
import type { Contribution } from "../../types";
import HighlightedMessage from "../highlighted-message";
import type { Contribution } from "../../../types";
import HighlightedMessage from "../../../components/highlighted-message";
import { useLocation } from "react-router-dom";
import EditModal from "../edit-modal";
import EditModal from "../../../components/edit-modal";
import { useState, useCallback } from "react";
import { capitalizeFirstLetter } from "./utils/capitalize";
import { CopyButton } from "./utils/copy-button";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Col, Text } from "@dataesr/dsfr-plus";
import EmailSender from "../../api/send-mail";
import type { Contribution } from "../../types";
import EmailSender from "../../../api/send-mail";
import type { Contribution } from "../../../types";
import { useLocation } from "react-router-dom";
// import { useMutation, useQueryClient } from "@tanstack/react-query";
import "./styles.scss";
Expand All @@ -17,16 +17,16 @@ const StaffActions = ({
}) => {
const location = useLocation();

let baseUrl = "contacts";
if (location?.pathname?.includes("scanr-contributionpage")) {
baseUrl = "contribute";
} else if (location?.pathname?.includes("removeuser")) {
baseUrl = "remove-user";
} else if (location?.pathname?.includes("namechange")) {
baseUrl = "update-user-data";
} else if (location?.pathname?.includes("apioperations")) {
baseUrl = "production";
}
// let baseUrl = "contacts";
// if (location?.pathname?.includes("scanr-contributionpage")) {
// baseUrl = "contribute";
// } else if (location?.pathname?.includes("removeuser")) {
// baseUrl = "remove-user";
// } else if (location?.pathname?.includes("namechange")) {
// baseUrl = "update-user-data";
// } else if (location?.pathname?.includes("apioperations")) {
// baseUrl = "production";
// }

const contributorClassName = location.pathname.includes("contributionpage")
? "staffSide"
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions client/src/pages/contact-contributionbyobject-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Contribution, ContributionPageProps } from "../../types";
import BottomPaginationButtons from "../../components/pagination/bottom-buttons";
import TopPaginationButtons from "../../components/pagination/top-buttons";
import Selectors from "../../components/selectors";
import ContributionItem from "../../components/items/contribution-item";
import ContributorSummary from "../../components/items/contributor-summary";
import ContributionItem from "./components/contribution-item";
import ContributorSummary from "./components/contributor-summary";
import { contactUrl, contributionUrl } from "../../config/api";

const ContactAndContributionPage: React.FC<ContributionPageProps> = ({
Expand All @@ -26,7 +26,7 @@ const ContactAndContributionPage: React.FC<ContributionPageProps> = ({
const [status, setStatus] = useState("choose");
const [query, setQuery] = useState<string[]>([]);
const [page, setPage] = useState(1);
const [searchInMessage, setSearchInMessage] = useState(true);
const [searchInMessage, setSearchInMessage] = useState(false);
const [highlightedQuery, setHighlightedQuery] = useState("");
const [selectedContribution, setSelectedContribution] = useState<string>("");
const location = useLocation();
Expand Down
13 changes: 12 additions & 1 deletion client/src/pages/last-mails-sent/components/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ const LastMailsSentItem: React.FC<LastMailsSentProps> = ({ data }) => {
>
{collectionNameMapping[email.collectionName]}
</Badge>

{(collectionNameMapping[email.collectionName] ===
"Changement de nom" ||
collectionNameMapping[email.collectionName] ===
"Lier des publications") && (
<Badge
size="sm"
color="blue-ecume"
className="fr-mr-1w fr-mb-1w"
>
Scanr
</Badge>
)}
{email.fromApplication && (
<Badge
size="sm"
Expand Down
3 changes: 1 addition & 2 deletions client/src/pages/last-mails-sent/components/selectors.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Col } from "@dataesr/dsfr-plus";

const Selectors = ({ uniqueProfiles, setStatus }) => {
const handleProfileChange = (event) => {
setStatus(event.target.value);
Expand All @@ -9,7 +8,7 @@ const Selectors = ({ uniqueProfiles, setStatus }) => {
<Col>
<Col className="fr-mb-1w">
<select onChange={handleProfileChange} className="fr-select">
<option value="choose">Par</option>
<option value="all">Tout le monde</option>
{uniqueProfiles.map((profile, index) => (
<option key={index} value={profile}>
{profile}
Expand Down
15 changes: 10 additions & 5 deletions client/src/pages/last-mails-sent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Selectors from "./components/selectors";
const LastMailsSent: React.FC = () => {
const location = useLocation();
const [sort, setSort] = useState("DESC");
const [status, setStatus] = useState("choose");
const [status, setStatus] = useState("all");
const [query, setQuery] = useState<string[]>([]);
const [page, setPage] = useState(1);
const [searchInMessage, setSearchInMessage] = useState(false);
const [searchInMessage, setSearchInMessage] = useState(true);

const { data, isLoading, isError } = useSentEmails();
const sentEmails: Contribution[] = data ? data.emails : [];
Expand All @@ -24,6 +24,11 @@ const LastMailsSent: React.FC = () => {
new Set(sentEmails.map((email) => email.selectedProfile))
);

const filteredEmails =
status === "all"
? sentEmails
: sentEmails.filter((email) => email.selectedProfile === status);

useEffect(() => {
const params = new URLSearchParams(location.search);
setPage(parseInt(params.get("page") || "1"));
Expand All @@ -39,7 +44,7 @@ const LastMailsSent: React.FC = () => {
newSearchParams.set("query", query.join(","));
newSearchParams.set("searchInMessage", searchInMessage.toString());
newSearchParams.set("sort", sort);
if (status !== "choose") {
if (status !== "all") {
newSearchParams.set("status", status);
}
const newURL = `${window.location.pathname}?${newSearchParams.toString()}`;
Expand All @@ -66,7 +71,7 @@ const LastMailsSent: React.FC = () => {
<Row gutters className="fr-mb-3w">
<Col>
<TopPaginationButtons
meta={{ total: sentEmails.length }}
meta={{ total: filteredEmails.length }}
page={page}
maxPage={maxPage}
setPage={setPage}
Expand All @@ -78,7 +83,7 @@ const LastMailsSent: React.FC = () => {
</Row>
<Row>
<Col>
<LastMailsSentItem data={data} />
<LastMailsSentItem data={{ emails: filteredEmails }} />
</Col>
</Row>
<BottomPaginationButtons
Expand Down
2 changes: 1 addition & 1 deletion client/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface Contribution {
}

export interface LastMailsSentProps {
data: Contribution;
data: { emails: Contribution[] };
}
export interface ContributorSummaryProps {
contributions: Contribution[];
Expand Down
2 changes: 1 addition & 1 deletion server/routes/receive-email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,4 @@ function determineCollectionName(collectionPrefix: string) {
setInterval(() => {
console.log("Vérification des emails...");
fetchEmails().catch(console.error);
}, 120 * 1000);
}, 200 * 1000);

0 comments on commit 5b4b2d3

Please sign in to comment.