Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/images/icons/checkmark-green-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/icons/crossmark-red-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions app/assets/stylesheets/components/_hub-doc-assessment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,27 @@
font-weight: bold;
text-transform: capitalize;
}
}

.feedback-box {
padding: 2.5rem 2rem;
border: 1px solid #525252;
border-radius: 8px;
word-break: break-word;
background-color: #F7F7F7;
font-weight: bold;

#top-question{
display: flex;
align-items: center;
gap: 8px;
}

#additional-feedback{
width: 100%;
background: white;
box-sizing: border-box;
min-height: 10rem;
font-weight: $font-weight-normal;
}
}
14 changes: 13 additions & 1 deletion app/controllers/hub/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class DocumentsController < Hub::BaseController
load_and_authorize_resource through: :client
before_action :load_document_type_options
helper_method :transient_storage_url
before_action :require_admin, only: [:rerun_screener, :record_feedback]

layout "hub"

Expand Down Expand Up @@ -67,13 +68,24 @@ def destroy
end

def rerun_screener
return head :forbidden if acts_like_production? || !current_user.admin?
return head :forbidden if acts_like_production?

DocScreenerJob.perform_now(@document.id)

redirect_back(fallback_location: edit_hub_client_document_path(client_id: @document.client.id, id: @document), notice: "Re-ran document screening.")
end

def record_feedback
DocAssessmentFeedback.create!(
doc_assessment: @document.latest_assessment,
user: current_user,
feedback: params[:feedback],
feedback_notes: params[:feedback_notes]
)

redirect_back fallback_location: edit_hub_client_document_path(client_id: @document.client.id, id: @document)
end

private
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to add a spec under the controller spec?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! just added one


def load_document_type_options
Expand Down
8 changes: 8 additions & 0 deletions app/javascript/hub/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function feedback() {
document.querySelectorAll('[data-feedback-x]').forEach(button => {
button.addEventListener('click', () => {
const notesDiv = document.querySelector('[data-feedback-notes]')
notesDiv.classList.remove('hidden')
})
})
}
2 changes: 2 additions & 0 deletions app/javascript/packs/hub.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// See `app/javascript/hub/README.md`
import MainMenuComponent from "../hub/MainMenuComponent";
import imageRotate from "../hub/image_rotate";
import feedback from "../hub/feedback";

window.addEventListener("load", function() {
MainMenuComponent();
imageRotate();
feedback();
})
2 changes: 2 additions & 0 deletions app/models/doc_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
#
class DocAssessment < ApplicationRecord
belongs_to :document
has_many :feedbacks, class_name: "DocAssessmentFeedback", dependent: :destroy

end
30 changes: 30 additions & 0 deletions app/models/doc_assessment_feedback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# == Schema Information
#
# Table name: doc_assessment_feedbacks
#
# id :bigint not null, primary key
# feedback :integer default("unfilled"), not null
# feedback_notes :text
# created_at :datetime not null
# updated_at :datetime not null
# doc_assessment_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_doc_assessment_feedbacks_on_doc_assessment_id (doc_assessment_id)
# index_doc_assessment_feedbacks_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (doc_assessment_id => doc_assessments.id)
# fk_rails_... (user_id => users.id)
#
class DocAssessmentFeedback < ApplicationRecord
belongs_to :doc_assessment
belongs_to :user

enum feedback: { unfilled: 0, correct: 1, incorrect: 2 }, _prefix: :feedback

validates :feedback, presence: true
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class User < ApplicationRecord
has_many :access_logs
has_many :notifications, class_name: "UserNotification"
belongs_to :role, polymorphic: true
has_many :doc_assessment_feedbacks

validates_presence_of :name
validates_inclusion_of :timezone, in: ActiveSupport::TimeZone.country_zones("us").map { |tz| tz.tzinfo.name }
Expand Down
31 changes: 31 additions & 0 deletions app/views/hub/documents/_feedback_collection.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<% if current_user.admin? && (@document.latest_assessment.present? && @document.latest_assessment&.feedbacks.blank?) %>
<div class="feedback-box">
<div id="top-question">
<span>Is the Smart Scan label correct?</span>

