Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions app/definitions/profile_definition.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
class ProfileDefinition < ::ResourceDefinition
new_page_title "Complete Your Profile"
show_page_title "Profile"

edit_page_title "Edit Your Profile"
index_page_title "Team Members"

input :skillsets, as: :select, multiple: true, choices: Profile::SKILLSETS.invert

class Form < Form
private

def render_actions
input name: "return_to", value: request.params[:return_to], type: :hidden, hidden: true

actions_wrapper {
render submit_button
}
end
input :skillsets, as: :slim_select, multiple: true, choices: Profile::SKILLSETS.invert
input :sex, choices: Profile::SEXES.invert
display :skillsets, wrapper: {class: "col-span-full"} do |a|
Profile::SKILLSETS.invert.slice(*a.value).values.join ", "
end
end
17 changes: 10 additions & 7 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
// Run that command whenever you add a new controller or create them with
// ./bin/rails generate stimulus controllerName

import { application } from "./application";
import { application } from "./application"

import HelloController from "./hello_controller";
application.register("hello", HelloController);
import { registerControllers } from "@radioactive-labs/plutonium"
registerControllers(application);

import MobileMenuController from "./mobile_menu_controller";
application.register("mobile-menu", MobileMenuController);
import HelloController from "./hello_controller"
application.register("hello", HelloController)

import { registerControllers } from "@radioactive-labs/plutonium";
registerControllers(application);
import MobileMenuController from "./mobile_menu_controller"
application.register("mobile-menu", MobileMenuController)

import ModalController from "./modal_controller"
application.register("modal", ModalController)
17 changes: 17 additions & 0 deletions app/javascript/controllers/modal_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["modal"]

open() {
this.modalTarget.classList.remove("hidden")
}

close() {
this.modalTarget.classList.add("hidden")
}

stopPropagation(event) {
event.stopPropagation()
}
}
15 changes: 15 additions & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# id :integer not null, primary key
# name :string not null
# region :string
# sex :string
# skillsets :text
# telephone_number :string
# created_at :datetime not null
Expand Down Expand Up @@ -50,6 +51,11 @@ class Profile < ::ResourceRecord
"Ahafo"
].freeze

SEXES = {
"Male" => "male",
"Female" => "female"
}.freeze

belongs_to :hacker
has_one :team, through: :hacker
has_one :emergency_contact, through: :hacker
Expand All @@ -60,6 +66,7 @@ class Profile < ::ResourceRecord
validates :telephone_number, presence: true, phone: {possible: true, types: :mobile}
validates :skillsets, presence: true
validates :region, presence: true, inclusion: {in: REGIONS}
validates :sex, presence: true, inclusion: {in: SEXES.values}, allow_blank: true

def telephone_number=(value)
parsed = Phonelib.parse(value)
Expand All @@ -71,6 +78,14 @@ def skillsets=(value)
super
end

def completed?
name.present? &&
telephone_number.present? &&
region.present? &&
sex.present? &&
skillsets.present?
end

private

def skillsets_must_be_valid
Expand Down
4 changes: 2 additions & 2 deletions app/policies/profile_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def read?
# Core attributes

def permitted_attributes_for_create
[:hacker, :name, :telephone_number, :region, :skillsets]
[:hacker, :name, :telephone_number, :sex, :region, :skillsets]
end

def permitted_attributes_for_read
%i[hacker name telephone_number region skillsets]
%i[hacker name telephone_number sex region skillsets]
end

# Associations
Expand Down
15 changes: 14 additions & 1 deletion app/views/homepage/about.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@
<div>
<h3 class="text-lg font-semibold text-gray-900">Team Requirements</h3>
<p class="mt-2 text-gray-600">2-4 members per team</p>
<p class="text-sm text-gray-500">Diverse backgrounds encouraged</p>
<div class="mt-2 space-y-1">
<p class="text-sm text-gray-700 flex items-center">
<svg class="w-4 h-4 text-primary-600 mr-1.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
At least 1 member from outside Greater Accra
</p>
<p class="text-sm text-gray-700 flex items-center">
<svg class="w-4 h-4 text-primary-600 mr-1.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
At least 1 female member
</p>
</div>
</div>
</div>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20251010183403_add_sex_to_profiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSexToProfiles < ActiveRecord::Migration[8.0]
def change
add_column :profiles, :sex, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
Qualified Teams
</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
Qualified teams are teams with a minimum of <%= Hackathon::Team::MINIMUM_TEAM_MEMBERSHIPS %> registered members.
Qualified teams have <%= Hackathon::Team::MINIMUM_TEAM_MEMBERSHIPS %>+ members, with at least 1 from outside Greater Accra and 1 female member.
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
class Hackathon::HealthAndSafetyDefinition < Hackathon::ResourceDefinition
show_page_description "This person will be contacted in case of an emergency"

class Form < Form
private

def render_actions
input name: "return_to", value: request.params[:return_to], type: :hidden, hidden: true

actions_wrapper {
render submit_button
}
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Hackathon::TeamDefinition < Hackathon::ResourceDefinition
display :status, formatter: ->(value) { value.titleize }

