@@ -72,11 +72,11 @@ defmodule AlgoraWeb.User.DashboardLive do
72
72
|> to_form ( )
73
73
74
74
availability_form =
75
- % AvailabilityForm { }
76
- |> AvailabilityForm . changeset ( % {
75
+ % AvailabilityForm {
77
76
hourly_rate_min: socket . assigns . current_user . hourly_rate_min ,
78
77
hours_per_week: socket . assigns . current_user . hours_per_week
79
- } )
78
+ }
79
+ |> AvailabilityForm . changeset ( % { } )
80
80
|> to_form ( )
81
81
82
82
total_earned =
@@ -201,38 +201,12 @@ defmodule AlgoraWeb.User.DashboardLive do
201
201
<!-- Sidebar -->
202
202
< 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 " >
203
203
<!-- 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 >
225
204
< . form
226
205
for = { @ availability_form }
227
206
id = "availability-form "
228
207
phx-change = "validate_availability "
229
208
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 "
236
210
>
237
211
< . input
238
212
field = { @ availability_form [ :hourly_rate_min ] }
@@ -244,11 +218,7 @@ defmodule AlgoraWeb.User.DashboardLive do
244
218
label = "Hours per Week "
245
219
icon = "tabler-clock "
246
220
/>
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 " >
252
222
Save
253
223
</ . button >
254
224
</ . form >
@@ -406,9 +376,7 @@ defmodule AlgoraWeb.User.DashboardLive do
406
376
407
377
@ impl true
408
378
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
412
380
{ :ok , user } ->
413
381
{ :noreply , socket |> assign ( :current_user , user ) |> assign_bounties ( ) }
414
382
@@ -417,50 +385,34 @@ defmodule AlgoraWeb.User.DashboardLive do
417
385
end
418
386
end
419
387
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
-
429
388
@ impl true
430
389
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 ) ) }
438
392
end
439
393
440
394
@ impl true
441
395
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
448
397
% { 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
452
399
{ :ok , user } ->
453
400
{ :noreply ,
454
401
socket
455
402
|> put_flash ( :info , "Availability updated!" )
456
403
|> 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
+ ) }
458
410
459
411
{ :error , _changeset } ->
460
412
{ :noreply , put_flash ( socket , :error , "Failed to update availability" ) }
461
413
end
462
414
463
- % { valid?: false } ->
415
+ % { valid?: false } = changeset ->
464
416
{ :noreply , assign ( socket , availability_form: to_form ( changeset ) ) }
465
417
end
466
418
end
0 commit comments