Skip to content
Open
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
51 changes: 51 additions & 0 deletions app/assets/stylesheets/pages/_project_setup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,57 @@
&__submit {
margin-top: 0.75rem;
}

&__funding {
border: none;
margin: 0.5rem 0 0;
padding: 0;
width: 100%;
}

&__funding-legend {
color: var(--color-brand-off-white);
font-family: var(--font-family-text);
font-size: 1.1rem;
font-weight: 700;
margin-bottom: 0.75rem;
}

&__funding-options {
display: flex;
flex-direction: column;
gap: 0.6rem;
}

&__funding-option {
align-items: center;
background: rgba(8, 6, 31, 0.75);
border: 2px solid var(--color-space-border);
border-radius: 0.5rem;
cursor: pointer;
display: flex;
gap: 0.75rem;
padding: 0.75rem 1rem;
transition: border-color 180ms ease;

&:hover,
&:has(:checked) {
border-color: var(--color-brand-lilac);
}
}

&__funding-radio {
accent-color: var(--color-brand-lilac);
flex-shrink: 0;
height: 1.1rem;
width: 1.1rem;
}

&__funding-label {
color: var(--color-brand-off-white);
font-family: var(--font-family-text);
font-size: 1rem;
}
}

// Missions step — grid of mission cards + escape hatch.
Expand Down
11 changes: 7 additions & 4 deletions app/components/projects/setup/progress_bar_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class ProgressBarComponent < ViewComponent::Base

# Per-action mapping into the visible 3-phase progress.
ACTION_TO_STEP = {
idea: :idea,
name: :details,
missions: :details,
link: :link
idea: :idea,
project_type: :idea,
name: :details,
missions: :details,
link: :link
}.freeze

attr_reader :action
Expand Down Expand Up @@ -46,6 +47,8 @@ def back_path
case action
when :idea, :link
append_back_param(helpers.back_path)
when :project_type
helpers.projects_setup_path(back: 1)
when :name, :missions
helpers.projects_setup_path(back: 1)
end
Expand Down
28 changes: 26 additions & 2 deletions app/controllers/projects/setup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def submit_idea
case params[:idea].to_s
when "yes"
track_event "project_setup_started", { has_idea: true }
redirect_to projects_setup_name_path
redirect_to projects_setup_project_type_path
when "no"
track_event "project_setup_started", { has_idea: false }
redirect_to projects_setup_missions_path
Expand All @@ -34,8 +34,28 @@ def submit_idea
end
end

def project_type
authorize :project_setup
end

def submit_project_type
authorize :project_setup

case params[:project_type].to_s
when "software"
session[:setup_is_hardware] = false
redirect_to projects_setup_name_path
when "hardware"
session[:setup_is_hardware] = true
redirect_to projects_setup_name_path
else
redirect_to projects_setup_project_type_path, alert: "Please pick one."
end
end

def name
authorize :project_setup
@is_hardware = session[:setup_is_hardware] == true
end

MAX_TITLE_LENGTH = 120
Expand All @@ -58,7 +78,11 @@ def submit_name
end

project = find_or_create_setup_project!
project.update!(title: title, description: description.presence)
is_hardware = session.delete(:setup_is_hardware)
hardware_stage = if is_hardware
params[:needs_funding].to_s == "no" ? "build" : "design"
end
project.update!(title: title, description: description.presence, hardware_stage: hardware_stage)
redirect_to next_gate_after_details_path
end

Expand Down
2 changes: 2 additions & 0 deletions app/policies/project_setup_policy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ProjectSetupPolicy < ApplicationPolicy
def idea? = signed_in_any?
def submit_idea? = signed_in_any?
def project_type? = signed_in_any?
def submit_project_type? = signed_in_any?
def name? = signed_in_any?
def submit_name? = signed_in_any?
def missions? = signed_in_any?
Expand Down
16 changes: 16 additions & 0 deletions app/views/projects/setup/name.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
maxlength: Projects::SetupController::MAX_DESCRIPTION_LENGTH,
class: "project-setup-name__textarea" %>

