From 0deb3cd782ab16a5db0edd37e685685003414ec1 Mon Sep 17 00:00:00 2001 From: Arthur Vieira Date: Wed, 8 Jun 2022 11:37:35 -0300 Subject: [PATCH] Replace url generation with 'whatsapp_url' method As suggested by mkllnk's following comment: https://github.com/openfoodfoundation/openfoodnetwork/pull/9236/commits/1eda7d8a4cf5fa4f1beed51be75a2e205340ac39#r890656117 --- .../javascripts/templates/partials/contact.html.haml | 2 +- app/models/enterprise.rb | 8 ++++---- app/serializers/api/cached_enterprise_serializer.rb | 6 +++--- app/serializers/api/enterprise_shopfront_serializer.rb | 6 +++--- app/views/producers/_fat.html.haml | 2 +- app/views/shopping_shared/tabs/_contact.html.haml | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index e0150ce65b..72ea06b9d6 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -4,7 +4,7 @@ %p{"ng-if" => "::enterprise.phone", "ng-bind" => "::enterprise.phone"} %p{"ng-if" => "::enterprise.whatsapp_phone"} - %a{"ng-href" => "http://wa.me/{{::enterprise.whatsapp_phone}}", target: "_blank", "ng-bind" => "::enterprise.whatsapp_phone"} + %a{"ng-href" => "{{::enterprise.whatsapp_url}}", target: "_blank", "ng-bind" => "::enterprise.whatsapp_phone"} %p{"ng-if" => "::enterprise.email_address"} %a{"ng-href" => "{{::enterprise.email_address | stripUrl}}", target: "_blank", mailto: true} diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 91ccf04a66..5d7892f3ee 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -312,8 +312,8 @@ class Enterprise < ApplicationRecord correct_instagram_url self[:instagram] end - def whatsapp_phone - correct_whatsapp_phone self[:whatsapp_phone] + def whatsapp_url + correct_whatsapp_url self[:whatsapp_phone] end def inventory_variants @@ -452,8 +452,8 @@ class Enterprise < ApplicationRecord url&.sub(%r{(https?://)?}, '') end - def correct_whatsapp_phone(phone_number) - phone_number&.tr('+ ', '') + def correct_whatsapp_url(phone_number) + phone_number && "https://wa.me/" + phone_number.tr('+ ', '') end def correct_instagram_url(url) diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index 846a56896a..bef58f0c77 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -14,9 +14,9 @@ module Api attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, - :facebook, :is_primary_producer, :is_distributor, :phone, :whatsapp_phone, :visible, - :email_address, :hash, :logo, :promo_image, :path, :pickup, :delivery, - :icon, :icon_font, :producer_icon_font, :category + :facebook, :is_primary_producer, :is_distributor, :phone, :whatsapp_phone, + :whatsapp_url, :visible, :email_address, :hash, :logo, :promo_image, :path, :pickup, + :delivery, :icon, :icon_font, :producer_icon_font, :category attributes :taxons, :supplied_taxons diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index 5ee13b3544..ae0e30ff66 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -7,9 +7,9 @@ module Api attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor, - :phone, :whatsapp_phone, :visible, :email_address, :hash, :logo, :promo_image, :path, - :category, :active, :producers, :orders_close_at, :hubs, :taxons, :supplied_taxons, - :pickup, :delivery, :preferred_product_low_stock_display + :phone, :whatsapp_phone, :whatsapp_url, :visible, :email_address, :hash, :logo, + :promo_image, :path, :category, :active, :producers, :orders_close_at, :hubs, + :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display has_one :address, serializer: Api::AddressSerializer has_many :supplied_properties, serializer: Api::PropertySerializer diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 0037b0992f..f99594dea1 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -39,7 +39,7 @@ %span{"ng-bind" => "::producer.phone"} %p.word-wrap{"ng-if" => "::producer.whatsapp_phone"} - %a{"ng-href" => "http://wa.me/{{::producer.whatsapp_phone}}", target: "_blank"} + %a{"ng-href" => "{{::producer.whatsapp_url}}", target: "_blank"} %span{"ng-bind" => "::producer.whatsapp_phone"} %p.word-wrap{"ng-if" => "::producer.email_address"} diff --git a/app/views/shopping_shared/tabs/_contact.html.haml b/app/views/shopping_shared/tabs/_contact.html.haml index 769c10cdac..8ba32bee92 100644 --- a/app/views/shopping_shared/tabs/_contact.html.haml +++ b/app/views/shopping_shared/tabs/_contact.html.haml @@ -27,7 +27,7 @@ = current_distributor.phone %br - if current_distributor.whatsapp_phone.present? - %a{href: "https://wa.me/#{current_distributor.whatsapp_phone}", target: "_blank" } + %a{href: "#{current_distributor.whatsapp_url}", target: "_blank" } = current_distributor.whatsapp_phone %br - if current_distributor.website.present?