Skip to content

Commit 0350713

Browse files
Rework hacker dashboard (#15)
* rework create profile * add new profile fields * rework health and safety * fix header
1 parent 7d548c3 commit 0350713

File tree

17 files changed

+378
-7
lines changed

17 files changed

+378
-7
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ gem "litestream", "~> 0.14.0"
107107
gem "aws-sdk-s3", "~> 1.199", require: false
108108

109109
gem "postmark-rails", "~> 0.22.1"
110+
111+
gem "phonelib", "~> 0.10.12"

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ GEM
378378
phlexi-display
379379
phlexi-field (~> 0.2.0)
380380
zeitwerk
381+
phonelib (0.10.12)
381382
plutonium (0.26.10)
382383
action_policy (~> 0.7.0)
383384
listen (~> 3.8)
@@ -668,6 +669,7 @@ DEPENDENCIES
668669
omniauth-github (~> 2.0)
669670
omniauth-google-oauth2 (~> 1.2)
670671
pg (~> 1.6)
672+
phonelib (~> 0.10.12)
671673
plutonium
672674
postmark-rails (~> 0.22.1)
673675
propshaft

app/definitions/profile_definition.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class ProfileDefinition < ::ResourceDefinition
55
edit_page_title "Edit Your Profile"
66
index_page_title "Team Members"
77

8+
input :skillsets, as: :select, multiple: true, choices: Profile::SKILLSETS.invert
9+
810
class Form < Form
911
private
1012

app/models/profile.rb

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# id :integer not null, primary key
66
# name :string not null
7+
# region :string
8+
# skillsets :text
79
# telephone_number :string
810
# created_at :datetime not null
911
# updated_at :datetime not null
@@ -18,10 +20,63 @@
1820
# hacker_id (hacker_id => hackers.id)
1921
#
2022
class Profile < ::ResourceRecord
23+
SKILLSETS = {
24+
"Frontend Developer" => "frontend",
25+
"Backend Developer" => "backend",
26+
"Mobile Engineer" => "mobile",
27+
"Full Stack Developer" => "fullstack",
28+
"UI/UX Designer" => "designer",
29+
"Product Manager" => "product",
30+
"Data Scientist" => "data_science",
31+
"DevOps Engineer" => "devops"
32+
}.freeze
33+
34+
REGIONS = [
35+
"Greater Accra",
36+
"Ashanti",
37+
"Western",
38+
"Western North",
39+
"Eastern",
40+
"Central",
41+
"Volta",
42+
"Oti",
43+
"Northern",
44+
"Savannah",
45+
"North East",
46+
"Upper East",
47+
"Upper West",
48+
"Bono",
49+
"Bono East",
50+
"Ahafo"
51+
].freeze
52+
2153
belongs_to :hacker
2254
has_one :team, through: :hacker
2355
has_one :emergency_contact, through: :hacker
2456

57+
serialize :skillsets, coder: JSON
58+
2559
validates :name, presence: true
26-
validates :telephone_number, presence: true
60+
validates :telephone_number, presence: true, phone: {possible: true, types: :mobile}
61+
validates :skillsets, presence: true
62+
validates :region, presence: true, inclusion: {in: REGIONS}
63+
64+
def telephone_number=(value)
65+
parsed = Phonelib.parse(value)
66+
super(parsed.valid? ? parsed.e164 : value)
67+
end
68+
69+
def skillsets=(value)
70+
value = value.compact_blank if value.is_a?(Array)
71+
super
72+
end
73+
74+
private
75+
76+
def skillsets_must_be_valid
77+
return if skillsets.blank?
78+
79+
invalid = skillsets - SKILLSETS.values
80+
errors.add(:skillsets, "contains invalid values: #{invalid.join(", ")}") if invalid.any?
81+
end
2782
end

app/policies/profile_policy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def read?
1010
# Core attributes
1111

1212
def permitted_attributes_for_create
13-
[:hacker, :name, :telephone_number]
13+
[:hacker, :name, :telephone_number, :region, :skillsets]
1414
end
1515

1616
def permitted_attributes_for_read
17-
%i[hacker name telephone_number]
17+
%i[hacker name telephone_number region skillsets]
1818
end
1919

2020
# Associations
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddSkillsetsAndRegionToProfiles < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :profiles, :skillsets, :text
4+
add_column :profiles, :region, :string
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hackathon/app/models/hackathon/health_and_safety.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ class Hackathon::HealthAndSafety < Hackathon::ResourceRecord
2323
belongs_to :hacker
2424

2525
validates :name, presence: true
26-
validates :phone_number, presence: true
26+
validates :phone_number, presence: true, phone: {possible: true, types: :mobile}
2727
validates :consent, acceptance: true
2828

29+
def phone_number=(value)
30+
parsed = Phonelib.parse(value)
31+
super(parsed.valid? ? parsed.e164 : value)
32+
end
33+
2934
def consented
3035
valid? ? "Accepted" : "Declined"
3136
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module HackerDashboardPortal
2+
class OnboardingLayout < ::Plutonium::UI::Layout::ResourceLayout
3+
include Phlex::Rails::Helpers::LinkTo
4+
include Phlex::Rails::Helpers::ImageTag
5+
6+
private
7+
8+
def main_attributes = mix(super, {
9+
class!: ""
10+
})
11+
12+
def render_before_main
13+
div(class: "flex justify-center pt-8 pb-4") do
14+
link_to main_app.root_path, class: "group" do
15+
image_tag "icon_256.png",
16+
class: "w-16 h-16 transition-transform group-hover:scale-105"
17+
end
18+
end
19+
end
20+
end
21+
end

packages/hacker_dashboard_portal/app/controllers/hacker_dashboard_portal/hackathon/health_and_safeties_controller.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,23 @@ class HackerDashboardPortal::Hackathon::HealthAndSafetiesController < ::Hackatho
33

44
skip_before_action :ensure_emergency_contact_exists, only: [:new, :create]
55
skip_before_action :ensure_joined_team, only: [:new, :create]
6+
7+
layout :resolve_layout
8+
9+
def new
10+
authorize_current! resource_class
11+
12+
unless current_user.emergency_contact.nil?
13+
redirect_to root_path
14+
return
15+
end
16+
17+
super
18+
end
19+
20+
private
21+
22+
def resolve_layout
23+
%w[new create].include?(action_name) ? "onboarding" : "resource"
24+
end
625
end

0 commit comments

Comments
 (0)