-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFS-2453: Replace Help Modal iframe with Turbo Frame (#459)
Co-authored-by: George Byers <[email protected]>
- Loading branch information
1 parent
ab90d33
commit ad07a68
Showing
8 changed files
with
57 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,24 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { trackUserAction } from "../utilities/api" | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { trackUserAction } from "../utilities/api"; | ||
|
||
export default class extends Controller { | ||
static targets = ["iframe"] | ||
static targets = ["content"]; | ||
|
||
connect() { | ||
this.handleClick = (event) => { | ||
if (event.target.href?.includes("#help-modal")) { | ||
trackUserAction("ApplicantOpenedHelpModal", { source: event.target.dataset.source }) | ||
} | ||
handleClick(event) { | ||
if (event.target.href?.includes("#help-modal")) { | ||
trackUserAction("ApplicantOpenedHelpModal", { | ||
source: event.target.dataset.source, | ||
}); | ||
// reset the help modal src on mousedown to ensure the help modal src is reset to "/help" | ||
document.querySelector("#help_modal_content").src = "/help"; | ||
} | ||
|
||
document.addEventListener("click", this.handleClick) | ||
} | ||
|
||
disconnect() { | ||
document.removeEventListener("click", this.handleClick) | ||
connect() { | ||
document.addEventListener("click", this.handleClick); | ||
} | ||
|
||
/** | ||
* This function is used to prepare the next URL for the iframe. | ||
* It generates a new random parameter and updates the iframe src | ||
* so that when the modal is opened, the iframe will load the | ||
* default help topics rather than the last viewed topic. | ||
*/ | ||
prepareNextUrl() { | ||
const iframe = this.iframeTarget | ||
const currentSrc = new URL(iframe.src) | ||
|
||
// Generate a new random parameter | ||
const randomHex = Array.from(crypto.getRandomValues(new Uint8Array(2))) | ||
.map(b => b.toString(16).padStart(2, "0")) | ||
.join("") | ||
|
||
// Update the iframe src with new random parameter | ||
currentSrc.searchParams.set("r", randomHex) | ||
iframe.src = currentSrc.toString() | ||
disconnect() { | ||
document.removeEventListener("click", this.handleClick); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<%= link_to help_topic_path(topic: topic, locale: I18n.locale), | ||
class: "usa-button margin-bottom-1 height-5 text-left display-block" do %> | ||
class: "usa-button margin-bottom-1 height-5 text-left display-block", | ||
data: { turbo_frame: "help_modal_content" } do %> | ||
<%= text %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
<div class="padding-2"> | ||
<h2 class="margin-top-0"><%= t("help.index.title") %></h2> | ||
<div class="usa-prose"> | ||
<p><%= t("help.index.select_prompt") %></p> | ||
<%= turbo_frame_tag "help_modal_content" do %> | ||
<div class="padding-2"> | ||
<h2 class="margin-top-0"><%= t("help.index.title") %></h2> | ||
<div class="usa-prose"> | ||
<p><%= t("help.index.select_prompt") %></p> | ||
|
||
<%= render "help_topic_link", topic: "username", text: t("help.index.username") %> | ||
<%= render "help_topic_link", topic: "password", text: t("help.index.password") %> | ||
<%= render "help_topic_link", topic: "company-id", text: t("help.index.company_id") %> | ||
<%= render "help_topic_link", topic: "employer", text: t("help.index.employer") %> | ||
<%= render "help_topic_link", topic: "provider", text: t("help.index.provider") %> | ||
<%= render "help_topic_link", topic: "credentials", text: t("help.index.credentials") %> | ||
<%= render "help/help_topic_link", topic: "username", text: t("help.index.username") %> | ||
<%= render "help/help_topic_link", topic: "password", text: t("help.index.password") %> | ||
<%= render "help/help_topic_link", topic: "company-id", text: t("help.index.company_id") %> | ||
<%= render "help/help_topic_link", topic: "employer", text: t("help.index.employer") %> | ||
<%= render "help/help_topic_link", topic: "provider", text: t("help.index.provider") %> | ||
<%= render "help/help_topic_link", topic: "credentials", text: t("help.index.credentials") %> | ||
|
||
<% if current_agency && current_agency.caseworker_feedback_form.present? %> | ||
<%= link_to feedback_form_url, class: "usa-button margin-bottom-1 height-5 text-left display-block", target: "_blank" do %> | ||
<%= t("help.index.feedback") %> | ||
<% if current_agency && current_agency.caseworker_feedback_form.present? %> | ||
<%= link_to feedback_form_url, class: "usa-button margin-bottom-1 height-5 text-left display-block", target: "_blank" do %> | ||
<%= t("help.index.feedback") %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
<div class="padding-3"> | ||
<h2 class="margin-top-0"> | ||
<%= t("help.show.#{@help_topic}.title") %> | ||
</h2> | ||
<%= turbo_frame_tag "help_modal_content" do %> | ||
<div class="padding-3"> | ||
<h2 class="margin-top-0"> | ||
<%= t("help.show.#{@help_topic}.title") %> | ||
</h2> | ||
|
||
<%= render partial: "help_topic_content", locals: { topic: @help_topic } %> | ||
<%= render partial: "help_topic_content", locals: { topic: @help_topic } %> | ||
|
||
<div class="margin-top-3"> | ||
<%= link_to t("help.show.go_back"), help_path, class: "usa-link" %> | ||
<div class="margin-top-3"> | ||
<%= link_to t("help.show.go_back"), | ||
help_path, | ||
class: "usa-link", | ||
data: { turbo_frame: "help_modal_content" } %> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> |