diff --git a/targets/frontend/src/components/button/PublishButton.tsx b/targets/frontend/src/components/button/PublishButton.tsx
new file mode 100644
index 000000000..b598cd87b
--- /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: React.ReactNode;
+};
+
+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 03fb17684..a201e20a9 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({
@@ -315,36 +316,32 @@ export const AnswerForm = ({
: undefined
}
/>
- {!submitting && (
-
-
-
- {primaryButtonLabel && (
- submit(getNextStatus(status))}
- disabled={submitting || status === "TO_PUBLISH"}
- >
- {primaryButtonLabel}
-
- )}
-
- )}
+ {primaryButtonLabel}
+
+ )}
+
);
diff --git a/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx b/targets/frontend/src/components/contributions/questions/EditQuestionAnswerList.tsx
index a313e6a44..a7f040cb2 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";
import { StatusPublicationContainer } from "../status/StatusPublication";
type EditQuestionAnswerListProps = {
@@ -77,8 +77,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) {
@@ -89,7 +91,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}`);
@@ -104,15 +111,13 @@ export const QuestionAnswerList = ({
-
Publier
-
+
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 }) {
- Modifier
+ Sauvegarder
);
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 ? (