Skip to content

Commit

Permalink
feat(ready to send): add budget component to ready to send screen
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleith committed Dec 4, 2024
1 parent 43e37ac commit 91d8009
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
29 changes: 29 additions & 0 deletions app/main/views/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
TemplateList,
TemplateLists,
)
from app.notify_client.notification_counts_client import notification_counts_client
from app.template_previews import TemplatePreview, get_page_count_for_letter
from app.utils import (
email_or_sms_not_enabled,
Expand Down Expand Up @@ -134,6 +135,26 @@ def view_template(service_id, template_id):

user_has_template_permission = current_user.has_template_folder_permission(template_folder)

# get the limit stats for the current service
limit_stats = notification_counts_client.get_limit_stats(current_service)

# transform the stats into a format that can be used in the template
notification_type = template["template_type"]
dailyLimit = limit_stats[notification_type]["daily"]["limit"]
dailyUsed = limit_stats[notification_type]["daily"]["sent"]
dailyRemaining = limit_stats[notification_type]["daily"]["remaining"]
yearlyLimit = limit_stats[notification_type]["annual"]["limit"]
yearlyUsed = limit_stats[notification_type]["annual"]["sent"]
yearlyRemaining = limit_stats[notification_type]["annual"]["remaining"]

# determine ready to send heading
if yearlyRemaining == 0:
heading = _("Sending paused until annual limit resets")
elif dailyRemaining == 0:
heading = _('Sending paused until 7pm ET. You can schedule more messages to send later.')
else:
heading = _("Ready to send?")

if should_skip_template_page(template["template_type"]):
return redirect(url_for(".send_one_off", service_id=service_id, template_id=template_id))

Expand All @@ -142,6 +163,14 @@ def view_template(service_id, template_id):
template=get_email_preview_template(template, template_id, service_id),
template_postage=template["postage"],
user_has_template_permission=user_has_template_permission,
dailyLimit=dailyLimit,
dailyUsed=dailyUsed,
yearlyLimit=yearlyLimit,
yearlyUsed=yearlyUsed,
notification_type=notification_type,
dailyRemaining=dailyRemaining,
yearlyRemaining=yearlyRemaining,
heading=heading,
)


Expand Down
31 changes: 22 additions & 9 deletions app/templates/views/templates/_template.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{% from 'components/message-count-label.html' import message_count_label %}
{% from 'components/remaining-messages-summary.html' import remaining_messages_summary with context %}


<!-- dailyLimit: {{ dailyLimit }} <br />
dailyUsed: {{ dailyUsed }} <br />
yearlyLimit: {{ yearlyLimit }} <br />
yearlyUsed: {{ yearlyUsed }} <br />
dailyRemaining : {{ dailyRemaining }} <br />
yearlyRemaining : {{ yearlyRemaining }} <br /> -->

<div>
{% if template._template.archived %}
Expand All @@ -13,19 +22,23 @@
</p>
{% else %}
{% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %}
<h2 class="heading-medium">{{ _('Ready to send?') }}</h2>

<div class="mb-12">
<a href="{{ url_for('.add_recipients', service_id=current_service.id, template_id=template.id) }}" class="button" data-testid="add-recipients">
{{ _('Yes, add recipients') }}
</a>
<a href="{{ url_for('.send_test', service_id=current_service.id, template_id=template.id) }}" class="button button-secondary">{{ _('No, send yourself this message') }}</a>
</div>
<h2 class="heading-medium">{{ heading }}</h2>

{{ remaining_messages_summary(dailyLimit, dailyUsed, yearlyLimit, yearlyUsed, notification_type, yearlyRemaining == 0 or dailyRemaining == 0) }}

{% if yearlyRemaining > 0 %}
<div class="mb-12 mt-12">
<a href="{{ url_for('.add_recipients', service_id=current_service.id, template_id=template.id) }}" class="button" data-testid="add-recipients">
{{ _('Yes, add recipients') }}
</a>
<a href="{{ url_for('.send_test', service_id=current_service.id, template_id=template.id) }}" class="button button-secondary">{{ _('No, send yourself this message') }}</a>
</div>
{% endif %}
{% endif %}
{% endif %}
</div>

<div class="w-full template-container">
<div class="w-full template-container mt-10">
{{ template|string|translate_preview_template }}
</div>

Expand Down

0 comments on commit 91d8009

Please sign in to comment.