Skip to content

Commit

Permalink
WIP self reg form
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWalkingLeek committed Jan 24, 2025
1 parent d8afaf7 commit 56d0eaa
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/models/jubla/wizards/register_new_user_wizard.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

module Jubla::Wizards::RegisterNewUserWizard
extend ActiveSupport::Concern
PHONE_NUMBER_LABEL = "Privat"

prepended do
# attribute :address_care_of, :string
# attribute :street, :string
# attribute :housenumber, :string

# attribute :postbox, :string
# attribute :zip_code, :string
# attribute :town, :string
# attribute :country, :string

# attribute :phone_number, :string
# attribute :email, :string

# validates :email, presence: true

end

delegate :person_attributes, to: :new_user_form

end
53 changes: 53 additions & 0 deletions app/models/jubla/wizards/steps/new_user_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

module Jubla::Wizards::Steps::NewUserForm
extend ActiveSupport::Concern
PHONE_NUMBER_LABEL = "Privat"

prepended do
attribute :address_care_of, :string
attribute :street, :string
attribute :housenumber, :string

attribute :postbox, :string
attribute :zip_code, :string
attribute :town, :string
attribute :country, :string

attribute :phone_number, :string
attribute :email, :string

validates :email, presence: true

end

def initialize(...)
super

if current_user
self.id = current_user.id
self.gender ||= current_user.gender
self.first_name ||= current_user.first_name
self.last_name ||= current_user.last_name
self.birthday ||= current_user.birthday
self.email ||= current_user.email
self.address_care_of ||= current_user.address_care_of
self.street ||= current_user.street
self.housenumber ||= current_user.housenumber
self.postbox ||= current_user.postbox
self.zip_code ||= current_user.zip_code
self.town ||= current_user.town
self.country ||= current_user.country
self.phone_number ||= current_user.phone_numbers.find_by(label: PHONE_NUMBER_LABEL)&.number
else
self.country ||= Settings.addresses.imported_countries.to_a.first
end
end

def person_attributes
attributes.compact.symbolize_keys.except(:phone_number).then do |attrs|
next attrs if phone_number.blank?

attrs.merge(phone_numbers_attributes: [{label: PHONE_NUMBER_LABEL, number: phone_number, id: phone_number_id}.compact])
end
end
end
18 changes: 18 additions & 0 deletions app/views/wizards/steps/_new_user_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-# Copyright (c) 2025, Jungwacht Blauring Schweiz. This file is part of
-# hitobito_sac_cas and licensed under the Aformero General Public License version 3
-# or later. See the COPYING file at the top-level directory or at
-# https://github.com/hitobito/hitobito_sac_cas.
= c.fields_for do |ff|
= ff.labeled_input_fields :first_name, :last_name
- if f.object.new_user_form.support_company?
= ff.labeled_input_fields :company_name
= ff.labeled_boolean_field :company
= render 'contactable/address_fields', f: ff
= ff.labeled_input_field :phone_number
= ff.labeled_input_field :email, help_inline: t('people.email_field.used_as_login'), class: 'd-inline'

- if f.object.steps.one?
= render 'groups/self_registration/adult_consent_field', f: ff
= field_set_tag(nil, class: 'privacy-policy-fields') do
= render('people/privacy_policy_acceptance_field', f: ff, policy_finder: f.object.policy_finder)
6 changes: 6 additions & 0 deletions lib/hitobito_jubla/wagon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Wagon < Rails::Engine
Event::RegisterController.include Jubla::Event::RegisterController
Event::ParticipationsController.prepend Jubla::Event::ParticipationsController


### decorators
Event::ParticipationDecorator.include Jubla::Event::ParticipationDecorator

Expand All @@ -114,6 +115,11 @@ class Wagon < Rails::Engine
### helpers
EventParticipationsHelper.prepend Jubla::EventParticipationsHelper

### wizards
Wizards::RegisterNewUserWizard.prepend Jubla::Wizards::RegisterNewUserWizard
Wizards::Steps::NewUserForm.prepend Jubla::Wizards::Steps::NewUserForm
Wizards::Steps::NewUserForm.support_company = false

# add more active_for urls to main navigation
admin = NavigationHelper::MAIN.find { |opts| opts[:label] == :admin }
admin[:active_for] << "event_camp_kinds"
Expand Down

0 comments on commit 56d0eaa

Please sign in to comment.