Skip to content

Commit 71f95a5

Browse files
committed
feat: add contract type to bounties and update related forms and schemas
1 parent 41162de commit 71f95a5

File tree

6 files changed

+68
-17
lines changed

6 files changed

+68
-17
lines changed

lib/algora/bounties/bounties.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ defmodule Algora.Bounties do
5353
visibility: Bounty.visibility(),
5454
shared_with: [String.t()],
5555
hours_per_week: integer() | nil,
56-
hourly_rate: Money.t() | nil
56+
hourly_rate: Money.t() | nil,
57+
contract_type: Bounty.contract_type() | nil
5758
}) ::
5859
{:ok, Bounty.t()} | {:error, atom()}
5960
defp do_create_bounty(%{creator: creator, owner: owner, amount: amount, ticket: ticket} = params) do
@@ -66,7 +67,8 @@ defmodule Algora.Bounties do
6667
visibility: params[:visibility] || owner.bounty_mode,
6768
shared_with: params[:shared_with] || [],
6869
hours_per_week: params[:hours_per_week],
69-
hourly_rate: params[:hourly_rate]
70+
hourly_rate: params[:hourly_rate],
71+
contract_type: params[:contract_type]
7072
})
7173

7274
changeset
@@ -115,7 +117,8 @@ defmodule Algora.Bounties do
115117
visibility: Bounty.visibility() | nil,
116118
shared_with: [String.t()] | nil,
117119
hourly_rate: Money.t() | nil,
118-
hours_per_week: integer() | nil
120+
hours_per_week: integer() | nil,
121+
contract_type: Bounty.contract_type() | nil
119122
]
120123
) ::
121124
{:ok, Bounty.t()} | {:error, atom()}
@@ -148,7 +151,8 @@ defmodule Algora.Bounties do
148151
visibility: opts[:visibility],
149152
shared_with: shared_with,
150153
hourly_rate: opts[:hourly_rate],
151-
hours_per_week: opts[:hours_per_week]
154+
hours_per_week: opts[:hours_per_week],
155+
contract_type: opts[:contract_type]
152156
})
153157

154158
:set ->
@@ -200,7 +204,8 @@ defmodule Algora.Bounties do
200204
visibility: Bounty.visibility() | nil,
201205
shared_with: [String.t()] | nil,
202206
hours_per_week: integer() | nil,
203-
hourly_rate: Money.t() | nil
207+
hourly_rate: Money.t() | nil,
208+
contract_type: Bounty.contract_type() | nil
204209
]
205210
) ::
206211
{:ok, Bounty.t()} | {:error, atom()}
@@ -221,7 +226,8 @@ defmodule Algora.Bounties do
221226
visibility: opts[:visibility],
222227
shared_with: shared_with,
223228
hours_per_week: opts[:hours_per_week],
224-
hourly_rate: opts[:hourly_rate]
229+
hourly_rate: opts[:hourly_rate],
230+
contract_type: opts[:contract_type]
225231
}),
226232
{:ok, _job} <- notify_bounty(%{owner: owner, bounty: bounty}) do
227233
broadcast()

lib/algora/bounties/schemas/bounty.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ defmodule Algora.Bounties.Bounty do
77
alias Algora.Types.Money
88

99
@type visibility :: :community | :exclusive | :public
10+
@type contract_type :: :bring_your_own | :marketplace
1011

1112
typed_schema "bounties" do
1213
field :amount, Money
1314
field :status, Ecto.Enum, values: [:open, :cancelled, :paid]
1415
field :number, :integer, default: 0
1516
field :autopay_disabled, :boolean, default: false
1617
field :visibility, Ecto.Enum, values: [:community, :exclusive, :public], null: false, default: :community
18+
field :contract_type, Ecto.Enum, values: [:bring_your_own, :marketplace]
1719
field :shared_with, {:array, :string}, null: false, default: []
1820
field :deadline, :utc_datetime_usec
1921
field :hours_per_week, :integer
@@ -36,7 +38,17 @@ defmodule Algora.Bounties.Bounty do
3638

3739
def changeset(bounty, attrs) do
3840
bounty
39-
|> cast(attrs, [:amount, :ticket_id, :owner_id, :creator_id, :visibility, :shared_with, :hours_per_week, :hourly_rate])
41+
|> cast(attrs, [
42+
:amount,
43+
:ticket_id,
44+
:owner_id,
45+
:creator_id,
46+
:visibility,
47+
:shared_with,
48+
:hours_per_week,
49+
:hourly_rate,
50+
:contract_type
51+
])
4052
|> validate_required([:amount, :ticket_id, :owner_id, :creator_id])
4153
|> generate_id()
4254
|> foreign_key_constraint(:ticket)

lib/algora_web/forms/contract_form.ex

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule AlgoraWeb.Forms.ContractForm do
1313
field :amount, USD
1414
field :hourly_rate, USD
1515
field :hours_per_week, :integer
16-
field :marketplace?, :boolean, default: false
16+
field :contract_type, Ecto.Enum, values: [:bring_your_own, :marketplace], default: :bring_your_own
1717
field :type, Ecto.Enum, values: [:fixed, :hourly], default: :fixed
1818
field :title, :string
1919
field :description, :string
@@ -28,7 +28,16 @@ defmodule AlgoraWeb.Forms.ContractForm do
2828

