From 7889924fe497cb7a82204b263ab24930e753e726 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Wed, 21 Feb 2024 10:57:27 -0500 Subject: [PATCH 1/2] Unify loading button --- src/components/Buttons/LoadingButton.tsx | 8 ++--- src/components/Dialogs/ButtonConfirmation.tsx | 7 +--- .../Dialogs/CancelConfirmDialog.tsx | 32 ++++++++++++------- .../Dialogs/DeleteEditTextDialog.tsx | 7 +--- src/components/Login/Login.tsx | 6 +--- src/components/ProjectExport/ExportButton.tsx | 1 - .../ProjectSchedule/DateScheduleEdit.tsx | 2 -- .../ProjectSchedule/DateSelector.tsx | 2 -- .../CharacterInventory/CharInv/index.tsx | 2 +- .../MergeDupsStep/SaveDeferButtons.tsx | 3 -- 10 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/components/Buttons/LoadingButton.tsx b/src/components/Buttons/LoadingButton.tsx index 1f00dd5ee7..cf82b7705e 100644 --- a/src/components/Buttons/LoadingButton.tsx +++ b/src/components/Buttons/LoadingButton.tsx @@ -11,14 +11,14 @@ interface LoadingProps { loading?: boolean; } -/** - * A button that shows a spinning wheel when loading=true - */ +/** A button that shows a spinning wheel when `loading = true`. + * Default button props: `color: "primary", variant: "contained"`. */ export default function LoadingButton(props: LoadingProps): ReactElement { return ( {t("buttons.confirm")} diff --git a/src/components/Dialogs/CancelConfirmDialog.tsx b/src/components/Dialogs/CancelConfirmDialog.tsx index e6daa72b13..6519c0c391 100644 --- a/src/components/Dialogs/CancelConfirmDialog.tsx +++ b/src/components/Dialogs/CancelConfirmDialog.tsx @@ -6,14 +6,17 @@ import { DialogContentText, DialogTitle, } from "@mui/material"; -import { ReactElement } from "react"; +import { type ReactElement, useState } from "react"; import { useTranslation } from "react-i18next"; +import LoadingButton from "components/Buttons/LoadingButton"; + interface CancelConfirmDialogProps { open: boolean; - textId: string; + text?: string | ReactElement; + textId?: string; handleCancel: () => void; - handleConfirm: () => void; + handleConfirm: () => Promise | void; buttonIdCancel?: string; buttonIdConfirm?: string; } @@ -24,8 +27,14 @@ interface CancelConfirmDialogProps { export default function CancelConfirmDialog( props: CancelConfirmDialogProps ): ReactElement { + const [loading, setLoading] = useState(false); const { t } = useTranslation(); + const onConfirm = async (): Promise => { + setLoading(true); + await props.handleConfirm(); + }; + return ( - {t(props.textId)} + {props.text || t(props.textId ?? "")} - + ); diff --git a/src/components/Dialogs/DeleteEditTextDialog.tsx b/src/components/Dialogs/DeleteEditTextDialog.tsx index ab27fe933c..d50307e9f1 100644 --- a/src/components/Dialogs/DeleteEditTextDialog.tsx +++ b/src/components/Dialogs/DeleteEditTextDialog.tsx @@ -127,12 +127,7 @@ export default function DeleteEditTextDialog( {t(props.buttonTextIdSave ?? "buttons.save")} diff --git a/src/components/Login/Login.tsx b/src/components/Login/Login.tsx index f498f08f84..fa00ca5907 100644 --- a/src/components/Login/Login.tsx +++ b/src/components/Login/Login.tsx @@ -185,11 +185,7 @@ export default function Login(): ReactElement { diff --git a/src/components/ProjectExport/ExportButton.tsx b/src/components/ProjectExport/ExportButton.tsx index 4b17e033f0..5b304500e2 100644 --- a/src/components/ProjectExport/ExportButton.tsx +++ b/src/components/ProjectExport/ExportButton.tsx @@ -45,7 +45,6 @@ export default function ExportButton(props: ExportButtonProps): ReactElement { buttonProps={{ ...props.buttonProps, onClick: exportProj, - color: "primary", id: `project-${props.projectId}-export`, }} > diff --git a/src/components/ProjectSettings/ProjectSchedule/DateScheduleEdit.tsx b/src/components/ProjectSettings/ProjectSchedule/DateScheduleEdit.tsx index 5094f5a671..1ea9e8cc65 100644 --- a/src/components/ProjectSettings/ProjectSchedule/DateScheduleEdit.tsx +++ b/src/components/ProjectSettings/ProjectSchedule/DateScheduleEdit.tsx @@ -84,8 +84,6 @@ export default function DateScheduleEdit( buttonProps={{ id: "DateSelectorSubmitButton", onClick: handleSubmit, - variant: "contained", - color: "primary", }} > {t("buttons.confirm")} diff --git a/src/components/ProjectSettings/ProjectSchedule/DateSelector.tsx b/src/components/ProjectSettings/ProjectSchedule/DateSelector.tsx index 7bcd1ec0e6..212c4ad9cb 100644 --- a/src/components/ProjectSettings/ProjectSchedule/DateSelector.tsx +++ b/src/components/ProjectSettings/ProjectSchedule/DateSelector.tsx @@ -88,8 +88,6 @@ export default function DateSelector(props: DateSelectorProps): ReactElement { buttonProps={{ id: "DateSelectorSubmitButton", onClick: () => handleSubmit(), - variant: "contained", - color: "primary", }} > {t("buttons.confirm")} diff --git a/src/goals/CharacterInventory/CharInv/index.tsx b/src/goals/CharacterInventory/CharInv/index.tsx index 34a853cc27..0dcce33f16 100644 --- a/src/goals/CharacterInventory/CharInv/index.tsx +++ b/src/goals/CharacterInventory/CharInv/index.tsx @@ -95,7 +95,6 @@ export default function CharacterInventory(): ReactElement { loading={saveInProgress} buttonProps={{ id: buttonIdSave, - color: "primary", onClick: () => save(), style: { margin: theme.spacing(1) }, }} @@ -103,6 +102,7 @@ export default function CharacterInventory(): ReactElement { {t("buttons.save")}