From 2ea43d9f5c412c9d3fc04f3b8e77f8f5de93a810 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 25 Jun 2024 18:58:59 -0700 Subject: [PATCH] revert renaming of adopter applications to custom form submissions --- .../adoptable_pets_controller.rb | 8 +- .../adopter_applications_controller.rb | 57 +++++++++++ .../custom_form/submissions_controller.rb | 63 ------------- .../adopter_fosterer/dashboard_controller.rb | 2 +- ...adoption_application_reviews_controller.rb | 57 +++++++++++ .../organizations/staff/matches_controller.rb | 4 +- .../organizations/staff/pets_controller.rb | 2 +- .../staff/submission_reviews_controller.rb | 58 ------------ .../adoption_application_reviews_helper.rb | 4 +- ... staff_application_notification_mailer.rb} | 4 +- app/models/adopter_application.rb | 92 ++++++++++++++++++ app/models/adopter_foster_account.rb | 2 +- app/models/concerns/authorizable.rb | 10 +- app/models/custom_form/submission.rb | 94 ------------------- app/models/match.rb | 12 +-- app/models/pet.rb | 16 ++-- app/policies/adopter_application_policy.rb | 44 +++++++++ app/policies/custom_form/submission_policy.rb | 46 --------- .../adopter_application_policy.rb | 16 ++++ .../organizations/submission_policy.rb | 18 ---- .../layouts/adopter_foster_dashboard.html.erb | 4 +- app/views/layouts/dashboard/_sidebar.html.erb | 2 +- .../adoptable_pets/show.html.erb | 16 ++-- .../_application_cards.html.erb} | 24 ++--- .../_applications_table.html.erb} | 30 +++--- .../index.html.erb | 6 +- .../adopter_fosterer/dashboard/index.html.erb | 4 +- .../_search_results.html.erb | 10 ++ .../edit.html.erb | 14 +-- .../index.html.erb | 12 +-- .../update.turbo_stream.erb | 7 ++ .../organizations/staff/pets/show.html.erb | 4 +- ...ssions.html.erb => _applications.html.erb} | 16 ++-- ...rb => _application_create_button.html.erb} | 8 +- .../partials/_application_info_card.html.erb | 29 ++++++ .../partials/_application_info_table.html.erb | 19 ++++ ...s.html.erb => _application_notes.html.erb} | 18 ++-- .../partials/_application_status.html.erb | 16 ++++ .../partials/_submission_info_card.html.erb | 29 ------ .../partials/_submission_info_table.html.erb | 19 ---- .../tabs/partials/_submission_status.html.erb | 16 ---- .../_search_results.html.erb | 10 -- .../update.turbo_stream.erb | 7 -- .../new_adoption_application.html.erb} | 0 .../new_adoption_application.text.erb} | 0 config/locales/en.yml | 49 +++++----- config/locales/views/dashboard.en.yml | 4 +- config/routes.rb | 7 +- ...ename_adopter_application_to_submission.rb | 15 --- db/schema.rb | 17 ++++ db/seeds/01_alta.rb | 12 +-- db/seeds/02_baja.rb | 12 +-- ...> adopter_applications_controller_test.rb} | 36 +++---- ...on_application_reviews_controller_test.rb} | 58 ++++++------ ...submissions.rb => adopter_applications.rb} | 2 +- test/factories/pets.rb | 4 +- .../{custom_form => }/submitted_answers.rb | 0 test/integration/adoptable_pet_show_test.rb | 4 +- .../adoption_application_reviews_test.rb | 85 +++++++++++++++++ test/integration/revoke_adoption_test.rb | 2 +- test/integration/submission_reviews_test.rb | 85 ----------------- test/models/adopter_application_test.rb | 48 ++++++++++ test/models/adopter_foster_account_test.rb | 2 +- test/models/custom_form/submission_test.rb | 48 ---------- test/models/match_test.rb | 22 ++--- test/models/pet_test.rb | 36 +++---- ....rb => adopter_application_policy_test.rb} | 42 ++++----- ....rb => adopter_application_policy_test.rb} | 24 ++--- .../profile_review_policy_test.rb | 8 +- test/system/adoption_creation_test.rb | 8 +- test/system/adoption_fosterer_test.rb | 10 +- 71 files changed, 777 insertions(+), 792 deletions(-) create mode 100644 app/controllers/organizations/adopter_fosterer/adopter_applications_controller.rb delete mode 100644 app/controllers/organizations/adopter_fosterer/custom_form/submissions_controller.rb create mode 100644 app/controllers/organizations/staff/adoption_application_reviews_controller.rb delete mode 100644 app/controllers/organizations/staff/submission_reviews_controller.rb rename app/mailers/{staff_submission_notification_mailer.rb => staff_application_notification_mailer.rb} (79%) create mode 100644 app/models/adopter_application.rb delete mode 100644 app/models/custom_form/submission.rb create mode 100644 app/policies/adopter_application_policy.rb delete mode 100644 app/policies/custom_form/submission_policy.rb create mode 100644 app/policies/organizations/adopter_application_policy.rb delete mode 100644 app/policies/organizations/submission_policy.rb rename app/views/organizations/adopter_fosterer/{custom_form/submissions/_submission_cards.html.erb => adopter_applications/_application_cards.html.erb} (55%) rename app/views/organizations/adopter_fosterer/{custom_form/submissions/_submissions_table.html.erb => adopter_applications/_applications_table.html.erb} (53%) rename app/views/organizations/adopter_fosterer/{custom_form/submissions => adopter_applications}/index.html.erb (61%) create mode 100644 app/views/organizations/staff/adoption_application_reviews/_search_results.html.erb rename app/views/organizations/staff/{submission_reviews => adoption_application_reviews}/edit.html.erb (75%) rename app/views/organizations/staff/{submission_reviews => adoption_application_reviews}/index.html.erb (66%) create mode 100644 app/views/organizations/staff/adoption_application_reviews/update.turbo_stream.erb rename app/views/organizations/staff/pets/tabs/{_submissions.html.erb => _applications.html.erb} (70%) rename app/views/organizations/staff/pets/tabs/partials/{_submission_create_button.html.erb => _application_create_button.html.erb} (69%) create mode 100644 app/views/organizations/staff/pets/tabs/partials/_application_info_card.html.erb create mode 100644 app/views/organizations/staff/pets/tabs/partials/_application_info_table.html.erb rename app/views/organizations/staff/pets/tabs/partials/{_submission_notes.html.erb => _application_notes.html.erb} (75%) create mode 100644 app/views/organizations/staff/pets/tabs/partials/_application_status.html.erb delete mode 100644 app/views/organizations/staff/pets/tabs/partials/_submission_info_card.html.erb delete mode 100644 app/views/organizations/staff/pets/tabs/partials/_submission_info_table.html.erb delete mode 100644 app/views/organizations/staff/pets/tabs/partials/_submission_status.html.erb delete mode 100644 app/views/organizations/staff/submission_reviews/_search_results.html.erb delete mode 100644 app/views/organizations/staff/submission_reviews/update.turbo_stream.erb rename app/views/{staff_submission_notification_mailer/new_adoption_submission.html.erb => staff_application_notification_mailer/new_adoption_application.html.erb} (100%) rename app/views/{staff_submission_notification_mailer/new_adoption_submission.text.erb => staff_application_notification_mailer/new_adoption_application.text.erb} (100%) delete mode 100644 db/migrate/20240610194826_rename_adopter_application_to_submission.rb rename test/controllers/organizations/adopter_fosterer/{custom_form/submissions_controller_test.rb => adopter_applications_controller_test.rb} (54%) rename test/controllers/organizations/staff/{submission_reviews_controller_test.rb => adoption_application_reviews_controller_test.rb} (55%) rename test/factories/{custom_form/submissions.rb => adopter_applications.rb} (91%) rename test/factories/{custom_form => }/submitted_answers.rb (100%) create mode 100644 test/integration/adoption_application_reviews_test.rb delete mode 100644 test/integration/submission_reviews_test.rb create mode 100644 test/models/adopter_application_test.rb delete mode 100644 test/models/custom_form/submission_test.rb rename test/policies/{custom_form/submission_policy_test.rb => adopter_application_policy_test.rb} (80%) rename test/policies/organizations/{submission_policy_test.rb => adopter_application_policy_test.rb} (85%) diff --git a/app/controllers/organizations/adoptable_pets_controller.rb b/app/controllers/organizations/adoptable_pets_controller.rb index ce01deb94..c6c4aacc5 100644 --- a/app/controllers/organizations/adoptable_pets_controller.rb +++ b/app/controllers/organizations/adoptable_pets_controller.rb @@ -5,7 +5,7 @@ class Organizations::AdoptablePetsController < Organizations::BaseController helper_method :get_animals def index - @q = authorized_scope(Pet.includes(:submissions, images_attachments: :blob), + @q = authorized_scope(Pet.includes(:adopter_applications, images_attachments: :blob), with: Organizations::AdoptablePetPolicy).ransack(params[:q]) @pagy, paginated_adoptable_pets = pagy( @q.result, @@ -20,12 +20,12 @@ def show authorize! @pet, with: Organizations::AdoptablePetPolicy if current_user&.adopter_foster_account - @submission = - CustomForm::Submission.find_by( + @adoption_application = + AdopterApplication.find_by( pet_id: @pet.id, adopter_foster_account_id: current_user.adopter_foster_account.id ) || - @pet.submissions.build( + @pet.adopter_applications.build( adopter_foster_account: current_user.adopter_foster_account ) end diff --git a/app/controllers/organizations/adopter_fosterer/adopter_applications_controller.rb b/app/controllers/organizations/adopter_fosterer/adopter_applications_controller.rb new file mode 100644 index 000000000..ac1321b70 --- /dev/null +++ b/app/controllers/organizations/adopter_fosterer/adopter_applications_controller.rb @@ -0,0 +1,57 @@ +class Organizations::AdopterFosterer::AdopterApplicationsController < Organizations::BaseController + before_action :authenticate_user! + before_action :set_application, only: %i[update] + layout "adopter_foster_dashboard" + + def index + authorize! with: AdopterApplicationPolicy + + @applications = authorized_scope(AdopterApplication.where(profile_show: true), with: AdopterApplicationPolicy) + end + + def create + @pet = Pet.find(application_params[:pet_id]) + authorize! context: {pet: @pet}, with: AdopterApplicationPolicy + + @application = AdopterApplication.new(application_params) + + if @application.save + redirect_to adoptable_pet_path(@application.pet), + notice: t(".success", message: MessagesHelper.affirmations.sample) + + # mailer + @org_staff = User.organization_staff(@pet.organization_id) + StaffApplicationNotificationMailer.with(pet: @pet, + organization_staff: @org_staff) + .new_adoption_application.deliver_now + else + redirect_to adoptable_pet_path(@pet), + alert: t(".error") + end + end + + # update :status to 'withdrawn' or :profile_show to false + def update + if @application.update(application_params) + redirect_to adopter_fosterer_adopter_applications_path + else + redirect_to adopter_fosterer_profile_path, alert: t(".error") + end + end + + private + + def set_application + @application = AdopterApplication.find(params[:id]) + authorize! @application, with: AdopterApplicationPolicy + end + + def application_params + params.require(:adopter_application).permit( + :pet_id, + :adopter_foster_account_id, + :status, + :profile_show + ) + end +end diff --git a/app/controllers/organizations/adopter_fosterer/custom_form/submissions_controller.rb b/app/controllers/organizations/adopter_fosterer/custom_form/submissions_controller.rb deleted file mode 100644 index 3a3f518cd..000000000 --- a/app/controllers/organizations/adopter_fosterer/custom_form/submissions_controller.rb +++ /dev/null @@ -1,63 +0,0 @@ -module Organizations - module AdopterFosterer - module CustomForm - class SubmissionsController < Organizations::BaseController - before_action :authenticate_user! - before_action :set_submission, only: %i[update] - layout "adopter_foster_dashboard" - - def index - authorize! ::CustomForm::Submission, with: ::CustomForm::SubmissionPolicy - - @submissions = authorized_scope(::CustomForm::Submission.where(profile_show: true), with: ::CustomForm::SubmissionPolicy) - end - - def create - @pet = Pet.find(submission_params[:pet_id]) - authorize! ::CustomForm::Submission, context: {pet: @pet}, with: ::CustomForm::SubmissionPolicy - - @submission = ::CustomForm::Submission.new(submission_params) - - if @submission.save - redirect_to adoptable_pet_path(@submission.pet), - notice: t(".success", message: MessagesHelper.affirmations.sample) - - # mailer - @org_staff = User.organization_staff(@pet.organization_id) - StaffSubmissionNotificationMailer.with(pet: @pet, - organization_staff: @org_staff) - .new_adoption_submission.deliver_now - else - redirect_to adoptable_pet_path(@pet), - alert: t(".error") - end - end - - # update :status to 'withdrawn' or :profile_show to false - def update - if @submission.update(submission_params) - redirect_to adopter_fosterer_custom_form_submissions_path - else - redirect_to adopter_fosterer_profile_path, alert: t(".error") - end - end - - private - - def set_submission - @submission = ::CustomForm::Submission.find(params[:id]) - authorize! @submission, with: ::CustomForm::SubmissionPolicy - end - - def submission_params - params.require(:custom_form_submission).permit( - :pet_id, - :adopter_foster_account_id, - :status, - :profile_show - ) - end - end - end - end -end diff --git a/app/controllers/organizations/adopter_fosterer/dashboard_controller.rb b/app/controllers/organizations/adopter_fosterer/dashboard_controller.rb index eab0a7fe2..e4c3841cb 100644 --- a/app/controllers/organizations/adopter_fosterer/dashboard_controller.rb +++ b/app/controllers/organizations/adopter_fosterer/dashboard_controller.rb @@ -5,7 +5,7 @@ def index @user = current_user @organization = Current.organization @hide_footer = true - @submission_count = @user.adopter_foster_account&.submissions&.count.to_i + @application_count = @user.adopter_foster_account&.adopter_applications&.count.to_i authorize! :adopter_foster_dashboard, context: {organization: @organization} end diff --git a/app/controllers/organizations/staff/adoption_application_reviews_controller.rb b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb new file mode 100644 index 000000000..0445a9b81 --- /dev/null +++ b/app/controllers/organizations/staff/adoption_application_reviews_controller.rb @@ -0,0 +1,57 @@ +class Organizations::Staff::AdoptionApplicationReviewsController < Organizations::BaseController + before_action :set_adopter_application, only: %i[edit update] + + include ::Pagy::Backend + + layout "dashboard" + + def index + authorize! AdopterApplication, + context: {organization: Current.organization} + + @q = authorized_scope( + Pet.org_pets_with_apps(current_user.staff_account.organization_id) + ).ransack(params[:q]) + @pets_with_applications = @q.result.includes(:adopter_applications) + + # Combining these into a single chained statement does not yield the same result due to how Ransack processes parameters. + if params[:q].present? && params[:q]["adopter_applications_status_eq"].present? + status_filter = params[:q]["adopter_applications_status_eq"] + @pets_with_applications = filter_by_application_status(@pets_with_applications, status_filter) + end + + @pagy, @pets_with_applications = pagy(@pets_with_applications, items: 10) + end + + def edit + end + + def update + @applications_tab = request.referrer.include?("applications") # Change table display in pets/applications tab + + respond_to do |format| + if @application.update(application_params) + format.html { redirect_to staff_dashboard_index_path } + format.turbo_stream { flash.now[:notice] = t(".success") } + else + format.html { render :edit, status: :unprocessable_entity } + format.turbo_stream { flash.now[:alert] = t(".error") } + end + end + end + + private + + def application_params + params.require(:adopter_application).permit(:status, :notes, :profile_show) + end + + def set_adopter_application + @application = AdopterApplication.find(params[:id]) + authorize! @application + end + + def filter_by_application_status(pets_relation, status_filter) + pets_relation.joins(:adopter_applications).where(adopter_applications: {status: status_filter}) + end +end diff --git a/app/controllers/organizations/staff/matches_controller.rb b/app/controllers/organizations/staff/matches_controller.rb index ea6cba86e..87295ecca 100644 --- a/app/controllers/organizations/staff/matches_controller.rb +++ b/app/controllers/organizations/staff/matches_controller.rb @@ -11,7 +11,7 @@ def create if @match.save AdoptionMailer.reminder(@match).deliver_later - @match.retire_submissions + @match.retire_applications redirect_back_or_to staff_dashboard_index_path, notice: t(".success") else @@ -21,7 +21,7 @@ def create def destroy if @match.destroy - @match.withdraw_submission + @match.withdraw_application redirect_to staff_pets_path, notice: t(".success") else diff --git a/app/controllers/organizations/staff/pets_controller.rb b/app/controllers/organizations/staff/pets_controller.rb index 6dd8a1913..bb2f014aa 100644 --- a/app/controllers/organizations/staff/pets_controller.rb +++ b/app/controllers/organizations/staff/pets_controller.rb @@ -114,6 +114,6 @@ def set_pet end def determine_active_tab - ["tasks", "submissions", "fosters", "photos", "files"].include?(params[:active_tab]) ? params[:active_tab] : "overview" + ["tasks", "applications", "fosters", "photos", "files"].include?(params[:active_tab]) ? params[:active_tab] : "overview" end end diff --git a/app/controllers/organizations/staff/submission_reviews_controller.rb b/app/controllers/organizations/staff/submission_reviews_controller.rb deleted file mode 100644 index 091db6515..000000000 --- a/app/controllers/organizations/staff/submission_reviews_controller.rb +++ /dev/null @@ -1,58 +0,0 @@ -class Organizations::Staff::SubmissionReviewsController < Organizations::BaseController - before_action :set_adopter_submission, only: %i[edit update] - - include ::Pagy::Backend - - layout "dashboard" - - def index - authorize! CustomForm::Submission, - context: {organization: Current.organization}, - with: Organizations::SubmissionPolicy - - @q = authorized_scope( - Pet.org_pets_with_subs(current_user.staff_account.organization_id) - ).ransack(params[:q]) - @pets_with_submissions = @q.result.includes(:submissions) - - # Combining these into a single chained statement does not yield the same result due to how Ransack processes parameters. - if params[:q].present? && params[:q]["submissions_status_eq"].present? - status_filter = params[:q]["submissions_status_eq"] - @pets_with_submissions = filter_by_submission_status(@pets_with_submissions, status_filter) - end - - @pagy, @pets_with_submissions = pagy(@pets_with_submissions, items: 10) - end - - def edit - end - - def update - @submissions_tab = request.referrer.include?("submissions") # Change table display in pets/submissions tab - - respond_to do |format| - if @submission.update(submission_params) - format.html { redirect_to staff_dashboard_index_path } - format.turbo_stream { flash.now[:notice] = t(".success") } - else - format.html { render :edit, status: :unprocessable_entity } - format.turbo_stream { flash.now[:alert] = t(".error") } - end - end - end - - private - - def submission_params - params.require(:custom_form_submission).permit(:status, :notes, :profile_show) - end - - def set_adopter_submission - @submission = CustomForm::Submission.find(params[:id]) - authorize! @submission, with: Organizations::SubmissionPolicy - end - - def filter_by_submission_status(pets_relation, status_filter) - pets_relation.joins(:submissions).where(submissions: {status: status_filter}) - end -end diff --git a/app/helpers/adoption_application_reviews_helper.rb b/app/helpers/adoption_application_reviews_helper.rb index 70ab50fd8..e7bc6e8df 100644 --- a/app/helpers/adoption_application_reviews_helper.rb +++ b/app/helpers/adoption_application_reviews_helper.rb @@ -1,5 +1,5 @@ module AdoptionApplicationReviewsHelper - def submission_status_classes(submission) + def application_status_classes(application) status_classes = {awaiting_review: "text-white bg-dark-primary", under_review: "text-white bg-dark-info", adoption_pending: "text-black bg-light-warning", @@ -7,6 +7,6 @@ def submission_status_classes(submission) successful_applicant: "text-black bg-light-success", adoption_made: "text-black bg-light-success"} - status_classes[submission.status.to_sym] + status_classes[application.status.to_sym] end end diff --git a/app/mailers/staff_submission_notification_mailer.rb b/app/mailers/staff_application_notification_mailer.rb similarity index 79% rename from app/mailers/staff_submission_notification_mailer.rb rename to app/mailers/staff_application_notification_mailer.rb index 9c08f89eb..d8791d582 100644 --- a/app/mailers/staff_submission_notification_mailer.rb +++ b/app/mailers/staff_application_notification_mailer.rb @@ -1,5 +1,5 @@ -class StaffSubmissionNotificationMailer < ApplicationMailer - def new_adoption_submission +class StaffApplicationNotificationMailer < ApplicationMailer + def new_adoption_application @organization_staff = params[:organization_staff] @pet = params[:pet] diff --git a/app/models/adopter_application.rb b/app/models/adopter_application.rb new file mode 100644 index 000000000..06a2c5a62 --- /dev/null +++ b/app/models/adopter_application.rb @@ -0,0 +1,92 @@ +# == Schema Information +# +# Table name: adopter_applications +# +# id :bigint not null, primary key +# notes :text +# profile_show :boolean default(TRUE) +# status :integer default("awaiting_review") +# created_at :datetime not null +# updated_at :datetime not null +# adopter_foster_account_id :bigint not null +# organization_id :bigint not null +# pet_id :bigint not null +# +# Indexes +# +# index_adopter_applications_on_account_and_pet (pet_id,adopter_foster_account_id) UNIQUE +# index_adopter_applications_on_adopter_foster_account_id (adopter_foster_account_id) +# index_adopter_applications_on_organization_id (organization_id) +# index_adopter_applications_on_pet_id (pet_id) +# +# Foreign Keys +# +# fk_rails_... (adopter_foster_account_id => adopter_foster_accounts.id) +# fk_rails_... (pet_id => pets.id) +# +class AdopterApplication < ApplicationRecord + acts_as_tenant(:organization) + belongs_to :pet, touch: true + belongs_to :adopter_foster_account + + broadcasts_refreshes + + enum :status, [:awaiting_review, + :under_review, + :adoption_pending, + :withdrawn, + :successful_applicant, + :adoption_made] + + validates :adopter_foster_account, + uniqueness: { + scope: :pet, + message: "has already applied for this pet." + } + # remove adoption_made status as not necessary for staff + def self.app_review_statuses + AdopterApplication.statuses.keys.map do |status| + unless status == "adoption_made" + [status.titleize, status] + end + end.compact! + end + + # check if an adopter has applied to adopt a pet + def self.adoption_exists?(adopter_foster_account_id, pet_id) + AdopterApplication.where(adopter_foster_account_id: adopter_foster_account_id, + pet_id: pet_id).exists? + end + + # check if any applications are set to profile_show: true + def self.any_applications_profile_show_true?(adopter_foster_account_id) + applications = AdopterApplication.where(adopter_foster_account_id: adopter_foster_account_id) + applications.any? { |app| app.profile_show == true } + end + + def self.retire_applications(pet_id:) + where(pet_id:).each do |adopter_application| + adopter_application.update!(status: :adoption_made) + end + end + + def applicant_name + adopter_foster_account.user.full_name.to_s + end + + def withdraw + update!(status: :withdrawn) + end + + ransacker :applicant_name do + Arel.sql("CONCAT(users.last_name, ', ', users.first_name)") + end + + ransacker :status, formatter: proc { |v| statuses[v] } do |parent| + parent.table[:status] + end + + def self.ransackable_attributes(auth_object = nil) + ["applicant_name", "status"] + end +end diff --git a/app/models/adopter_foster_account.rb b/app/models/adopter_foster_account.rb index 8c2b6e5dc..47cd6c03b 100644 --- a/app/models/adopter_foster_account.rb +++ b/app/models/adopter_foster_account.rb @@ -21,7 +21,7 @@ class AdopterFosterAccount < ApplicationRecord acts_as_tenant(:organization) belongs_to :user has_one :adopter_foster_profile, dependent: :destroy - has_many :submissions, class_name: "CustomForm::Submission", dependent: :destroy + has_many :adopter_applications, dependent: :destroy has_many :matches, dependent: :destroy has_many :likes, dependent: :destroy has_many :liked_pets, through: :likes, source: :pet diff --git a/app/models/concerns/authorizable.rb b/app/models/concerns/authorizable.rb index f518a381f..16dcb18b7 100644 --- a/app/models/concerns/authorizable.rb +++ b/app/models/concerns/authorizable.rb @@ -1,8 +1,8 @@ ADOPTER_PERMISSIONS = %i[ view_adopter_foster_dashboard - create_adopter_submissions - view_adopter_submissions - withdraw_adopter_submissions + create_adopter_applications + view_adopter_applications + withdraw_adopter_applications create_adopter_foster_profiles manage_adopter_foster_profiles purge_avatar @@ -20,13 +20,13 @@ ADOPTER_PERMISSIONS.excluding( %i[ view_adopter_foster_dashboard - create_adopter_submissions + create_adopter_applications create_adopter_foster_profiles manage_adopter_foster_profiles manage_likes ] ) + %i[ - review_adopter_submissions + review_adopter_applications view_adopter_foster_accounts view_adopter_foster_profiles invite_fosterers diff --git a/app/models/custom_form/submission.rb b/app/models/custom_form/submission.rb deleted file mode 100644 index ba831fab1..000000000 --- a/app/models/custom_form/submission.rb +++ /dev/null @@ -1,94 +0,0 @@ -# == Schema Information -# -# Table name: submissions -# -# id :bigint not null, primary key -# notes :text -# profile_show :boolean default(TRUE) -# status :integer default("awaiting_review") -# created_at :datetime not null -# updated_at :datetime not null -# adopter_foster_account_id :bigint not null -# organization_id :bigint not null -# pet_id :bigint not null -# -# Indexes -# -# index_submissions_on_adopter_foster_account_id (adopter_foster_account_id) -# index_submissions_on_organization_id (organization_id) -# index_submissions_on_pet_id (pet_id) -# index_submissions_on_pet_id_and_adopter_foster_account_id (pet_id,adopter_foster_account_id) UNIQUE -# -# Foreign Keys -# -# fk_rails_... (adopter_foster_account_id => adopter_foster_accounts.id) -# fk_rails_... (pet_id => pets.id) -# -module CustomForm - class Submission < ApplicationRecord - acts_as_tenant(:organization) - belongs_to :pet, touch: true - belongs_to :adopter_foster_account - - broadcasts_refreshes - - enum :status, [:awaiting_review, - :under_review, - :adoption_pending, - :withdrawn, - :successful_applicant, - :adoption_made] - - validates :adopter_foster_account, - uniqueness: { - scope: :pet, - message: "has already applied for this pet." - } - # remove adoption_made status as not necessary for staff - def self.sub_review_statuses - CustomForm::Submission.statuses.keys.map do |status| - unless status == "adoption_made" - [status.titleize, status] - end - end.compact! - end - - # check if an adopter has applied to adopt a pet - def self.adoption_exists?(adopter_foster_account_id, pet_id) - CustomForm::Submission.where(adopter_foster_account_id: adopter_foster_account_id, - pet_id: pet_id).exists? - end - - # check if any submissions are set to profile_show: true - def self.any_submissions_profile_show_true?(adopter_foster_account_id) - submissions = CustomForm::Submission.where(adopter_foster_account_id: adopter_foster_account_id) - submissions.any? { |sub| sub.profile_show == true } - end - - def self.retire_submissions(pet_id:) - where(pet_id:).each do |submission| - submission.update!(status: :adoption_made) - end - end - - def applicant_name - adopter_foster_account.user.full_name.to_s - end - - def withdraw - update!(status: :withdrawn) - end - - ransacker :applicant_name do - Arel.sql("CONCAT(users.last_name, ', ', users.first_name)") - end - - ransacker :status, formatter: proc { |v| statuses[v] } do |parent| - parent.table[:status] - end - - def self.ransackable_attributes(auth_object = nil) - ["applicant_name", "status"] - end - end -end diff --git a/app/models/match.rb b/app/models/match.rb index 3d94e4189..98cd519b2 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -77,12 +77,12 @@ def status end end - def withdraw_submission - adopter_submission&.withdraw + def withdraw_application + adopter_application&.withdraw end - def retire_submissions(submission_class: CustomForm::Submission) - submission_class.retire_submissions(pet_id: pet_id) + def retire_applications(application_class: AdopterApplication) + application_class.retire_applications(pet_id: pet_id) end private @@ -93,8 +93,8 @@ def belongs_to_same_organization_as_pet end end - def adopter_submission - CustomForm::Submission.find_by(pet:, adopter_foster_account:) + def adopter_application + AdopterApplication.find_by(pet:, adopter_foster_account:) end ransacker :status do diff --git a/app/models/pet.rb b/app/models/pet.rb index dd3d3776e..e254dea1b 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -30,7 +30,7 @@ class Pet < ApplicationRecord acts_as_tenant(:organization) - has_many :submissions, class_name: "CustomForm::Submission", dependent: :destroy + has_many :adopter_applications, dependent: :destroy has_many :tasks, dependent: :destroy has_many :matches, dependent: :destroy has_many :likes, dependent: :destroy @@ -84,13 +84,13 @@ class Pet < ApplicationRecord attr_writer :toggle - # check if pet has any submissions with adoption pending status + # check if pet has any applications with adoption pending status def has_adoption_pending? - submissions.any? { |sub| sub.status == "adoption_pending" } + adopter_applications.any? { |app| app.status == "adoption_pending" } end def is_adopted? - submissions.any? { |sub| sub.status == "adoption_made" } + adopter_applications.any? { |app| app.status == "adoption_made" } end # active storage: using.attach for appending images per rails guide @@ -109,9 +109,9 @@ def self.org_pets(staff_org_id) Pet.where(organization_id: staff_org_id) end - def self.org_pets_with_subs(staff_org_id) - org_pets(staff_org_id).includes(submissions: [adopter_foster_account: [:user]]).where - .not(submissions: {id: nil}).references(:users) + def self.org_pets_with_apps(staff_org_id) + org_pets(staff_org_id).includes(adopter_applications: [adopter_foster_account: [:user]]).where + .not(adopter_applications: {id: nil}).references(:users) end def self.ransackable_attributes(auth_object = nil) @@ -119,7 +119,7 @@ def self.ransackable_attributes(auth_object = nil) end def self.ransackable_associations(auth_object = nil) - ["submissions"] + ["adopter_applications"] end def self.ransackable_scopes(auth_object = nil) diff --git a/app/policies/adopter_application_policy.rb b/app/policies/adopter_application_policy.rb new file mode 100644 index 000000000..2ab201c4d --- /dev/null +++ b/app/policies/adopter_application_policy.rb @@ -0,0 +1,44 @@ +class AdopterApplicationPolicy < ApplicationPolicy + authorize :pet, optional: true + + pre_check :verify_profile! + pre_check :verify_pet_appliable!, only: %i[create?] + + relation_scope do |relation| + relation.where(adopter_foster_account_id: user.adopter_foster_account.id) + end + + def update? + applicant? && permission?(:withdraw_adopter_applications) + end + + def index? + permission?(:view_adopter_applications) + end + + def create? + permission?(:create_adopter_applications) + end + + private + + def applicant? + user.id == record.adopter_foster_account.user_id + end + + def already_applied? + user.adopter_foster_account.adopter_applications.any? do |application| + application.pet_id == pet.id + end + end + + def verify_profile! + deny! unless user.adopter_foster_account.present? + deny! unless user.adopter_foster_account.adopter_foster_profile.present? + end + + def verify_pet_appliable! + deny! if pet.application_paused + deny! if already_applied? + end +end diff --git a/app/policies/custom_form/submission_policy.rb b/app/policies/custom_form/submission_policy.rb deleted file mode 100644 index c4d9f54a1..000000000 --- a/app/policies/custom_form/submission_policy.rb +++ /dev/null @@ -1,46 +0,0 @@ -module CustomForm - class SubmissionPolicy < ApplicationPolicy - authorize :pet, optional: true - - pre_check :verify_profile! - pre_check :verify_pet_appliable!, only: %i[create?] - - relation_scope do |relation| - relation.where(adopter_foster_account_id: user.adopter_foster_account.id) - end - - def update? - applicant? && permission?(:withdraw_adopter_submissions) - end - - def index? - permission?(:view_adopter_submissions) - end - - def create? - permission?(:create_adopter_submissions) - end - - private - - def applicant? - user.id == record.adopter_foster_account.user_id - end - - def already_applied? - user.adopter_foster_account.submissions.any? do |submission| - submission.pet_id == pet.id - end - end - - def verify_profile! - deny! unless user.adopter_foster_account.present? - deny! unless user.adopter_foster_account.adopter_foster_profile.present? - end - - def verify_pet_appliable! - deny! if pet.application_paused - deny! if already_applied? - end - end -end diff --git a/app/policies/organizations/adopter_application_policy.rb b/app/policies/organizations/adopter_application_policy.rb new file mode 100644 index 000000000..c15f131e1 --- /dev/null +++ b/app/policies/organizations/adopter_application_policy.rb @@ -0,0 +1,16 @@ +class Organizations::AdopterApplicationPolicy < ApplicationPolicy + pre_check :verify_organization! + pre_check :verify_active_staff! + + alias_rule :index?, to: :manage? + + def manage? + permission?(:review_adopter_applications) + end + + private + + def organization + @organization || record.pet.organization + end +end diff --git a/app/policies/organizations/submission_policy.rb b/app/policies/organizations/submission_policy.rb deleted file mode 100644 index 0f14ce905..000000000 --- a/app/policies/organizations/submission_policy.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Organizations - class SubmissionPolicy < ApplicationPolicy - pre_check :verify_organization! - pre_check :verify_active_staff! - - alias_rule :index?, to: :manage? - - def manage? - permission?(:review_adopter_submissions) - end - - private - - def organization - @organization || record.pet.organization - end - end -end diff --git a/app/views/layouts/adopter_foster_dashboard.html.erb b/app/views/layouts/adopter_foster_dashboard.html.erb index d0f3a9846..40e809359 100644 --- a/app/views/layouts/adopter_foster_dashboard.html.erb +++ b/app/views/layouts/adopter_foster_dashboard.html.erb @@ -57,8 +57,8 @@ diff --git a/app/views/layouts/dashboard/_sidebar.html.erb b/app/views/layouts/dashboard/_sidebar.html.erb index cd57edfbd..5725a6b1c 100644 --- a/app/views/layouts/dashboard/_sidebar.html.erb +++ b/app/views/layouts/dashboard/_sidebar.html.erb @@ -21,7 +21,7 @@ <% end %> diff --git a/app/views/organizations/adoptable_pets/show.html.erb b/app/views/organizations/adoptable_pets/show.html.erb index 943c81a1c..1ee478e6b 100644 --- a/app/views/organizations/adoptable_pets/show.html.erb +++ b/app/views/organizations/adoptable_pets/show.html.erb @@ -89,25 +89,25 @@
<% unless user_signed_in? && current_user.staff_account %> <% if user_signed_in? %> - <% if allowed_to?(:create?, with: CustomForm::SubmissionPolicy, context: {pet: @pet, user: current_user}) %> + <% if allowed_to?(:create?, with: AdopterApplicationPolicy, context: {pet: @pet, user: current_user}) %>

In love with this pooch?

- <%= form_with model: [:adopter_fosterer, @submission] do |form| %> - <%= form.hidden_field :pet_id, value: @submission.pet_id %> - <%= form.hidden_field :adopter_foster_account_id, value: @submission.adopter_foster_account_id %> + <%= form_with model: [:adopter_fosterer, @adoption_application] do |form| %> + <%= form.hidden_field :pet_id, value: @adoption_application.pet_id %> + <%= form.hidden_field :adopter_foster_account_id, value: @adoption_application.adopter_foster_account_id %> <%= form.submit t(".apply_to_adopt"), class: "custom-btn-pink", data: {turbo: false} %> <% end %> <% else %> - <% if CustomForm::Submission.adoption_exists?(current_user.adopter_foster_account&.id, @pet.id) %> + <% if AdopterApplication.adoption_exists?(current_user.adopter_foster_account&.id, @pet.id) %>

- <%= "#{@submission.human_enum_name(:status) || t('.status.default')}" %> + <%= "#{@adoption_application.human_enum_name(@adoption_application.status) || t('.status.default')}" %>

- <% if %w[under_review adoption_pending].include?(@submission.status) %> + <% if %w[under_review adoption_pending].include?(@adoption_application.status) %> <%= image_tag('pause.png', height: '21') %> - <% elsif 'withdrawn' == @submission.status %> + <% elsif 'withdrawn' == @adoption_application.status %> <%= image_tag('red_no.png', height: '21') %> <% else %> <%= image_tag('green_check.png', height: '21') %> diff --git a/app/views/organizations/adopter_fosterer/custom_form/submissions/_submission_cards.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb similarity index 55% rename from app/views/organizations/adopter_fosterer/custom_form/submissions/_submission_cards.html.erb rename to app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb index 53a61e1f9..f542d0a58 100644 --- a/app/views/organizations/adopter_fosterer/custom_form/submissions/_submission_cards.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/_application_cards.html.erb @@ -1,6 +1,6 @@ <%= turbo_refreshes_with method: :morph, scroll: :preserve %> -<% pet = submission.pet %> +<% pet = application.pet %>
<%= link_to image_tag(pet.images.attached? ? pet.images.first : 'coming_soon.jpg', class: 'card-img-top pet-card'), adoptable_pet_path(pet) %>
    @@ -11,26 +11,26 @@ <% li_classes = %w[list-group-item text-secondary] %>
  • - <%= t("views.dashboard.submissions.created")%>: - <%= l submission.created_at.to_date, format: :long %> + <%= t("views.dashboard.applications.created")%>: + <%= l application.created_at.to_date, format: :long %>
  • -
    <%= t("views.dashboard.submissions.status")%>:
    +
    <%= t("views.dashboard.applications.status")%>:
    - <%= submission.human_enum_name(:status) %> + <%= application.human_enum_name(:status) %>
  • - <% if submission.status == 'withdrawn' %> + <% if application.status == 'withdrawn' %> <%= button_to t("general.delete"), - adopter_fosterer_custom_form_submission_path(submission, custom_form_submission: + adopter_fosterer_adopter_application_path(application, adopter_application: { profile_show: false }), method: :patch, class: 'btn btn-outline-danger', - data: { turbo_confirm: t("dashboard.submissions.confirm_delete") } %> - <% elsif submission.status != 'adoption_made' %> - <%= button_to t("dashboard.submissions.withdraw_submission"), - adopter_fosterer_custom_form_submission_path(submission, custom_form_submission: + data: { turbo_confirm: t("dashboard.applications.confirm_delete") } %> + <% elsif application.status != 'adoption_made' %> + <%= button_to t("dashboard.applications.withdraw_application"), + adopter_fosterer_adopter_application_path(application, adopter_application: { status: 'withdrawn'}), method: :patch, class: 'btn btn-outline-danger', - data: { turbo_confirm: t("dashboard.submissions.confirm_withdraw", pet_name: pet.name.capitalize) } %> + data: { turbo_confirm: t("dashboard.applications.confirm_withdraw", pet_name: pet.name.capitalize) } %> <% end %>
diff --git a/app/views/organizations/adopter_fosterer/custom_form/submissions/_submissions_table.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb similarity index 53% rename from app/views/organizations/adopter_fosterer/custom_form/submissions/_submissions_table.html.erb rename to app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb index 3ee3e6ac1..7b1d548ad 100644 --- a/app/views/organizations/adopter_fosterer/custom_form/submissions/_submissions_table.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/_applications_table.html.erb @@ -5,16 +5,16 @@ - - - + + + - <% submissions.each do |sub| %> - <%= turbo_stream_from sub %> - <% pet = sub.pet %> + <% applications.each do |app| %> + <%= turbo_stream_from app %> + <% pet = app.pet %> diff --git a/app/views/organizations/adopter_fosterer/custom_form/submissions/index.html.erb b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb similarity index 61% rename from app/views/organizations/adopter_fosterer/custom_form/submissions/index.html.erb rename to app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb index ac2143bb7..e8f80c38f 100644 --- a/app/views/organizations/adopter_fosterer/custom_form/submissions/index.html.erb +++ b/app/views/organizations/adopter_fosterer/adopter_applications/index.html.erb @@ -1,15 +1,15 @@ <%= render "components/adopter_foster_dashboard/page" do |p| %> - <% p.header_title t("dashboard.submissions.header_title") %> + <% p.header_title t("dashboard.applications.header_title") %> <% p.content do %>
- <%= render partial: "submissions_table", locals: { submissions: @submissions} %> + <%= render partial: "applications_table", locals: { applications: @applications} %>
- <%= render partial:"submission_cards", collection: @submissions, as: :submission %> + <%= render partial:"application_cards", collection: @applications, as: :application %>
<% end %> diff --git a/app/views/organizations/adopter_fosterer/dashboard/index.html.erb b/app/views/organizations/adopter_fosterer/dashboard/index.html.erb index c835123fa..884f222d4 100644 --- a/app/views/organizations/adopter_fosterer/dashboard/index.html.erb +++ b/app/views/organizations/adopter_fosterer/dashboard/index.html.erb @@ -26,11 +26,11 @@
- <%= link_to adopter_fosterer_custom_form_submissions_path, class: "card-link" do %> + <%= link_to adopter_fosterer_adopter_applications_path, class: "card-link" do %> <%= render "components/data_card" do |c| %> <% c.title "Applications" %> #here erin <% c.icon "file-text" %> - <% c.value @submission_count %> + <% c.value @application_count %> <% end %> <% end %>
diff --git a/app/views/organizations/staff/adoption_application_reviews/_search_results.html.erb b/app/views/organizations/staff/adoption_application_reviews/_search_results.html.erb new file mode 100644 index 000000000..1c1aff475 --- /dev/null +++ b/app/views/organizations/staff/adoption_application_reviews/_search_results.html.erb @@ -0,0 +1,10 @@ +<%# @pet, @pets are defined in the adoption_application_reviews controller %> + +<% @collection = @pet.nil? ? @pets_with_applications : @pet %> + +
+ <% @collection.each do |pet| %> + + <%= render "organizations/staff/pets/tabs/applications", applications: pet.adopter_applications, pet: pet %> + <% end %> +
\ No newline at end of file diff --git a/app/views/organizations/staff/submission_reviews/edit.html.erb b/app/views/organizations/staff/adoption_application_reviews/edit.html.erb similarity index 75% rename from app/views/organizations/staff/submission_reviews/edit.html.erb rename to app/views/organizations/staff/adoption_application_reviews/edit.html.erb index fbcf9b122..b5c568aa8 100644 --- a/app/views/organizations/staff/submission_reviews/edit.html.erb +++ b/app/views/organizations/staff/adoption_application_reviews/edit.html.erb @@ -1,7 +1,7 @@ <%= render "components/dashboard/page" do |p| %> <% p.header_title do %> - <%= @submission.adopter_foster_account.user.full_name %>'s application for - <%= @submission.pet.name %> + <%= @application.adopter_foster_account.user.full_name %>'s application for + <%= @application.pet.name %> <% end %> <% p.content do %> @@ -10,16 +10,16 @@
- <%= link_to "#{@submission.adopter_foster_account.user.first_name}'s Profile", - staff_profile_review_path(@submission.adopter_foster_account.adopter_foster_profile.id), + <%= link_to "#{@application.adopter_foster_account.user.first_name}'s Profile", + staff_profile_review_path(@application.adopter_foster_account.adopter_foster_profile.id), class: 'text-decoration-none bigger' %>
- <%= bootstrap_form_with model: @submission, :url => staff_submission_review_path do |form| %> + <%= bootstrap_form_with model: @application, :url => staff_adoption_application_review_path do |form| %>
<%= form.select(:status, - CustomForm::Submission.sub_review_statuses, + AdopterApplication.app_review_statuses, { label: 'Application status' }, {:class => "form-control"}) %>
@@ -29,7 +29,7 @@ class: 'form-control mb-2' %>
- <% if @submission.profile_show == false %> + <% if @application.profile_show == false %>
<%= form.check_box :profile_show, {}, true, false, label: 'Reinstate application:' %> diff --git a/app/views/organizations/staff/submission_reviews/index.html.erb b/app/views/organizations/staff/adoption_application_reviews/index.html.erb similarity index 66% rename from app/views/organizations/staff/submission_reviews/index.html.erb rename to app/views/organizations/staff/adoption_application_reviews/index.html.erb index c4c00e5e0..d6c215883 100644 --- a/app/views/organizations/staff/submission_reviews/index.html.erb +++ b/app/views/organizations/staff/adoption_application_reviews/index.html.erb @@ -6,25 +6,25 @@
- <%= search_form_for @q, url: staff_submission_reviews_path do |f| %> + <%= search_form_for @q, url: staff_adoption_application_reviews_path do |f| %>
<%= f.label :name_cont, "Pet Name" %> <%= f.text_field :name_i_cont, class: "form-control", placeholder: "Enter Pet Name" %>
- <%= f.label :submissions_applicant_name_cont, "Applicant Name" %> - <%= f.text_field :submissions_applicant_name_i_cont, class: "form-control", placeholder: "Enter Applicant Name" %> + <%= f.label :adopter_applications_applicant_name_cont, "Applicant Name" %> + <%= f.text_field :adopter_applications_applicant_name_i_cont, class: "form-control", placeholder: "Enter Applicant Name" %>
- <%= f.label :submissions_status_eq, "Application Status" %> - <%= f.select :submissions_status_eq, CustomForm::Submission.statuses.keys.map { |status| [status.titleize, status] }, { include_blank: 'All' }, class: "form-select" %> + <%= f.label :adopter_applications_status_eq, "Application Status" %> + <%= f.select :adopter_applications_status_eq, AdopterApplication.statuses.keys.map { |status| [status.titleize, status] }, { include_blank: 'All' }, class: "form-select" %>
<%= f.submit "Search", class: "btn btn-primary" %> - <%= link_to "Clear filters", staff_submission_reviews_path, class: "btn btn-default" %> + <%= link_to "Clear filters", staff_adoption_application_reviews_path, class: "btn btn-default" %>
<% end %> diff --git a/app/views/organizations/staff/adoption_application_reviews/update.turbo_stream.erb b/app/views/organizations/staff/adoption_application_reviews/update.turbo_stream.erb new file mode 100644 index 000000000..178b55e0c --- /dev/null +++ b/app/views/organizations/staff/adoption_application_reviews/update.turbo_stream.erb @@ -0,0 +1,7 @@ +<%= turbo_stream.replace "table_adopter_application_#{@application.id}", + partial: "organizations/staff/pets/tabs/partials/application_info_table", + locals: {app: @application}%> +<%= turbo_stream.replace "card_adopter_application_#{@application.id}", + partial: "organizations/staff/pets/tabs/partials/application_info_card", + locals: {app: @application}%> +<%= turbo_stream.replace "flash", partial: "layouts/shared/flash_messages" %> diff --git a/app/views/organizations/staff/pets/show.html.erb b/app/views/organizations/staff/pets/show.html.erb index 682dc8273..df9c0cb1d 100644 --- a/app/views/organizations/staff/pets/show.html.erb +++ b/app/views/organizations/staff/pets/show.html.erb @@ -5,7 +5,7 @@ <% p.nav_tabs do %> <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet), text: "Overview", options: { active: :exact } %> <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'tasks'), text: "Tasks", options: { active: :exact } %> - <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'submissions'), text: "Applications", options: { active: :exact } %> + <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'applications'), text: "Applications", options: { active: :exact } %> <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'fosters'), text: "Fosters", options: { active: :exact } %> <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'photos'), text: "Photos", options: { active: :exact } %> <%= render "components/dashboard/nav_tab", url: staff_pet_path(@pet, active_tab: 'files'), text: "Files", options: { active: :exact } %> @@ -14,7 +14,7 @@ <% p.content do %>
- <%= render partial: "organizations/staff/pets/tabs/#{@active_tab}", locals: { submissions: @pet.submissions, pet: @pet, fosters: @pet.matches.fosters } %> + <%= render partial: "organizations/staff/pets/tabs/#{@active_tab}", locals: { applications: @pet.adopter_applications, pet: @pet, fosters: @pet.matches.fosters } %>
diff --git a/app/views/organizations/staff/pets/tabs/_submissions.html.erb b/app/views/organizations/staff/pets/tabs/_applications.html.erb similarity index 70% rename from app/views/organizations/staff/pets/tabs/_submissions.html.erb rename to app/views/organizations/staff/pets/tabs/_applications.html.erb index 30a98a4ec..0faa9c1b7 100644 --- a/app/views/organizations/staff/pets/tabs/_submissions.html.erb +++ b/app/views/organizations/staff/pets/tabs/_applications.html.erb @@ -1,6 +1,6 @@ <%# Table layout %>
- <% if current_page?(staff_submission_reviews_path) %> + <% if current_page?(staff_adoption_application_reviews_path) %>

