Skip to content

Commit

Permalink
1058 Add Feedback Subject (#1116)
Browse files Browse the repository at this point in the history
* #984
- Added Feedback Controller and Feedback Mailer To Handle Feedback for staff and adopter
- Remove DevContactsController and DevContactsMailer
- Fix the test

* fix the test

* add subject to mailer

* add turbo_frame how to

* spacing

* lint

* add required true to subject

* pr changes

pr changes

* fix validation

* add feedback model

* update tests

* use private method for path

* use bootstrap collapse

* remove show action

* fix path method

---------

Co-authored-by: Aaryanpal <aryan.pal0ppq@gmail.com>
  • Loading branch information
jmilljr24 and Aaryanpal authored Nov 11, 2024
1 parent a2969d9 commit 49e62a7
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 44 deletions.
33 changes: 23 additions & 10 deletions app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
@@ -1,35 +1,48 @@
class FeedbackController < ApplicationController
include OrganizationScopable

skip_before_action :authenticate_user!
skip_verify_authorized only: %i[new create]
layout :set_layout, only: %i[new create]
layout :set_layout, only: %i[new]

def new
@contact = Contact.new
@feedback = Feedback.new
end

def create
@contact = Contact.new(contact_params)
if @contact.valid?
FeedbackMailer.with(contact_params).send_message.deliver_later
redirect_to root_path, notice: I18n.t("contacts.create.success")
@feedback = Feedback.new(feedback_params)

if @feedback.valid?
FeedbackMailer.with(feedback_params).send_message.deliver_now
redirect_to path, notice: I18n.t("contacts.create.success")
else
render :new, status: :unprocessable_entity
end
end

private

def contact_params
params.require(:contact).permit(:name, :email, :message)
def feedback_params
params.require(:feedback).permit(:name, :email, :message, :subject)
end

def set_layout
if current_user.nil?
"application"
elsif current_user.staff_account
elsif current_user.has_role?(:adopter, ActsAsTenant.current_tenant)
"adopter_foster_dashboard"
else
"dashboard"
end
end

def path
if current_user.nil?
root_path
elsif current_user.has_role?(:adopter, ActsAsTenant.current_tenant)
adopter_fosterer_dashboard_index_path
else
"adopter_foster_dashboard"
staff_dashboard_index_path
end
end
end
3 changes: 2 additions & 1 deletion app/mailers/feedback_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class FeedbackMailer < ApplicationMailer
def send_message
@name = params[:name]
@email = params[:email]
@subject = params[:subject]
@message = params[:message]

mail to: "devs@email.com", subject: "New Support Message"
mail to: "devs@email.com", subject: @subject
end
end
1 change: 1 addition & 0 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Contact
include ActiveModel::Model
attr_accessor :name, :email, :message

validates :name, :email, :message, presence: true

# credit: https://medium.com/@limichelle21/building-and-debugging-a-contact-form-with-rails-mailgun-heroku-c0185b8bf419
Expand Down
8 changes: 8 additions & 0 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Feedback
include ActiveModel::Model
attr_accessor :name, :email, :message, :subject

validates :name, :email, :message, :subject, presence: true

# credit: https://medium.com/@limichelle21/building-and-debugging-a-contact-form-with-rails-mailgun-heroku-c0185b8bf419
end
8 changes: 4 additions & 4 deletions app/views/feedback/_feedback.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<div class="container mb-md-5 mt-md-5">
<div class="text-center mb-5">
<h1 class="section-heading text-uppercase underline">
<%= t('feedback.new.header') %>
<%= t("feedback.new.header") %>
</h1>
</div>
</div>

<div class='mb-3 text-center bigger'>
<%= t('feedback.new.description') %>
<%= t("feedback.new.description") %>
</div>
<div class="row">
<div class="col-md-6 mx-auto card p-5">
<%= render 'form', contact: @contact %>
<%= render "form" %>
</div>
</div>
</div>
</section>
</section>
47 changes: 29 additions & 18 deletions app/views/feedback/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
<%= bootstrap_form_with url: feedback_index_path, scope: :contact, method: :post do | f | %>
<% if contact.errors.count > 0 %>
<%= bootstrap_form_with url: feedback_index_path, scope: :feedback, method: :post do | f | %>

<% if @feedback.errors.count > 0 %>
<div class="alert alert-danger mt-1" role="alert">
<p>
<%= I18n.t('general.please_fix') %> <%= @contact.errors.count %> <%= 'error'.pluralize(contact.errors.count) %> highlighted below.
<%= I18n.t("general.please_fix") %>
<%= @feedback.errors.count %>
<%= "error".pluralize(@feedback.errors.count) %>
highlighted below.
</p>
</div>
<% end %>
<div class="row mb-2">

<div class="mb-3 form-group">
<%= f.text_field :name, autofocus: true,
class: 'form-control',
required: true %>
<% @contact.errors.full_messages_for(:name).each do |message| %>
<%= f.select :subject,
["General Feedback", "Feature Request", "Bug"],
required: true %>
</div>
<div class="mb-3 form-group">
<%= f.text_field :name, autofocus: true, class: "form-control", required: true %>
<% @feedback.errors.full_messages_for(:name).each do |message| %>
<div class="alert alert-danger mt-1" role="alert"><%= message %></div>
<% end %>
</div>
<div class="mb-3 form-group">
<%= f.email_field :email, class: 'form-control',
required: true %>
<% @contact.errors.full_messages_for(:email).each do |message| %>
<%= f.email_field :email, class: "form-control", required: true %>
<% @feedback.errors.full_messages_for(:email).each do |message| %>
<div class="alert alert-danger mt-1" role="alert"><%= message %></div>
<% end %>
</div>
<div class="mb-3 form-group" data-controller='counter'>
<%= f.text_area :message, class: 'form-control',
data: { action: "input->counter#countLarge",
counter_target: 'input' },
placeholder: t('feedback.new.message_placeholder'),
required: true %>
<%= f.text_area :message,
class: "form-control",
data: {
action: "input->counter#countLarge",
counter_target: "input",
},
placeholder: t("feedback.new.message_placeholder"),
required: true %>
<div data-counter-target='output' class='small'></div>
<% @contact.errors.full_messages_for(:message).each do |message| %>
<% @feedback.errors.full_messages_for(:message).each do |message| %>
<div class="alert alert-danger mt-1" role="alert"><%= message %></div>
<% end %>
</div>
<div class="form-group">
<%= f.submit I18n.t('general.submit'), class: 'btn btn-primary' %>
<%= f.submit I18n.t("general.submit"), class: "btn btn-primary" %>
</div>
<%= render "tips" %>
</div>
<% end %>
<% end %>
44 changes: 44 additions & 0 deletions app/views/feedback/_tips.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div class="accordion accordion-flush" id="accordion-tips">
<div class="pt-5" id="heading_tips">
<h3 class="mb-0 fw-bold">
<a
href="#"
class="d-flex align-items-center text-inherit active collapsed"
data-bs-toggle="collapse"
data-bs-target="#tips"
aria-expanded="false"
aria-controls="tips"
>
<span>Tips on submitting feedback</span>
<span class="collapse-toggle ms-4">
<i class="fe fe-chevron-down text-primary"></i>
</span>
</a>
</h3>
</div>
<div
id="tips"
class="collapse"
aria-labelledby="heading_tips"
data-bs-parent="#accordion-tips"
>
<div class="py-3 fs-6">
<h3>Reporting Bugs</h3>
<p>Please provide the following details:</p>
<ul>
<li>Organization Name</li>
<li>Page URL</li>
<li>Steps to Reproduce</li>
<li>Expected vs. Actual Outcomes</li>
</ul>

<h3>Requesting Features</h3>
<p>Please include:</p>
<ul>
<li>Page for the Feature</li>
<li>Feature Description</li>
<li>Utility of the Feature</li>
</ul>
</div>
</div>
</div>
20 changes: 12 additions & 8 deletions app/views/feedback/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<% if current_user.nil? %>
<%= render 'feedback', contact: @contact %>
<%= render "feedback" %>
<% else %>
<%= render DashboardPageComponent.new(crumb: current_user&.staff_account ? :new_feedback : nil) do |c| %>
<% c.with_header_title { t('feedback.new.header') } %>
<% admin =
current_user.has_role?(:adopter, ActsAsTenant.current_tenant) ? false : true %>
<%= render DashboardPageComponent.new(crumb: admin ? :new_feedback : nil) do |c| %>
<% c.with_header_title { t("feedback.new.header") } %>
<% c.with_body do %>
<section class="<%= current_user&.staff_account ? 'container-fluid p-4' : 'pb-5' %>">
<div class="<%= current_user&.staff_account ? 'row' : 'container' %>">
<section class="<%= admin ? 'container-fluid p-4' : 'pb-5' %>">
<div class="<%= admin ? 'row' : 'container' %>">
<div class="row">
<div class="<%= current_user&.staff_account ? 'col-md-8 mx-auto card p-5 bigger' : 'col-md-12 mx-auto card p-5' %>">
<%= render 'form', contact: @contact %>
<div
class="<%= admin ? 'col-md-8 mx-auto card p-5 bigger' : 'col-md-12 mx-auto card p-5' %>"
>
<%= render "form" %>
</div>
</div>
</div>
</section>
<% end %>
<% end %>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions test/controllers/feedback_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class FeedbackControllerTest < ActionDispatch::IntegrationTest
end

context "create" do
should "create contact mailer if valid params" do
should "create feedback mailer if valid params" do
assert_emails 1 do
post feedback_index_url, params: {contact: {name: "test sender", email: "sender@test.com", message: "test message"}}
post feedback_index_url, params: {feedback: {name: "test sender", email: "sender@test.com", message: "test message", subject: "Bug"}}
end
end

should "return unprocessable entity if invalid params" do
post feedback_index_url, params: {contact: {name: "test sender", email: "sender@test.com"}}
post feedback_index_url, params: {feedback: {name: "test sender", email: "sender@test.com"}}
assert_response :unprocessable_entity
end
end
Expand Down

0 comments on commit 49e62a7

Please sign in to comment.