<% if @is_hardware %>
<fieldset class="project-setup-name__funding">
<legend class="project-setup-name__funding-legend">Do you need funding to buy parts?</legend>
<div class="project-setup-name__funding-options">
<label class="project-setup-name__funding-option">
<%= radio_button_tag :needs_funding, "yes", true, class: "project-setup-name__funding-radio" %>
<span class="project-setup-name__funding-label">Yes — I need funding for parts</span>
</label>
<label class="project-setup-name__funding-option">
<%= radio_button_tag :needs_funding, "no", false, class: "project-setup-name__funding-radio" %>
<span class="project-setup-name__funding-label">No — I already have what I need</span>
</label>
</div>
</fieldset>
<% end %>

<%= render SpecialActionButtonComponent.new(
text: "Continue",
type: :submit,
Expand Down
22 changes: 22 additions & 0 deletions app/views/projects/setup/project_type.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<% content_for :title, "What type of project?" %>
<main class="onboarding-screen onboarding-screen--project-type project-setup-screen"
data-controller="onboarding-transition">
<%= render Projects::Setup::ProgressBarComponent.new(action: :project_type) %>

<div class="onboarding-screen__content">
<p class="onboarding-screen__eyebrow">tell us more ✦</p>
<h1 class="onboarding-screen__title">Is it a software project<br>or a hardware project?</h1>

<%= form_with url: projects_setup_submit_project_type_path, method: :post,
class: "project-setup-idea__form" do %>
<div class="project-setup-idea__cards">
<%= render Onboarding::ChoiceCardComponent.new(name: "project_type", value: "software", variant: :pair) do %>
Software — an app, website, game, or bot.
<% end %>
<%= render Onboarding::ChoiceCardComponent.new(name: "project_type", value: "hardware", variant: :pair) do %>
Hardware — something I build physically.
<% end %>
</div>
<% end %>
</div>
</main>
4 changes: 2 additions & 2 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
</header>
<% end %>
<% unless @hackatime_linked %>
<form id="hackatime-connect-form" method="post" action="/auth/hackatime" hidden>
<form id="hackatime-connect-form" method="post" action="/auth/hackatime<%= "?skip_setup_flow" if @project.hardware? %>" hidden>
<input type="hidden" name="origin" value="<%= request.fullpath %>">
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>">
</form>
Expand Down Expand Up @@ -655,7 +655,7 @@
project: @project,
disabled_message: "Link your Hackatime account to start recording" %>
<% end %>
<%= button_to "/auth/hackatime",
<%= button_to "/auth/hackatime#{"?skip_setup_flow" if @project.hardware?}",
method: :post,
params: { origin: request.fullpath },
class: "action-btn action-btn--large action-btn--primary project-show__hackatime-cta",
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def callback_url
{
name: :hackatime,
scope: "profile read",
setup: lambda { |env|
request = Rack::Request.new(env)
if request.params.key?("skip_setup_flow")
env["omniauth.strategy"].options[:authorize_params] ||= {}
env["omniauth.strategy"].options[:authorize_params][:skip_setup_flow] = request.params["skip_setup_flow"]
end
},
client_options: {
site: "https://hackatime.hackclub.com",
authorize_url: "/oauth/authorize",
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,8 @@
namespace :projects do
get "setup", to: "setup#idea", as: :setup
post "setup/idea", to: "setup#submit_idea", as: :setup_submit_idea
get "setup/project_type", to: "setup#project_type", as: :setup_project_type
post "setup/project_type", to: "setup#submit_project_type", as: :setup_submit_project_type
get "setup/name", to: "setup#name", as: :setup_name
post "setup/name", to: "setup#submit_name", as: :setup_submit_name
get "setup/missions", to: "setup#missions", as: :setup_missions
Expand Down