Address modal safeguard review feedback

This commit is contained in:
mirfalltnixein committed 2026-10-28 00:30:52 +01:00
1 parent 6838868fdc
commit 5e76f904ee
15 files changed
+701 -631

No files matched your search

@@ -4,9 +4,9 @@ import Modal from "react-bootstrap/Modal";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { FormModal } from "./FormModal";
const renderModal = (onHide = vi.fn()) => {
const renderModal = (onHide = vi.fn(), preventHide = false) => {
render(
<FormModal show onHide={onHide} initialValues={{ name: "" }} onSubmit={vi.fn()}>
<FormModal show onHide={onHide} preventHide={preventHide} initialValues={{ name: "" }} onSubmit={vi.fn()}>
{({ onHide: hide }) => (
<Form>
<Modal.Header closeButton />
@@ -67,4 +67,16 @@ describe("FormModal", () => {
expect(onHide).toHaveBeenCalledOnce();
});
it("does not offer to discard changes while submission is in progress", () => {
const onHide = renderModal(vi.fn(), true);
const confirm = vi.spyOn(window, "confirm");
fireEvent.change(screen.getByLabelText("Name"), { target: { value: "example.com" } });
fireEvent.click(screen.getByRole("button", { name: "Close" }));
expect(confirm).not.toHaveBeenCalled();
expect(onHide).not.toHaveBeenCalled();
expect(screen.getByLabelText("Name")).toHaveValue("example.com");
});
});
+29 -12
View File
@@ -1,27 +1,44 @@
import { Formik, type FormikConfig, type FormikProps, type FormikValues } from "formik";
import type { ReactNode } from "react";
import { type ReactNode, useEffect } from "react";
import Modal from "react-bootstrap/Modal";
import { intl } from "src/locale";
const confirmDiscardChanges = (dirty: boolean) =>
!dirty ||
window.confirm(
intl.formatMessage({
id: "form.unsaved-changes",
defaultMessage: "You have unsaved changes. Are you sure you want to discard them?",
}),
);
const FormDirtyState = ({ dirty, onChange }: { dirty: boolean; onChange: (dirty: boolean) => void }) => {
useEffect(() => {
onChange(dirty);
return () => onChange(false);
}, [dirty, onChange]);
return null;
};
interface FormModalProps<Values extends FormikValues> extends Omit<FormikConfig<Values>, "children"> {
show: boolean;
onHide: () => void;
preventHide?: boolean;
children: (props: FormikProps<Values> & { onHide: () => void }) => ReactNode;
}
const FormModal = <Values extends FormikValues>({ show, onHide, children, ...formikProps }: FormModalProps<Values>) => (
const FormModal = <Values extends FormikValues>({
show,
onHide,
preventHide = false,
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?",
}),
)
) {
if (!preventHide && confirmDiscardChanges(formikProps.dirty)) {
onHide();
}
};
@@ -35,4 +52,4 @@ const FormModal = <Values extends FormikValues>({ show, onHide, children, ...for
</Formik>
);
export { FormModal };
export { confirmDiscardChanges, FormDirtyState, FormModal };
+11 -6
View File
@@ -1,12 +1,12 @@
import cn from "classnames";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import type { AccessList, AccessListClient, AccessListItem } from "src/api/backend";
import { AccessClientFields, BasicAuthFields, Button, Loading } from "src/components";
import { FormModal } from "src/components/Form";
import { useAccessList, useSetAccessList } from "src/hooks";
import { intl, T } from "src/locale";
import { validateString } from "src/modules/Validations";
@@ -88,16 +88,21 @@ const AccessListModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || (error && !data)) && (
<Modal show={visible} onHide={remove}>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
{isLoading && <Loading noLogo />}
</Modal>
)}
{isLoading && <Loading noLogo />}
{!isLoading && data && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
name: data?.name,
+125 -126
View File
@@ -1,11 +1,11 @@
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { updateAuth } from "src/api/backend";
import { Button } from "src/components";
import { FormModal } from "src/components/Form";
import { intl, T } from "src/locale";
import { validateString } from "src/modules/Validations";
@@ -42,131 +42,130 @@ const ChangePasswordModal = EasyModal.create(({ id, visible, remove }: Props) =>
};
return (
<>
<FormModal
show={visible}
onHide={remove}
initialValues={
{
current: "",
new: "",
confirm: "",
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="user.change-password" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Alert variant="danger" show={!!error} onClose={() => setError(null)} dismissible>
{error}
</Alert>
<div className="mb-3">
<Field name="current">
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="current"
type="password"
autoComplete="current-password"
required
className={`form-control ${form.errors.current && form.touched.current ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({
id: "user.current-password",
})}
{...field}
/>
<label htmlFor="current">
<T id="user.current-password" />
</label>
{form.errors.name ? (
<div className="invalid-feedback">
{form.errors.current && form.touched.current
? form.errors.current
: null}
</div>
) : null}
</div>
)}
</Field>
</div>
<div className="mb-3">
<Field name="new" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="new"
type="password"
autoComplete="new-password"
required
className={`form-control ${form.errors.new && form.touched.new ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.new-password" })}
{...field}
/>
<label htmlFor="new">
<T id="user.new-password" />
</label>
{form.errors.new ? (
<div className="invalid-feedback">
{form.errors.new && form.touched.new ? form.errors.new : null}
</div>
) : null}
</div>
)}
</Field>
</div>
<div className="mb-3">
<Field name="confirm" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="confirm"
type="password"
autoComplete="new-password"
required
className={`form-control ${form.errors.confirm && form.touched.confirm ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.confirm-password" })}
{...field}
/>
{form.errors.confirm ? (
<div className="invalid-feedback">
{form.errors.confirm && form.touched.confirm
? form.errors.confirm
: null}
</div>
) : null}
<label htmlFor="confirm">
<T id="user.confirm-password" />
</label>
</div>
)}
</Field>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
</>
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
current: "",
new: "",
confirm: "",
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="user.change-password" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Alert variant="danger" show={!!error} onClose={() => setError(null)} dismissible>
{error}
</Alert>
<div className="mb-3">
<Field name="current">
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="current"
type="password"
autoComplete="current-password"
required
className={`form-control ${form.errors.current && form.touched.current ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({
id: "user.current-password",
})}
{...field}
/>
<label htmlFor="current">
<T id="user.current-password" />
</label>
{form.errors.name ? (
<div className="invalid-feedback">
{form.errors.current && form.touched.current
? form.errors.current
: null}
</div>
) : null}
</div>
)}
</Field>
</div>
<div className="mb-3">
<Field name="new" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="new"
type="password"
autoComplete="new-password"
required
className={`form-control ${form.errors.new && form.touched.new ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.new-password" })}
{...field}
/>
<label htmlFor="new">
<T id="user.new-password" />
</label>
{form.errors.new ? (
<div className="invalid-feedback">
{form.errors.new && form.touched.new ? form.errors.new : null}
</div>
) : null}
</div>
)}
</Field>
</div>
<div className="mb-3">
<Field name="confirm" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<div className="form-floating mb-3">
<input
id="confirm"
type="password"
autoComplete="new-password"
required
className={`form-control ${form.errors.confirm && form.touched.confirm ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.confirm-password" })}
{...field}
/>
{form.errors.confirm ? (
<div className="invalid-feedback">
{form.errors.confirm && form.touched.confirm
? form.errors.confirm
: null}
</div>
) : null}
<label htmlFor="confirm">
<T id="user.confirm-password" />
</label>
</div>
)}
</Field>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
);
});
+170 -171
View File
@@ -2,12 +2,12 @@ import { IconAlertTriangle } from "@tabler/icons-react";
import { useQueryClient } from "@tanstack/react-query";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { type Certificate, createCertificate, uploadCertificate, validateCertificate } from "src/api/backend";
import { Button } from "src/components";
import { FormModal } from "src/components/Form";
import { T } from "src/locale";
import { validateString } from "src/modules/Validations";
import { showObjectSuccess } from "src/notifications";
@@ -58,177 +58,176 @@ const CustomCertificateModal = EasyModal.create(({ visible, remove }: InnerModal
};
return (
<>
<FormModal
show={visible}
onHide={remove}
initialValues={
{
niceName: "",
provider: "other",
certificate: null,
certificateKey: null,
intermediateCertificate: null,
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "certificates.custom" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<p className="text-warning">
<IconAlertTriangle size={16} className="me-1" />
<T id="certificates.custom.warning" />
</p>
<Field name="niceName" validate={validateString(1, 255)}>
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="niceName" className="form-label">
<T id="column.name" />
</label>
<input
id="niceName"
type="text"
required
autoComplete="off"
className="form-control"
{...field}
/>
{form.errors.niceName ? (
<div className="invalid-feedback">
{form.errors.niceName && form.touched.niceName
? form.errors.niceName
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="certificateKey">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="certificateKey" className="form-label">
<T id="certificate.custom-certificate-key" />
</label>
<input
id="certificateKey"
type="file"
required
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.certificateKey ? (
<div className="invalid-feedback">
{form.errors.certificateKey && form.touched.certificateKey
? form.errors.certificateKey
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="certificate">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="certificate" className="form-label">
<T id="certificate.custom-certificate" />
</label>
<input
id="certificate"
type="file"
required
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.certificate ? (
<div className="invalid-feedback">
{form.errors.certificate && form.touched.certificate
? form.errors.certificate
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="intermediateCertificate">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="intermediateCertificate" className="form-label">
<T id="certificate.custom-intermediate" />
</label>
<input
id="intermediateCertificate"
type="file"
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.intermediateCertificate ? (
<div className="invalid-feedback">
{form.errors.intermediateCertificate &&
form.touched.intermediateCertificate
? form.errors.intermediateCertificate
: null}
</div>
) : null}
</div>
)}
</Field>
</div>
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
niceName: "",
provider: "other",
certificate: null,
certificateKey: null,
intermediateCertificate: null,
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "certificates.custom" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<p className="text-warning">
<IconAlertTriangle size={16} className="me-1" />
<T id="certificates.custom.warning" />
</p>
<Field name="niceName" validate={validateString(1, 255)}>
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="niceName" className="form-label">
<T id="column.name" />
</label>
<input
id="niceName"
type="text"
required
autoComplete="off"
className="form-control"
{...field}
/>
{form.errors.niceName ? (
<div className="invalid-feedback">
{form.errors.niceName && form.touched.niceName
? form.errors.niceName
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="certificateKey">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="certificateKey" className="form-label">
<T id="certificate.custom-certificate-key" />
</label>
<input
id="certificateKey"
type="file"
required
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.certificateKey ? (
<div className="invalid-feedback">
{form.errors.certificateKey && form.touched.certificateKey
? form.errors.certificateKey
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="certificate">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="certificate" className="form-label">
<T id="certificate.custom-certificate" />
</label>
<input
id="certificate"
type="file"
required
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.certificate ? (
<div className="invalid-feedback">
{form.errors.certificate && form.touched.certificate
? form.errors.certificate
: null}
</div>
) : null}
</div>
)}
</Field>
<Field name="intermediateCertificate">
{({ field, form }: any) => (
<div className="mb-3">
<label htmlFor="intermediateCertificate" className="form-label">
<T id="certificate.custom-intermediate" />
</label>
<input
id="intermediateCertificate"
type="file"
autoComplete="off"
className="form-control"
onChange={(event) => {
form.setFieldValue(
field.name,
event.currentTarget.files?.length
? event.currentTarget.files[0]
: null,
);
}}
/>
{form.errors.intermediateCertificate ? (
<div className="invalid-feedback">
{form.errors.intermediateCertificate &&
form.touched.intermediateCertificate
? form.errors.intermediateCertificate
: null}
</div>
) : null}
</div>
)}
</Field>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
</>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
);
});
+72 -73
View File
@@ -1,12 +1,12 @@
import { useQueryClient } from "@tanstack/react-query";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { createCertificate } from "src/api/backend";
import { Button, DNSProviderFields, DomainNamesField } from "src/components";
import { FormModal } from "src/components/Form";
import { T } from "src/locale";
import { showObjectSuccess } from "src/notifications";
@@ -37,79 +37,78 @@ const DNSCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPro
};
return (
<>
<FormModal
show={visible}
onHide={remove}
initialValues={
{
domainNames: [],
provider: "letsencrypt",
meta: {
dnsChallenge: true,
keyType: "ecdsa",
},
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "lets-encrypt-via-dns" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<DomainNamesField isWildcardPermitted dnsProviderWildcardSupported />
<Field name="meta.keyType">
{({ field }: any) => (
<div className="mb-3">
<label htmlFor="keyType" className="form-label">
<T id="certificates.key-type" />
</label>
<select id="keyType" className="form-select" {...field}>
<option value="rsa">
<T id="certificates.key-type-rsa" />
</option>
<option value="ecdsa">
<T id="certificates.key-type-ecdsa" />
</option>
</select>
<small className="form-text text-muted">
<T id="certificates.key-type-description" />
</small>
</div>
)}
</Field>
<DNSProviderFields />
</div>
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
domainNames: [],
provider: "letsencrypt",
meta: {
dnsChallenge: true,
keyType: "ecdsa",
},
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "lets-encrypt-via-dns" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<DomainNamesField isWildcardPermitted dnsProviderWildcardSupported />
<Field name="meta.keyType">
{({ field }: any) => (
<div className="mb-3">
<label htmlFor="keyType" className="form-label">
<T id="certificates.key-type" />
</label>
<select id="keyType" className="form-select" {...field}>
<option value="rsa">
<T id="certificates.key-type-rsa" />
</option>
<option value="ecdsa">
<T id="certificates.key-type-ecdsa" />
</option>
</select>
<small className="form-text text-muted">
<T id="certificates.key-type-description" />
</small>
</div>
)}
</Field>
<DNSProviderFields />
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
</>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
);
});
+11 -6
View File
@@ -1,7 +1,6 @@
import { IconSettings } from "@tabler/icons-react";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
@@ -13,6 +12,7 @@ import {
SSLCertificateField,
SSLOptionsFields,
} from "src/components";
import { FormModal } from "src/components/Form";
import { useDeadHost, useSetDeadHost } from "src/hooks";
import { T } from "src/locale";
import { showObjectSuccess } from "src/notifications";
@@ -55,16 +55,21 @@ const DeadHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || (error && !data)) && (
<Modal show={visible} onHide={remove}>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
{isLoading && <Loading noLogo />}
</Modal>
)}
{isLoading && <Loading noLogo />}
{!isLoading && data && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
domainNames: data?.domainNames,
+99 -100
View File
@@ -2,12 +2,12 @@ import { IconAlertTriangle } from "@tabler/icons-react";
import { useQueryClient } from "@tanstack/react-query";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { createCertificate, testHttpCertificate } from "src/api/backend";
import { Button, DomainNamesField } from "src/components";
import { FormModal } from "src/components/Form";
import { T } from "src/locale";
import { showObjectSuccess } from "src/notifications";
@@ -110,107 +110,106 @@ const HTTPCertificateModal = EasyModal.create(({ visible, remove }: InnerModalPr
};
return (
<>
<FormModal
show={visible}
onHide={remove}
initialValues={
{
domainNames: [],
provider: "letsencrypt",
meta: {
keyType: "ecdsa",
},
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "lets-encrypt-via-http" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<p className="text-warning">
<IconAlertTriangle size={16} className="me-1" />
<T id="certificates.http.warning" />
</p>
<DomainNamesField
onChange={(doms) => {
setDomains(doms);
setTestResults(null);
}}
/>
<Field name="meta.keyType">
{({ field }: any) => (
<div className="mb-3">
<label htmlFor="keyType" className="form-label">
<T id="certificates.key-type" />
</label>
<select id="keyType" className="form-select" {...field}>
<option value="rsa">
<T id="certificates.key-type-rsa" />
</option>
<option value="ecdsa">
<T id="certificates.key-type-ecdsa" />
</option>
</select>
<small className="form-text text-muted">
<T id="certificates.key-type-description" />
</small>
</div>
)}
</Field>
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting || isTesting}
initialValues={
{
domainNames: [],
provider: "letsencrypt",
meta: {
keyType: "ecdsa",
},
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="object.add" tData={{ object: "lets-encrypt-via-http" }} />
</Modal.Title>
</Modal.Header>
<Modal.Body className="p-0">
<Alert variant="danger" show={!!errorMsg} onClose={() => setErrorMsg(null)} dismissible>
{errorMsg}
</Alert>
<div className="card m-0 border-0">
<div className="card-body">
<p className="text-warning">
<IconAlertTriangle size={16} className="me-1" />
<T id="certificates.http.warning" />
</p>
<DomainNamesField
onChange={(doms) => {
setDomains(doms);
setTestResults(null);
}}
/>
<Field name="meta.keyType">
{({ field }: any) => (
<div className="mb-3">
<label htmlFor="keyType" className="form-label">
<T id="certificates.key-type" />
</label>
<select id="keyType" className="form-select" {...field}>
<option value="rsa">
<T id="certificates.key-type-rsa" />
</option>
<option value="ecdsa">
<T id="certificates.key-type-ecdsa" />
</option>
</select>
<small className="form-text text-muted">
<T id="certificates.key-type-description" />
</small>
</div>
)}
</Field>
</div>
{testResults ? (
<div className="card-footer">
<h5>
<T id="certificates.http.test-results" />
</h5>
{parseTestResults()}
</div>
{testResults ? (
<div className="card-footer">
<h5>
<T id="certificates.http.test-results" />
</h5>
{parseTestResults()}
</div>
) : null}
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting || isTesting}>
<T id="cancel" />
) : null}
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting || isTesting}>
<T id="cancel" />
</Button>
<div className="ms-auto">
<Button
type="button"
actionType="secondary"
className="me-3"
data-bs-dismiss="modal"
isLoading={isTesting}
disabled={isSubmitting || domains.length === 0}
onClick={handleTest}
>
<T id="test" />
</Button>
<div className="ms-auto">
<Button
type="button"
actionType="secondary"
className="me-3"
data-bs-dismiss="modal"
isLoading={isTesting}
disabled={isSubmitting || domains.length === 0}
onClick={handleTest}
>
<T id="test" />
</Button>
<Button
type="submit"
actionType="primary"
className="bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting || isTesting}
>
<T id="save" />
</Button>
</div>
</Modal.Footer>
</Form>
)}
</FormModal>
</>
<Button
type="submit"
actionType="primary"
className="bg-pink"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting || isTesting}
>
<T id="save" />
</Button>
</div>
</Modal.Footer>
</Form>
)}
</FormModal>
);
});
+11 -6
View File
@@ -2,12 +2,12 @@ import { useQueryClient } from "@tanstack/react-query";
import cn from "classnames";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { setPermissions } from "src/api/backend";
import { Button, Loading } from "src/components";
import { FormModal } from "src/components/Form";
import { useUser } from "src/hooks";
import { T } from "src/locale";
import styles from "./PermissionsModal.module.css";
@@ -135,16 +135,21 @@ const PermissionsModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || (error && !data)) && (
<Modal show={visible} onHide={remove}>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
{isLoading && <Loading noLogo />}
</Modal>
)}
{isLoading && <Loading noLogo />}
{!isLoading && data && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
visibility: data.permissions?.visibility,
+11 -6
View File
@@ -2,7 +2,6 @@ import { IconSettings } from "@tabler/icons-react";
import cn from "classnames";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
@@ -17,6 +16,7 @@ import {
SSLCertificateField,
SSLOptionsFields,
} from "src/components";
import { FormModal } from "src/components/Form";
import { useProxyHost, useSetProxyHost, useUser } from "src/hooks";
import { T } from "src/locale";
import { MANAGE, PROXY_HOSTS } from "src/modules/Permissions";
@@ -62,16 +62,21 @@ const ProxyHostModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && (error || userError) && (
<Alert variant="danger" className="m-3">
{error?.message || userError?.message || "Unknown error"}
</Alert>
{(isLoading || userIsLoading || ((error || userError) && (!data || !currentUser))) && (
<Modal show={visible} onHide={remove}>
{!isLoading && (error || userError) && (
<Alert variant="danger" className="m-3">
{error?.message || userError?.message || "Unknown error"}
</Alert>
)}
{(isLoading || userIsLoading) && <Loading noLogo />}
</Modal>
)}
{isLoading || (userIsLoading && <Loading noLogo />)}
{!isLoading && !userIsLoading && data && currentUser && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
// Details tab
+11 -6
View File
@@ -2,7 +2,6 @@ import { IconSettings } from "@tabler/icons-react";
import cn from "classnames";
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
@@ -14,6 +13,7 @@ import {
SSLCertificateField,
SSLOptionsFields,
} from "src/components";
import { FormModal } from "src/components/Form";
import { useRedirectionHost, useSetRedirectionHost } from "src/hooks";
import { T } from "src/locale";
import { validateString } from "src/modules/Validations";
@@ -57,16 +57,21 @@ const RedirectionHostModal = EasyModal.create(({ id, visible, remove }: Props) =
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || (error && !data)) && (
<Modal show={visible} onHide={remove}>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
{isLoading && <Loading noLogo />}
</Modal>
)}
{isLoading && <Loading noLogo />}
{!isLoading && data && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
// Details tab
+99 -100
View File
@@ -1,12 +1,12 @@
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import Modal from "react-bootstrap/Modal";
import { updateAuth } from "src/api/backend";
import { Button } from "src/components";
import { FormModal } from "src/components/Form";
import { intl, T } from "src/locale";
import { validateString } from "src/modules/Validations";
@@ -36,105 +36,104 @@ const SetPasswordModal = EasyModal.create(({ id, visible, remove }: Props) => {
};
return (
<>
<FormModal
show={visible}
onHide={remove}
initialValues={
{
new: "",
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="user.set-password" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Alert variant="danger" show={!!error} onClose={() => setError(null)} dismissible>
{error}
</Alert>
<div className="mb-3">
<Field name="new" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<>
<p className="text-end">
<small>
<a
href="#"
onClick={(e) => {
e.preventDefault();
form.setFieldValue(
field.name,
generate({
length: 12,
numbers: true,
}),
);
setShowPassword(true);
}}
>
<T id="password.generate" />
</a>{" "}
&mdash;{" "}
<a
href="#"
className="text-xs"
onClick={(e) => {
e.preventDefault();
setShowPassword(!showPassword);
}}
>
<T id={showPassword ? "password.hide" : "password.show"} />
</a>
</small>
</p>
<div className="form-floating mb-3">
<input
id="new"
type={showPassword ? "text" : "password"}
required
className={`form-control ${form.errors.new && form.touched.new ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.new-password" })}
{...field}
/>
<label htmlFor="new">
<T id="user.new-password" />
</label>
{form.errors.new ? (
<div className="invalid-feedback">
{form.errors.new && form.touched.new ? form.errors.new : null}
</div>
) : null}
</div>
</>
)}
</Field>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
</>
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
new: "",
} as any
}
onSubmit={onSubmit}
>
{({ onHide }) => (
<Form>
<Modal.Header closeButton>
<Modal.Title>
<T id="user.set-password" />
</Modal.Title>
</Modal.Header>
<Modal.Body>
<Alert variant="danger" show={!!error} onClose={() => setError(null)} dismissible>
{error}
</Alert>
<div className="mb-3">
<Field name="new" validate={validateString(8, 100)}>
{({ field, form }: any) => (
<>
<p className="text-end">
<small>
<a
href="#"
onClick={(e) => {
e.preventDefault();
form.setFieldValue(
field.name,
generate({
length: 12,
numbers: true,
}),
);
setShowPassword(true);
}}
>
<T id="password.generate" />
</a>{" "}
&mdash;{" "}
<a
href="#"
className="text-xs"
onClick={(e) => {
e.preventDefault();
setShowPassword(!showPassword);
}}
>
<T id={showPassword ? "password.hide" : "password.show"} />
</a>
</small>
</p>
<div className="form-floating mb-3">
<input
id="new"
type={showPassword ? "text" : "password"}
required
className={`form-control ${form.errors.new && form.touched.new ? "is-invalid" : ""}`}
placeholder={intl.formatMessage({ id: "user.new-password" })}
{...field}
/>
<label htmlFor="new">
<T id="user.new-password" />
</label>
{form.errors.new ? (
<div className="invalid-feedback">
{form.errors.new && form.touched.new ? form.errors.new : null}
</div>
) : null}
</div>
</>
)}
</Field>
</div>
</Modal.Body>
<Modal.Footer>
<Button data-bs-dismiss="modal" onClick={onHide} disabled={isSubmitting}>
<T id="cancel" />
</Button>
<Button
type="submit"
actionType="primary"
className="ms-auto"
data-bs-dismiss="modal"
isLoading={isSubmitting}
disabled={isSubmitting}
>
<T id="save" />
</Button>
</Modal.Footer>
</Form>
)}
</FormModal>
);
});
+11 -6
View File
@@ -1,10 +1,10 @@
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { Button, Loading, SSLCertificateField, SSLOptionsFields } from "src/components";
import { FormModal } from "src/components/Form";
import { useSetStream, useStream } from "src/hooks";
import { intl, T } from "src/locale";
import { validateNumber, validateString } from "src/modules/Validations";
@@ -48,16 +48,21 @@ const StreamModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || (error && !data)) && (
<Modal show={visible} onHide={remove}>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
)}
{isLoading && <Loading noLogo />}
</Modal>
)}
{isLoading && <Loading noLogo />}
{!isLoading && data && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
incomingPort: data?.incomingPort,
+15 -4
View File
@@ -6,6 +6,7 @@ import Modal from "react-bootstrap/Modal";
import QRCode from "react-qr-code";
import { disable2FA, enable2FA, get2FAStatus, regenerateBackupCodes, start2FASetup } from "src/api/backend";
import { Button } from "src/components";
import { confirmDiscardChanges, FormDirtyState } from "src/components/Form";
import { T } from "src/locale";
import { validateString } from "src/modules/Validations";
import styles from "./TwoFactorModal.module.css";
@@ -28,6 +29,13 @@ const TwoFactorModal = EasyModal.create(({ id, visible, remove }: Props) => {
const [setupData, setSetupData] = useState<{ secret: string; otpauthUrl: string } | null>(null);
const [backupCodes, setBackupCodes] = useState<string[]>([]);
const [isSubmitting, setIsSubmitting] = useState(false);
const [formDirty, setFormDirty] = useState(false);
const handleHide = () => {
if (!isSubmitting && confirmDiscardChanges(formDirty)) {
remove();
}
};
const loadStatus = useCallback(async () => {
try {
@@ -172,8 +180,9 @@ const TwoFactorModal = EasyModal.create(({ id, visible, remove }: Props) => {
/>
</label>
<Formik initialValues={{ code: "" }} onSubmit={handleVerify}>
{() => (
{({ dirty }) => (
<Form>
<FormDirtyState dirty={dirty} onChange={setFormDirty} />
<Field name="code" validate={validateString(6, 6)}>
{({ field, form }: any) => (
<label className="mb-3 d-block">
@@ -242,8 +251,9 @@ const TwoFactorModal = EasyModal.create(({ id, visible, remove }: Props) => {
<T id="2fa.disable-warning" />
</Alert>
<Formik initialValues={{ code: "" }} onSubmit={handleDisable}>
{() => (
{({ dirty }) => (
<Form>
<FormDirtyState dirty={dirty} onChange={setFormDirty} />
<Field name="code" validate={validateString(6, 6)}>
{({ field, form }: any) => (
<label className="mb-3 d-block">
@@ -290,8 +300,9 @@ const TwoFactorModal = EasyModal.create(({ id, visible, remove }: Props) => {
<T id="2fa.regenerate-instructions" />
</p>
<Formik initialValues={{ code: "" }} onSubmit={handleRegenerateBackup}>
{() => (
{({ dirty }) => (
<Form>
<FormDirtyState dirty={dirty} onChange={setFormDirty} />
<Field name="code" validate={validateString(6, 6)}>
{({ field, form }: any) => (
<label className="mb-3 d-block">
@@ -335,7 +346,7 @@ const TwoFactorModal = EasyModal.create(({ id, visible, remove }: Props) => {
};
return (
<Modal show={visible} onHide={remove}>
<Modal show={visible} onHide={handleHide}>
<Modal.Header closeButton>
<Modal.Title>
<T id="2fa.title" />
+12 -7
View File
@@ -1,10 +1,10 @@
import EasyModal, { type InnerModalProps } from "ez-modal-react";
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";
import { Button, Loading } from "src/components";
import { FormModal } from "src/components/Form";
import { useSetUser, useUser } from "src/hooks";
import { intl, T } from "src/locale";
import { validateEmail, validateString } from "src/modules/Validations";
@@ -19,7 +19,7 @@ interface Props extends InnerModalProps {
}
const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
const { data, isLoading, error } = useUser(id);
const { data: currentUser, isLoading: currentIsLoading } = useUser("me");
const { data: currentUser, isLoading: currentIsLoading, error: currentError } = useUser("me");
const { mutate: setUser } = useSetUser();
const [errorMsg, setErrorMsg] = useState<string | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -61,16 +61,21 @@ const UserModal = EasyModal.create(({ id, visible, remove }: Props) => {
return (
<>
{!isLoading && error && (
<Alert variant="danger" className="m-3">
{error?.message || "Unknown error"}
</Alert>
{(isLoading || currentIsLoading || ((error || currentError) && (!data || !currentUser))) && (
<Modal show={visible} onHide={remove}>
{!isLoading && (error || currentError) && (
<Alert variant="danger" className="m-3">
{error?.message || currentError?.message || "Unknown error"}
</Alert>
)}
{(isLoading || currentIsLoading) && <Loading noLogo />}
</Modal>
)}
{(isLoading || currentIsLoading) && <Loading noLogo />}
{!isLoading && !currentIsLoading && data && currentUser && (
<FormModal
show={visible}
onHide={remove}
preventHide={isSubmitting}
initialValues={
{
name: data?.name,