Skip to content

Commit 4d32c94

Browse files
committed
refactor: enhance form handling and share drawer logic in DashboardLive
- Updated the ticket reference structure in the tip creation process to ensure consistent data handling. - Replaced individual form assignments with a unified approach for contract, tip, and bounty forms, improving maintainability. - Enhanced the share drawer content rendering to dynamically utilize the appropriate form based on the selected share drawer type, streamlining the user experience.
1 parent 7a8832f commit 4d32c94

File tree

1 file changed

+128
-133
lines changed

1 file changed

+128
-133
lines changed

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 128 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ defmodule AlgoraWeb.Org.DashboardLive do
499499
creator: socket.assigns.current_user,
500500
owner: socket.assigns.current_org,
501501
amount: amount,
502-
ticket_ref: ticket_ref
502+
ticket_ref: %{
503+
owner: ticket_ref.owner,
504+
repo: ticket_ref.repo,
505+
number: ticket_ref.number
506+
}
503507
}) do
504508
{:noreply,
505509
socket
@@ -528,9 +532,11 @@ defmodule AlgoraWeb.Org.DashboardLive do
528532
if socket.assigns.has_fresh_token? do
529533
changeset =
530534
%TipForm{}
531-
|> TipForm.changeset(params)
535+
|> TipForm.changeset(Map.put(params, "github_handle", socket.assigns.current_user.provider_login))
532536
|> Map.put(:action, :validate)
533537

538+
ticket_ref = get_field(changeset, :ticket_ref)
539+
534540
with %{valid?: true} <- changeset,
535541
{:ok, checkout_url} <-
536542
Bounties.create_tip(
@@ -540,7 +546,11 @@ defmodule AlgoraWeb.Org.DashboardLive do
540546
recipient: socket.assigns.selected_developer,
541547
amount: get_field(changeset, :amount)
542548
},
543-
ticket_ref: get_field(changeset, :ticket_ref)
549+
ticket_ref: %{
550+
owner: ticket_ref.owner,
551+
repo: ticket_ref.repo,
552+
number: ticket_ref.number
553+
}
544554
) do
545555
{:noreply, redirect(socket, external: checkout_url)}
546556
else
@@ -1220,91 +1230,95 @@ defmodule AlgoraWeb.Org.DashboardLive do
12201230

12211231
defp share_drawer_content(%{share_drawer_type: "contract"} = assigns) do
12221232
~H"""
1223-
<.card>
1224-
<.card_header>
1225-
<.card_title>Contract Details</.card_title>
1226-
</.card_header>
1227-
<.card_content>
1228-
<div class="space-y-4">
1229-
<.input label="Hourly Rate" icon="tabler-currency-dollar" field={@form[:hourly_rate]} />
1230-
<.input label="Hours per Week" field={@form[:hours_per_week]} />
1231-
</div>
1232-
</.card_content>
1233-
</.card>
1234-
1235-
<div class="ml-auto flex gap-4">
1236-
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1237-
Cancel
1238-
</.button>
1239-
<.button type="submit">
1240-
Send Contract Offer <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1241-
</.button>
1242-
</div>
1233+
<.form for={@contract_form} phx-submit="create_contract">
1234+
<.card>
1235+
<.card_header>
1236+
<.card_title>Contract Details</.card_title>
1237+
</.card_header>
1238+
<.card_content>
1239+
<div class="space-y-4">
1240+
<.input
1241+
label="Hourly Rate"
1242+
icon="tabler-currency-dollar"
1243+
field={@contract_form[:hourly_rate]}
1244+
/>
1245+
<.input label="Hours per Week" field={@contract_form[:hours_per_week]} />
1246+
</div>
1247+
</.card_content>
1248+
</.card>
1249+
1250+
<div class="ml-auto flex gap-4">
1251+
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1252+
Cancel
1253+
</.button>
1254+
<.button type="submit">
1255+
Send Contract Offer <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1256+
</.button>
1257+
</div>
1258+
</.form>
12431259
"""
12441260
end
12451261

