Verified Production Fix
[gitlab-org/gitlab] Refactor billings page view logic to use ViewComponent for namespace state rendering
GL-gitlab-org/gitlab#592638 • Mar 07, 2026
### ROOT CAUSE
The billings page uses inline conditional logic to determine the view, and the controller duplicates this logic in a helper method. This duplication complicates maintenance and introduces tech debt as new namespace states are added.
### CODE FIX
1. **Create a ViewComponent to encapsulate rendering logic**:
- Create a new component `NamespaceBillingComponent` under `app/components/groups/billing/`.
- Use this component to centralize the conditional rendering logic.
2. **Refactor the Controller**:
- Remove the `free_or_trial_namespace?` helper method as the component now handles the state check.
3. **Update the View**:
- Replace the inline conditionals with the ViewComponent.
**New Code:**
haml
# app/components/groups/billing/namespace_bills_component.rb
class NamespaceBillsComponent < ViewComponent::Base
def call
if @group.paid? && !@group.trial?
# Render paid plan UI
else
# Render free/trial UI
end
end
end
**Controller Update**:
ruby
# controllers/groups/bills_controller.rb
def index
@namespace_bills = NamespaceBillsComponent.new(group: @group, plans_data: @plans_data)
end
**View Update**:
haml
# app/views/groups/bills/index.html.haml
= NamespaceBillsComponent.new(group: @group, plans_data: @plans_data)
This refactoring centralizes the rendering logic, reduces duplication, and improves maintainability.
Deploy with DigitalOcean
Use this fix in production instantly. Claim your $200 developer credit.
Get Started →
digital