Skip to content

Commit

Permalink
feat(contribute_production): add production page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed May 27, 2024
1 parent 9f1e6f6 commit 61d1cd8
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/api/send-mail/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useEffect, useState } from "react";
import { Button, Col, Container, Row, TextArea } from "@dataesr/dsfr-plus";
import { Contribution } from "../../types";
import { Contribution, Contribute_Production } from "../../types";
import { postHeaders } from "../../config/api";
import { toast } from "react-toastify";

function EmailSender({
contribution,
setResponseScanR,
}: {
contribution: Contribution;
contribution: Contribution | Contribute_Production;
setResponseScanR: any;
}) {
const [, setEmailSent] = useState(false);
Expand Down
10 changes: 7 additions & 3 deletions src/api/utils/buildURL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ export const buildURL = (
searchInMessages: boolean = false
): string => {
const location = useLocation();
const baseUrl = location.pathname.includes("contributionpage")
? "contribute"
: "contact";
let baseUrl = "contact";

if (location.pathname.includes("contributionpage")) {
baseUrl = "contribute";
} else if (location.pathname.includes("apioperations")) {
baseUrl = "contribute_productions";
}

const sorted = sort === "ASC" ? "sort=created_at" : "sort=-created_at";
const where: any = {};
Expand Down
32 changes: 19 additions & 13 deletions src/components/edit-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ const EditModal: React.FC<EditModalProps> = ({ isOpen, data, onClose }) => {
setInputs((prevInputs) => ({ ...prevInputs, idRef: newIdref }));
};

const basePath = window.location.pathname.includes("contact")
? "contact"
: "contribute";
let basePath = "contact";

if (window.location.pathname.includes("contribute")) {
basePath = "contribute";
} else if (window.location.pathname.includes("contribute_production")) {
basePath = "contribute_production";
}

const handleSubmit = async () => {
try {
const response = await fetch(`${window.location.origin}/api/${basePath}/${data._id}`, {
method: "PATCH",
headers: postHeaders,
body: JSON.stringify({
status: inputs.status,
tag: inputs.tag,
idref: inputs.idRef,
}),
});
const response = await fetch(
`${window.location.origin}/api/${basePath}/${data._id}`,
{
method: "PATCH",
headers: postHeaders,
body: JSON.stringify({
status: inputs.status,
tag: inputs.tag,
idref: inputs.idRef,
}),
}
);
if (!response.ok) {
console.log("Erreur de réponse", response);
} else {
Expand Down Expand Up @@ -133,7 +140,6 @@ const EditModal: React.FC<EditModalProps> = ({ isOpen, data, onClose }) => {
/>
</Col>
</Row>

<Col className="fr-mt-5w">
<Button onClick={handleSubmit} variant="secondary" size="sm">
<Title as="h3">Enregistrer</Title>
Expand Down
16 changes: 9 additions & 7 deletions src/components/selectors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ const Selectors = ({
onChange={(selectedOption) => setStatus(selectedOption.value)}
styles={customStyles}
/>
<Toggle
checked={searchInMessage}
id="searchInMessage"
name={"Rechercher dans les messages"}
onChange={(e) => setSearchInMessage(e.target.checked)}
label="Rechercher dans les messages"
/>
{location.pathname !== "/apioperations" && (
<Toggle
checked={searchInMessage}
id="searchInMessage"
name={"Rechercher dans les messages"}
onChange={(e) => setSearchInMessage(e.target.checked)}
label="Rechercher dans les messages"
/>
)}
</Col>
);
};
Expand Down
5 changes: 4 additions & 1 deletion src/config/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export const contributionUrl = "/api/contribute?max_results=2000";
// "https://scanr-api.dataesr.ovh/contribute?max_results=2000";
export const contactUrl = "/api/contact?max_results=2000";
// export const contactUrl =
// "https://scanr-api.dataesr.ovh/contact?max_results=2000";
// "https://scanr-api.dataesr.ovh/contact?max_results=2000";
// export const productionUrl =
// "https://scanr-api.dataesr.ovh/contribute_production?max_results=2000";
export const productionUrl = "/api/contribute_production?max_results=2000";
65 changes: 65 additions & 0 deletions src/pages/api-operation-page/contribution-production-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {
Accordion,
AccordionGroup,
Badge,
Col,
Container,
Row,
Text,
} from "@dataesr/dsfr-plus";
import "./styles.scss";
import { Contribute_Production } from "../../types";
import ContributorProductionInfo from "./contributor-production-info";
import StaffProductionActions from "./staff-production-action";

const ContributionProductionItem = ({
data,
}: {
data: Contribute_Production;
}) => {
const renderAccordion = () => (
<Container fluid className="accordion">
<Row>
<Col>
<Badge
size="sm"
color="purple-glycine"
className="fr-mr-1w fr-mb-1w status"
>
{data.status}
</Badge>
<Badge
size="sm"
color="green-emeraude"
className="fr-mr-1w fr-mb-1w status"
>
{data.productions.length.toString() + " Publications à lier "}
</Badge>
</Col>
<Text size="sm">
<i className="date">
Reçu le {new Date(data.created_at).toLocaleDateString()}
</i>
</Text>
</Row>
<Row>
<Col>
<Text size="sm" bold className="name">
{data.name}
</Text>
</Col>
</Row>
</Container>
);

return (
<AccordionGroup>
<Accordion title={renderAccordion}>
<ContributorProductionInfo data={data} />
<StaffProductionActions data={data} />
</Accordion>
</AccordionGroup>
);
};

export default ContributionProductionItem;
12 changes: 12 additions & 0 deletions src/pages/api-operation-page/contributor-production-info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Contribute_Production } from "../../types";
import MessagePreview from "./message-preview";

const ContributorProductionInfo = ({
data,
}: {
data: Contribute_Production;
}) => {
return <MessagePreview data={data} />;
};

export default ContributorProductionInfo;
81 changes: 81 additions & 0 deletions src/pages/api-operation-page/contributor-requests.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Col, Link, Text } from "@dataesr/dsfr-plus";
import React, { useState } from "react";
import { Production } from "../../types";

const ContributorRequests: React.FC<{
data: { productions: Production[] };
}> = ({ data }) => {
const [copiedId, setCopiedId] = useState<string | null>(null);

const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text).then(() => {
setCopiedId(text);
});
};

return (
<>
{data.productions.map((production, index) => (
<Col md="3" className="fr-mr-1v">
<Text
size="sm"
key={index}
style={{
border: "1px solid #ccc",
borderRadius: "5px",
padding: "5px",
}}
>
<Text size="sm" className="textInCard">
<strong>ID :</strong>{" "}
<span onClick={() => copyToClipboard(production.id)}>
{production.id}
</span>
{copiedId === production.id && (
<span
style={{
color: "white",
backgroundColor: "#efcb3a",
marginLeft: "10px",
padding: "2px 5px",
borderRadius: "5px",
fontSize: "0.8em",
}}
>
ID copié
</span>
)}
</Text>
<Text className="textInCard" size="sm">
<Link
className="fr-mr-1w"
target="_blank"
rel="noreferrer noopener external"
href={`https://scanr.enseignementsup-recherche.gouv.fr/publication/${production.id}`}
>
scanR
</Link>
<Link
className="fr-mr-1w"
target="_blank"
rel="noreferrer noopener external"
href={`https://paysage.enseignementsup-recherche.gouv.fr/`}
>
Paysage
</Link>
<Link
target="_blank"
rel="noreferrer noopener external"
href={`https://paysage.enseignementsup-recherche.gouv.fr/`}
>
dataESR
</Link>
</Text>
</Text>
</Col>
))}
</>
);
};

export default ContributorRequests;
Loading

0 comments on commit 61d1cd8

Please sign in to comment.