mirror of
https://github.com/outline/outline.git
synced 2025-12-21 02:29:41 -06:00
* Upgrade Prettier to v3.6.2 and eslint-plugin-prettier to v5.5.1 - Upgraded prettier from ^2.8.8 to ^3.6.2 (latest version) - Upgraded eslint-plugin-prettier from ^4.2.1 to ^5.5.1 for compatibility - Applied automatic formatting changes from new Prettier version - All existing ESLint and Prettier configurations remain compatible * Applied automatic fixes * Trigger CI --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
import Button from "~/components/Button";
|
|
import Flex from "~/components/Flex";
|
|
import Text from "~/components/Text";
|
|
import useStores from "~/hooks/useStores";
|
|
|
|
type Props = {
|
|
/** Callback when the dialog is submitted. Return false to prevent closing. */
|
|
onSubmit: () => Promise<void | boolean> | void;
|
|
/** Text to display on the submit button */
|
|
submitText?: string;
|
|
/** Text to display while the form is saving */
|
|
savingText?: string;
|
|
/** If true, the submit button will be a dangerous red */
|
|
danger?: boolean;
|
|
/** Keep the submit button disabled */
|
|
disabled?: boolean;
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
const ConfirmationDialog: React.FC<Props> = ({
|
|
onSubmit,
|
|
children,
|
|
submitText,
|
|
savingText,
|
|
danger,
|
|
disabled = false,
|
|
}: Props) => {
|
|
const [isSaving, setIsSaving] = React.useState(false);
|
|
const { t } = useTranslation();
|
|
const { dialogs } = useStores();
|
|
|
|
const handleSubmit = React.useCallback(
|
|
async (ev: React.SyntheticEvent) => {
|
|
ev.preventDefault();
|
|
setIsSaving(true);
|
|
try {
|
|
const res = await onSubmit();
|
|
if (res === false) {
|
|
return;
|
|
}
|
|
dialogs.closeAllModals();
|
|
} catch (err) {
|
|
toast.error(err.message);
|
|
} finally {
|
|
setIsSaving(false);
|
|
}
|
|
},
|
|
[onSubmit, dialogs]
|
|
);
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<Flex gap={12} column>
|
|
<Text type="secondary">{children}</Text>
|
|
|
|
<Flex justify="flex-end">
|
|
<Button
|
|
type="submit"
|
|
disabled={isSaving || disabled}
|
|
danger={danger}
|
|
autoFocus
|
|
>
|
|
{isSaving && savingText ? savingText : (submitText ?? t("Confirm"))}
|
|
</Button>
|
|
</Flex>
|
|
</Flex>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
export default observer(ConfirmationDialog);
|