From e9aadf694856e5a701f404804857063c03b0a2c3 Mon Sep 17 00:00:00 2001 From: carolineBda Date: Tue, 18 Jun 2024 16:47:34 +0200 Subject: [PATCH 1/4] =?UTF-8?q?feat(loader):=20ajout=20d'un=20loader=20?= =?UTF-8?q?=C3=A0=20la=20place=20du=20bouton=20lorsque=20l'on=20publie=20u?= =?UTF-8?q?n=20document?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/button/PublishButton.tsx | 30 +++++++++++++ .../contributions/answers/AnswerForm.tsx | 11 +++-- .../questions/EditQuestionAnswerList.tsx | 19 +++++--- .../src/components/layout/Navigation.tsx | 1 + .../agreements/components/Common/Form.tsx | 19 ++++---- .../informationsEdit/InformationsForm.tsx | 45 +++++++++---------- .../modules/models/components/Common/Form.tsx | 42 ++++++++--------- .../frontend/src/pages/themes/edit/[id].js | 4 +- 8 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 targets/frontend/src/components/button/PublishButton.tsx diff --git a/targets/frontend/src/components/button/PublishButton.tsx b/targets/frontend/src/components/button/PublishButton.tsx new file mode 100644 index 000000000..291e5c9d2 --- /dev/null +++ b/targets/frontend/src/components/button/PublishButton.tsx @@ -0,0 +1,30 @@ +import React from "react"; +import { Button, CircularProgress as Spinner } from "@mui/material"; + +type Props = { + disabled?: boolean; + isPublishing: boolean; + onClick: () => void; + children: JSX.Element | string | undefined; +}; + +export function PublishButton({ + disabled=false, + onClick, + children, + isPublishing, +}: Props) { + return isPublishing ? ( + + ) : ( + + ); +} diff --git a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx index bcab68eef..c756c0360 100644 --- a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx +++ b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx @@ -1,4 +1,4 @@ -import { Button, FormControl, Stack, Alert } from "@mui/material"; +import { Alert, Button, FormControl, Stack } from "@mui/material"; import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -16,6 +16,7 @@ import { } from "./references"; import { getNextStatus, getPrimaryButtonLabel } from "../status/utils"; import { FicheSpDocumentInput } from "./references/FicheSpDocumentInput"; +import { PublishButton } from "src/components/button/PublishButton"; const answerFormBaseSchema = answerRelationSchema .pick({ @@ -331,15 +332,13 @@ export const AnswerForm = ({ > Sauvegarder - + )} diff --git a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx index 7761df139..01ce22093 100644 --- a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx +++ b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx @@ -1,5 +1,4 @@ import { - Button, Checkbox, Paper, Stack, @@ -19,6 +18,7 @@ import { Answer } from "../type"; import { StatusContainer } from "../status"; import { useRouter } from "next/router"; import { fr } from "@codegouvfr/react-dsfr"; +import { PublishButton } from "../../button/PublishButton"; type EditQuestionAnswerListProps = { answers: Answer[]; @@ -76,8 +76,10 @@ export const QuestionAnswerList = ({ ) ); const [displayPublish, setDisplayPublish] = useState(false); + const [isPublishing, setIsPublishing] = useState(false); const publishAll = async () => { + setIsPublishing(true); const ids = Object.entries(answersCheck).reduce( (arr, [id, checked]) => { if (checked) { @@ -88,7 +90,12 @@ export const QuestionAnswerList = ({ [] ); const promises = ids.map((id) => onPublish(id)); - await Promise.all(promises); + try { + await Promise.all(promises).finally(() => setIsPublishing(false)); + } catch (e) { + setIsPublishing(false); + throw e; + } }; const redirectToAnswer = (id: string) => { router.push(`/contributions/answers/${id}`); @@ -103,15 +110,13 @@ export const QuestionAnswerList = ({ - + diff --git a/targets/frontend/src/components/layout/Navigation.tsx b/targets/frontend/src/components/layout/Navigation.tsx index a51668db1..855c633d5 100644 --- a/targets/frontend/src/components/layout/Navigation.tsx +++ b/targets/frontend/src/components/layout/Navigation.tsx @@ -127,6 +127,7 @@ export function Navigation() { ) : ( href && ( >; @@ -86,6 +83,7 @@ export const AgreementForm = ({ }); } }; + const [isPublishing, setIsPublishing] = useState(false); return (
@@ -199,11 +197,10 @@ export const AgreementForm = ({ {agreement ? "Sauvegarder" : "Créer"} {onPublish && ( - + )}
diff --git a/targets/frontend/src/modules/informations/components/informationsEdit/InformationsForm.tsx b/targets/frontend/src/modules/informations/components/informationsEdit/InformationsForm.tsx index ac2370ae7..b51bc042a 100644 --- a/targets/frontend/src/modules/informations/components/informationsEdit/InformationsForm.tsx +++ b/targets/frontend/src/modules/informations/components/informationsEdit/InformationsForm.tsx @@ -1,14 +1,15 @@ -import { Stack, Button, FormControl, Typography } from "@mui/material"; -import React from "react"; -import { useForm, useFieldArray } from "react-hook-form"; +import { Button, FormControl, Stack, Typography } from "@mui/material"; +import React, { useState } from "react"; +import { useFieldArray, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { FormTextField, FormRadioGroup } from "src/components/forms"; +import { FormRadioGroup, FormTextField } from "src/components/forms"; import { InformationsResult } from "./Informations.query"; import { Information, informationSchema } from "../../type"; import { InformationsContent } from "./InformationsContent"; import { InformationsReference } from "./InformationsReference"; import { FormCheckbox } from "src/components/forms/Checkbox"; +import { PublishButton } from "../../../../components/button/PublishButton"; export type InformationsFormProps = { data?: InformationsResult; @@ -23,12 +24,7 @@ export const InformationsForm = ({ onDelete, onPublish, }: InformationsFormProps): JSX.Element => { - const { - control, - handleSubmit, - trigger, - formState: { errors }, - } = useForm({ + const { control, handleSubmit } = useForm({ defaultValues: data ?? { title: "", dismissalProcess: false }, resolver: zodResolver(informationSchema), shouldFocusError: true, @@ -56,6 +52,7 @@ export const InformationsForm = ({ const [expandedContent, setExpandedContent] = React.useState( false ); + const [isPublishing, setIsPublishing] = useState(false); return ( <> @@ -222,19 +219,21 @@ export const InformationsForm = ({ Supprimer - + {onPublish && ( + { + if (data?.id) { + setIsPublishing(true); + await onPublish(); + setIsPublishing(false); + } + }} + isPublishing={isPublishing} + > + Publier + + )} diff --git a/targets/frontend/src/modules/models/components/Common/Form.tsx b/targets/frontend/src/modules/models/components/Common/Form.tsx index abde47b4f..cde82aeee 100644 --- a/targets/frontend/src/modules/models/components/Common/Form.tsx +++ b/targets/frontend/src/modules/models/components/Common/Form.tsx @@ -26,6 +26,7 @@ import { LegiReferenceInput } from "src/components/contributions/answers/referen import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { FormOtherReferences } from "../../../../components/forms/OtherReferences"; +import { PublishButton } from "../../../../components/button/PublishButton"; type FormData = Partial>; @@ -144,6 +145,7 @@ export const ModelForm = ({ }); } }; + const [isPublishing, setIsPublishing] = useState(false); const convertToHTML = async (file: File) => { setIsLoadingPreview(true); @@ -300,31 +302,31 @@ export const ModelForm = ({ {model ? "Sauvegarder" : "Créer"} {onPublish && ( - + )} diff --git a/targets/frontend/src/pages/themes/edit/[id].js b/targets/frontend/src/pages/themes/edit/[id].js index 547501241..3825da814 100644 --- a/targets/frontend/src/pages/themes/edit/[id].js +++ b/targets/frontend/src/pages/themes/edit/[id].js @@ -126,10 +126,8 @@ export function EditThemePage() { }); } - // const notFound = !fetching && !deleteResult.fetching && !theme?.cdtnId; - return ( - + {fetching ? ( From 0693c6c1081906929dde8c130465b2d3673eef99 Mon Sep 17 00:00:00 2001 From: carolineBda Date: Thu, 20 Jun 2024 11:34:15 +0200 Subject: [PATCH 2/4] fix contribs --- .../contributions/answers/AnswerForm.tsx | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx index c756c0360..3fe5ce385 100644 --- a/targets/frontend/src/components/contributions/answers/AnswerForm.tsx +++ b/targets/frontend/src/components/contributions/answers/AnswerForm.tsx @@ -315,32 +315,30 @@ export const AnswerForm = ({ : undefined } /> - {!submitting && ( - - - - submit(getNextStatus(status))} - disabled={submitting || status === "PUBLISHED"} - isPublishing={submitting} - > - {getPrimaryButtonLabel(status)} - - - )} + + + + submit(getNextStatus(status))} + disabled={submitting || status === "PUBLISHED"} + isPublishing={submitting} + > + {getPrimaryButtonLabel(status)} + + ); From 85b556a99b41b27dfb11c90a6b7d9c999d7de6e0 Mon Sep 17 00:00:00 2001 From: carolineBda Date: Thu, 20 Jun 2024 15:01:50 +0200 Subject: [PATCH 3/4] modify bouton --- .../src/components/documents/Actions.js | 7 ++-- .../src/components/documents/Container.js | 2 +- targets/frontend/src/pages/fichiers.tsx | 36 ++++++++++--------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/targets/frontend/src/components/documents/Actions.js b/targets/frontend/src/components/documents/Actions.js index 409a9e559..0ffb13539 100644 --- a/targets/frontend/src/components/documents/Actions.js +++ b/targets/frontend/src/components/documents/Actions.js @@ -42,13 +42,12 @@ export function DocumentsListActions({ onUpdatePublication }) { ); diff --git a/targets/frontend/src/components/documents/Container.js b/targets/frontend/src/components/documents/Container.js index 23470e40c..c8ebf5703 100644 --- a/targets/frontend/src/components/documents/Container.js +++ b/targets/frontend/src/components/documents/Container.js @@ -100,8 +100,8 @@ export function DocumentListContainer({ initialFilterValues }) { <>chargement... ) : data.documents.length ? (
- + ("files", () => request(`/api/storage`) @@ -174,7 +178,7 @@ function FilesPage() { {isSearching || (isValidating && !data) ? ( ) : data && data?.length > 0 ? ( - <> + {data .filter( @@ -272,9 +276,9 @@ function FilesPage() { ); })} - + ) : ( - <>Pas de résultats +

Pas de résultats

)}
); From 2004003b83fa100f131da2786d68d7e579c1594f Mon Sep 17 00:00:00 2001 From: Caroline <4971715+carolineBda@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:07:37 +0200 Subject: [PATCH 4/4] Update targets/frontend/src/components/button/PublishButton.tsx Co-authored-by: Maxime Golfier <25312957+maxgfr@users.noreply.github.com> --- targets/frontend/src/components/button/PublishButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/frontend/src/components/button/PublishButton.tsx b/targets/frontend/src/components/button/PublishButton.tsx index 291e5c9d2..b598cd87b 100644 --- a/targets/frontend/src/components/button/PublishButton.tsx +++ b/targets/frontend/src/components/button/PublishButton.tsx @@ -5,7 +5,7 @@ type Props = { disabled?: boolean; isPublishing: boolean; onClick: () => void; - children: JSX.Element | string | undefined; + children: React.ReactNode; }; export function PublishButton({