Skip to content

Commit

Permalink
fix(imap-server): update parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Oct 21, 2024
1 parent ac60cdf commit 17755cc
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 183 deletions.
Binary file modified bun.lockb
Binary file not shown.
75 changes: 35 additions & 40 deletions client/src/components/items/staff-action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLocation } from "react-router-dom";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import "./styles.scss";
import { useState, useEffect } from "react";

const StaffActions = ({
data,
refetch,
Expand All @@ -31,7 +32,6 @@ const StaffActions = ({
? "staffSide"
: "staffSideContact";

const displayedDates = new Set<string>();
const queryClient = useQueryClient();

const [isAllRead, setIsAllRead] = useState(() => {
Expand All @@ -41,6 +41,7 @@ const StaffActions = ({
) || false
);
});

const mutation = useMutation(
async (isRead: boolean) => {
return fetch(`api/${baseUrl}/${data.id}`, {
Expand Down Expand Up @@ -119,6 +120,14 @@ const StaffActions = ({
setIsAllRead(allRead);
}, [data]);

const cleanResponseMessage = (message: string) => {
return message
.replace(/De:.*$/s, "")
.replace(/Objet :.*$/s, "")
.replace(/Envoyé :.*$/s, "")
.trim();
};

return (
<>
{data?.threads?.length > 0 && (
Expand All @@ -131,45 +140,31 @@ const StaffActions = ({
/>
)}

{data.threads.map((thread, threadIndex) => {
const teamResponses = thread.responses.filter(
(response) => !response.team.includes("user")
);

return teamResponses.length > 0
? teamResponses.map((response, index) => {
const responseDate = new Date(
response.timestamp
).toLocaleDateString();
const responseTime = new Date(
response.timestamp
).toLocaleTimeString();

if (displayedDates.has(responseDate + responseTime)) {
return null;
}

displayedDates.add(responseDate + responseTime);

const responder = response.team.join(", ");

return (
<div key={`${threadIndex}-${index}`}>
<Text size="sm" className="staffSide">
{responder && (
<>
Réponse apportée par {responder} le {responseDate} à{" "}
{responseTime} :
<br />
{response.responseMessage}
</>
)}
</Text>
</div>
);
})
: null;
})}
{data.threads.map((thread, threadIndex) =>
thread.responses.map((response, index) => {
const responseDate = new Date(
response.timestamp
).toLocaleDateString();
const responseTime = new Date(
response.timestamp
).toLocaleTimeString();

const isStaffResponse = !response.team.includes("user");
const className = isStaffResponse ? "staffSide" : "user-side";

return (
<div key={`${threadIndex}-${index}`} className={className}>
<Text size="sm">
{cleanResponseMessage(response.responseMessage)}
<br />
<small>
Répondu le {responseDate} à {responseTime}
</small>
</Text>
</div>
);
})
)}
</Col>
)}

Expand Down
3 changes: 3 additions & 0 deletions client/src/components/items/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
background-color: var(--background-alt-pink-macaron);
border-radius: 20px;
padding: 20px;
margin-right: 50px;
margin-top: 10px;
margin-bottom: 10px;
}

.staffSide {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"start:server": "cd server && bun run --watch server.ts",
"start": "concurrently \"npm run start:client\" \"bun run start:server\"",
"deploy": "git switch main && git pull origin main --rebase --tags && git merge origin/staging && npm version $npm_config_level && git push origin main --tags && git switch staging"
},
"dependencies": {
"cheerio": "^1.0.0"
}
}
Loading

0 comments on commit 17755cc

Please sign in to comment.