contact form added

This commit is contained in:
Adrian Hinz 2022-04-04 18:13:39 +02:00
parent 90a317a4ac
commit ff22c1d2be
20 changed files with 216 additions and 10 deletions

View File

@ -31,6 +31,20 @@ class HomeController < ApplicationController
SendEmailJob.perform_later(@email_message.id) SendEmailJob.perform_later(@email_message.id)
end end
def order_meeting
@dotation = Dotation.friendly.find(params[:d])
@consultation_email = ConsultationEmail.new()
end
def order_meeting_save
@dotation = Dotation.friendly.find(params[:d])
@consultation_email = ConsultationEmail.new(consultation_email_params)
@consultation_email.dotation_id = @dotation.id
return unless @consultation_email.save
SendContactEmailJob.perform_later(@consultation_email.id)
end
def show def show
@dotation = Dotation.friendly.find(params[:id]) @dotation = Dotation.friendly.find(params[:id])
@company_sizes = CompanySize.all @company_sizes = CompanySize.all
@ -88,4 +102,9 @@ class HomeController < ApplicationController
def email_messages_params def email_messages_params
params.require(:email_message).permit(:subject, :email, :message) params.require(:email_message).permit(:subject, :email, :message)
end end
def consultation_email_params
params.require(:consultation_email).permit(:phone_number, :email,
:project_value)
end
end end

View File

@ -0,0 +1,12 @@
# frozen_string_literal: true
class SendContactEmailJob < ApplicationJob
queue_as :default
def perform(consult_email_id)
consultation_email = ConsultationEmail.where(id: consult_email_id).first
return if consultation_email.blank?
NotifyEmailMailer.with(email: consultation_email).contact_dotation.deliver
end
end

View File

@ -11,12 +11,8 @@ class NotifyEmailMailer < ApplicationMailer
end end
def contact_dotation def contact_dotation
@email_filter = FilterForEmail.where(id: params[:email_filter]).first @consultation_email = ConsultationEmail.where(id: params[:email]).first
@dotation = Dotation.where(id: params[:dotation_id]).first @dotation = @consultation_email.dotation
@email_params = { mail(to: @dotation.partner.link_url, subject: 'Prośba o wsparcie w sprawie dotacji')
i: @email_filter.email,
k: @email_filter.unique_name
}
mail(to: @email_filter.email, subject: 'Pojawiła się nowa dotacja')
end end
end end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
# Consulatation emails
class ConsultationEmail < ApplicationRecord
# == Constants ============================================================
PROJECT_VALUES = {
1 => '0 - 1 mln.',
2 => '1 - 2 mln.',
3 => '2 - 3 mln.',
4 => '3 mln i powyżej'
}.freeze
# == Attributes ===========================================================
# == Extensions ===========================================================
# == Relationships ========================================================
belongs_to :dotation
# == Validations ==========================================================
validates :phone_number, presence: true
validates :email, presence: true
validates :project_value, presence: true
# == Scopes ===============================================================
# == Callbacks ============================================================
# == Class Methods ========================================================
# == Instance Methods =====================================================
end

View File

@ -13,6 +13,8 @@ class Partner < ApplicationRecord
# == Validations ========================================================== # == Validations ==========================================================
validates :name, presence: true validates :name, presence: true
validates :description, presence: true
validates :link_url, presence: true
# == Scopes =============================================================== # == Scopes ===============================================================
# == Callbacks ============================================================ # == Callbacks ============================================================

View File

@ -6,7 +6,7 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<%= form.label :description %> <%= form.label :description %>
<%= form.text_field :description, class: 'form-control', placeholder: 'Wprowadź opis' %> <%= form.text_area :description, class: 'form-control', placeholder: 'Wprowadź opis' %>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@ -122,6 +122,7 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<%= render '/partners/partner_show', partner: @dotation.partner %> <%= render '/partners/partner_show', partner: @dotation.partner %>
<div id="consultation_form_id"></div>
</div> </div>
</div> </div>

View File

@ -0,0 +1,41 @@
<div class="card card-primary card-outline">
<div class="card-header">
<h3 class="card-title"><strong>Formularz bezpłatnej konsultacji</strong></h3>
</div>
<%= form_with(model: consultation_email, url: '/home/order_meeting_save', method: :post, remote: true, id: 'consultation_email_form') do |form| %>
<div class="card-body">
<div id="email_mess_div">
<%= render '/shared/errors_list', error_object: consultation_email %>
</div>
<div class="form-group">
<h5><%= I18n.t('consultation_email.form_line1') %> <strong><%= @dotation.formal_name %></strong></h5>
<p><%= I18n.t('consultation_email.form_line2') %></p>
</div>
<%= hidden_field_tag 'd', params[:d] %>
<div class="form-group">
<%= form.label :phone_number %>
<%= form.text_field :phone_number, class: 'form-control', placeholder: 'Podaj numer telefonu' %>
</div>
<div class="form-group">
<%= form.label :email %>
<%= form.email_field :email, class: 'form-control', placeholder: 'Wprowadź email' %>
</div>
<div class="form-group">
<%= form.label :project_value %><br />
<% ConsultationEmail::PROJECT_VALUES.each do |pv| %>
<%= radio_button_tag 'consultation_email[project_value]', pv[0] %>
<%= label 'consultation_email[project_value]', pv[1] %>
<% end %>
</div>
<div class="form-group">
<div class="alert alert-info">
<h5><i class="icon fas fa-info"></i> Ważne</h5>
<%= I18n.t('consultation_email.form_politics') %>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Zamów spotkanie</button>
</div>
<% end %>
</div>

