diff --git a/.iex.exs b/.iex.exs index 556a34bc3..60b413b54 100644 --- a/.iex.exs +++ b/.iex.exs @@ -6,6 +6,8 @@ alias Algora.Accounts alias Algora.Accounts.Identity alias Algora.Accounts.User alias Algora.Admin +alias Algora.Bounties +alias Algora.Bounties.Claim alias Algora.Contracts alias Algora.Contracts.Contract alias Algora.Contracts.Timesheet diff --git a/lib/algora_web/live/org/dashboard_live.ex b/lib/algora_web/live/org/dashboard_live.ex index 8d6b1c1c5..67546bdbf 100644 --- a/lib/algora_web/live/org/dashboard_live.ex +++ b/lib/algora_web/live/org/dashboard_live.ex @@ -4,15 +4,22 @@ defmodule AlgoraWeb.Org.DashboardLive do import AlgoraWeb.Components.Achievement import Ecto.Changeset + import Ecto.Query alias Algora.Accounts alias Algora.Accounts.User alias Algora.Bounties + alias Algora.Bounties.Bounty + alias Algora.Bounties.Claim alias Algora.Contracts alias Algora.Github + alias Algora.Payments.Transaction + alias Algora.Repo alias Algora.Types.USD alias Algora.Validations alias Algora.Workspace + alias Algora.Workspace.Repository + alias Algora.Workspace.Ticket alias AlgoraWeb.Components.Logos require Logger @@ -107,6 +114,7 @@ defmodule AlgoraWeb.Org.DashboardLive do |> assign(:contract_form, to_form(ContractForm.changeset(%ContractForm{}, %{}))) |> assign(:show_contract_modal, false) |> assign(:selected_developer, nil) + |> assign_payable_bounties() |> assign_contracts() |> assign_achievements()} else @@ -119,6 +127,115 @@ defmodule AlgoraWeb.Org.DashboardLive do ~H"""
+ <.section :if={@payable_bounties != []}> + <.card> + <.card_header> + <.card_title>Pending Payments + <.card_description> + The following claims have been approved and are ready for payment. + + + <.card_content> + + + <%= for {_group_id, [%{target: %{bounties: [bounty | _]}} | _] = claims} <- @payable_bounties do %> + + + + + + + + <% end %> + +
+
+
+
+
+
+
+ {Money.to_string!(bounty.amount)} +
+
+
+ <.link + rel="noopener" + class="group/issue inline-flex flex-col" + href={Bounty.url(bounty)} + > +
+
+

+ {Bounty.path(bounty)} +

+
+
+

+ {bounty.ticket.title} +

+ +

+ {Algora.Util.time_ago(bounty.inserted_at)} +

+
+
+
+
+
+
+
+ <%= for claim <- claims do %> +
+ {User.handle(claim.user)} +
+ <% end %> +
+
+
+ {claims + |> Enum.map(fn c -> User.handle(c.user) end) + |> Algora.Util.format_name_list()} +
+
+ {Algora.Util.time_ago(hd(claims).inserted_at)} +
+
+
+
+
+
+
+ <.button + :if={hd(claims).source} + href={hd(claims).source.url} + variant="secondary" + > + View + + <.button href={~p"/claims/#{hd(claims).group_id}"}> + Reward + +
+
+
+ + + + <.section :if={@installations == []}> <.card> <.card_header> @@ -635,6 +752,34 @@ defmodule AlgoraWeb.Org.DashboardLive do end end + defp assign_payable_bounties(socket) do + org = socket.assigns.current_org + + payable_claims = + Repo.all( + from c in Claim, + where: c.status == :approved, + join: t in assoc(c, :target), + join: b in assoc(t, :bounties), + where: b.owner_id == ^org.id, + left_join: tx in Transaction, + on: tx.claim_id == c.id and tx.type == :debit, + where: is_nil(tx.status) or tx.status not in [:initialized, :succeeded], + join: r in assoc(t, :repository), + join: ru in assoc(r, :user), + join: cu in assoc(c, :user), + left_join: s in assoc(c, :source), + select_merge: %{ + user: cu, + source: s, + target: %Ticket{t | bounties: [%Bounty{b | ticket: %{t | repository: %{r | user: ru}}}]} + } + ) + + payable_bounties = Enum.group_by(payable_claims, & &1.group_id) + assign(socket, :payable_bounties, payable_bounties) + end + defp assign_contracts(socket) do contracts = Contracts.list_contracts(client_id: socket.assigns.current_org.id, status: :draft) diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index 848cd6fdb..82ecae125 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -560,7 +560,7 @@ for {repo_name, issues} <- repos do target_id: issue.id, source_id: pull_request.id, type: :pull_request, - status: if(paid, do: :approved, else: :pending), + status: :approved, url: "https://github.com/piedpiper/#{repo_name}/pull/#{index}" })