Sha256: f25860c3bd6deffed3983a45a12b49d3ebef27660a96736b33ccae3e263d22d4

Contents?: true

Size: 896 Bytes

Versions: 32

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

class WCC::Contentful::App::ContactFormController < ApplicationController
  include WCC::Contentful::App::PreviewPassword

  def create
    address =
      form_model.to_address(email_object_id: params[:email_object_id])

    form_model.send_email(
      form_params.merge!(
        {
          notification_email: address,
          internal_title: params[:internal_title]
        }
      )
    )

    render json: { type: 'success', message: "Thanks for reaching out. We'll be in touch soon!" }
  end

  private

  def form_model
    raise ArgumentError, 'missing form ID' unless params[:id]

    @form_model ||= form_class.find(
      params[:id], options: { preview: preview? }
    )
  end

  def form_class
    WCC::Contentful::Model.resolve_constant('section-contact-form')
  end

  def form_params
    params.slice(*form_model.fields.map(&:title))
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
wcc-contentful-app-1.7.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.7.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.6.2 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.6.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.6.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.5.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.5.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.5.0.rc1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.4.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.4.0.rc3 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.4.0.rc2 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.3.2 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.4.0.rc1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.3.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.3.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.2.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.2.0 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.1.2 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.1.1 app/controllers/wcc/contentful/app/contact_form_controller.rb
wcc-contentful-app-1.1.0 app/controllers/wcc/contentful/app/contact_form_controller.rb