<%= link_to pet.name, staff_pet_path(pet), class: "link-underline link-underline-opacity-0" %>

@@ -9,18 +9,18 @@ <%# headers %>
- <%= t("organizations.staff.pets.submissions.applicant")%> + <%= t("organizations.staff.pets.applications.applicant")%>
- <%= t("organizations.staff.pets.submissions.status")%> + <%= t("organizations.staff.pets.applications.status")%>
- <%= t("organizations.staff.pets.submissions.notes")%> + <%= t("organizations.staff.pets.applications.notes")%>
- <% submissions.each do |sub|%> - <%= render 'organizations/staff/pets/tabs/partials/submission_info_table', sub: sub %> + <% applications.each do |app|%> + <%= render 'organizations/staff/pets/tabs/partials/application_info_table', app: app %> <% end %>
@@ -43,8 +43,8 @@
<%# Card body %> - <% submissions.each do |sub| %> - <%= render 'organizations/staff/pets/tabs/partials/submission_info_card', sub: sub %> + <% applications.each do |app| %> + <%= render 'organizations/staff/pets/tabs/partials/application_info_card', app: app %> <% end %>
diff --git a/app/views/organizations/staff/pets/tabs/partials/_submission_create_button.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb similarity index 69% rename from app/views/organizations/staff/pets/tabs/partials/_submission_create_button.html.erb rename to app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb index c51d7ada6..b445d923a 100644 --- a/app/views/organizations/staff/pets/tabs/partials/_submission_create_button.html.erb +++ b/app/views/organizations/staff/pets/tabs/partials/_application_create_button.html.erb @@ -1,9 +1,9 @@ -<% if sub.status == 'successful_applicant' %> +<% if app.status == 'successful_applicant' %> <%= button_to "New Adoption", staff_matches_path, method: :post, params: {match: - {pet_id: sub.pet_id, - adopter_foster_account_id: sub.adopter_foster_account_id, + {pet_id: app.pet_id, + adopter_foster_account_id: app.adopter_foster_account_id, match_type: :adoption} }, class: "btn btn-outline-primary", @@ -15,6 +15,6 @@ + disabled><%=t("organizations.staff.pets.applications.new_adoption")%> <% end %> \ No newline at end of file diff --git a/app/views/organizations/staff/pets/tabs/partials/_application_info_card.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_info_card.html.erb new file mode 100644 index 000000000..b58d6ab82 --- /dev/null +++ b/app/views/organizations/staff/pets/tabs/partials/_application_info_card.html.erb @@ -0,0 +1,29 @@ +
+
    + + +
  • + <%= t("organizations.staff.pets.applications.applicant")%>: +
    + <%= link_to app.applicant_name, + staff_profile_review_path(app.adopter_foster_account.adopter_foster_profile), + class: "link-underline link-underline-opacity-0" %> +
    +
  • + + +
  • + <%= render 'organizations/staff/pets/tabs/partials/application_status', app: app %> +
  • + + +
  • + <%= render 'organizations/staff/pets/tabs/partials/application_create_button', app: app %> +
  • + + +
  • + <%= render 'organizations/staff/pets/tabs/partials/application_notes', app: app, modal_id: 'card' %> +
  • +
+
\ No newline at end of file diff --git a/app/views/organizations/staff/pets/tabs/partials/_application_info_table.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_info_table.html.erb new file mode 100644 index 000000000..b628958db --- /dev/null +++ b/app/views/organizations/staff/pets/tabs/partials/_application_info_table.html.erb @@ -0,0 +1,19 @@ +
+ +
+ <%= link_to app.applicant_name, staff_profile_review_path(app.adopter_foster_account.adopter_foster_profile), + class: "link-underline link-underline-opacity-0" %> +
+ +
+ <%= render 'organizations/staff/pets/tabs/partials/application_status', app: app %> +
+ +
+ <%= render 'organizations/staff/pets/tabs/partials/application_create_button', app: app %> +
+ +
+ <%= render 'organizations/staff/pets/tabs/partials/application_notes', app: app, modal_id: 'table' %> +
+
diff --git a/app/views/organizations/staff/pets/tabs/partials/_submission_notes.html.erb b/app/views/organizations/staff/pets/tabs/partials/_application_notes.html.erb similarity index 75% rename from app/views/organizations/staff/pets/tabs/partials/_submission_notes.html.erb rename to app/views/organizations/staff/pets/tabs/partials/_application_notes.html.erb index 8ac67a97c..d56c87f6b 100644 --- a/app/views/organizations/staff/pets/tabs/partials/_submission_notes.html.erb +++ b/app/views/organizations/staff/pets/tabs/partials/_application_notes.html.erb @@ -1,27 +1,27 @@ - - <% if params[:active_tab] == 'submissions' || @submissions_tab == true %> - <%= sub.notes&.truncate(8) %> + + <% if params[:active_tab] == 'applications' || @applications_tab == true %> + <%= app.notes&.truncate(8) %> <% else %> - <%= sub.notes&.truncate(20) %> + <%= app.notes&.truncate(20) %> <% end %> - -
<%= t("views.dashboard.submissions.name")%><%= t("views.dashboard.submissions.created")%><%= t("views.dashboard.submissions.status")%><%= t("views.dashboard.applications.name")%><%= t("views.dashboard.applications.created")%><%= t("views.dashboard.applications.status")%>
@@ -29,22 +29,22 @@
<%# localize date %> - <%= l sub.created_at.to_date, format: :long %> + <%= l app.created_at.to_date, format: :long %> - <%= sub.human_enum_name(:status) %> + <%= app.human_enum_name(:status) %> - <% if sub.status == 'withdrawn' %> + <% if app.status == 'withdrawn' %> <%= button_to t("general.delete"), - adopter_fosterer_custom_form_submission_path(sub, custom_form_submission: + adopter_fosterer_adopter_application_path(app, adopter_application: { profile_show: false }), method: :patch, class: 'btn btn-outline-danger', - data: { turbo_confirm: t("dashboard.submissions.confirm_delete") } %> - <% elsif sub.status != 'adoption_made'%> - <%= button_to t("dashboard.submissions.withdraw_submission"), - adopter_fosterer_custom_form_submission_path(sub, custom_form_submission: + data: { turbo_confirm: t("dashboard.applications.confirm_delete") } %> + <% elsif app.status != 'adoption_made'%> + <%= button_to t("dashboard.applications.withdraw_application"), + adopter_fosterer_adopter_application_path(app, adopter_application: { status: 'withdrawn'}), method: :patch, class: 'btn btn-outline-danger', - data: { turbo_confirm: t("dashboard.submissions.confirm_withdraw", pet_name: pet.name.capitalize) } %> + data: { turbo_confirm: t("dashboard.applications.confirm_withdraw", pet_name: pet.name.capitalize) } %> <% end %>