diff --git a/lib/admin_command.rb b/lib/admin_command.rb index c408998c8a59300273650f64c7a209ed375dfb30..7d8a47a41bf36cf207301386591d3b2a23185ab5 100644 --- a/lib/admin_command.rb +++ b/lib/admin_command.rb @@ -6,12 +6,15 @@ require_relative "financial_info" require_relative "form_template" class AdminCommand - def initialize(target_customer) + def initialize(target_customer, customer_repo) @target_customer = target_customer + @customer_repo = customer_repo end def start - action_info.then { menu_or_done } + @target_customer.admin_info.then { |info| + reply(info.form) + }.then { menu_or_done } end def reply(form) @@ -40,19 +43,19 @@ class AdminCommand end def new_context(q) - CustomerInfoForm.new.parse_something(q).then do |new_customer| - if new_customer.respond_to?(:customer_id) - AdminCommand.new(new_customer).start - else - reply(new_customer.form) + CustomerInfoForm.new(@customer_repo) + .parse_something(q).then do |new_customer| + if new_customer.respond_to?(:customer_id) + AdminCommand.new(new_customer, @customer_repo).start + else + reply(new_customer.form) + end end - end end def action_info - @target_customer.admin_info.then do |info| - reply(info.form) - end + # Refresh the data + new_context(@target_customer.customer_id) end def action_financial diff --git a/sgx_jmp.rb b/sgx_jmp.rb index be6cbf60462a24ba756f7f997875fc962500dc15..763e025f11ada9a550d34290a4a67a5dc9116471 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -755,16 +755,18 @@ Command.new( Command.customer.then do |customer| raise AuthError, "You are not an admin" unless customer&.admin? + customer_repo = CustomerRepo.new( + sgx_repo: Bwmsgsv2Repo.new, + bandwidth_tn_repo: EmptyRepo.new # No CNAM in admin + ) + Command.reply { |reply| reply.allowed_actions = [:next] reply.command << FormTemplate.render("customer_picker") }.then { |response| - CustomerInfoForm.new(CustomerRepo.new( - sgx_repo: Bwmsgsv2Repo.new, - bandwidth_tn_repo: EmptyRepo.new # No CNAM in admin - )).find_customer(response) + CustomerInfoForm.new(customer_repo).find_customer(response) }.then do |target_customer| - AdminCommand.new(target_customer).start + AdminCommand.new(target_customer, customer_repo).start end end }.register(self).then(&CommandList.method(:register))