From 6fcd47e9d372ffd1e0324a6a245a3a46cf2851d6 Mon Sep 17 00:00:00 2001 From: Rafael Batista Date: Thu, 16 Apr 2026 12:08:48 -0300 Subject: [PATCH] =?UTF-8?q?instrumenta=C3=A7=C3=A3o=20de=20eventos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/app/clients_controller.rb | 1 + app/controllers/app/order_services_controller.rb | 2 ++ app/controllers/app/reports_controller.rb | 2 ++ app/controllers/app/technicians_controller.rb | 1 + app/controllers/application_controller.rb | 2 ++ app/controllers/concerns/onboarding_tracking.rb | 12 ++++++++++++ 6 files changed, 20 insertions(+) create mode 100644 app/controllers/concerns/onboarding_tracking.rb diff --git a/app/controllers/app/clients_controller.rb b/app/controllers/app/clients_controller.rb index b4c85ee7..ff1bafa1 100644 --- a/app/controllers/app/clients_controller.rb +++ b/app/controllers/app/clients_controller.rb @@ -33,6 +33,7 @@ def new def create if @client.save + mark_onboarding_step("created_customer") redirect_to app_clients_url, notice: "Cliente criado com sucesso." else render :new, status: :unprocessable_entity diff --git a/app/controllers/app/order_services_controller.rb b/app/controllers/app/order_services_controller.rb index ca2e8cb5..847dc00f 100644 --- a/app/controllers/app/order_services_controller.rb +++ b/app/controllers/app/order_services_controller.rb @@ -62,6 +62,7 @@ def create @order_service.created_without_budget = true if @order_service.update(order_service_params_with_auto_schedule_status) + mark_onboarding_step("created_first_work_order") redirect_to app_order_service_url(@order_service), notice: "Ordem de serviço criada com sucesso." else set_other_resources @@ -130,6 +131,7 @@ def update_status redirect_to schedule_app_order_service_path(@order_service) else if @order_service.update(status: target_status) + mark_onboarding_step("moved_work_order_status") redirect_to app_order_service_url(@order_service), notice: "Status atualizado com sucesso." else redirect_to app_order_service_url(@order_service), alert: @order_service.errors.full_messages.join(', ') diff --git a/app/controllers/app/reports_controller.rb b/app/controllers/app/reports_controller.rb index 49062bcf..600598ae 100644 --- a/app/controllers/app/reports_controller.rb +++ b/app/controllers/app/reports_controller.rb @@ -15,6 +15,8 @@ class App::ReportsController < ApplicationController BUDGET_REJECTED_STATUSES = %w[rejeitado cancelado].freeze def index + mark_onboarding_step("viewed_reports") + @reports = @reports.order(created_at: :desc) @generated_reports = @reports.limit(5) diff --git a/app/controllers/app/technicians_controller.rb b/app/controllers/app/technicians_controller.rb index 34e1a5b2..59c883a3 100644 --- a/app/controllers/app/technicians_controller.rb +++ b/app/controllers/app/technicians_controller.rb @@ -33,6 +33,7 @@ def create @technician.company_id = current_user.company_id if current_user.gestor? if @technician.save + mark_onboarding_step("created_technician") redirect_to app_technician_path(@technician), notice: "Técnico criado com sucesso." else render :new, :unprocessable_entity diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 35197b95..a2471f3e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,6 @@ class ApplicationController < ActionController::Base + include OnboardingTracking + before_action :custom_authenticate_user!, unless: :register_subdomain? before_action :block_inactive_company_access, if: :app_subdomain? before_action :ensure_terms_accepted!, if: :app_subdomain? diff --git a/app/controllers/concerns/onboarding_tracking.rb b/app/controllers/concerns/onboarding_tracking.rb new file mode 100644 index 00000000..6d305401 --- /dev/null +++ b/app/controllers/concerns/onboarding_tracking.rb @@ -0,0 +1,12 @@ +module OnboardingTracking + private + + def mark_onboarding_step(step_key) + return unless current_user + + progress = current_user.user_onboarding_progress || current_user.create_user_onboarding_progress! + progress.complete_step!(step_key) + rescue StandardError => e + Rails.logger.warn("[OnboardingTracking] Failed to complete step '#{step_key}' for user #{current_user&.id}: #{e.class} - #{e.message}") + end +end