2929
def changeset(form, attrs) do
3030
form
31-
|> cast(attrs, [:amount, :hourly_rate, :hours_per_week, :type, :title, :description, :contractor_handle])
31+
|> cast(attrs, [
32+
:amount,
33+
:hourly_rate,
34+
:hours_per_week,
35+
:type,
36+
:title,
37+
:description,
38+
:contractor_handle,
39+
:contract_type
40+
])
3241
|> validate_required([:contractor_handle])
3342
|> validate_type_fields()
3443
|> Validations.validate_github_handle(:contractor_handle, :contractor)
@@ -57,7 +66,9 @@ defmodule AlgoraWeb.Forms.ContractForm do
5766
phx-change="validate_contract_main"
5867
>
5968
<div class="space-y-4">
60-
<%= if get_field(@form.source, :marketplace?) do %>
69+
<.input type="hidden" field={@form[:contract_type]} />
70+
71+
<%= if get_field(@form.source, :contract_type) == :marketplace do %>
6172
<%= if contractor = get_field(@form.source, :contractor) do %>
6273
<.card>
6374
<.card_content>
@@ -129,7 +140,7 @@ defmodule AlgoraWeb.Forms.ContractForm do
129140
<.input label="Title" field={@form[:title]} />
130141
<.input label="Description (optional)" field={@form[:description]} type="textarea" />
131142
132-
<%= if not get_field(@form.source, :marketplace?) do %>
143+
<%= if get_field(@form.source, :contract_type) == :bring_your_own do %>
133144
<div>
134145
<label class="block text-sm font-semibold leading-6 text-foreground mb-2">
135146
Payment
@@ -191,7 +202,7 @@ defmodule AlgoraWeb.Forms.ContractForm do
191202
</div>
192203
<% end %>
193204
194-
<%= if get_field(@form.source, :marketplace?) do %>
205+
<%= if get_field(@form.source, :contract_type) == :marketplace do %>
195206
<.input type="hidden" field={@form[:amount]} />
196207
<.input type="hidden" field={@form[:hourly_rate]} />
197208
<.input type="hidden" field={@form[:hours_per_week]} />

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ defmodule AlgoraWeb.Org.DashboardLive do
333333
<.developer_card
334334
user={user}
335335
contract_for_user={contract_for_user(@contracts, user)}
336+
contract_type={
337+
if(Enum.find(@matches, &(&1.user.id == user.id)),
338+
do: "marketplace",
339+
else: "bring_your_own"
340+
)
341+
}
336342
current_org={@current_org}
337343
/>
338344
<% end %>
@@ -410,6 +416,12 @@ defmodule AlgoraWeb.Org.DashboardLive do
410416
<.developer_card
411417
user={user}
412418
contract_for_user={contract_for_user(@contracts, user)}
419+
contract_type={
420+
if(Enum.find(@matches, &(&1.user.id == user.id)),
421+
do: "marketplace",
422+
else: "bring_your_own"
423+
)
424+
}
413425
current_org={@current_org}
414426
/>
415427
<% end %>
@@ -658,7 +670,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
658670
@impl true
659671
def handle_event(
660672
"share_opportunity",
661-
%{"user_id" => user_id, "type" => "contract", "marketplace" => marketplace?},
673+
%{"user_id" => user_id, "type" => "contract", "contract_type" => contract_type},
662674
socket
663675
) do
664676
developer = Enum.find(socket.assigns.developers, &(&1.id == user_id))
@@ -673,7 +685,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
673685
|> assign(
674686
:main_contract_form,
675687
%ContractForm{
676-
marketplace?: marketplace? == "true",
688+
contract_type: String.to_existing_atom(contract_type),
677689
contractor: match[:user] || developer
678690
}
679691
|> ContractForm.changeset(%{
@@ -1287,7 +1299,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
12871299
phx-click="share_opportunity"
12881300
phx-value-user_id={@user.id}
12891301
phx-value-type="contract"
1290-
phx-value-marketplace="false"
1302+
phx-value-contract_type={@contract_type}
12911303
variant="none"
12921304
class="group bg-emerald-900/10 text-emerald-300 transition-colors duration-75 hover:bg-emerald-800/10 hover:text-emerald-300 hover:drop-shadow-[0_1px_5px_#34d39980] focus:bg-emerald-800/10 focus:text-emerald-300 focus:outline-none focus:drop-shadow-[0_1px_5px_#34d39980] border border-emerald-400/40 hover:border-emerald-400/50 focus:border-emerald-400/50"
12931305
>
@@ -1457,7 +1469,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
14571469
phx-click="share_opportunity"
14581470
phx-value-user_id={@match.user.id}
14591471
phx-value-type="contract"
1460-
phx-value-marketplace="true"
1472+
phx-value-contract_type="marketplace"
14611473
variant="none"
14621474
class="group bg-emerald-900/10 text-emerald-300 transition-colors duration-75 hover:bg-emerald-800/10 hover:text-emerald-300 hover:drop-shadow-[0_1px_5px_#34d39980] focus:bg-emerald-800/10 focus:text-emerald-300 focus:outline-none focus:drop-shadow-[0_1px_5px_#34d39980] border border-emerald-400/40 hover:border-emerald-400/50 focus:border-emerald-400/50 h-full py-4"
14631475
size="xl"

lib/algora_web/live/org/nav.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ defmodule AlgoraWeb.Org.Nav do
141141
hourly_rate: data.hourly_rate,
142142
hours_per_week: data.hours_per_week,
143143
shared_with: [data.contractor.provider_id],
144-
visibility: :exclusive
144+
visibility: :exclusive,
145+
contract_type: data.contract_type
145146
)
146147

147148
case bounty_res do
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddContractTypeToBounties do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:bounties) do
6+
add :contract_type, :string
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)