diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 73b20c0..4a2ad6d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -31,6 +31,20 @@ class HomeController < ApplicationController SendEmailJob.perform_later(@email_message.id) 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 @dotation = Dotation.friendly.find(params[:id]) @company_sizes = CompanySize.all @@ -88,4 +102,9 @@ class HomeController < ApplicationController def email_messages_params params.require(:email_message).permit(:subject, :email, :message) end + + def consultation_email_params + params.require(:consultation_email).permit(:phone_number, :email, + :project_value) + end end diff --git a/app/jobs/send_contact_email_job.rb b/app/jobs/send_contact_email_job.rb new file mode 100644 index 0000000..3a4bac7 --- /dev/null +++ b/app/jobs/send_contact_email_job.rb @@ -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 diff --git a/app/mailers/notify_email_mailer.rb b/app/mailers/notify_email_mailer.rb index cb8343b..f79f350 100644 --- a/app/mailers/notify_email_mailer.rb +++ b/app/mailers/notify_email_mailer.rb @@ -11,12 +11,8 @@ class NotifyEmailMailer < ApplicationMailer end def contact_dotation - @email_filter = FilterForEmail.where(id: params[:email_filter]).first - @dotation = Dotation.where(id: params[:dotation_id]).first - @email_params = { - i: @email_filter.email, - k: @email_filter.unique_name - } - mail(to: @email_filter.email, subject: 'Pojawiła się nowa dotacja') + @consultation_email = ConsultationEmail.where(id: params[:email]).first + @dotation = @consultation_email.dotation + mail(to: @dotation.partner.link_url, subject: 'Prośba o wsparcie w sprawie dotacji') end end diff --git a/app/models/consultation_email.rb b/app/models/consultation_email.rb new file mode 100644 index 0000000..a02d265 --- /dev/null +++ b/app/models/consultation_email.rb @@ -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 diff --git a/app/models/partner.rb b/app/models/partner.rb index 87bb7a6..3504834 100644 --- a/app/models/partner.rb +++ b/app/models/partner.rb @@ -13,6 +13,8 @@ class Partner < ApplicationRecord # == Validations ========================================================== validates :name, presence: true + validates :description, presence: true + validates :link_url, presence: true # == Scopes =============================================================== # == Callbacks ============================================================ diff --git a/app/views/experts/_form.html.erb b/app/views/experts/_form.html.erb index 6467a3a..4d963bc 100644 --- a/app/views/experts/_form.html.erb +++ b/app/views/experts/_form.html.erb @@ -6,7 +6,7 @@
<%= form.label :description %> - <%= form.text_field :description, class: 'form-control', placeholder: 'Wprowadź opis' %> + <%= form.text_area :description, class: 'form-control', placeholder: 'Wprowadź opis' %>
diff --git a/app/views/home/_show.html.erb b/app/views/home/_show.html.erb index 5607702..1310b07 100644 --- a/app/views/home/_show.html.erb +++ b/app/views/home/_show.html.erb @@ -122,6 +122,7 @@
<%= render '/partners/partner_show', partner: @dotation.partner %> +
diff --git a/app/views/home/consultation_email/_form.html.erb b/app/views/home/consultation_email/_form.html.erb new file mode 100644 index 0000000..07ba140 --- /dev/null +++ b/app/views/home/consultation_email/_form.html.erb @@ -0,0 +1,41 @@ +
+
+

Formularz bezpłatnej konsultacji

+
+ <%= form_with(model: consultation_email, url: '/home/order_meeting_save', method: :post, remote: true, id: 'consultation_email_form') do |form| %> +
+
+ <%= render '/shared/errors_list', error_object: consultation_email %> +
+
+
<%= I18n.t('consultation_email.form_line1') %> <%= @dotation.formal_name %>
+

<%= I18n.t('consultation_email.form_line2') %>

