-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/staging'
- Loading branch information
Showing
15 changed files
with
392 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { postHeaders } from "../../config/api"; | ||
|
||
const routes = [ | ||
"contacts", | ||
"contribute", | ||
"production", | ||
"remove-user", | ||
"update-user-data", | ||
]; | ||
|
||
const fetchAllData = async (baseApiUrl) => { | ||
const fetchPromises = routes.map(async (route) => { | ||
const url = `${baseApiUrl}/${route}`; | ||
const response = await fetch(url, { | ||
headers: postHeaders, | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch from ${route}`); | ||
} | ||
return response.json(); | ||
}); | ||
|
||
return Promise.all(fetchPromises); | ||
}; | ||
|
||
const ContributionAllDatas = (baseApiUrl) => { | ||
const fetchContributions = () => fetchAllData(baseApiUrl); | ||
const { data, isLoading, isError, refetch } = useQuery( | ||
["allContributions"], | ||
fetchContributions | ||
); | ||
return { data, isLoading, isError, refetch }; | ||
}; | ||
|
||
export default ContributionAllDatas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export function generateLinkFromAllDatas( | ||
collectionName: string, | ||
fromApplication?: string, | ||
id?: string, | ||
objectId?: boolean, | ||
productions?: Array<any> | ||
): string { | ||
const basePathMap: { [key: string]: { [key: string]: string } | string } = { | ||
contacts: { | ||
scanr: "/scanr-contact", | ||
paysage: "/paysage-contact", | ||
bso: "/bso-contact", | ||
curiexplore: "/curiexplore-contact", | ||
"works-magnet": "/works-magnet-contact", | ||
datasupr: "/datasupr-contact", | ||
}, | ||
contribute_production: "/scanr-apioperations", | ||
"remove-user": "/scanr-removeuser", | ||
"update-user-data": "/scanr-namechange", | ||
contribute: "/scanr-contributionPage", | ||
}; | ||
|
||
let basePath = ""; | ||
|
||
if (productions?.length > 1) { | ||
basePath = "/scanr-apioperations"; | ||
} else if (objectId) { | ||
basePath = "/scanr-contributionPage"; | ||
} else if (fromApplication) { | ||
basePath = "/scanr-contact"; | ||
} else { | ||
basePath = (basePathMap[collectionName] as string) || ""; | ||
} | ||
|
||
return id | ||
? `${basePath}?page=1&query=${id}&searchInMessage=false&sort=DESC&status=choose` | ||
: basePath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import { Badge, Col, Container, Link, Row, Text } from "@dataesr/dsfr-plus"; | ||
import "./styles.scss"; | ||
import { AllContributionsProps } from "../../../types"; | ||
import { generateLinkFromAllDatas } from "./generate-links"; | ||
import { | ||
BadgeColor, | ||
BadgeStatus, | ||
StatusLabel, | ||
typeIcon, | ||
TypeLabel, | ||
} from "../../../utils"; | ||
|
||
const AllContributions: React.FC<AllContributionsProps & { query: string }> = ({ | ||
data, | ||
query, | ||
}) => { | ||
const highlightQuery = (text: string, query: string) => { | ||
if (!query) return text; | ||
|
||
const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
const regex = new RegExp(`(${escapedQuery})`, "gi"); | ||
|
||
return text?.replace(regex, '<span class="highlight">$1</span>'); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
{data.length === 0 ? ( | ||
<p>Pas de résultat</p> | ||
) : ( | ||
data?.map((email, index) => { | ||
const link = generateLinkFromAllDatas( | ||
email.collectionName, | ||
email.fromApplication, | ||
email.id, | ||
email.objectId, | ||
email.productions | ||
); | ||
const creationDate = new Date(email.created_at); | ||
const formattedDate = creationDate.toLocaleDateString("fr-FR"); | ||
const formattedTime = creationDate.toLocaleTimeString("fr-FR", { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
}); | ||
|
||
let badgeContent = ""; | ||
if (email.productions?.length > 1) { | ||
badgeContent = "Lier des publications"; | ||
} else if (email.objectId && !email.productions) { | ||
badgeContent = "Contribution par objet"; | ||
} else badgeContent = "Contact"; | ||
|
||
return ( | ||
<Row gutters key={index} className="email-row"> | ||
<Link href={link} rel="noopener noreferrer"> | ||
<Col lg="12" md="10" sm="12" className="email-item fr-mb-2w"> | ||
<div> | ||
{badgeContent && ( | ||
<Badge | ||
size="sm" | ||
color="blue-ecume" | ||
className="fr-mr-1w fr-mb-1w" | ||
> | ||
{badgeContent} | ||
</Badge> | ||
)} | ||
{badgeContent === "Lier des publications" && ( | ||
<Badge | ||
size="sm" | ||
className="fr-mr-1w fr-mb-1w" | ||
color="blue-ecume" | ||
> | ||
scanR | ||
</Badge> | ||
)} | ||
{email.fromApplication && ( | ||
<Badge | ||
size="sm" | ||
color="blue-ecume" | ||
className="fr-mr-1w fr-mb-1w" | ||
> | ||
{email.fromApplication} | ||
</Badge> | ||
)} | ||
<Badge | ||
size="sm" | ||
color={BadgeStatus({ status: email?.status })} | ||
className="fr-mr-1w fr-mb-1w" | ||
> | ||
{StatusLabel({ status: email.status })} | ||
</Badge> | ||
{email?.objectType && ( | ||
<> | ||
<Badge | ||
size="sm" | ||
icon={typeIcon({ icon: email.objectType })} | ||
color={BadgeColor({ type: email.objectType })} | ||
className="fr-mr-1w fr-mb-1w" | ||
> | ||
{TypeLabel({ type: email.objectType })} | ||
</Badge> | ||
<Badge | ||
size="sm" | ||
className="fr-mr-1w fr-mb-1w" | ||
color="blue-ecume" | ||
> | ||
scanR | ||
</Badge> | ||
</> | ||
)} | ||
{email?.comment || | ||
(email?.team?.length > 0 && ( | ||
<Badge | ||
size="sm" | ||
color="green-emeraude" | ||
className="fr-mr-1w fr-mb-1w" | ||
> | ||
{`Traité par ${email.team[0]}`} | ||
</Badge> | ||
))} | ||
</div> | ||
<div> | ||
<Text className="fr-mb-0 "> | ||
Contribution de{" "} | ||
<i> | ||
{email?.name} - {email?.email} | ||
</i> | ||
</Text> | ||
<Text size="sm"> | ||
<i> | ||
Date de la contribution : {formattedDate} à{" "} | ||
{formattedTime} | ||
</i> | ||
</Text> | ||
<Text | ||
className="email-content" | ||
size="sm" | ||
dangerouslySetInnerHTML={{ | ||
__html: highlightQuery(email?.message, query), | ||
}} | ||
/> | ||
</div> | ||
</Col> | ||
</Link> | ||
</Row> | ||
); | ||
}) | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export default AllContributions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.email-item { | ||
padding: 1.5rem; | ||
border-radius: 8px; | ||
margin-top: 1rem; | ||
border-bottom: 3px solid #f0f0f0; | ||
} | ||
|
||
.email-content { | ||
word-wrap: break-word; | ||
overflow-wrap: break-word; | ||
word-break: break-all; | ||
} | ||
|
||
.copy-button { | ||
border: none; | ||
background: none; | ||
cursor: pointer; | ||
} | ||
|
||
.copied-text { | ||
color: #4caf50; | ||
margin-right: 0.5rem; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.email-item { | ||
padding: 1rem; | ||
} | ||
.email-content { | ||
font-size: 0.9rem; | ||
} | ||
.copy-icon { | ||
display: inline-block; | ||
margin-left: 0.5rem; | ||
} | ||
} | ||
.highlight { | ||
background-color: yellow; | ||
font-weight: bold; | ||
} |
Oops, something went wrong.