Skip to content

Commit

Permalink
add commentDialog and link to SU page
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Apr 22, 2024
1 parent 70bb09d commit d1b4671
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 41 deletions.
12 changes: 11 additions & 1 deletion src/i18n-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ export const messagesEn = {
no: 'No',
readQuestionnaire: 'Read questionnaire',
close: 'Close',
comment: 'Comment'
comment: 'Comment',
surveyUnitNumber: 'SU n°',
commentPlaceholder: 'Write a comment',
commentDialogHelpText: 'Edit the text directly in the input field and click “validate” to validate your changes.',
delete:'delete',
cancel: 'cancel',
closeButtonLabel: 'close',
validate: 'validate',
labelRowsPerPage: 'Rows per page:',
labelDisplayedRows: 'entities displayed',
on: 'on'
}
12 changes: 11 additions & 1 deletion src/i18n-fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ export const messagesFr = {
no: 'Non',
readQuestionnaire: 'Relire le questionnaire',
close: 'Clôturer',
comment: 'Commentaire'
comment: 'Commentaire',
surveyUnitNumber: 'UE n°',
commentPlaceholder: 'Rédiger un commentaire',
commentDialogHelpText: 'Modifiez le texte directement dans le champ de saisie et cliquez sur “valider” pour valider vos changements.',
delete:'supprimer',
cancel: 'annuler',
closeButtonLabel: 'fermer',
validate: 'valider',
labelRowsPerPage: 'Lignes par page :',
labelDisplayedRows: 'entités affichées',
on: 'sur'
}
7 changes: 7 additions & 0 deletions src/pages/SurveyUnitPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Stack } from "@mui/material";
import { useParams } from "react-router-dom";

export const SurveyUnitPage = () => {
const { id } = useParams();
return <Stack>UE {id}</Stack>;
};
2 changes: 2 additions & 0 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ClosePage } from "./pages/ClosePage";
import { NotifyPage } from "./pages/NotifyPage";
import { CollectOrganizationPage } from "./pages/CollectOrganizationPage";
import { ReassignmentPage } from "./pages/ReassignmentPage";
import { SurveyUnitPage } from "./pages/SurveyUnitPage";

