Sha256: 2076ac5944a3e0445f71ec0f9687fe06abd66741c4df188443cb620c0d2666f4

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

# frozen_string_literal: true

module Account
  class ProfileForm < ApplicationForm
    attribute :first_name,   String
    attribute :last_name,    String
    attribute :company_name, String
    attribute :time_zone,    String
    attribute :country_code, String

    validates :first_name, presence: true, length: { maximum: 130 }
    validates :last_name, presence: true, length: { maximum: 130 }
    validates :company_name, length: { maximum: 300 }, allow_blank: true
    validates :time_zone, length: { maximum: 100 }, allow_blank: true
    validate :valid_time_zone?

    def submit
      return false unless valid?

      api_answer = TranslationCms::Api::Customer.update_profile(customer: attributes)
      merge_responce! api_answer
      errors.empty?
    end

    protected

    def valid_time_zone?
      return if ActiveSupport::TimeZone[time_zone].present?

      errors.add :time_zone, :invalid
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translation_cms-0.1.5 app/forms/account/profile_form.rb