Skip to content

Commit a475a9f

Browse files
committed
misc
1 parent e3fe8c3 commit a475a9f

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/algora_web/forms/contract_form.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule AlgoraWeb.Forms.ContractForm do
1111

1212
embedded_schema do
1313
field :amount, USD
14+
field :hourly_rate, USD
1415
field :hours_per_week, :integer
1516
field :type, Ecto.Enum, values: [:fixed, :hourly], default: :fixed
1617
field :title, :string
@@ -26,17 +27,23 @@ defmodule AlgoraWeb.Forms.ContractForm do
2627

2728
def changeset(form, attrs) do
2829
form
29-
|> cast(attrs, [:amount, :hours_per_week, :type, :title, :description, :contractor_handle])
30+
|> cast(attrs, [:amount, :hourly_rate, :hours_per_week, :type, :title, :description, :contractor_handle])
3031
|> validate_required([:contractor_handle])
3132
|> validate_type_fields()
32-
|> Validations.validate_money_positive(:amount)
3333
|> Validations.validate_github_handle(:contractor_handle, :contractor)
3434
end
3535

3636
defp validate_type_fields(changeset) do
3737
case get_field(changeset, :type) do
38-
:hourly -> validate_required(changeset, [:amount, :hours_per_week])
39-
_ -> validate_required(changeset, [:amount])
38+
:hourly ->
39+
changeset
40+
|> validate_required([:hourly_rate, :hours_per_week])
41+
|> Validations.validate_money_positive(:hourly_rate)
42+
43+
_ ->
44+
changeset
45+
|> validate_required([:amount])
46+
|> Validations.validate_money_positive(:amount)
4047
end
4148
end
4249

@@ -92,7 +99,7 @@ defmodule AlgoraWeb.Forms.ContractForm do
9299
</div>
93100
<div data-tab="hourly" class="hidden">
94101
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
95-
<.input label="Hourly rate" icon="tabler-currency-dollar" field={@form[:amount]} />
102+
<.input label="Hourly rate" icon="tabler-currency-dollar" field={@form[:hourly_rate]} />
96103
<.input label="Hours per week" field={@form[:hours_per_week]} />
97104
</div>
98105
</div>

lib/algora_web/live/org/nav.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,18 @@ defmodule AlgoraWeb.Org.Nav do
124124

125125
case apply_action(changeset, :save) do
126126
{:ok, data} ->
127+
amount =
128+
case data.type do
129+
:fixed -> data.amount
130+
:hourly -> data.hourly_rate
131+
end
132+
127133
bounty_res =
128134
Bounties.create_bounty(
129135
%{
130136
creator: socket.assigns.current_user,
131137
owner: socket.assigns.current_org,
132-
amount: data.amount,
138+
amount: amount,
133139
title: data.title,
134140
description: data.description
135141
},
@@ -148,6 +154,7 @@ defmodule AlgoraWeb.Org.Nav do
148154
end
149155

150156
{:error, changeset} ->
157+
Logger.error("Failed to create bounty: #{inspect(changeset)}")
151158
{:cont, assign(socket, :main_bounty_form, to_form(changeset))}
152159
end
153160
end

0 commit comments

Comments
 (0)