ui/install: hook up {cancel, close} method
This commit is contained in:
@@ -6,38 +6,25 @@ import {
|
|||||||
useStepper,
|
useStepper,
|
||||||
} from "@/src/hooks/stepper";
|
} from "@/src/hooks/stepper";
|
||||||
import { createForm, FieldValues, SubmitHandler } from "@modular-forms/solid";
|
import { createForm, FieldValues, SubmitHandler } from "@modular-forms/solid";
|
||||||
import { Show } from "solid-js";
|
import { onMount, Show } from "solid-js";
|
||||||
import { Dynamic } from "solid-js/web";
|
import { Dynamic } from "solid-js/web";
|
||||||
import { initialSteps } from "./steps/Initial";
|
import { initialSteps } from "./steps/Initial";
|
||||||
import { createInstallerSteps } from "./steps/createInstaller";
|
import { createInstallerSteps } from "./steps/createInstaller";
|
||||||
import { installSteps } from "./steps/installSteps";
|
import { installSteps } from "./steps/installSteps";
|
||||||
import { ApiCall } from "@/src/hooks/api";
|
import { ApiCall } from "@/src/hooks/api";
|
||||||
|
|
||||||
interface InstallForm extends FieldValues {
|
interface InstallStepperProps {
|
||||||
data_from_step_1: string;
|
onDone: () => void;
|
||||||
data_from_step_2?: string;
|
|
||||||
data_from_step_3?: string;
|
|
||||||
}
|
}
|
||||||
|
const InstallStepper = (props: InstallStepperProps) => {
|
||||||
const InstallStepper = () => {
|
|
||||||
const stepSignal = useStepper<InstallSteps>();
|
const stepSignal = useStepper<InstallSteps>();
|
||||||
|
const [store, set] = getStepStore<InstallStoreType>(stepSignal);
|
||||||
|
|
||||||
const [formStore, { Form, Field, FieldArray }] = createForm<InstallForm>();
|
onMount(() => {
|
||||||
|
set("done", props.onDone);
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit: SubmitHandler<InstallForm> = (values, event) => {
|
return <Dynamic component={stepSignal.currentStep().content} />;
|
||||||
console.log("Installation started (submit)", values);
|
|
||||||
stepSignal.setActiveStep("install:progress");
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<Form onSubmit={handleSubmit}>
|
|
||||||
<div class="gap-6">
|
|
||||||
<Dynamic
|
|
||||||
component={stepSignal.currentStep().content}
|
|
||||||
machineName={"karl"}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface InstallModalProps {
|
export interface InstallModalProps {
|
||||||
@@ -108,7 +95,7 @@ export const InstallModal = (props: InstallModalProps) => {
|
|||||||
// @ts-expect-error some steps might not have
|
// @ts-expect-error some steps might not have
|
||||||
disablePadding={stepper.currentStep()?.isSplash}
|
disablePadding={stepper.currentStep()?.isSplash}
|
||||||
>
|
>
|
||||||
{(ctx) => <InstallStepper />}
|
{(ctx) => <InstallStepper onDone={ctx.close} />}
|
||||||
</Modal>
|
</Modal>
|
||||||
</StepperProvider>
|
</StepperProvider>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -308,6 +308,14 @@ const FlashProgress = () => {
|
|||||||
stepSignal.next();
|
stepSignal.next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const handleCancel = async () => {
|
||||||
|
const progress = store.flash.progress;
|
||||||
|
if (progress) {
|
||||||
|
await progress.cancel();
|
||||||
|
}
|
||||||
|
stepSignal.previous();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="flex h-60 w-full flex-col items-center justify-end bg-inv-4">
|
<div class="flex h-60 w-full flex-col items-center justify-end bg-inv-4">
|
||||||
<div class="mb-6 flex w-full max-w-md flex-col items-center gap-3 fg-inv-1">
|
<div class="mb-6 flex w-full max-w-md flex-col items-center gap-3 fg-inv-1">
|
||||||
@@ -320,7 +328,12 @@ const FlashProgress = () => {
|
|||||||
USB stick is being flashed
|
USB stick is being flashed
|
||||||
</Typography>
|
</Typography>
|
||||||
<LoadingBar />
|
<LoadingBar />
|
||||||
<Button hierarchy="primary" class="w-fit" size="s">
|
<Button
|
||||||
|
hierarchy="primary"
|
||||||
|
class="w-fit"
|
||||||
|
size="s"
|
||||||
|
onClick={handleCancel}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -537,6 +537,13 @@ const InstallProgress = () => {
|
|||||||
const stepSignal = useStepper<InstallSteps>();
|
const stepSignal = useStepper<InstallSteps>();
|
||||||
const [store, get] = getStepStore<InstallStoreType>(stepSignal);
|
const [store, get] = getStepStore<InstallStoreType>(stepSignal);
|
||||||
|
|
||||||
|
const handleCancel = async () => {
|
||||||
|
const progress = store.install.progress;
|
||||||
|
if (progress) {
|
||||||
|
await progress.cancel();
|
||||||
|
}
|
||||||
|
store.done();
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div class="flex h-60 w-full flex-col items-center justify-end bg-inv-4">
|
<div class="flex h-60 w-full flex-col items-center justify-end bg-inv-4">
|
||||||
<div class="mb-6 flex w-full max-w-md flex-col items-center gap-3 fg-inv-1">
|
<div class="mb-6 flex w-full max-w-md flex-col items-center gap-3 fg-inv-1">
|
||||||
@@ -549,7 +556,12 @@ const InstallProgress = () => {
|
|||||||
Machine is beeing installed
|
Machine is beeing installed
|
||||||
</Typography>
|
</Typography>
|
||||||
<LoadingBar />
|
<LoadingBar />
|
||||||
<Button hierarchy="primary" class="w-fit" size="s">
|
<Button
|
||||||
|
hierarchy="primary"
|
||||||
|
class="w-fit"
|
||||||
|
size="s"
|
||||||
|
onClick={handleCancel}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user