Files
nairobi/app/components/shared/date_of_birth_field_component.rb
Javi Martín 6af8ddd324 Extract component to render the date of birth
We reduce code duplication thanks to that, and make it easier
to change this field.

Note that there was one place where the "16.years" value was
hardcoded. We're moving the test for this case to the
component and changing it so the test doesn't use the default
age.

We're also removing the redundant helper method that had the
same code as a method in the User class which is called
everywhere else.
2024-11-12 15:15:34 +01:00

27 lines
478 B
Ruby

class Shared::DateOfBirthFieldComponent < ApplicationComponent
attr_reader :form, :options
def initialize(form, **options)
@form = form
@options = options
end
private
def default_options
{
prompt: true,
start_year: 1900,
end_year: minimum_required_age.years.ago.year
}
end
def field_options
default_options.merge(options)
end
def minimum_required_age
User.minimum_required_age
end
end