+
+ <%= hidden_field_tag 'd', params[:d] %> +
+ <%= form.label :phone_number %> + <%= form.text_field :phone_number, class: 'form-control', placeholder: 'Podaj numer telefonu' %> +
+
+ <%= form.label :email %> + <%= form.email_field :email, class: 'form-control', placeholder: 'Wprowadź email' %> +
+
+ <%= form.label :project_value %>
+ <% ConsultationEmail::PROJECT_VALUES.each do |pv| %> + <%= radio_button_tag 'consultation_email[project_value]', pv[0] %> + <%= label 'consultation_email[project_value]', pv[1] %> + <% end %> +
+
+
+
Ważne
+ <%= I18n.t('consultation_email.form_politics') %> +
+
+
+ + <% end %> +
diff --git a/app/views/home/order_meeting.js.erb b/app/views/home/order_meeting.js.erb new file mode 100644 index 0000000..db06c2c --- /dev/null +++ b/app/views/home/order_meeting.js.erb @@ -0,0 +1 @@ +$('#consultation_form_id').html("<%= escape_javascript(render '/home/consultation_email/form', consultation_email: @consultation_email) %>"); diff --git a/app/views/home/order_meeting_save.js.erb b/app/views/home/order_meeting_save.js.erb new file mode 100644 index 0000000..484df40 --- /dev/null +++ b/app/views/home/order_meeting_save.js.erb @@ -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 %> diff --git a/app/views/notify_email_mailer/contact_dotation.html.erb b/app/views/notify_email_mailer/contact_dotation.html.erb new file mode 100644 index 0000000..80df28e --- /dev/null +++ b/app/views/notify_email_mailer/contact_dotation.html.erb @@ -0,0 +1,16 @@ + + + + + + + + + +
 
+ 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] %> +
diff --git a/app/views/notify_email_mailer/contact_dotation.text.erb b/app/views/notify_email_mailer/contact_dotation.text.erb new file mode 100644 index 0000000..323adc9 --- /dev/null +++ b/app/views/notify_email_mailer/contact_dotation.text.erb @@ -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] %> diff --git a/app/views/partners/_partner_show.html.erb b/app/views/partners/_partner_show.html.erb index 895c7ba..6b3997a 100644 --- a/app/views/partners/_partner_show.html.erb +++ b/app/views/partners/_partner_show.html.erb @@ -11,7 +11,13 @@
<%= raw partner.description %> - + + <% if @dotation.blank? %> + + <% else %> + <%= link_to 'Zamów bezpłatną konsultację', "/home/order_meeting?d=#{@dotation.safe_id}", class: 'btn btn-block btn-success', remote: true %> + <% end %> + diff --git a/config/locales/pl/models/consultation_email.yml b/config/locales/pl/models/consultation_email.yml new file mode 100644 index 0000000..4810422 --- /dev/null +++ b/config/locales/pl/models/consultation_email.yml @@ -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 diff --git a/config/locales/pl/models/partner.yml b/config/locales/pl/models/partner.yml index da09e86..06cc744 100644 --- a/config/locales/pl/models/partner.yml +++ b/config/locales/pl/models/partner.yml @@ -14,3 +14,7 @@ pl: attributes: name: blank: nie może być pusta + link_url: + blank: nie może być pusty + description: + blank: nie może być pusty diff --git a/config/routes.rb b/config/routes.rb index 37f50e9..0807236 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,8 @@ Rails.application.routes.draw do post 'home/search' post 'home/emailfilter' post 'home/register_contact' + get 'home/order_meeting' + post 'home/order_meeting_save' resources :home, only: %i[index show] devise_for :users resources :company_sizes diff --git a/db/migrate/20220404150629_create_consultation_emails.rb b/db/migrate/20220404150629_create_consultation_emails.rb new file mode 100644 index 0000000..301c498 --- /dev/null +++ b/db/migrate/20220404150629_create_consultation_emails.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index e6a3c4b..cecb962 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| 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" 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| t.string "name" t.string "description" diff --git a/test/fixtures/consultation_emails.yml b/test/fixtures/consultation_emails.yml new file mode 100644 index 0000000..04b1bc5 --- /dev/null +++ b/test/fixtures/consultation_emails.yml @@ -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 diff --git a/test/models/consultation_email_test.rb b/test/models/consultation_email_test.rb new file mode 100644 index 0000000..b56e90d --- /dev/null +++ b/test/models/consultation_email_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ConsultationEmailTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end