From 381aac0f58fdb8f859f0dea7a80059200ec1486a Mon Sep 17 00:00:00 2001 From: William B <7444334+whabanks@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:56:19 -0400 Subject: [PATCH] Squash a few routing / UI bugs (#1957) * Squash a few routing / UI bugs - The delete button is not longer displayed when there isn't a callback configured - Fixed an issue where the delete confirmation banner wasn't displaying in some circumstances - Fixed a routing issue where deleting a received-text-messages callback was deleting the delivery status callback - Fixed an issue where the Test callback button was not remaining on the same page after clicking * Squash validation bug --- app/main/views/api_keys.py | 69 ++++++++++++++----- app/templates/components/page-footer.html | 2 +- .../callbacks/delivery-status-callback.html | 4 +- .../received-text-messages-callback.html | 5 +- 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/app/main/views/api_keys.py b/app/main/views/api_keys.py index b50286dce2..a86a6722e3 100644 --- a/app/main/views/api_keys.py +++ b/app/main/views/api_keys.py @@ -197,8 +197,8 @@ def delete_delivery_status_callback(service_id): "default_with_tick") return redirect(url_for(back_link, service_id=service_id)) - flash(["{}".format( - _l("Are you sure you want to delete this callback configuration?"))], "delete") + flash(["{}".format( + _l("Are you sure you want to delete this callback configuration?"))], "delete") form = ServiceDeliveryStatusCallbackForm( url=delivery_status_callback.get( @@ -250,26 +250,34 @@ def delivery_status_callback(service_id): callback_api_id=delivery_status_callback.get("id"), ) - # If the user is just testing their URL, don't send them back to the API Integration page - if request.form.get("button_pressed") == "test_response_time": - flash( - _l("The service {} responded in {} seconds.").format( - url_hostname, - response_time, - ), - "default_with_tick", - ) - return redirect(url_for("main.delivery_status_callback", service_id=service_id)) - + # If the user is just testing their URL, don't send them back to the API Integration page + if request.form.get("button_pressed") == "test_response_time" and g.callback_response_time >= 1: flash( - _l("We’ve saved your callback configuration. {} responded in {} seconds.").format( + _l("The service {} took longer than 1 second to respond.").format( + url_hostname, + ), + "error", + ) + return redirect(url_for("main.delivery_status_callback", service_id=service_id)) + else: + flash( + _l("The service {} responded in {} seconds.").format( url_hostname, response_time, ), "default_with_tick", ) + return redirect(url_for("main.delivery_status_callback", service_id=service_id)) - return redirect(url_for(back_link, service_id=service_id)) + flash( + _l("We’ve saved your callback configuration. {} responded in {} seconds.").format( + url_hostname, + response_time, + ), + "default_with_tick", + ) + + return redirect(url_for(back_link, service_id=service_id)) # Create a new callback elif form.url.data: service_api_client.create_service_callback_api( @@ -312,6 +320,16 @@ def delivery_status_callback(service_id): ) return redirect(url_for("main.delivery_status_callback", service_id=service_id)) + flash( + _l("We’ve saved your callback configuration. {} responded in {} seconds.").format( + url_hostname, + response_time, + ), + "default_with_tick", + ) + + return redirect(url_for(back_link, service_id=service_id)) + return render_template( "views/api/callbacks/delivery-status-callback.html", has_callback_config=delivery_status_callback is not None, @@ -362,7 +380,15 @@ def received_text_messages_callback(service_id): ) # If the user is just testing their URL, don't send them back to the API Integration page - if request.form.get("button_pressed") == "test_response_time": + if request.form.get("button_pressed") == "test_response_time" and g.callback_response_time >= 1: + flash( + _l("The service {} took longer than 1 second to respond.").format( + url_hostname, + ), + "error", + ) + return redirect(url_for("main.received_text_messages_callback", service_id=service_id)) + else: flash( _l("The service {} responded in {} seconds.").format( url_hostname, @@ -379,6 +405,7 @@ def received_text_messages_callback(service_id): ), "default_with_tick", ) + return redirect(url_for(back_link, service_id=service_id)) elif received_text_messages_callback and not form.url.data: service_api_client.delete_service_inbound_api( @@ -420,6 +447,16 @@ def received_text_messages_callback(service_id): ) return redirect(url_for("main.received_text_messages_callback", service_id=service_id)) + flash( + _l("We’ve saved your callback configuration. {} responded in {} seconds.").format( + url_hostname, + response_time, + ), + "default_with_tick", + ) + + return redirect(url_for(back_link, service_id=service_id)) + return render_template( "views/api/callbacks/received-text-messages-callback.html", has_callback_config=received_text_messages_callback is not None, diff --git a/app/templates/components/page-footer.html b/app/templates/components/page-footer.html index 144aaaccab..1528cb8f70 100644 --- a/app/templates/components/page-footer.html +++ b/app/templates/components/page-footer.html @@ -73,7 +73,7 @@ button1_value="b1", button2_text=None, button2_value=None, - delete_link=False, + delete_link=None, delete_link_text=_("Delete")) %}