Skip to content

Commit

Permalink
refactor: review
Browse files Browse the repository at this point in the history
  • Loading branch information
victor committed Jun 11, 2024
1 parent 2cc2dda commit 18eee26
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const ContributionsAnswer = ({
<StatusContainer status={answer.status.status} displayText />
<StatusPublicationContainer
status={answer.status.status}
statusDate={answer.status.createdAt}
exportDate={answer.publication?.export.createdAt}
displayText
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ export const QuestionAnswerList = ({
</TableHead>
<TableBody>
{answers?.map((answer) => {
const publicationDate = getLastPublicationDate({
status: answer.status,
exportStatus: answer.publication?.export,
});
return (
<TableRow
key={answer.agreement.id}
Expand Down Expand Up @@ -202,7 +198,12 @@ export const QuestionAnswerList = ({
onClick={() => redirectToAnswer(answer.id)}
>
{answer.status && (
<StatusContainer status={answer.status.status} />
<StatusContainer
status={answer.status.status}
exportDate={answer.publication?.export.createdAt}
statusDate={answer.status.createdAt}
center
/>
)}
</TableCell>
<TableCell
Expand All @@ -213,7 +214,7 @@ export const QuestionAnswerList = ({
<StatusPublicationContainer
status={answer.status.status}
exportDate={answer.publication?.export.createdAt}
statusDate={answer.status.createdAt}
center
/>
</TableCell>
</TableRow>
Expand Down
16 changes: 15 additions & 1 deletion targets/frontend/src/components/contributions/status/Status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ import { Box, Stack, Tooltip } from "@mui/material";

import { Status } from "../type";
import { statusesMapping } from "./data";
import { isPublished } from "../publication";

export const StatusContainer = ({
status,
statusDate,
exportDate,
displayText = false,
dataTestid,
center = false,
}: {
status: Status;
statusDate?: string;
exportDate?: string | null;
displayText?: boolean;
dataTestid?: string;
center?: boolean;
}) => {
if (status === "TO_PUBLISH") {
if (statusDate && exportDate && isPublished({ statusDate, exportDate })) {
status = "TO_PUBLISH";
} else {
status = "PUBLISHING";
}
}
const tooltipTitle = statusesMapping[status].text;
return (
<Tooltip title={tooltipTitle}>
Expand All @@ -21,7 +35,7 @@ export const StatusContainer = ({
color: statusesMapping[status].color,
}}
alignItems="center"
justifyContent="center"
justifyContent={center ? "center" : "flex-start"}
spacing={1}
data-testid={dataTestid}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,30 @@ import { Box, Stack, Tooltip } from "@mui/material";

import { Status } from "../type";
import { statusesMapping } from "./data";
import { isPublished } from "../publication";

export const StatusPublicationContainer = ({
status,
statusDate,
exportDate,
displayText = false,
dataTestid,
center = false,
}: {
status: Status;
statusDate?: string;
exportDate?: string | null;
displayText?: boolean;
dataTestid?: string;
center?: boolean;
}) => {
let tooltipText: string | undefined;
if (!exportDate || !statusDate) {
if (!exportDate) {
status = "NOT_PUBLISHED";
tooltipText = statusesMapping[status].text;
} else {
if (status !== "TO_PUBLISH" || isPublished({ statusDate, exportDate })) {
status = "PUBLISHED";
tooltipText = `${statusesMapping[status].text} le ${format(
parseISO(exportDate),
"dd/MM/yyyy HH:mm:ss"
)}`;
} else {
status = "PUBLISHING";
tooltipText = statusesMapping[status].text;
}
status = "PUBLISHED";
tooltipText = `${statusesMapping[status].text} le ${format(
parseISO(exportDate),
"dd/MM/yyyy HH:mm:ss"
)}`;
}
return (
<Tooltip title={tooltipText}>
Expand All @@ -42,7 +36,7 @@ export const StatusPublicationContainer = ({
color: statusesMapping[status].color,
}}
alignItems="center"
justifyContent="center"
justifyContent={center ? "center" : "flex-start"}
spacing={1}
data-testid={dataTestid}
>
Expand Down
7 changes: 3 additions & 4 deletions targets/frontend/src/components/contributions/status/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DescriptionIcon from "@mui/icons-material/Description";
import EditNoteIcon from "@mui/icons-material/EditNote";
import VisibilityIcon from "@mui/icons-material/Visibility";
import CloudDoneIcon from "@mui/icons-material/CloudDone";
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
import CloudOffIcon from "@mui/icons-material/CloudOff";
import TaskAltIcon from "@mui/icons-material/TaskAlt";
import { fr } from "@codegouvfr/react-dsfr";
Expand Down Expand Up @@ -49,12 +48,12 @@ export const statusesMapping: StatusesMapping = {
TO_PUBLISH: {
color: fr.colors.decisions.text.default.success.default,
icon: <TaskAltIcon titleAccess="Publié" fontSize="small" />,
text: "Publication",
text: "Publié",
},
PUBLISHING: {
color: fr.colors.decisions.text.default.warning.default,
icon: <CloudUploadIcon titleAccess="Publié" fontSize="small" />,
text: "En attente",
icon: <TaskAltIcon titleAccess="Publié" fontSize="small" />,
text: "À publier",
},
PUBLISHED: {
color: fr.colors.decisions.text.default.success.default,
Expand Down

0 comments on commit 18eee26

Please sign in to comment.