Skip to content

Commit

Permalink
feat: rework HistoryDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Nov 15, 2024
1 parent 140419e commit 1c9a8ac
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 164 deletions.
2 changes: 1 addition & 1 deletion src/pages/QuestioningPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const QuestioningPage = () => {
label,
];

const hasNoQuestioningUrl = questioning.readOnlyUrl === null && questioning.readOnlyUrl === "";
const hasNoQuestioningUrl = questioning.readOnlyUrl === null || questioning.readOnlyUrl === "";

return (
<>
Expand Down
7 changes: 3 additions & 4 deletions src/pages/Search/SearchQuestionings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Breadcrumbs } from "../../ui/Breadcrumbs.tsx";
import { Divider, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material";
import { SearchQuestioningTable } from "../../ui/Questioning/SearchQuestioningTable.tsx";
import { EmptyState } from "../../ui/TableComponents.tsx";
import { FilterSelect } from "../../ui/FilterSelect.tsx";
import { SearchSelectStatus } from "../../ui/Questioning/SearchSelectStatus.tsx";
import { SearchTextField } from "../../ui/SearchTextField.tsx";
import { useFetchQuery } from "../../hooks/useFetchQuery.ts";

Expand Down Expand Up @@ -115,11 +113,12 @@ export const SearchQuestionings = () => {
label={"Rechercher par unité enquêtée ou identifiant de connexion"}
inputProps={inputProps}
/>
<Row gap={3}>
{/* TODO: use it later
<Row gap={3}>
<FilterSelect options={[]} label={"Collecte"} name={"campaignId"} />
<SearchSelectStatus />
<FilterSelect options={[]} label={"Dernière communication"} name={"lastCommunication"} />
</Row>
</Row> */}
{hasNoQuestioning && (
<EmptyState
isFiltered={hasResetButton}
Expand Down
32 changes: 32 additions & 0 deletions src/ui/Questioning/HistoryDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Dialog from "@mui/material/Dialog";
import DialogTitle from "@mui/material/DialogTitle";
import DialogContent from "@mui/material/DialogContent";
import TableContainer from "@mui/material/TableContainer";
import Table from "@mui/material/Table";
import { ReactNode } from "react";

type Props = {
onClose: () => void;
open: boolean;
title: string;
children: ReactNode;
};

export const HistoryDialog = ({ onClose, open, children, title }: Props) => {
return (
<Dialog onClose={onClose} open={open} sx={{ ".MuiPaper-root": { maxWidth: "715px" } }}>
<DialogTitle sx={{ pb: 2.5 }}>{title}</DialogTitle>
<DialogContent
sx={{
minWidth: "715px",
width: "fit-content",
height: "450px",
}}
>
<TableContainer>
<Table>{children}</Table>
</TableContainer>
</DialogContent>
</Dialog>
);
};
96 changes: 39 additions & 57 deletions src/ui/Questioning/LastComunicationHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Chip, Table, TableBody, TableCell, TableHead, TableRow } from "@mui/material";
import Dialog from "@mui/material/Dialog";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import TableContainer from "@mui/material/TableContainer";
import { Chip, TableBody, TableCell, TableHead, TableRow } from "@mui/material";
import { APISchemas } from "../../types/api.ts";
import { communicationsList } from "../../constants/communications.ts";
import { HistoryDialog } from "./HistoryDialog.tsx";

type Props = {
questioning: APISchemas["QuestioningDetailsDto"];
Expand All @@ -17,58 +14,43 @@ export const LastCommunicationHistory = ({ questioning, onClose, open }: Props)
questioning.listCommunications?.sort((a, b) => b.date!.localeCompare(a.date!)) ?? [];

return (
<Dialog onClose={onClose} open={open} sx={{ ".MuiPaper-root": { maxWidth: "715px" } }}>
<DialogTitle sx={{ pb: 2.5 }}>Historique des communications</DialogTitle>
<DialogContent
sx={{
minWidth: "715px",
width: "fit-content",
height: "450px",
}}
>
<TableContainer>
<Table>
<TableHead sx={{ backgroundColor: "#EBEFF5" }}>
<TableRow>
<TableCell sx={{ typography: "titleSmall", width: "115px" }}>Date</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "75px" }}>Heure</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "120px" }}>Type</TableCell>
<TableCell sx={{ typography: "titleSmall" }}>Type de communication</TableCell>
</TableRow>
</TableHead>
<TableBody>
{sortedCommunications.map(communication => {
const date =
communication.date && new Date(Date.parse(communication.date)).toLocaleDateString();
const hour =
communication.date && new Date(Date.parse(communication.date)).toLocaleTimeString();
<HistoryDialog onClose={onClose} open={open} title={"Historique des communications"}>
<TableHead sx={{ backgroundColor: "#EBEFF5" }}>
<TableRow>
<TableCell sx={{ typography: "titleSmall", width: "115px" }}>Date</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "75px" }}>Heure</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "120px" }}>Type</TableCell>
<TableCell sx={{ typography: "titleSmall" }}>Type de communication</TableCell>
</TableRow>
</TableHead>
<TableBody>
{sortedCommunications.map(communication => {
const date =
communication.date && new Date(Date.parse(communication.date)).toLocaleDateString();
const hour =
communication.date && new Date(Date.parse(communication.date)).toLocaleTimeString();

return (
<TableRow key={communication.id}>
<TableCell>{date}</TableCell>
<TableCell>{hour}</TableCell>
<TableCell>
{communication.status === "AUTOMATIC" ? "Automatique" : "Manuel"}
</TableCell>
<TableCell>
<Chip
sx={{
typography: "titleSmall",
textOverflow: "ellipsis",
}}
label={
communicationsList.find(com => com.value === communication.type)?.label ??
"Aucun état"
}
/>
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
</DialogContent>
</Dialog>
return (
<TableRow key={communication.id}>
<TableCell>{date}</TableCell>
<TableCell>{hour}</TableCell>
<TableCell>{communication.status === "AUTOMATIC" ? "Automatique" : "Manuel"}</TableCell>
<TableCell>
<Chip
sx={{
typography: "titleSmall",
textOverflow: "ellipsis",
}}
label={
communicationsList.find(com => com.value === communication.type)?.label ??
"Aucun état"
}
/>
</TableCell>
</TableRow>
);
})}
</TableBody>
</HistoryDialog>
);
};
13 changes: 8 additions & 5 deletions src/ui/Questioning/QuestioningCommentsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import { QuestioningCommentDialog } from "./QuestioningCommentDialog.tsx";
import { useFetchMutation } from "../../hooks/useFetchQuery.ts";
import { useQueryClient } from "@tanstack/react-query";
import { useMaybeUser } from "../../hooks/useAuth.ts";
import { APISchemas } from "../../types/api.ts";

