Skip to content

Commit a41def0

Browse files
committed
feat: add categories field to users
1 parent f8b8b06 commit a41def0

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ defmodule Algora.Accounts.User do
3535
field :stargazers_count, :integer, default: 0
3636
field :domain, :string
3737
field :tech_stack, {:array, :string}, default: []
38+
field :categories, {:array, :string}, default: []
3839
field :featured, :boolean, default: false
3940
field :priority, :integer, default: 0
4041
field :fee_pct, :integer, default: 19
@@ -227,8 +228,10 @@ defmodule Algora.Accounts.User do
227228
:handle,
228229
:domain,
229230
:tech_stack,
231+
:categories,
230232
:hourly_rate_min,
231233
:hourly_rate_max,
234+
:hours_per_week,
232235
:last_context
233236
])
234237
|> generate_id()

lib/algora/organizations/schemas/org.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule Algora.Organizations.Org do
1515
:location,
1616
:stargazers_count,
1717
:tech_stack,
18+
:categories,
1819
:featured,
1920
:priority,
2021
:fee_pct,

lib/algora_web/live/onboarding/org.ex

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
127127
field :hourly_rate_max, :integer
128128
field :hours_per_week, :integer
129129
field :hiring, :boolean
130-
field :company_types, {:array, :string}
130+
field :categories, {:array, :string}
131131
end
132132

133133
def hiring_options do
134134
[{"Yes", "true"}, {"No", "false"}]
135135
end
136136

137-
def company_types_options do
137+
def categories_options do
138138
[
139139
{"Open source company", "open_source"},
140140
{"Closed source company", "closed_source"},
@@ -144,7 +144,7 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
144144
end
145145

146146
def init do
147-
to_form(PreferencesForm.changeset(%PreferencesForm{}, %{company_types: []}))
147+
to_form(PreferencesForm.changeset(%PreferencesForm{}, %{categories: []}))
148148
end
149149

150150
def changeset(form, attrs) do
@@ -154,7 +154,7 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
154154
:hourly_rate_max,
155155
:hours_per_week,
156156
:hiring,
157-
:company_types
157+
:categories
158158
])
159159
|> validate_required([:hourly_rate_min], message: "Please enter a minimum hourly rate")
160160
|> validate_required([:hourly_rate_max], message: "Please enter a maximum hourly rate")
@@ -163,14 +163,8 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
163163
|> validate_number(:hourly_rate_min, greater_than: 0)
164164
|> validate_number(:hourly_rate_max, greater_than: 0)
165165
|> validate_number(:hours_per_week, greater_than: 0)
166-
|> validate_length(:company_types,
167-
min: 1,
168-
message: "Please select at least one company type"
169-
)
170-
|> validate_subset(
171-
:company_types,
172-
Enum.map(PreferencesForm.company_types_options(), &elem(&1, 1))
173-
)
166+
|> validate_length(:categories, min: 1, message: "Please select at least one category")
167+
|> validate_subset(:categories, Enum.map(PreferencesForm.categories_options(), &elem(&1, 1)))
174168
|> validate_rate_range()
175169
end
176170

@@ -409,6 +403,7 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
409403
og_title: get_in(metadata, [:org, :og_title]),
410404
og_image_url: get_in(metadata, [:org, :og_image_url]),
411405
tech_stack: tech_stack,
406+
categories: preferences.categories,
412407
hourly_rate_min: Money.new!(preferences.hourly_rate_min, :USD),
413408
hourly_rate_max: Money.new!(preferences.hourly_rate_max, :USD),
414409
hours_per_week: preferences.hours_per_week,
@@ -769,18 +764,18 @@ defmodule AlgoraWeb.Onboarding.OrgLive do
769764
Select all that apply
770765
</p>
771766
<div class="grid grid-cols-2 gap-4">
772-
<%= for {label, value} <- PreferencesForm.company_types_options() do %>
767+
<%= for {label, value} <- PreferencesForm.categories_options() do %>
773768
<label class={[
774769
"group relative flex cursor-pointer rounded-lg px-3 py-2 shadow-sm focus:outline-none",
775770
"border-2 bg-background transition-all duration-200 hover:border-primary hover:bg-primary/10",
776771
"border-border has-[:checked]:border-primary has-[:checked]:bg-primary/10"
777772
]}>
778773
<div class="sr-only">
779774
<.input
780-
field={@preferences_form[:company_types]}
775+
field={@preferences_form[:categories]}
781776
type="checkbox"
782777
value={value}
783-
checked={value in (get_field(@preferences_form.source, :company_types) || [])}
778+
checked={value in (get_field(@preferences_form.source, :categories) || [])}
784779
multiple
785780
/>
786781
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddCompanyTypesToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add :categories, {:array, :string}, default: []
7+
end
8+
end
9+
end

test/algora/organizations_test.exs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ defmodule Algora.OrganizationsTest do
66
user: %{
77
display_name: "Algora",
88
handle: "algora-pZW6",
9-
tech_stack: ["Elixir", "Pheonix"],
9+
tech_stack: ["Elixir", "Phoenix"],
1010
1111
timezone: "America/New_York"
1212
},
1313
organization: %{
1414
display_name: "Algora",
1515
handle: "algora-tkPF",
1616
domain: "algora.io",
17-
tech_stack: ["test"],
17+
tech_stack: ["Elixir", "Phoenix"],
1818
1919
hourly_rate_min: Money.new(:USD, "50"),
2020
hourly_rate_max: Money.new(:USD, "150"),
21-
hours_per_week: 40
21+
hours_per_week: 40,
22+
categories: ["open_source", "agency"]
2223
},
2324
contract: %{
2425
start_date: DateTime.utc_now(),
@@ -39,7 +40,7 @@ defmodule Algora.OrganizationsTest do
3940
display_name: "dev",
4041
last_context: "algora-CEec",
4142
timezone: "America/New_York",
42-
tech_stack: ["Elixir", "Pheonix"]
43+
tech_stack: ["Elixir", "Phoenix"]
4344
},
4445
organization: %{
4546
handle: "algora-CEec",
@@ -51,7 +52,7 @@ defmodule Algora.OrganizationsTest do
5152
5253
display_name: "Algora",
5354
bio: "Algora is a developer tool & community simplifying bounties, hiring & open source sustainability.",
54-
tech_stack: ["Elixir", "Pheonix"],
55+
tech_stack: ["Elixir", "Phoenix"],
5556
hourly_rate_min: Money.new(:USD, "50"),
5657
hourly_rate_max: Money.new(:USD, "150"),
5758
hours_per_week: 40,
@@ -86,6 +87,8 @@ defmodule Algora.OrganizationsTest do
8687
assert org.hourly_rate_min == Money.new(:USD, "50")
8788
assert org.hourly_rate_max == Money.new(:USD, "150")
8889
assert org.display_name == "Algora"
90+
assert org.tech_stack == ["Elixir", "Phoenix"]
91+
assert org.categories == ["open_source", "agency"]
8992
end
9093

9194
test "onboard with crawler" do

0 commit comments

Comments
 (0)