View File

@ -0,0 +1 @@
$('#consultation_form_id').html("<%= escape_javascript(render '/home/consultation_email/form', consultation_email: @consultation_email) %>");

View File

@ -0,0 +1,6 @@
<% if @consultation_email.errors.any? %>
$("#email_mess_div").html("<%= escape_javascript(render '/shared/errors_list', error_object: @consultation_email) %>");
<% else %>
document.getElementById("consultation_email_form").reset();
$("#email_mess_div").html("<%= escape_javascript(render '/home/message_sent_info') %>");
<% end %>

View File

@ -0,0 +1,16 @@
<table style="font-family:Verdana,sans-serif; font-size:18px; color:#374953;">
<tbody>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left">
Witaj, <br />
Pojawiła się nowa prośba w pozyskaniu dotacji <strong><%= @dotation.formal_name %></strong><br />
Nadawca wiadomości: <strong><%= @consultation_email.email %></strong><br />
Numer telefonu: <strong><%= @consultation_email.phone_number %></strong><br />
Wartość projektu: <strong><%= ConsultationEmail::PROJECT_VALUES[@consultation_email.project_value] %></strong>
</td>
</tr>
</tbody>
</table>

View File

@ -0,0 +1,5 @@
Witaj,
Pojawiła się nowa prośba w pozyskaniu dotacji <%= @dotation.formal_name %>
Nadawca wiadomości: <%= @consultation_email.email %>
Numer telefonu: <%= @consultation_email.phone_number %>
Wartość projektu: <%= ConsultationEmail::PROJECT_VALUES[@consultation_email.project_value] %>

View File

@ -11,7 +11,13 @@
</div> </div>
</td> </td>
<td><%= raw partner.description %></td> <td><%= raw partner.description %></td>
<td><button type="button" class="btn btn-block btn-success">Zamów bezpłatną konsultację</button></td> <td>
<% if @dotation.blank? %>
<button type="button" class="btn btn-block btn-success">Zamów bezpłatną konsultację</button>
<% else %>
<%= link_to 'Zamów bezpłatną konsultację', "/home/order_meeting?d=#{@dotation.safe_id}", class: 'btn btn-block btn-success', remote: true %>
<% end %>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -0,0 +1,25 @@
pl:
consultation_email:
message_sent: 'Dziękujemy za zgłoszenie, wiadomość została przyjęta. Odpowiemy najszybciej jak to będzie możliwe.'
form_line1: "Wsparcie w pozyskaniu dotacji z programu"
form_line2: "Wypełnij formularz i skorzystaj z pomocy eksperta."
form_politics: "Wysyłając formularz wyrażasz zgodę na kontakt telefoniczny w celu obsługi niniejszego zgłoszenie, zgodę na otrzymywanie informacji handlowych środkami komunikacji elektronicznej wysyłanymi przez kalendarzdotacji.pl i zgodę na wykorzystanie komunikacji e-mail w celach marketingowych."
activerecord:
models:
consultation_email: Zamoienie spotkania
attributes:
consultation_email:
dotation_id: "Dotacja"
phone_number: "Numer telefonu"
email: "Adres e-mail w domenie firmowej"
project_value: Wartość projektu
errors:
models:
consultation_email:
attributes:
phone_number:
blank: nie może być pusty
email:
blank: nie może być pusty
project_value:
blank: nie może być pusta

View File

@ -14,3 +14,7 @@ pl:
attributes: attributes:
name: name:
blank: nie może być pusta blank: nie może być pusta
link_url:
blank: nie może być pusty
description:
blank: nie może być pusty

View File

@ -8,6 +8,8 @@ Rails.application.routes.draw do
post 'home/search' post 'home/search'
post 'home/emailfilter' post 'home/emailfilter'
post 'home/register_contact' post 'home/register_contact'
get 'home/order_meeting'
post 'home/order_meeting_save'
resources :home, only: %i[index show] resources :home, only: %i[index show]
devise_for :users devise_for :users
resources :company_sizes resources :company_sizes

View File

@ -0,0 +1,12 @@
class CreateConsultationEmails < ActiveRecord::Migration[5.2]
def change
create_table :consultation_emails do |t|
t.bigint :dotation_id
t.string :phone_number
t.string :email
t.integer :project_value
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_03_30_152005) do ActiveRecord::Schema.define(version: 2022_04_04_150629) do
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
@ -63,6 +63,15 @@ ActiveRecord::Schema.define(version: 2022_03_30_152005) do
t.index ["dotation_id", "company_size_id"], name: "dot_csize_ind" t.index ["dotation_id", "company_size_id"], name: "dot_csize_ind"
end end
create_table "consultation_emails", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.bigint "dotation_id"
t.string "phone_number"
t.string "email"
t.integer "project_value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "currencies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "currencies", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"

13
test/fixtures/consultation_emails.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
dotation_id:
phone_number: MyString
email: MyString
project_value: 1
two:
dotation_id:
phone_number: MyString
email: MyString
project_value: 1

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ConsultationEmailTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end