field :status, description: "#{Hackathon::Team::MINIMUM_TEAM_MEMBERSHIPS} members are required to qualify"
field :status, description: "Qualified teams have #{Hackathon::Team::MINIMUM_TEAM_MEMBERSHIPS}+ members, with at least 1 from outside Greater Accra and 1 female member"

scope :qualified do |scope|
scope.qualified
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Hackathon::TeamMembershipDefinition < Hackathon::ResourceDefinition
field :role, choices: Hackathon::TeamMembership.roles.keys.to_h { |role|
[role.to_sym, role.titleize]
}, hint: "Your role on the team"
}, hint: "Role on the team"
display :role, as: :string, formatter: ->(value) { value.titleize }
end
21 changes: 19 additions & 2 deletions packages/hackathon/app/models/hackathon/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,29 @@ def has_minimum_memberships?
team_memberships.count >= MINIMUM_TEAM_MEMBERSHIPS
end

def has_member_from_outside_accra?
hackers.joins(:profile).where.not("LOWER(profiles.region) = ?", "greater accra").exists?
end

def has_female_member?
hackers.joins(:profile).where(profiles: {sex: "female"}).exists?
end

def meets_qualification_requirements?
has_minimum_memberships? &&
has_member_from_outside_accra? &&
has_female_member?
end

# Runs the qualification checks for the team and sends an email to the team
# if they are qualified.
#
# A team is qualified if they have at least {MINIMUM_TEAM_MEMBERSHIPS} members.
# A team is qualified if they have:
# - at least {MINIMUM_TEAM_MEMBERSHIPS} members
# - at least 1 member from outside Greater Accra
# - at least 1 female member
def run_qualification_checks
return unless unqualified? && has_minimum_memberships?
return unless unqualified? && meets_qualification_requirements?

if limit_reached?
late_qualify!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module Controller
# add concerns above.

included do
before_action :ensure_profile_complete
before_action :ensure_profile_created
before_action :ensure_profile_completed
before_action :ensure_emergency_contact_exists
before_action :ensure_joined_team
end
Expand All @@ -16,18 +17,24 @@ module Controller

def app_name = "UNICEF StartUp Lab Hack"

def ensure_profile_complete
def ensure_profile_created
if current_user.profile.nil?
redirect_to(resource_url_for(Profile, action: :new))
end
end

def ensure_joined_team
if current_user.team.nil?
redirect_to(resource_url_for(::Hackathon::Team, action: :new))
def ensure_profile_completed
if current_user.profile.present? && !current_user.profile.completed?
redirect_to(resource_url_for(current_user.profile, action: :edit))
end
end

def ensure_joined_team
# if current_user.team.nil?
# redirect_to(resource_url_for(::Hackathon::Team, action: :new))
# end
end

def ensure_emergency_contact_exists
if current_user.emergency_contact.nil?
redirect_to resource_url_for(::Hackathon::HealthAndSafety, action: :new)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
module HackerDashboardPortal
class DashboardController < PlutoniumController
def index
redirect_to resource_url_for(current_user.team) if current_user.team
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ def new
def resolve_layout
%w[new create].include?(action_name) ? "onboarding" : "resource"
end

def redirect_url_after_submit
if (return_to = url_from(params[:return_to]))
return return_to
end

if action_name == "create"
root_path
else
super
end
end
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class HackerDashboardPortal::ProfilesController < ::ProfilesController
include HackerDashboardPortal::Concerns::Controller

skip_before_action :ensure_profile_complete, only: [:new, :create]
skip_before_action :ensure_profile_created, only: [:new, :create]
skip_before_action :ensure_profile_completed, only: [:edit, :update]
skip_before_action :ensure_emergency_contact_exists, only: [:new, :create]
skip_before_action :ensure_joined_team, only: [:new, :create]

layout :resolve_layout

def new
authorize_current! resource_class

Expand All @@ -17,10 +16,4 @@ def new

super
end

private

def resolve_layout
%w[new create].include?(action_name) ? "onboarding" : "resource"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,33 @@ class HackerDashboardPortal::Hackathon::HealthAndSafetyDefinition < ::Hackathon:
By providing this information, you confirm that you are in good health
and consent to this person being contacted in case of an emergency.
DESC

show_page_description "This person will be contacted in case of an emergency"

class Form < Form
private

def render_actions
input name: "return_to", value: request.params[:return_to], type: :hidden, hidden: true

actions_wrapper {
render submit_button
}
end
end

class ShowPage < ShowPage
include Phlex::Rails::Helpers::LinkTo

def render_breadcrumbs
nav(class: "flex py-3 text-gray-700 mb-2") do
link_to helpers.root_path, class: "inline-flex items-center text-sm font-medium text-gray-700 hover:text-primary-600 dark:text-gray-200 dark:hover:text-white" do
svg(class: "w-4 h-4 me-2", fill: "none", stroke: "currentColor", viewbox: "0 0 24 24") do |s|
s.path(stroke_linecap: "round", stroke_linejoin: "round", stroke_width: "2", d: "M10 19l-7-7m0 0l7-7m-7 7h18")
end
plain "Back to Dashboard"
end
end
end
end
end
Loading