-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #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
Showing
9 changed files
with
126 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters