Skip to content

Commit

Permalink
Move Not interested CTA form action modal
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jan 26, 2024
1 parent 157934d commit 701c71e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 52 deletions.
51 changes: 16 additions & 35 deletions lemarche/templates/tenders/_detail_cta_not_interested.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
<div id="detail_not_interested_container" class="mt-3">
{% if not tender.siae_detail_not_interested_click_date_count %}
<div class="card c-card rounded-lg shadow-lg">
<div class="card-body">
<h3>Pas intéressé ?</h3>
<p>
Cette demande ne vous intéresse pas ? Dites-le nous !
</p>
{% if user_can_click %}
<form method="POST" action="{% url 'tenders:detail-not-interested-click' tender.slug %}?siae_id=">
{% csrf_token %}
<div class="form-group">
<label for="id_detail_not_interested_feedback">Afin d'améliorer la pertinence des demandes que nous vous envoyons, expliquez-nous pourquoi celle-ci ne vous intéresse pas.</label>
<textarea id="id_detail_not_interested_feedback" class="form-control" name="detail_not_interested_feedback" placeholder="Parce que..." rows="3"></textarea>
</div>
<div>
{% if user.is_authenticated %}
<button type="submit" class="btn btn-warning btn-block" title="{{ tender.cta_not_interested_card_button_text|safe }}" hx-post="{% url 'tenders:detail-not-interested-click' tender.slug %}" hx-target="#detail_not_interested_container">
<span>{{ tender.cta_not_interested_card_button_text|safe }}</span>
</button>
{% elif siae_id %}
<button type="submit" class="btn btn-warning btn-block" title="{{ tender.cta_not_interested_card_button_text|safe }}" hx-post="{% url 'tenders:detail-not-interested-click' tender.slug %}?siae_id={{siae_id}}" hx-target="#detail_not_interested_container">
<span>{{ tender.cta_not_interested_card_button_text|safe }}</span>
</button>
{% endif %}
</div>
</form>
{% else %}
<a href="#" id="show-tender-not-interested-modal-btn" class="btn btn-primary btn-block" data-toggle="modal" data-target="#login_or_signup_siae_tender_modal" data-next-params="{% url 'tenders:detail' tender.slug %}">
<span>{{ tender.cta_not_interested_card_button_text|safe }}</span>
</a>
{% endif %}
</div>
<div class="card c-card rounded-lg shadow-lg">
<div class="card-body">
<h3>Pas intéressé ?</h3>
<p>
Cette demande ne vous intéresse pas ? Dites-le nous !
</p>
{% if user_can_click %}
<button type="button" id="show-tender-contact-modal-btn" class="btn btn-warning btn-block" data-toggle="modal" data-target="#detail_not_interested_click_confirm_modal" data-siae-id="{{ siae_id }}" title="{{ tender.cta_not_interested_card_button_text|safe }}">
{{ tender.cta_not_interested_card_button_text|safe }}
</button>
{% else %}
<a href="#" id="show-tender-not-interested-modal-btn" class="btn btn-warning btn-block" data-toggle="modal" data-target="#login_or_signup_siae_tender_modal" data-next-params="{% url 'tenders:detail' tender.slug %}">
<span>{{ tender.cta_not_interested_card_button_text|safe }}</span>
</a>
{% endif %}
</div>
{% else %}
{% include "tenders/_detail_not_interested_click_confirm.html" %}
{% endif %}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="modal fade modal-siae" id="detail_not_interested_click_confirm_modal" tabindex="-1" role="dialog" aria-modal="true" data-backdrop="static" data-keyboard="false" aria-labelledby="modalTitle">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="modalTitle">Pas intéressé ?</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Fermer">
<i class="ri-close-line"></i>
</button>
</div>
<form method="POST" action="{% url 'tenders:detail-not-interested-click' tender.slug %}?siae_id=siae-id-params-to-replace">
{% csrf_token %}
<div class="modal-body home-content-body">
<div class="form-group">
<label for="id_detail_not_interested_feedback">Afin d'améliorer la pertinence des demandes que nous vous envoyons, expliquez-nous pourquoi celle-ci ne vous intéresse pas.</label>
<textarea id="id_detail_not_interested_feedback" class="form-control" name="detail_not_interested_feedback" placeholder="Parce que..." rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-sm btn-warning" title="{{ tender.cta_not_interested_card_button_text|safe }}">
<span>{{ tender.cta_not_interested_card_button_text|safe }}</span>
</button>
</div>
</form>
</div>
</div>
</div>

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
const MODAL_ID = '#detail_not_interested_click_confirm_modal';
$(MODAL_ID).on('show.bs.modal', function (event) {
// Button that triggered the modal
var button = $(event.relatedTarget);

// Extract info from data-* attributes
var siaeIdParams = button.data('siae-id');

// Update the modal's content
var modal = document.querySelector(MODAL_ID);
var form = modal.querySelector('form');
var formAction = form.getAttribute('action');
form.setAttribute('action', formAction.replace('siae-id-params-to-replace', siaeIdParams));
});
});
</script>
1 change: 1 addition & 0 deletions lemarche/templates/tenders/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
{% block modals %}
{% include "auth/_login_or_signup_siae_tender_modal.html" %}
{% include "tenders/_detail_contact_click_confirm_modal.html" %}
{% include "tenders/_detail_not_interested_click_confirm_modal.html" %}
{% endblock %}

{% block extra_js %}
Expand Down
43 changes: 26 additions & 17 deletions lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,25 +506,34 @@ def get_object(self):
def post(self, request, *args, **kwargs):
self.object = self.get_object()
user = self.request.user

if self.request.user.is_authenticated:
siae = user.siaes.first()
else:
siae = Siae.objects.filter(pk=self.request.GET.get("siae_id", None)).first()

if siae:
# save the datetime of this action
TenderSiae.objects.filter(
tender=self.object, siae=siae, detail_not_interested_click_date__isnull=True
).update(
detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
detail_not_interested_click_date=timezone.now(),
updated_at=timezone.now(),
)
siae_id = request.GET.get("siae_id", None)
if (user.is_authenticated and user.kind == User.KIND_SIAE) or siae_id:
if user.is_authenticated:
TenderSiae.objects.filter(
tender=self.object, siae__in=user.siaes.all(), detail_not_interested_click_date__isnull=True
).update(
detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
detail_not_interested_click_date=timezone.now(),
updated_at=timezone.now(),
)
else:
TenderSiae.objects.filter(
tender=self.object, siae_id=int(siae_id), detail_not_interested_click_date__isnull=True
).update(
detail_not_interested_feedback=self.request.POST.get("detail_not_interested_feedback", ""),
detail_not_interested_click_date=timezone.now(),
updated_at=timezone.now(),
)
# redirect
return HttpResponseRedirect(self.get_success_url(siae_id))
else:
self.template_name = "tenders/_detail_not_interested_click_error.html"
return HttpResponseForbidden()

return self.get(request)
def get_success_url(self, siae_id=None):
success_url = reverse_lazy("tenders:detail", args=[self.kwargs.get("slug")])
if siae_id:
success_url += f"?siae_id={siae_id}"
return success_url


class TenderSiaeListView(TenderAuthorOrAdminRequiredMixin, FormMixin, ListView):
Expand Down

0 comments on commit 701c71e

Please sign in to comment.