Skip to content

Commit a20cc51

Browse files
committed
feat: always display hourly rate and hours per week on dev dashboard
1 parent a64a580 commit a20cc51

File tree

1 file changed

+17
-65
lines changed

1 file changed

+17
-65
lines changed

lib/algora_web/live/user/dashboard_live.ex

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ defmodule AlgoraWeb.User.DashboardLive do
7272
|> to_form()
7373

7474
availability_form =
75-
%AvailabilityForm{}
76-
|> AvailabilityForm.changeset(%{
75+
%AvailabilityForm{
7776
hourly_rate_min: socket.assigns.current_user.hourly_rate_min,
7877
hours_per_week: socket.assigns.current_user.hours_per_week
79-
})
78+
}
79+
|> AvailabilityForm.changeset(%{})
8080
|> to_form()
8181

8282
total_earned =
@@ -201,38 +201,12 @@ defmodule AlgoraWeb.User.DashboardLive do
201201
<!-- Sidebar -->
202202
<aside class="lg:fixed lg:top-16 lg:right-0 lg:bottom-0 lg:w-96 lg:overflow-y-auto scrollbar-thin lg:border-l lg:border-border lg:bg-background p-4 pt-6 sm:p-6 md:p-8">
203203
<!-- Availability Section -->
204-
<div class="flex items-center justify-between">
205-
<div class="flex items-center gap-2">
206-
<label for="available" class="text-sm font-medium">Open to contract work</label>
207-
<.tooltip>
208-
<.icon name="tabler-help-circle" class="h-4 w-4 text-muted-foreground" />
209-
<.tooltip_content side="bottom" class="min-w-[300px]">
210-
When enabled, you will receive contract work offers from companies on Algora.
211-
</.tooltip_content>
212-
</.tooltip>
213-
</div>
214-
<.switch
215-
id="available"
216-
name="available"
217-
value={@current_user.seeking_contracts}
218-
on_click={
219-
%JS{}
220-
|> JS.push("toggle_availability")
221-
|> JS.toggle(to: "#availability-details")
222-
}
223-
/>
224-
</div>
225204
<.form
226205
for={@availability_form}
227206
id="availability-form"
228207
phx-change="validate_availability"
229208
phx-submit="save_availability"
230-
class={
231-
classes([
232-
"mt-4 grid grid-cols-1 lg:grid-cols-2 gap-4",
233-
@current_user.seeking_contracts || "hidden"
234-
])
235-
}
209+
class="grid grid-cols-1 lg:grid-cols-2 gap-4"
236210
>
237211
<.input
238212
field={@availability_form[:hourly_rate_min]}
@@ -244,11 +218,7 @@ defmodule AlgoraWeb.User.DashboardLive do
244218
label="Hours per Week"
245219
icon="tabler-clock"
246220
/>
247-
<.button
248-
:if={@availability_form.source.action == :validate}
249-
type="submit"
250-
class="lg:col-span-2"
251-
>
221+
<.button :if={@availability_form.source.changes != %{}} type="submit" class="lg:col-span-2">
252222
Save
253223
</.button>
254224
</.form>
@@ -406,9 +376,7 @@ defmodule AlgoraWeb.User.DashboardLive do
406376

407377
@impl true
408378
def handle_event("tech_stack_changed", params, socket) do
409-
case socket.assigns.current_user
410-
|> User.settings_changeset(%{tech_stack: params["tech_stack"]})
411-
|> Repo.update() do
379+
case socket.assigns.current_user |> User.settings_changeset(%{tech_stack: params["tech_stack"]}) |> Repo.update() do
412380
{:ok, user} ->
413381
{:noreply, socket |> assign(:current_user, user) |> assign_bounties()}
414382

@@ -417,50 +385,34 @@ defmodule AlgoraWeb.User.DashboardLive do
417385
end
418386
end
419387

420-
@impl true
421-
def handle_event("toggle_availability", _params, socket) do
422-
current_user = socket.assigns.current_user
423-
424-
{:ok, user} = Accounts.update_settings(current_user, %{seeking_contracts: !current_user.seeking_contracts})
425-
426-
{:noreply, assign(socket, :current_user, user)}
427-
end
428-
429388
@impl true
430389
def handle_event("validate_availability", %{"availability_form" => params}, socket) do
431-
form =
432-
%AvailabilityForm{}
433-
|> AvailabilityForm.changeset(params)
434-
|> Map.put(:action, :validate)
435-
|> to_form()
436-
437-
{:noreply, assign(socket, availability_form: form)}
390+
changeset = AvailabilityForm.changeset(socket.assigns.availability_form.source, params)
391+
{:noreply, assign(socket, availability_form: to_form(changeset))}
438392
end
439393

440394
@impl true
441395
def handle_event("save_availability", %{"availability_form" => params}, socket) do
442-
changeset =
443-
%AvailabilityForm{}
444-
|> AvailabilityForm.changeset(params)
445-
|> Map.put(:action, :validate)
446-
447-
case changeset do
396+
case AvailabilityForm.changeset(%AvailabilityForm{}, params) do
448397
%{valid?: true} ->
449-
case socket.assigns.current_user
450-
|> User.settings_changeset(params)
451-
|> Repo.update() do
398+
case socket.assigns.current_user |> User.settings_changeset(params) |> Repo.update() do
452399
{:ok, user} ->
453400
{:noreply,
454401
socket
455402
|> put_flash(:info, "Availability updated!")
456403
|> assign(:current_user, user)
457-
|> assign(:availability_form, changeset |> Map.put(:action, nil) |> to_form())}
404+
|> assign(
405+
:availability_form,
406+
%AvailabilityForm{hourly_rate_min: user.hourly_rate_min, hours_per_week: user.hours_per_week}
407+
|> AvailabilityForm.changeset(%{})
408+
|> to_form()
409+
)}
458410

459411
{:error, _changeset} ->
460412
{:noreply, put_flash(socket, :error, "Failed to update availability")}
461413
end
462414

463-
%{valid?: false} ->
415+
%{valid?: false} = changeset ->
464416
{:noreply, assign(socket, availability_form: to_form(changeset))}
465417
end
466418
end

0 commit comments

Comments
 (0)