type Props = {
questioning: any;
questioning: APISchemas["QuestioningDetailsDto"];
};

enum Tab {
Expand Down Expand Up @@ -53,13 +54,13 @@ export const QuestioningCommentsCard = ({ questioning }: Props) => {
return;
}

if (category === "SurveyUnit") {
if (category === "SurveyUnit" && questioning.surveyUnitId && questioning.surveyUnitId !== "") {
await mutateAsyncSurveyUnit({
body: {
comment,
author: `${user?.given_name} ${user?.family_name}`,
},
urlParams: { id: questioning.idSu },
urlParams: { id: questioning.surveyUnitId },
});

queryClient.invalidateQueries({ queryKey: ["/api/survey-units/{id}"] });
Expand Down Expand Up @@ -89,10 +90,12 @@ export const QuestioningCommentsCard = ({ questioning }: Props) => {
</Tabs>
<Stack sx={{ py: 2, px: 1 }} gap={0.5}>
{currentTab === Tab.Questioning && (
<CommentsList comments={questioning.questioningComments} sx={{ px: 2.5 }} />
// TODO: use data when get comments
<CommentsList comments={[]} sx={{ px: 2.5 }} />
)}
{currentTab === Tab.SurveyUnit && (
<CommentsList comments={questioning.surveyUnitComments} sx={{ px: 2.5 }} />
// TODO: use data when get comments
<CommentsList comments={[]} sx={{ px: 2.5 }} />
)}
</Stack>
</Stack>
Expand Down
34 changes: 0 additions & 34 deletions src/ui/Questioning/SearchSelectStatus.tsx

This file was deleted.

110 changes: 47 additions & 63 deletions src/ui/Questioning/StatusHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Chip, Table, TableBody, TableCell, TableHead, TableRow } from "@mui/material";
import Dialog from "@mui/material/Dialog";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import TableContainer from "@mui/material/TableContainer";
import { Chip, TableBody, TableCell, TableHead, TableRow } from "@mui/material";
import { getCollectStateChipColor } from "./SearchQuestioningTable.tsx";
import { collectStatus } from "../../constants/collectStatus.ts";
import { APISchemas } from "../../types/api.ts";
import { HistoryDialog } from "./HistoryDialog.tsx";

type Props = {
onClose: () => void;
Expand All @@ -18,66 +15,53 @@ export const StatusHistory = ({ onClose, open, questioning }: Props) => {
questioning.listEvents?.sort((a, b) => b.eventDate!.localeCompare(a.eventDate!)) ?? [];

return (
<Dialog onClose={onClose} open={open} sx={{ ".MuiPaper-root": { maxWidth: "715px" } }}>
<DialogTitle sx={{ pb: 2.5 }}>Historique des statuts</DialogTitle>
<DialogContent
sx={{
minWidth: "715px",
width: "fit-content",
height: "450px",
}}
>
<TableContainer>
<Table>
<TableHead sx={{ backgroundColor: "#EBEFF5" }}>
<TableRow>
<TableCell sx={{ typography: "titleSmall", width: "115px" }}>Date</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "75px" }}>Heure</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "120px" }}>Type</TableCell>
<TableCell sx={{ typography: "titleSmall" }}>Statut</TableCell>
</TableRow>
</TableHead>
<TableBody>
{sortedStatus.map(statusElement => {
const date =
statusElement.eventDate &&
new Date(Date.parse(statusElement.eventDate)).toLocaleDateString();
const hour =
statusElement.eventDate &&
new Date(Date.parse(statusElement.eventDate)).toLocaleTimeString();
<HistoryDialog onClose={onClose} open={open} title={"Historique des statuts"}>
<TableHead sx={{ backgroundColor: "#EBEFF5" }}>
<TableRow>
<TableCell sx={{ typography: "titleSmall", width: "115px" }}>Date</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "75px" }}>Heure</TableCell>
<TableCell sx={{ typography: "titleSmall", width: "120px" }}>Type</TableCell>
<TableCell sx={{ typography: "titleSmall" }}>Statut</TableCell>
</TableRow>
</TableHead>
<TableBody>
{sortedStatus.map(statusElement => {
const date =
statusElement.eventDate &&
new Date(Date.parse(statusElement.eventDate)).toLocaleDateString();
const hour =
statusElement.eventDate &&
new Date(Date.parse(statusElement.eventDate)).toLocaleTimeString();

const source =
typeof statusElement.payload === "object" && "source" in statusElement.payload
? statusElement.payload.source
: undefined;
const type = source === "platine-gestion" ? "Manuel" : "Automatique";
const source =
typeof statusElement.payload === "object" && "source" in statusElement.payload
? statusElement.payload.source
: undefined;
const type = source === "platine-gestion" ? "Manuel" : "Automatique";

return (
<TableRow key={statusElement.id}>
<TableCell>{date}</TableCell>
<TableCell>{hour}</TableCell>
<TableCell>{type} </TableCell>
<TableCell>
<Chip
sx={{
typography: "titleSmall",
return (
<TableRow key={statusElement.id}>
<TableCell>{date}</TableCell>
<TableCell>{hour}</TableCell>
<TableCell>{type} </TableCell>
<TableCell>
<Chip
sx={{
typography: "titleSmall",

textOverflow: "ellipsis",
}}
label={
collectStatus.find(state => state.value === statusElement.type)?.label ??
"Aucun état"
}
color={getCollectStateChipColor(statusElement.type)}
/>
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
</DialogContent>
</Dialog>
textOverflow: "ellipsis",
}}
label={
collectStatus.find(state => state.value === statusElement.type)?.label ??
"Aucun état"
}
color={getCollectStateChipColor(statusElement.type)}
/>
</TableCell>
</TableRow>
);
})}
</TableBody>
</HistoryDialog>
);
};

0 comments on commit 1c9a8ac

Please sign in to comment.