Skip to content

Commit

Permalink
www.apply: fix htmx swap when accept confirmation fails
Browse files Browse the repository at this point in the history
It's quite unlikely to fail since the modal is only shown when the forms
are valid.
However:
- with the help of some JS (:wave: 71a19fc),
- or if the form is submitted at 23:59 with hiring_start_at=today,
  the modal might be shown but the confirmation might happen the next day
  returning an error

In such case, the htmx swap produced a mess with the complete page
inserted inside the modal: let's fix that.
  • Loading branch information
xavfernandez committed Aug 26, 2024
1 parent 74b4258 commit 404dd54
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion itou/templates/apply/includes/accept_section.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h3 class="modal-title" id="confirmation-modal-label">Confirmation de l’embauc
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-outline-primary" data-bs-dismiss="modal">Retour</button>
<button class="btn btn-sm btn-primary" hx-post={{ request.path }} hx-vals='{"confirmed": "True"}' hx-include="#acceptForm" {% matomo_event "candidature" "submit" "accept_application_confirmation" %}>Confirmer
<button class="btn btn-sm btn-primary" hx-post={{ request.path }} hx-target="#acceptFormDiv" hx-swap="outerHTML" hx-vals='{"confirmed": "True"}' hx-include="#acceptForm" {% matomo_event "candidature" "submit" "accept_application_confirmation" %} data-bs-dismiss="modal">Confirmer
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load matomo %}
{% load buttons_form %}

<div class="c-form">
<div class="c-form" id="acceptFormDiv">
<form id="acceptForm" method="post" hx-post="{{ request.path }}" hx-swap="outerHTML show:#acceptForm:top" hx-select="#acceptForm" class="js-format-nir">
{% if has_form_error %}
<div class="alert alert-danger">
Expand Down
3 changes: 3 additions & 0 deletions itou/www/apply/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def _accept(request, siae, job_seeker, error_url, back_url, template_name, extra

return HttpResponseClientRedirect(final_url)

if request.htmx:
template_name = "apply/includes/job_application_accept_form.html"

return render(request, template_name, {**context, "has_form_error": any(form.errors for form in forms)})


Expand Down

0 comments on commit 404dd54

Please sign in to comment.