<%= form_with model: @customer, url: step2_submit_agent_portal_customer_onboarding_path, method: :post, local: true do |f| %>
Step 2: Representatives & Documents
<% if show_representative_step? %>
Representative Details
<% if representative_documents_required? %>
Representative documents are mandatory for this customer.
<% else %>
Representative documents are optional for this customer.
<% end %>
<%= f.fields_for :representatives do |r| %>
<%= render "agent_portal/customers/representative_fields", f: r, required_docs: @representative_required_documents %>
<% end %>
<%= f.fields_for :representatives, f.object.representatives.build, child_index: "NEW_RECORD" do |r| %>
<%= render "agent_portal/customers/representative_fields", f: r, required_docs: @representative_required_documents %>
<% end %>
<%= link_to "➕ Add Representative", "#", class: "btn btn-outline-primary btn-sm mt-2", data: { action: "click->representatives#add" } %>
<% end %>
Customer Documents
<% @required_documents.each do |req| %>
- <%= req.description %>
<% end %>
<% mandatory_reqs = @required_documents.select(&:mandatory?) %>
<% if mandatory_reqs.any? %>
The following documents are mandatory for this customer:
<% @customer.documents.each do |doc| %>
<% next unless mandatory_reqs.any? { |r| r.description == doc.title } %>
<%= f.fields_for :documents, doc do |d| %>
<%= render "agent_portal/customers/document_fields",
f: d,
required_docs: @required_documents.map(&:description),
controller_name: "documents" %>
<% end %>
<% end %>
<% end %>
You may also upload additional documents (optional):
<%= f.fields_for :documents, f.object.documents.build, child_index: "NEW_RECORD" do |d| %>
<%= render "agent_portal/customers/document_fields",
f: d,
required_docs: @required_documents,
controller_name: "documents" %>
<% end %>
<%= link_to "➕ Add Document",
"#",
class: "btn btn-outline-primary btn-sm",
data: { action: "click->documents#add" } %>
<%= link_to "← Back", step1_agent_portal_customer_onboarding_path, class: "btn btn-secondary" %>
<%= f.submit "Next →", data: { turbo: false }, class: "btn btn-primary" %>
<% end %>