12461262
defp share_drawer_content(%{share_drawer_type: "bounty"} = assigns) do
12471263
~H"""
1248-
<.card>
1249-
<.card_header>
1250-
<.card_title>Bounty Details</.card_title>
1251-
</.card_header>
1252-
<.card_content>
1253-
<div class="space-y-4">
1254-
<.input
1255-
label="URL"
1256-
field={@form[:url]}
1257-
placeholder="https://github.com/owner/repo/issues/123"
1258-
/>
1259-
<.input label="Amount" icon="tabler-currency-dollar" field={@form[:amount]} />
1260-
</div>
1261-
</.card_content>
1262-
</.card>
1263-
1264-
<div class="ml-auto flex gap-4">
1265-
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1266-
Cancel
1267-
</.button>
1268-
<.button type="submit">
1269-
Share Bounty <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1270-
</.button>
1271-
</div>
1264+
<.form for={@bounty_form} phx-submit="create_bounty">
1265+
<.card>
1266+
<.card_header>
1267+
<.card_title>Bounty Details</.card_title>
1268+
</.card_header>
1269+
<.card_content>
1270+
<div class="space-y-4">
1271+
<.input
1272+
label="URL"
1273+
field={@bounty_form[:url]}
1274+
placeholder="https://github.com/owner/repo/issues/123"
1275+
/>
1276+
<.input label="Amount" icon="tabler-currency-dollar" field={@bounty_form[:amount]} />
1277+
</div>
1278+
</.card_content>
1279+
</.card>
1280+
1281+
<div class="ml-auto flex gap-4">
1282+
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1283+
Cancel
1284+
</.button>
1285+
<.button type="submit">
1286+
Share Bounty <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1287+
</.button>
1288+
</div>
1289+
</.form>
12721290
"""
12731291
end
12741292

12751293
defp share_drawer_content(%{share_drawer_type: "tip"} = assigns) do
12761294
~H"""
1277-
<.card>
1278-
<.card_header>
1279-
<.card_title>Tip Details</.card_title>
1280-
</.card_header>
1281-
<.card_content>
1282-
<div class="space-y-4">
1283-
<.input label="Amount" icon="tabler-currency-dollar" field={@form[:amount]} />
1284-
<.input
1285-
label="URL"
1286-
field={@form[:url]}
1287-
placeholder="https://github.com/owner/repo/issues/123"
1288-
helptext="We'll add a comment to the issue to notify the developer."
1289-
/>
1290-
<%!-- # TODO: implement --%>
1291-
<.input
1292-
label="Review (optional)"
1293-
field={@form[:message]}
1294-
placeholder="Thanks for your great work!"
1295-
/>
1296-
</div>
1297-
</.card_content>
1298-
</.card>
1299-
1300-
<div class="ml-auto flex gap-4">
1301-
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1302-
Cancel
1303-
</.button>
1304-
<.button type="submit">
1305-
Send Tip <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1306-
</.button>
1307-
</div>
1295+
<.form for={@tip_form} phx-submit="create_tip">
1296+
<.card>
1297+
<.card_header>
1298+
<.card_title>Tip Details</.card_title>
1299+
</.card_header>
1300+
<.card_content>
1301+
<div class="space-y-4">
1302+
<.input label="Amount" icon="tabler-currency-dollar" field={@tip_form[:amount]} />
1303+
<.input
1304+
label="URL"
1305+
field={@tip_form[:url]}
1306+
placeholder="https://github.com/owner/repo/issues/123"
1307+
helptext="We'll add a comment to the issue to notify the developer."
1308+
/>
1309+
</div>
1310+
</.card_content>
1311+
</.card>
1312+
1313+
<div class="ml-auto flex gap-4">
1314+
<.button variant="secondary" phx-click="close_share_drawer" type="button">
1315+
Cancel
1316+
</.button>
1317+
<.button type="submit">
1318+
Send Tip <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
1319+
</.button>
1320+
</div>
1321+
</.form>
13081322
"""
13091323
end
13101324

@@ -1381,27 +1395,6 @@ defmodule AlgoraWeb.Org.DashboardLive do
13811395
end
13821396

