From e15673829a9359b13b81b11773df0207e875b8f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Dreptin?= <44998961+ClementDreptin@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:10:51 +0200 Subject: [PATCH] fix: download form (#242) * feat: displayed the results count instead of the maximum allowed * feat(download-modal): added a close icon * feat: disabled the all button when the input is already set to the max size --- cypress/e2e/download-page.cy.ts | 1 + .../@modal/(..)download/DownloadModal.tsx | 28 +++++++++++++++++-- .../download/components/DownloadForm.tsx | 16 ++++++++--- .../download/components/ResultsSettings.tsx | 6 ++-- src/app/[locale]/download/page.tsx | 2 +- 5 files changed, 43 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/download-page.cy.ts b/cypress/e2e/download-page.cy.ts index a7af7c1b..ba0b264f 100644 --- a/cypress/e2e/download-page.cy.ts +++ b/cypress/e2e/download-page.cy.ts @@ -129,6 +129,7 @@ describe("The Download Page", () => { cy.get(inputSelector).type("99"); cy.get(inputSelector).should("have.value", maxSize); cy.url().should("include", `size=${maxSize}`); + cy.get("button#all-button").should("be.disabled"); }); }); }); diff --git a/src/app/[locale]/(search)/results/@modal/(..)download/DownloadModal.tsx b/src/app/[locale]/(search)/results/@modal/(..)download/DownloadModal.tsx index 8424251d..aeea0ff5 100644 --- a/src/app/[locale]/(search)/results/@modal/(..)download/DownloadModal.tsx +++ b/src/app/[locale]/(search)/results/@modal/(..)download/DownloadModal.tsx @@ -1,8 +1,16 @@ "use client"; import { useState, forwardRef } from "react"; +import { useTranslations } from "next-intl"; import { useRouter } from "next-intl/client"; -import { Dialog, DialogContent, Slide } from "@mui/material"; +import CloseIcon from "@mui/icons-material/Close"; +import { + Dialog, + DialogContent, + DialogTitle, + IconButton, + Slide, +} from "@mui/material"; import { useTheme } from "@mui/material/styles"; import type { TransitionProps } from "@mui/material/transitions"; import type { ClientComponent } from "@/types/next"; @@ -17,11 +25,12 @@ const Transition = forwardRef(function Transition( const DownloadModal: ClientComponent, true> = ({ children, }) => { + const t = useTranslations("download"); const [open, setOpen] = useState(true); const router = useRouter(); const theme = useTheme(); - const close = (): void => { + const close = () => { setOpen(false); // Wait until the leaving screen animation is over to go back to the /results page @@ -38,7 +47,20 @@ const DownloadModal: ClientComponent, true> = ({ maxWidth="xl" scroll="body" > - {children} + {t("title")} + + + + + {children} + ); }; diff --git a/src/app/[locale]/download/components/DownloadForm.tsx b/src/app/[locale]/download/components/DownloadForm.tsx index 7e7d03e6..b26db1e4 100644 --- a/src/app/[locale]/download/components/DownloadForm.tsx +++ b/src/app/[locale]/download/components/DownloadForm.tsx @@ -12,8 +12,14 @@ import UsageSelector from "./UsageSelector"; import useSearchParams from "@/lib/useSearchParams"; import type { ClientComponent } from "@/types/next"; -const DownloadForm: ClientComponent<{ resultsCount: number }> = ({ +interface DownloadFormProps { + resultsCount: number; + displayTitle?: boolean; +} + +const DownloadForm: ClientComponent = ({ resultsCount, + displayTitle, }) => { const t = useTranslations("download"); const searchParams = useSearchParams(); @@ -26,9 +32,11 @@ const DownloadForm: ClientComponent<{ resultsCount: number }> = ({ return ( <> - - {t("title")} - + {displayTitle === true && ( + + {t("title")} + + )} diff --git a/src/app/[locale]/download/components/ResultsSettings.tsx b/src/app/[locale]/download/components/ResultsSettings.tsx index 29a3dc32..3e90cbdc 100644 --- a/src/app/[locale]/download/components/ResultsSettings.tsx +++ b/src/app/[locale]/download/components/ResultsSettings.tsx @@ -54,7 +54,7 @@ const ResultsSettings: ClientComponent<{ resultsCount: number }> = ({ onChange={handleChange} /> - / {maxSize.toLocaleString(locale)} + / {resultsCount.toLocaleString(locale)} {resultsCount > maxSize && ( = ({ )} diff --git a/src/app/[locale]/download/page.tsx b/src/app/[locale]/download/page.tsx index 57bc075c..e4df7514 100644 --- a/src/app/[locale]/download/page.tsx +++ b/src/app/[locale]/download/page.tsx @@ -22,7 +22,7 @@ const DownloadPage: Page = async ({ searchParams: nextSearchParams }) => { return ( - + ); };