Task 11: Remove direct API calls from components
This commit is contained in:
@@ -27,11 +27,12 @@ import {
|
||||
Text,
|
||||
tokens,
|
||||
} from "@fluentui/react-components";
|
||||
import { activateJail, validateJailConfig } from "../../api/config";
|
||||
import type {
|
||||
ActivateJailRequest,
|
||||
JailActivationResponse,
|
||||
InactiveJail,
|
||||
JailValidationIssue,
|
||||
JailValidationResult,
|
||||
} from "../../types/config";
|
||||
import { ApiError } from "../../api/client";
|
||||
|
||||
@@ -48,6 +49,10 @@ export interface ActivateJailDialogProps {
|
||||
onClose: () => void;
|
||||
/** Called after the jail has been successfully activated. */
|
||||
onActivated: () => void;
|
||||
/** Validates the inactive jail configuration before activation. */
|
||||
onValidate: () => Promise<JailValidationResult>;
|
||||
/** Activates the jail with optional override fields. */
|
||||
onActivate: (payload: ActivateJailRequest) => Promise<JailActivationResponse>;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -68,6 +73,8 @@ export function ActivateJailDialog({
|
||||
open,
|
||||
onClose,
|
||||
onActivated,
|
||||
onValidate,
|
||||
onActivate,
|
||||
}: ActivateJailDialogProps): React.JSX.Element {
|
||||
const [bantime, setBantime] = useState("");
|
||||
const [findtime, setFindtime] = useState("");
|
||||
@@ -103,7 +110,7 @@ export function ActivateJailDialog({
|
||||
setValidationIssues([]);
|
||||
setValidationWarnings([]);
|
||||
|
||||
validateJailConfig(jail.name)
|
||||
onValidate()
|
||||
.then((result) => {
|
||||
setValidationIssues(result.issues);
|
||||
})
|
||||
@@ -114,7 +121,7 @@ export function ActivateJailDialog({
|
||||
.finally(() => {
|
||||
setValidating(false);
|
||||
});
|
||||
}, [open, jail]);
|
||||
}, [open, jail, onValidate]);
|
||||
|
||||
const handleClose = (): void => {
|
||||
if (submitting) return;
|
||||
@@ -143,7 +150,7 @@ export function ActivateJailDialog({
|
||||
setSubmitting(true);
|
||||
setError(null);
|
||||
|
||||
activateJail(jail.name, overrides)
|
||||
onActivate(overrides)
|
||||
.then((result) => {
|
||||
if (!result.active) {
|
||||
if (result.recovered === true) {
|
||||
|
||||
Reference in New Issue
Block a user