discourse/app/assets/javascripts/wizard/addon/templates/step.gjs
David Taylor e4c373194d
DEV: Refactor Wizard components (#24770)
This commit refactors the Wizard component code in preparation for moving it to the 'static' directory for Embroider route-splitting. It also includes a number of general improvements and simplifications.

Extracted from https://github.com/discourse/discourse/pull/23678

Co-authored-by: Godfrey Chan <godfreykfc@gmail.com>
2023-12-07 16:33:38 +00:00

59 lines
1.4 KiB
Plaintext

import Component from "@glimmer/component";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import RouteTemplate from "ember-route-template";
import getUrl from "discourse-common/lib/get-url";
import WizardCanvas from "../components/wizard-canvas";
import WizardStep from "../components/wizard-step";
export default RouteTemplate(
class extends Component {
@service router;
<template>
{{#if this.showCanvas}}
<WizardCanvas />
{{/if}}
<WizardStep
@step={{@model.step}}
@wizard={{@model.wizard}}
@goNext={{this.goNext}}
@goBack={{this.goBack}}
@goHome={{this.goHome}}
/>
</template>
get step() {
return this.args.model.step;
}
get showCanvas() {
return this.step.id === "ready";
}
@action
goNext(response) {
const next = this.step.next;
if (response?.refresh_required) {
document.location = getUrl(`/wizard/steps/${next}`);
} else if (response?.success && next) {
this.router.transitionTo("wizard.step", next);
} else if (response?.success) {
this.router.transitionTo("discovery.latest");
}
}
@action
goBack() {
this.router.transitionTo("wizard.step", this.step.previous);
}
@action
goHome() {
this.router.transitionTo("discovery.latest");
}
}
);