Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/javascript/controllers/onboarding_tour_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default class extends Controller {
async startTour() {
if (typeof window.introJs === "undefined") return

await this.resumeIfRequested()

const progress = await this.fetchProgress()
const builtSteps = this.buildSteps()
if (builtSteps.length === 0) return
Expand Down Expand Up @@ -61,6 +63,13 @@ export default class extends Controller {
}
}

async resumeIfRequested() {
const url = new URL(window.location.href)
if (url.searchParams.get("resume_onboarding") !== "1") return

await this.sendOperation("resume")
}

async fetchProgress() {
if (!this.hasEndpointValue || !this.endpointValue) return null

Expand Down Expand Up @@ -110,9 +119,15 @@ export default class extends Controller {
}

async persistLastSeen(stepKey) {
if (!this.hasEndpointValue || !this.endpointValue || !stepKey) return
await this.sendOperation("set_last_seen", stepKey)
}

async sendOperation(operation, stepKey = null) {
if (!this.hasEndpointValue || !this.endpointValue) return

const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute("content")
const body = { operation }
if (stepKey) body.step_key = stepKey

try {
await fetch(this.endpointValue, {
Expand All @@ -123,7 +138,7 @@ export default class extends Controller {
"X-CSRF-Token": csrfToken || ""
},
credentials: "same-origin",
body: JSON.stringify({ operation: "set_last_seen", step_key: stepKey })
body: JSON.stringify(body)
})
} catch (_error) {
// noop
Expand All @@ -133,6 +148,7 @@ export default class extends Controller {
clearAutoStartParam() {
const url = new URL(window.location.href)
url.searchParams.delete("onboarding_tour")
url.searchParams.delete("resume_onboarding")
window.history.replaceState({}, "", url.toString())
}
}
7 changes: 7 additions & 0 deletions app/views/layouts/partials/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@
<% end %>
</li>
<% end %>
<% unless current_user.tecnico? %>
<li>
<%= link_to app_dashboard_path(onboarding_tour: 1, resume_onboarding: 1) do %>
<i class="bx bx-compass"></i> Ver tour novamente
<% end %>
</li>
<% end %>
<% end %>
</ul>
</li>
Expand Down
Loading