Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Storefront: fixed contact us form
Damian Legawieca59484a6ceaa
diff --git a/storefront/app/controllers/spree/contacts_controller.rb b/storefront/app/controllers/spree/contacts_controller.rbindex 2b10cefc2c..81e65cbfb3 100644--- a/storefront/app/controllers/spree/contacts_controller.rb+++ b/storefront/app/controllers/spree/contacts_controller.rb@@ -1,7 +1,6 @@module Spreeclass ContactsController < StoreControllerbefore_action :load_store- before_action :validate_captcha, only: :createbefore_action :ensure_customer_support_emaildef new@@ -46,21 +45,5 @@ module Spreeflash[:error] = Spree.t(:customer_support_email_not_configured)redirect_back_or_default root_pathend-- def validate_captcha- return unless store_integration('recaptcha')-- hostname = request.host || @store.url_or_custom_domain- return if verify_recaptcha(- action: 'contacts/create',- hostname: hostname,- secret_key: store_integration('recaptcha').secret_key,- site_key: store_integration('recaptcha').site_key,- minimum_score: 0.5- )-- flash[:error] = 'Captcha verification failed, please try again.'- redirect_to action: :new- endendenddiff --git a/storefront/app/views/themes/default/spree/contacts/new.html.erb b/storefront/app/views/themes/default/spree/contacts/new.html.erbnew file mode 100644index 0000000000..705d7e6ec1--- /dev/null+++ b/storefront/app/views/themes/default/spree/contacts/new.html.erb@@ -0,0 +1,23 @@+<div class="page-container">+ <div class="card-dialog mx-auto lg:w-1/3 pt-5">+ <h3 class="mb-5 font-semibold"><%= Spree.t(:contact_us) %></h3>+ <%= form_for @contact, data: { controller: 'recaptcha-form', recaptcha_form_action_value: 'contacts/create' } do |f| %>+ <div class="mb-5">+ <p>+ <%= f.text_field :name, required: true, class: "text-input w-full", placeholder: Spree.t(:name) %>+ </p>+ </div>+ <div class="mb-5">+ <p>+ <%= f.email_field :email, required: true, class: "text-input w-full", placeholder: Spree.t(:email) %>+ </p>+ </div>+ <div class="mb-5">+ <p>+ <%= f.text_area :message, rows: 8, cols: 40, required: true, class: "text-input w-full", placeholder: Spree.t(:send_us_a_message), style: 'min-height: 8rem' %>+ </p>+ </div>+ <%= f.submit Spree.t(:send_message), class: 'btn btn-primary' %>+ <% end %>+ </div>+</div>diff --git a/storefront/spec/controllers/spree/contacts_controller_spec.rb b/storefront/spec/controllers/spree/contacts_controller_spec.rbindex 828c8c3744..f1952e49e5 100644--- a/storefront/spec/controllers/spree/contacts_controller_spec.rb+++ b/storefront/spec/controllers/spree/contacts_controller_spec.rb@@ -1,10 +1,14 @@-require 'rails_helper'+require 'spec_helper'RSpec.describe Spree::ContactsController, type: :controller dolet(:store) { Spree::Store.default }let(:contact_params) { { name: "John Doe", email: "[email protected]", message: "Test message" } }context 'when customer support email is not configured' do+ before do+ store.update(customer_support_email: nil)+ end+it 'redirects to root path' doget :newexpect(response).to redirect_to(root_path)@@ -49,32 +53,5 @@ RSpec.describe Spree::ContactsController, type: :controller doendendend-- describe "#validate_captcha" do- context "when recaptcha integration is present" do- let!(:recaptcha_integration) { create(:recaptcha_integration) }-- it "verifies recaptcha" do- expect(controller).to receive(:verify_recaptcha).and_return(true)- post :create, params: { contact: contact_params }- end-- context "when recaptcha verification fails" do- before do- allow(controller).to receive(:verify_recaptcha).and_return(false)- end-- it "sets an error flash message" do- post :create, params: { contact: contact_params }- expect(flash[:error]).to eq('Captcha verification failed, please try again.')- end-- it "redirects to new action" do- post :create, params: { contact: contact_params }- expect(response).to redirect_to(action: :new)- end- end- end- endendend