mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-11-17 01:08:16 +00:00
Prevent dismissing unsaved form modals
This commit is contained in:
1 parent
1aca775cb9
commit
6838868fdc
17 files changed
+235
-84
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||
import { Field, Form } from "formik";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { FormModal } from "./FormModal";
|
||||
|
||||
const renderModal = (onHide = vi.fn()) => {
|
||||
render(
|
||||
<FormModal show onHide={onHide} initialValues={{ name: "" }} onSubmit={vi.fn()}>
|
||||
{({ onHide: hide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton />
|
||||
<label htmlFor="name">Name</label>
|
||||
<Field id="name" name="name" />
|
||||
<button type="button" onClick={hide}>
|
||||
Cancel
|
||||
</button>
|
||||
</Form>
|
||||
)}
|
||||
</FormModal>,
|
||||
);
|
||||
return onHide;
|
||||
};
|
||||
|
||||
describe("FormModal", () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal("confirm", vi.fn());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.restoreAllMocks();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("dismisses a pristine form without confirmation", () => {
|
||||
const onHide = renderModal();
|
||||
const confirm = vi.spyOn(window, "confirm");
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
|
||||
expect(confirm).not.toHaveBeenCalled();
|
||||
expect(onHide).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("keeps a dirty form open when dismissal is cancelled", () => {
|
||||
const onHide = renderModal();
|
||||
const confirm = vi.spyOn(window, "confirm").mockReturnValue(false);
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "example.com" } });
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Close" }));
|
||||
fireEvent.click(document.querySelector(".modal") as Element);
|
||||
fireEvent.keyDown(document, { key: "Escape", keyCode: 27 });
|
||||
|
||||
expect(confirm).toHaveBeenCalledTimes(4);
|
||||
expect(onHide).not.toHaveBeenCalled();
|
||||
expect(screen.getByLabelText("Name")).toHaveValue("example.com");
|
||||
});
|
||||
|
||||
it("dismisses a dirty form after confirmation", () => {
|
||||
const onHide = renderModal();
|
||||
vi.spyOn(window, "confirm").mockReturnValue(true);
|
||||
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "example.com" } });
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
|
||||
|
||||
expect(onHide).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Formik, type FormikConfig, type FormikProps, type FormikValues } from "formik";
|
||||
import type { ReactNode } from "react";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
import { intl } from "src/locale";
|
||||
|
||||
interface FormModalProps<Values extends FormikValues> extends Omit<FormikConfig<Values>, "children"> {
|
||||
show: boolean;
|
||||
onHide: () => void;
|
||||
children: (props: FormikProps<Values> & { onHide: () => void }) => ReactNode;
|
||||
}
|
||||
|
||||
const FormModal = <Values extends FormikValues>({ show, onHide, children, ...formikProps }: FormModalProps<Values>) => (
|
||||
<Formik {...formikProps}>
|
||||
{(formikProps) => {
|
||||
const handleHide = () => {
|
||||
if (
|
||||
!formikProps.dirty ||
|
||||
window.confirm(
|
||||
intl.formatMessage({
|
||||
id: "form.unsaved-changes",
|
||||
defaultMessage: "You have unsaved changes. Are you sure you want to discard them?",
|
||||
}),
|
||||
)
|
||||
) {
|
||||
onHide();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={show} onHide={handleHide}>
|
||||
{children({ ...formikProps, onHide: handleHide })}
|
||||
</Modal>
|
||||
);
|
||||
}}
|
||||
</Formik>
|
||||
);
|
||||
|
||||
export { FormModal };
|
||||
@@ -3,6 +3,7 @@ export * from "./AccessField";
|
||||
export * from "./BasicAuthFields";
|
||||
export * from "./DNSProviderFields";
|
||||
export * from "./DomainNamesField";
|
||||
export * from "./FormModal";
|
||||
export * from "./LocationsFields";
|
||||
export * from "./NginxConfigField";
|
||||
export * from "./SSLCertificateField";
|
||||
|
||||
@@ -437,6 +437,9 @@
|
||||
"footer.github-fork": {
|
||||
"defaultMessage": "Fork me on Github"
|
||||
},
|
||||
"form.unsaved-changes": {
|
||||
"defaultMessage": "You have unsaved changes. Are you sure you want to discard them?"
|
||||
},
|
||||
"host.flags.block-exploits": {
|
||||
"defaultMessage": "Block Common Exploits"
|
||||
},
|
||||
|
||||
@@ -437,6 +437,9 @@
|
||||
"footer.github-fork": {
|
||||
"defaultMessage": "Tee GitHubis fork"
|
||||
},
|
||||
"form.unsaved-changes": {
|
||||
"defaultMessage": "Sul on salvestamata muudatusi. Kas oled kindel, et soovid need tühistada?"
|
||||
},
|
||||
"host.flags.block-exploits": {
|
||||
"defaultMessage": "Blokeeri levinud ründed"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import cn from "classnames";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -86,7 +87,7 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const toggleEnabled = cn(toggleClasses, "bg-cyan");
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -94,7 +95,9 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{isLoading && <Loading noLogo />}
|
||||
{!isLoading && data && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
name: data?.name,
|
||||
@@ -106,7 +109,7 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{({ setFieldValue }: any) => (
|
||||
{({ onHide, setFieldValue }: any) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -267,7 +270,7 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -283,9 +286,9 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -41,8 +42,10 @@ const ChangePasswordModal = EasyModal.create(({ id, visible, remove }: Props) =>
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<Formik
|
||||
<>
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
current: "",
|
||||
@@ -52,7 +55,7 @@ const ChangePasswordModal = EasyModal.create(({ id, visible, remove }: Props) =>
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -146,7 +149,7 @@ const ChangePasswordModal = EasyModal.create(({ id, visible, remove }: Props) =>
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -162,8 +165,8 @@ const ChangePasswordModal = EasyModal.create(({ id, visible, remove }: Props) =>
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
</FormModal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -57,8 +58,10 @@ const CustomCertificateModal = EasyModal.create(({ visible, remove }: InnerModal
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<Formik
|
||||
<>
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
niceName: "",
|
||||
@@ -70,7 +73,7 @@ const CustomCertificateModal = EasyModal.create(({ visible, remove }: InnerModal
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -208,7 +211,7 @@ const CustomCertificateModal = EasyModal.create(({ visible, remove }: InnerModal
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -224,8 +227,8 @@ const CustomCertificateModal = EasyModal.create(({ visible, remove }: InnerModal
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
</FormModal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Form, Formik, Field } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -36,8 +37,10 @@ const DNSCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPro
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<Formik
|
||||
<>
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
domainNames: [],
|
||||
@@ -50,7 +53,7 @@ const DNSCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPro
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -89,7 +92,7 @@ const DNSCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPro
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -105,8 +108,8 @@ const DNSCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPro
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
</FormModal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { IconSettings } from "@tabler/icons-react";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Form, Formik } from "formik";
|
||||
import { Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -53,7 +54,7 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -61,7 +62,9 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{isLoading && <Loading noLogo />}
|
||||
{!isLoading && data && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
domainNames: data?.domainNames,
|
||||
@@ -76,7 +79,7 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -149,7 +152,7 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -165,9 +168,9 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Form, Formik, Field } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -109,8 +110,10 @@ const HTTPCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPr
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<Formik
|
||||
<>
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
domainNames: [],
|
||||
@@ -122,7 +125,7 @@ const HTTPCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPr
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -177,7 +180,7 @@ const HTTPCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPr
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting || isTesting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting || isTesting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<div className="ms-auto">
|
||||
@@ -206,8 +209,8 @@ const HTTPCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPr
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
</FormModal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import cn from "classnames";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -133,7 +134,7 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
const isAdmin = data?.roles.indexOf("admin") !== -1;
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -141,7 +142,9 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{isLoading && <Loading noLogo />}
|
||||
{!isLoading && data && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
visibility: data.permissions?.visibility,
|
||||
@@ -155,7 +158,7 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -263,7 +266,7 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -278,9 +281,9 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IconSettings } from "@tabler/icons-react";
|
||||
import cn from "classnames";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -60,7 +61,7 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && (error || userError) && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || userError?.message || "Unknown error"}
|
||||
@@ -68,7 +69,9 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{isLoading || (userIsLoading && <Loading noLogo />)}
|
||||
{!isLoading && !userIsLoading && data && currentUser && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
// Details tab
|
||||
@@ -96,7 +99,7 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -350,7 +353,7 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<HasPermission section={PROXY_HOSTS} permission={MANAGE} hideError>
|
||||
@@ -368,9 +371,9 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { IconSettings } from "@tabler/icons-react";
|
||||
import cn from "classnames";
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -55,7 +56,7 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -63,7 +64,9 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
)}
|
||||
{isLoading && <Loading noLogo />}
|
||||
{!isLoading && data && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
// Details tab
|
||||
@@ -86,7 +89,7 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -326,7 +329,7 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -342,9 +345,9 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { generate } from "generate-password-browser";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
@@ -35,8 +36,10 @@ const SetPasswordModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<Formik
|
||||
<>
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
new: "",
|
||||
@@ -44,7 +47,7 @@ const SetPasswordModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -114,7 +117,7 @@ const SetPasswordModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -130,8 +133,8 @@ const SetPasswordModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</Modal>
|
||||
</FormModal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { type ReactNode, useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -46,7 +47,7 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -54,7 +55,9 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{isLoading && <Loading noLogo />}
|
||||
{!isLoading && data && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
incomingPort: data?.incomingPort,
|
||||
@@ -68,7 +71,7 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{({ setFieldValue }: any) => (
|
||||
{({ onHide, setFieldValue }: any) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -302,7 +305,7 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</div>
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -318,9 +321,9 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import EasyModal, { type InnerModalProps } from "ez-modal-react";
|
||||
import { Field, Form, Formik } from "formik";
|
||||
import { Field, Form } from "formik";
|
||||
import { FormModal } from "src/components/Form";
|
||||
import { useState } from "react";
|
||||
import { Alert } from "react-bootstrap";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
@@ -59,7 +60,7 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal show={visible} onHide={remove}>
|
||||
<>
|
||||
{!isLoading && error && (
|
||||
<Alert variant="danger" className="m-3">
|
||||
{error?.message || "Unknown error"}
|
||||
@@ -67,7 +68,9 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
)}
|
||||
{(isLoading || currentIsLoading) && <Loading noLogo />}
|
||||
{!isLoading && !currentIsLoading && data && currentUser && (
|
||||
<Formik
|
||||
<FormModal
|
||||
show={visible}
|
||||
onHide={remove}
|
||||
initialValues={
|
||||
{
|
||||
name: data?.name,
|
||||
@@ -79,7 +82,7 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
}
|
||||
onSubmit={onSubmit}
|
||||
>
|
||||
{() => (
|
||||
{({ onHide }) => (
|
||||
<Form>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title>
|
||||
@@ -222,7 +225,7 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
) : null}
|
||||
</Modal.Body>
|
||||
<Modal.Footer>
|
||||
<Button data-bs-dismiss="modal" onClick={remove} disabled={isSubmitting}>
|
||||
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
|
||||
<T id="cancel" />
|
||||
</Button>
|
||||
<Button
|
||||
@@ -237,9 +240,9 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
|
||||
</Modal.Footer>
|
||||
</Form>
|
||||
)}
|
||||
</Formik>
|
||||
</FormModal>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user