13831397
defp share_drawer(assigns) do
1384-
assigns =
1385-
case assigns.share_drawer_type do
1386-
nil ->
1387-
assigns
1388-
1389-
"contract" ->
1390-
assigns
1391-
|> assign(:phx_submit, "create_contract")
1392-
|> assign(:form, assigns.contract_form)
1393-
1394-
"tip" ->
1395-
assigns
1396-
|> assign(:phx_submit, "create_tip")
1397-
|> assign(:form, assigns.tip_form)
1398-
1399-
"bounty" ->
1400-
assigns
1401-
|> assign(:phx_submit, "create_bounty")
1402-
|> assign(:form, assigns.bounty_form)
1403-
end
1404-
14051398
~H"""
14061399
<.drawer show={@show_share_drawer} direction="right" on_cancel="close_share_drawer">
14071400
<.share_drawer_header
@@ -1410,41 +1403,43 @@ defmodule AlgoraWeb.Org.DashboardLive do
14101403
share_drawer_type={@share_drawer_type}
14111404
/>
14121405
<.drawer_content :if={@selected_developer} class="mt-4">
1413-
<.form for={@form} phx-submit={@phx_submit}>
1414-
<div class="flex flex-col gap-8">
1415-
<.share_drawer_developer_info selected_developer={@selected_developer} />
1416-
<%= if incomplete?(@achievements, :connect_github_status) do %>
1417-
<div class="relative">
1418-
<div class="absolute inset-0 z-10 bg-background/50" />
1419-
<div class="pointer-events-none">
1420-
<.share_drawer_content
1421-
:if={@selected_developer}
1422-
share_drawer_type={@share_drawer_type}
1423-
form={@form}
1424-
/>
1425-
</div>
1426-
<.alert
1427-
variant="default"
1428-
class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-20 w-auto flex flex-col items-center justify-center gap-2 text-center"
1429-
>
1430-
<.alert_title>Connect GitHub</.alert_title>
1431-
<.alert_description>
1432-
Connect your GitHub account to create a {@share_drawer_type}.
1433-
</.alert_description>
1434-
<.button phx-click="close_share_drawer" type="button" variant="subtle">
1435-
Go back
1436-
</.button>
1437-
</.alert>
1406+
<div class="flex flex-col gap-8">
1407+
<.share_drawer_developer_info selected_developer={@selected_developer} />
1408+
<%= if incomplete?(@achievements, :connect_github_status) do %>
1409+
<div class="relative">
1410+
<div class="absolute inset-0 z-10 bg-background/50" />
1411+
<div class="pointer-events-none">
1412+
<.share_drawer_content
1413+
:if={@selected_developer}
1414+
share_drawer_type={@share_drawer_type}
1415+
bounty_form={@bounty_form}
1416+
tip_form={@tip_form}
1417+
contract_form={@contract_form}
1418+
/>
14381419
</div>
1439-
<% else %>
1440-
<.share_drawer_content
1441-
:if={@selected_developer}
1442-
share_drawer_type={@share_drawer_type}
1443-
form={@form}
1444-
/>
1445-
<% end %>
1446-
</div>
1447-
</.form>
1420+
<.alert
1421+
variant="default"
1422+
class="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-20 w-auto flex flex-col items-center justify-center gap-2 text-center"
1423+
>
1424+
<.alert_title>Connect GitHub</.alert_title>
1425+
<.alert_description>
1426+
Connect your GitHub account to create a {@share_drawer_type}.
1427+
</.alert_description>
1428+
<.button phx-click="close_share_drawer" type="button" variant="subtle">
1429+
Go back
1430+
</.button>
1431+
</.alert>
1432+
</div>
1433+
<% else %>
1434+
<.share_drawer_content
1435+
:if={@selected_developer}
1436+
share_drawer_type={@share_drawer_type}
1437+
bounty_form={@bounty_form}
1438+
tip_form={@tip_form}
1439+
contract_form={@contract_form}
1440+
/>
1441+
<% end %>
1442+
</div>
14481443
</.drawer_content>
14491444
</.drawer>
14501445
"""

0 commit comments

Comments
 (0)