<%= button_to record_feedback_hub_client_document_path,
params: { feedback: "correct" },
style: "background:none; border:none; padding:0; cursor:pointer;" do %>
<%= image_tag('icons/checkmark-green-circle.svg', alt: "correct") %>
<% end %>

<button type="button"
data-feedback-x
style="background:none; border:none; padding:0; cursor:pointer;">
<%= image_tag('icons/crossmark-red-circle.svg', alt: "incorrect") %>
</button>
</div>

<div data-feedback-notes class="hidden spacing-above-15 spacing-below-0">
<p class="spacing-below-5">Provide additional feedback</p>
<%= form_with url: record_feedback_hub_client_document_path, method: :post do |f| %>
<%= f.hidden_field :feedback, value: "incorrect" %>
<%= f.text_area :feedback_notes, id: "additional-feedback" %>
<div class="spacing-above-10 spacing-below-0">
<%= f.submit "Submit feedback", class: "button" %>
</div>
<% end %>
</div>

</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/hub/documents/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@
hub_client_documents_path(client_id: @client),
class: "button" %>
<% end %>

<%= render 'hub/documents/feedback_collection' %>
</div>

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def scoped_navigation_routes(context, navigation)
get "/archived", to: "documents#archived", on: :collection, as: :archived
get "/confirm", to: "documents#confirm", on: :member, as: :confirm
post :rerun_screener, on: :member
post :record_feedback, on: :member
end
resources :notes, only: [:create, :index]
resources :messages, only: [:index]
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20260223212700_create_doc_assessment_feedbacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateDocAssessmentFeedbacks < ActiveRecord::Migration[7.1]
def change
create_table :doc_assessment_feedbacks do |t|
t.references :doc_assessment, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true

t.integer :feedback, null: false, default: 0
t.text :feedback_notes

t.timestamps
end
end
end
15 changes: 14 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2026_02_18_162315) do
ActiveRecord::Schema[7.1].define(version: 2026_02_23_212700) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "plpgsql"
Expand Down Expand Up @@ -834,6 +834,17 @@
t.string "zip_code"
end

create_table "doc_assessment_feedbacks", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "doc_assessment_id", null: false
t.integer "feedback", default: 0, null: false
t.text "feedback_notes"
t.datetime "updated_at", null: false
t.bigint "user_id", null: false
t.index ["doc_assessment_id"], name: "index_doc_assessment_feedbacks_on_doc_assessment_id"
t.index ["user_id"], name: "index_doc_assessment_feedbacks_on_user_id"
end

create_table "doc_assessments", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "document_id", null: false
Expand Down Expand Up @@ -3131,6 +3142,8 @@
add_foreign_key "clients", "vita_partners"
add_foreign_key "coalition_lead_roles", "coalitions"
add_foreign_key "dependents", "intakes"
add_foreign_key "doc_assessment_feedbacks", "doc_assessments"
add_foreign_key "doc_assessment_feedbacks", "users"
add_foreign_key "doc_assessments", "documents"
add_foreign_key "documents", "clients"
add_foreign_key "documents", "documents_requests"
Expand Down
40 changes: 40 additions & 0 deletions spec/controllers/hub/documents_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,44 @@
end
end
end

describe "#record_feedback" do
let(:document) { create :document, intake: client.intake }
let!(:assessment) { create :doc_assessment, :with_json, document: document }
let(:params) do
{
client_id: client.id,
id: document.id,
feedback: "incorrect",
feedback_notes: "wrong doc type"
}
end

before do
sign_in(user)
end

context "user is not admin" do
it "returns forbidden" do
post :record_feedback, params: params
expect(response).to be_forbidden
end
end

context "in demo and admin user" do
let(:user) { create :admin_user }

it "creates a DocAssessmentFeedback record" do
expect {
post :record_feedback, params: params
}.to change(DocAssessmentFeedback, :count).by(1)

expect(response).not_to be_forbidden
expect(response).to redirect_to edit_hub_client_document_path({client_id: client.id, id: document.id})

expect(DocAssessmentFeedback.last.feedback).to eq "incorrect"
expect(DocAssessmentFeedback.last.feedback_notes).to eq "wrong doc type"
end
end
end
end
Loading