export const routes: RouteObject[] = [
{
Expand All @@ -26,6 +27,7 @@ export const routes: RouteObject[] = [
{ path: "notify", element: <NotifyPage /> },
{ path: "collectOrganization", element: <CollectOrganizationPage /> },
{ path: "reassignment", element: <ReassignmentPage /> },
{ path: "surveyUnits/:id", element: <SurveyUnitPage /> },
],
},
];
5 changes: 3 additions & 2 deletions src/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const typography = {
fontSize: 12,
lineHeight: "16px",
fontWeight: 600,
letterSpacing: 0.5,
letterSpacing: 0.1,
},
labelSmall: {
fontSize: 11,
Expand Down Expand Up @@ -366,7 +366,7 @@ export const theme = createTheme({
MuiTableCell: {
styleOverrides: {
root: {
borderBottom: "none",
borderBottom: `solid 1px ${palette.text.hint}`,
},
},
},
Expand Down Expand Up @@ -409,6 +409,7 @@ export const theme = createTheme({
...typography.titleMedium,
fontSize: "20px",
lineHeight: "32px",
fontWeight: 400,
},
},
},
Expand Down
15 changes: 7 additions & 8 deletions src/ui/AccountNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ export const AccountNavigation = () => {
{intl.formatMessage({ id: "selectFavoriteSurveys" })}
</Link>
</MenuItem>
<Link to={"/"} color="inherit" underline="none" target="_blank">
<MenuItem key={"help"} value={"help"}>
<Row gap={0.5}>
<OpenInNewIcon fontSize="small" />
<Typography> {intl.formatMessage({ id: "goToHelp" })}</Typography>
</Row>
</MenuItem>
</Link>
{/* TODO: change link */}
<MenuItem {...{ component: Link, to: "/", target: "_blank" }}>
<Row gap={0.5}>
<OpenInNewIcon fontSize="small" />
<Typography> {intl.formatMessage({ id: "goToHelp" })}</Typography>
</Row>
</MenuItem>
<MenuItem
key={"logout"}
value={"logout"}
Expand Down
121 changes: 121 additions & 0 deletions src/ui/CommentDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import Button from "@mui/material/Button";
import Dialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import TextField from "@mui/material/TextField";
import { theme } from "../theme";
import { ChangeEvent, useState } from "react";
import { Box, Divider, InputAdornment, Stack, Typography } from "@mui/material";
import { Row } from "./Row";
import { useIntl } from "react-intl";

type Props = {
open: boolean;
onClose: () => void;
comment?: string;
surveyUnitId: string;
};

export const CommentDialog = ({ open, onClose, comment = "", surveyUnitId }: Props) => {
const intl = useIntl();

const [newComment, setNewComment] = useState(comment);

const onChange = (event: ChangeEvent<HTMLInputElement>) => {
const value = event.target.value;
value !== newComment && setNewComment(value);
};

const handleCancel = () => {
onClose();
setNewComment(comment);
};

const handleDelete = () => {
// TODO call api to delete comment
onClose();
setNewComment("");
};

const handleSubmit: React.FormEventHandler<HTMLFormElement> = e => {
e.preventDefault();
// TODO call api to add comment
onClose();
};

const isModified = newComment !== comment;

return (
<Dialog
open={open}
onClose={handleCancel}
sx={{ ".MuiPaper-root": { width: "560px", px: 3, borderRadius: "8px", pb: 2 } }}
>
<form onSubmit={handleSubmit}>
<DialogTitle>
<Row justifyContent={"space-between"}>
<Box>{intl.formatMessage({ id: "comment" })}</Box>
<Row gap={1}>
<Divider orientation="vertical" variant="middle" sx={{ height: "20px" }} />
<Box>
{intl.formatMessage({ id: "surveyUnitNumber" })} {surveyUnitId}
</Box>
</Row>
</Row>
</DialogTitle>
<DialogContent>
<Stack gap={1}>
<TextField
sx={{
mt: 1,
".MuiInputLabel-root": {
typography: "labelMedium",
},
".MuiInputBase-root": {
typography: "bodyMedium",
},
".MuiOutlinedInput-notchedOutline": {
borderColor: theme.palette.text.secondary,
},
}}
InputProps={{
startAdornment: <InputAdornment position="start" />,
}}
autoFocus
id="comment"
name="comment"
label={intl.formatMessage({ id: "comment" })}
placeholder={intl.formatMessage({ id: "commentPlaceholder" })}
type="text"
fullWidth
variant="outlined"
multiline
rows={3}
value={newComment}
onChange={onChange}
/>
<Typography variant="bodySmall" color={"text.tertiary"}>
{intl.formatMessage({ id: "commentDialogHelpText" })}
</Typography>
</Stack>
</DialogContent>
{comment === "" || isModified ? (
<DialogActions>
<Button onClick={handleCancel}>{intl.formatMessage({ id: "cancel" })}</Button>
<Button type="submit" variant="contained" disabled={!isModified}>
{intl.formatMessage({ id: "validate" })}
</Button>
</DialogActions>
) : (
<DialogActions>
<Button onClick={handleDelete}>{intl.formatMessage({ id: "delete" })}</Button>
<Button onClick={handleCancel} variant="contained">
{intl.formatMessage({ id: "closeButtonLabel" })}
</Button>
</DialogActions>
)}
</form>
</Dialog>
);
};
13 changes: 4 additions & 9 deletions src/ui/HomeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TableHeadCell } from "./TableHeadCell";
import { useState } from "react";
import { HomeTableRow } from "./HomeTableRow";
import { TableFooter } from "./TableFooter";
import { theme } from "../theme";
import { SurveyUnitTemporaryType } from "../types/temporaryTypes";

type Props = {
Expand Down Expand Up @@ -94,17 +93,13 @@ export const HomeTable = ({ surveyUnits }: Props) => {
setOrderBy(property);
};

const sortedRows = surveyUnits.sort(getComparator(order, orderBy));
surveyUnits.sort(getComparator(order, orderBy));

return (
<TableContainer>
<Table aria-label="survey units table" size="small">
<TableHead>
<TableRow
sx={{
borderBottom: `solid 1px ${theme.palette.text.hint}`,
}}
>
<TableRow>
{columns.map(c => (
<TableHeadCell
key={c.label}
Expand All @@ -119,12 +114,12 @@ export const HomeTable = ({ surveyUnits }: Props) => {
</TableRow>
</TableHead>
<TableBody>
{sortedRows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map(su => (
{surveyUnits.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map(su => (
<HomeTableRow surveyUnit={su} key={`surveyUnit-${su.id}`} />
))}
</TableBody>
<TableFooter
count={sortedRows.length}
count={surveyUnits.length}
rowsPerPage={rowsPerPage}
page={page}
onChangePage={handleChangePage}
Expand Down
33 changes: 16 additions & 17 deletions src/ui/HomeTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import TableRow from "@mui/material/TableRow";
import { theme } from "../theme";
import TableCell from "@mui/material/TableCell";
import { useIntl } from "react-intl";
import { styled } from "@mui/material/styles";
Expand All @@ -10,6 +9,9 @@ import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile";
import NotInterestedIcon from "@mui/icons-material/NotInterested";
import InsertCommentIcon from "@mui/icons-material/InsertComment";
import { SurveyUnitTemporaryType } from "../types/temporaryTypes";
import { useToggle } from "react-use";
import { CommentDialog } from "./CommentDialog";
import { Link } from "./Link";

type Props = {
surveyUnit: SurveyUnitTemporaryType; // TODO change type after backend rework
Expand All @@ -24,18 +26,14 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
export const HomeTableRow = ({ surveyUnit }: Props) => {
const intl = useIntl();

const [isDialogOpen, toggleDialog] = useToggle(false);

return (
<StyledTableRow
tabIndex={-1}
key={`row-${surveyUnit.id}`}
sx={{
borderBottom: `solid 1px ${theme.palette.text.hint}`,
}}
>
<TableCell
sx={{ typography: "itemSmall", textDecoration: "underline", ":hover": { cursor: "pointer" } }}
>
{surveyUnit.id}
<StyledTableRow tabIndex={-1} key={`row-${surveyUnit.id}`}>
<TableCell sx={{ typography: "itemSmall" }}>
<Link to={`/surveyUnits/${surveyUnit.id}`} color="inherit">
{surveyUnit.id}
</Link>
</TableCell>
<TableCell sx={{ typography: "itemSmall" }}>{surveyUnit.campaignLabel}</TableCell>
<TableCell sx={{ typography: "itemSmall" }}>{surveyUnit.ssech ?? "-"}</TableCell>
Expand Down Expand Up @@ -65,20 +63,21 @@ export const HomeTableRow = ({ surveyUnit }: Props) => {
</Tooltip>
<Divider orientation="vertical" variant="middle" sx={{ height: "24px" }} />

<Tooltip title={intl.formatMessage({ id: "close" })} placement="bottom-start" arrow>
<IconButton color="inherit">
<NotInterestedIcon fontSize="small" />
<Tooltip title={intl.formatMessage({ id: "comment" })} placement="bottom-start" arrow>
<IconButton color="inherit" onClick={toggleDialog}>
<InsertCommentIcon fontSize="small" />
</IconButton>
</Tooltip>
<Divider orientation="vertical" variant="middle" sx={{ height: "24px" }} />

<Tooltip title={intl.formatMessage({ id: "comment" })} placement="bottom-start" arrow>
<Tooltip title={intl.formatMessage({ id: "close" })} placement="bottom-start" arrow>
<IconButton color="inherit">
<InsertCommentIcon fontSize="small" />
<NotInterestedIcon fontSize="small" />
</IconButton>
</Tooltip>
</Row>
</TableCell>
<CommentDialog open={isDialogOpen} onClose={toggleDialog} surveyUnitId={surveyUnit.id} />
</StyledTableRow>
);
};
8 changes: 6 additions & 2 deletions src/ui/TableFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TableFooter as MuiTableFooter, TablePagination, TableRow } from "@mui/material";
import { useIntl } from "react-intl";

const style = {
root: {
Expand All @@ -12,6 +13,7 @@ const style = {
typography: "bodySmall",
color: "text.tertiary",
},
borderBottom: "none",
},
};

Expand All @@ -30,15 +32,17 @@ export const TableFooter = ({
onChangePage,
onChangeRowsPerPage,
}: TableFooterProps) => {
const intl = useIntl();

return (
<MuiTableFooter>
<TableRow>
<TablePagination
sx={style.root}
rowsPerPageOptions={[10, 20, 50]}
labelRowsPerPage={"Lignes par page :"}
labelRowsPerPage={intl.formatMessage({ id: "labelRowsPerPage" })}
labelDisplayedRows={page =>
`${page.from}-${page.to === -1 ? page.count : page.to} sur ${page.count} entités affichées`
`${page.from}-${page.to === -1 ? page.count : page.to} ${intl.formatMessage({ id: "on" })} ${page.count} ${intl.formatMessage({ id: "labelDisplayedRows" })}`
}
count={count}
rowsPerPage={rowsPerPage}
Expand Down
3 changes: 2 additions & 1 deletion src/ui/TableHeadCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export const TableHeadCell = ({
<MuiTableCell sx={{ ...sx, typography: "titleSmall", pb: 2 }}>
{sort ? (
<TableSortLabel
className="Mui-active"
active={orderBy === columnId}
direction={orderBy === columnId ? order : "asc"}
direction={orderBy === columnId ? order : "desc"}
onClick={createSortHandler(columnId)}
>
{intl.formatMessage({ id: label })}
Expand Down

0 comments on commit d1b4671

Please sign in to comment.