-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[283] Eval Form: Cancelation modal #315
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4f266bd
283 Initial cancel modal for eval form
cpreisinger 41c0b14
Merge branch 'dev' of github.com:GSA/Challenge_platform into 283/eval…
cpreisinger 5e6d03a
283 Add accessibility test for cancel modal
cpreisinger 6fa9b5a
Merge branch 'dev' into 283/eval-form-cancelation-modal
stepchud 9995753
Merge branch 'dev' of github.com:GSA/Challenge_platform into 283/eval…
cpreisinger 65cf200
283 Change confirm/cancel modal to stimulus
cpreisinger 9f6080d
283 Allow modal actions. Confirm criteria removal
cpreisinger 8cfbaca
Merge branch '283/eval-form-cancelation-modal' of github.com:GSA/Chal…
cpreisinger 27e2749
Merge branch 'dev' into 283/eval-form-cancelation-modal
stepchud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
static targets = ["modal"]; | ||
static values = { | ||
modalId: String, | ||
}; | ||
|
||
open(event) { | ||
const modalId = event.currentTarget.dataset.modalTargetId; | ||
const modal = this.modalTargets.find((modal) => modal.id === modalId); | ||
|
||
this.openEvent = event; | ||
|
||
event.preventDefault(); | ||
|
||
if (modal) { | ||
modal.showModal(); | ||
} else { | ||
console.warn(`Modal with ID '${modalId}' not found.`); | ||
} | ||
} | ||
|
||
confirm(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const confirmRedirect = modal.dataset.modalConfirmRedirect; | ||
const confirmAction = modal.dataset.modalConfirmAction; | ||
|
||
if (confirmRedirect) { | ||
window.location.href = confirmRedirect; | ||
} else if (confirmAction) { | ||
this.invokeAction(confirmAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
cancel(event) { | ||
const modal = this._getModal(event); | ||
|
||
if (modal) { | ||
const cancelRedirect = modal.dataset.modalCancelRedirect; | ||
const cancelAction = modal.dataset.modalCancelAction; | ||
|
||
if (cancelRedirect) { | ||
window.location.href = cancelRedirect; | ||
} else if (cancelAction) { | ||
this.invokeAction(cancelAction); | ||
modal.close(); | ||
} else { | ||
modal.close(); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
_getModal(event) { | ||
return event.currentTarget.closest("dialog"); | ||
} | ||
|
||
invokeAction(actionName) { | ||
const [controllerName, action] = actionName.split("#"); | ||
const controllerElement = document.querySelector( | ||
`[data-controller~="${controllerName}"]` | ||
); | ||
|
||
if (!controllerElement) { | ||
console.warn(`Controller element for ${controllerName} not found.`); | ||
} | ||
|
||
const controller = this.application.getControllerForElementAndIdentifier( | ||
controllerElement, | ||
controllerName | ||
); | ||
|
||
if (controller && typeof controller[action] === "function") { | ||
controller[action](this.openEvent); | ||
} else { | ||
console.warn(`Action ${actionName} not found on ${controllerName}`); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<dialog | ||
id="<%= id %>" | ||
class="border-width-0 radius-lg" | ||
aria-labelledby=<%= "#{id}-heading" %> | ||
aria-describedby=<%= "#{id}-description" %> | ||
data-modal-target="modal" | ||
data-modal-confirm-redirect="<%= defined?(confirm_redirect) ? confirm_redirect : '' %>" | ||
data-modal-cancel-redirect="<%= defined?(cancel_redirect) ? cancel_redirect : '' %>" | ||
data-modal-confirm-action="<%= defined?(confirm_action) ? confirm_action : '' %>" | ||
data-modal-cancel-action="<%= defined?(cancel_action) ? cancel_action : '' %>" | ||
> | ||
<div class="usa-modal__content"> | ||
<div class="usa-modal__main"> | ||
<h2 class="usa-modal__heading" id=<%= "#{id}-heading" %>> | ||
<%= heading %> | ||
</h2> | ||
<div class="usa-prose"> | ||
<p id=<%= "#{id}-description" %>> | ||
<%= description %> | ||
</p> | ||
</div> | ||
<div class="usa-modal__footer"> | ||
<button id="modal-btn-confirm" class="usa-button" type="button" data-action="modal#confirm"><%= confirm_text %></button> | ||
<button id="modal-btn-cancel" class="usa-button--unstyled" type="button" data-action="modal#cancel"><%= cancel_text %></button> | ||
</div> | ||
</div> | ||
</div> | ||
</dialog> |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!