From 77360f41af237be550d05acd8b97a77cfd773199 Mon Sep 17 00:00:00 2001 From: Arthur Vieira Date: Fri, 3 Jun 2022 19:33:55 -0300 Subject: [PATCH] Show WhatsApp link on contact modal on map Strips '+' and ' ' characters from the phone number for the generated link, but doesn't guarantee the link is valid because the number registered isn't validated for now. --- .../javascripts/templates/partials/contact.html.haml | 5 ++++- app/models/enterprise.rb | 8 ++++++++ app/serializers/api/cached_enterprise_serializer.rb | 2 +- app/serializers/api/enterprise_shopfront_serializer.rb | 6 +++--- app/services/permitted_attributes/enterprise.rb | 10 +++++----- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/templates/partials/contact.html.haml b/app/assets/javascripts/templates/partials/contact.html.haml index 58c8c4a64d..e0150ce65b 100644 --- a/app/assets/javascripts/templates/partials/contact.html.haml +++ b/app/assets/javascripts/templates/partials/contact.html.haml @@ -1,8 +1,11 @@ %div.contact-container - %div.modal-centered{"ng-if" => "::enterprise.email_address || enterprise.website || enterprise.phone"} + %div.modal-centered{"ng-if" => "::enterprise.email_address || enterprise.website || enterprise.phone || enterprise.whatsapp_phone"} %p.modal-header {{'contact' | t}} %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"} + %p{"ng-if" => "::enterprise.email_address"} %a{"ng-href" => "{{::enterprise.email_address | stripUrl}}", target: "_blank", mailto: true} %span.obfuscatedEmail.email{"ng-bind" => "::enterprise.email_address | stripUrl"} diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index aa7edfc960..91ccf04a66 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -312,6 +312,10 @@ class Enterprise < ApplicationRecord correct_instagram_url self[:instagram] end + def whatsapp_phone + correct_whatsapp_phone self[:whatsapp_phone] + end + def inventory_variants if prefers_product_selection_from_inventory_only? Spree::Variant.visible_for(self) @@ -448,6 +452,10 @@ class Enterprise < ApplicationRecord url&.sub(%r{(https?://)?}, '') end + def correct_whatsapp_phone(phone_number) + phone_number&.tr('+ ', '') + end + def correct_instagram_url(url) url && strip_url(url).sub(%r{www.instagram.com/}, '').delete("@") end diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index ef6b37c9cf..846a56896a 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -14,7 +14,7 @@ module Api attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, - :facebook, :is_primary_producer, :is_distributor, :phone, :visible, + :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 diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index 894152778f..5ee13b3544 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, :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, :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/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index f651edf77a..5aff8fbb76 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -24,11 +24,11 @@ module PermittedAttributes def self.basic_permitted_attributes [ - :id, :name, :visible, :permalink, :owner_id, :contact_name, :email_address, :phone, :whatsapp_phone, - :is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, :twitter, - :description, :long_description, :logo, :promo_image, :terms_and_conditions, - :allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions, - :abn, :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text, + :id, :name, :visible, :permalink, :owner_id, :contact_name, :email_address, :phone, + :whatsapp_phone, :is_primary_producer, :sells, :website, :facebook, :instagram, :linkedin, + :twitter, :description, :long_description, :logo, :promo_image, :terms_and_conditions, + :allow_guest_orders, :allow_order_changes, :require_login, :enable_subscriptions, :abn, + :acn, :charges_sales_tax, :display_invoice_logo, :invoice_text, :preferred_product_selection_from_inventory_only, :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order, :preferred_shopfront_producer_order, :preferred_shopfront_order_cycle_order,