Skip to content

Commit 36e7223

Browse files
committed
feat: add prompt to complete GitHub OAuth in main bounty form
1 parent 735485b commit 36e7223

File tree

5 files changed

+95
-57
lines changed

5 files changed

+95
-57
lines changed

lib/algora_web/components/layouts/user.html.heex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,10 @@
344344
</.drawer_description>
345345
</.drawer_header>
346346
<.drawer_content>
347-
<AlgoraWeb.Forms.BountyForm.bounty_form form={main_bounty_form} />
347+
<AlgoraWeb.Forms.BountyForm.bounty_form
348+
form={main_bounty_form}
349+
has_fresh_token?={Map.get(assigns, :has_fresh_token?)}
350+
/>
348351
</.drawer_content>
349352
</.drawer>
350353
<% end %>

lib/algora_web/forms/bounty_form.ex

Lines changed: 85 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -47,68 +47,97 @@ defmodule AlgoraWeb.Forms.BountyForm do
4747

4848
def bounty_form(assigns) do
4949
~H"""
50-
<.form id="main-bounty-form" for={@form} phx-submit="create_bounty_main">
51-
<div class="space-y-4">
52-
<div class="grid grid-cols-2 gap-4" phx-update="ignore" id="main-bounty-form-tabs">
53-
<%= for {label, value} <- type_options() do %>
54-
<label class={[
55-
"group relative flex cursor-pointer rounded-lg px-3 py-2 shadow-sm focus:outline-none",
56-
"border-2 bg-background transition-all duration-200 hover:border-primary hover:bg-primary/10",
57-
"border-border has-[:checked]:border-primary has-[:checked]:bg-primary/10"
58-
]}>
59-
<.input
60-
id={"main-bounty-form-type-#{value}"}
61-
type="radio"
62-
field={@form[:type]}
63-
checked={@form[:type].value == value}
64-
value={value}
65-
class="sr-only"
66-
phx-click={
67-
%JS{}
68-
|> JS.hide(to: "#main-bounty-form [data-tab]:not([data-tab=#{value}])")
69-
|> JS.show(to: "#main-bounty-form [data-tab=#{value}]")
70-
}
71-
/>
72-
<span class="flex flex-1 items-center justify-between">
73-
<span class="text-sm font-medium">{label}</span>
74-
<.icon
75-
name="tabler-check"
76-
class="invisible size-5 text-primary group-has-[:checked]:visible"
50+
<.bounty_form_wrapper has_fresh_token?={@has_fresh_token?}>
51+
<.form id="main-bounty-form" for={@form} phx-submit="create_bounty_main">
52+
<div class="space-y-4">
53+
<div class="grid grid-cols-2 gap-4" phx-update="ignore" id="main-bounty-form-tabs">
54+
<%= for {label, value} <- type_options() do %>
55+
<label class={[
56+
"group relative flex cursor-pointer rounded-lg px-3 py-2 shadow-sm focus:outline-none",
57+
"border-2 bg-background transition-all duration-200 hover:border-primary hover:bg-primary/10",
58+
"border-border has-[:checked]:border-primary has-[:checked]:bg-primary/10"
59+
]}>
60+
<.input
61+
id={"main-bounty-form-type-#{value}"}
62+
type="radio"
63+
field={@form[:type]}
64+
checked={@form[:type].value == value}
65+
value={value}
66+
class="sr-only"
67+
phx-click={
68+
%JS{}
69+
|> JS.hide(to: "#main-bounty-form [data-tab]:not([data-tab=#{value}])")
70+
|> JS.show(to: "#main-bounty-form [data-tab=#{value}]")
71+
}
7772
/>
78-
</span>
79-
</label>
80-
<% end %>
81-
</div>
73+
<span class="flex flex-1 items-center justify-between">
74+
<span class="text-sm font-medium">{label}</span>
75+
<.icon
76+
name="tabler-check"
77+
class="invisible size-5 text-primary group-has-[:checked]:visible"
78+
/>
79+
</span>
80+
</label>
81+
<% end %>
82+
</div>
8283
83-
<div data-tab="github">
84-
<.input
85-
label="URL"
86-
field={@form[:url]}
87-
placeholder="https://github.com/owner/repo/issues/123"
88-
/>
89-
</div>
84+
<div data-tab="github">
85+
<.input
86+
label="URL"
87+
field={@form[:url]}
88+
placeholder="https://github.com/owner/repo/issues/123"
89+
/>
90+
</div>
91+
92+
<div data-tab="custom" class="hidden space-y-4">
93+
<.input label="Title" field={@form[:title]} placeholder="Brief description of the bounty" />
94+
<.input
95+
label="Description (optional)"
96+
field={@form[:description]}
97+
type="textarea"
98+
placeholder="Requirements and acceptance criteria"
99+
/>
100+
</div>
90101
91-
<div data-tab="custom" class="hidden space-y-4">
92-
<.input label="Title" field={@form[:title]} placeholder="Brief description of the bounty" />
93-
<.input
94-
label="Description (optional)"
95-
field={@form[:description]}
96-
type="textarea"
97-
placeholder="Requirements and acceptance criteria"
98-
/>
102+
<.input label="Amount" icon="tabler-currency-dollar" field={@form[:amount]} />
99103
</div>
104+
<div class="pt-4 ml-auto flex gap-4">
105+
<.button variant="secondary" phx-click="close_share_drawer" type="button">
106+
Cancel
107+
</.button>
108+
<.button type="submit">
109+
Share Bounty <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
110+
</.button>
111+
</div>
112+
</.form>
113+
</.bounty_form_wrapper>
114+
"""
115+
end
100116

101-
<.input label="Amount" icon="tabler-currency-dollar" field={@form[:amount]} />
102-
</div>
103-
<div class="pt-4 ml-auto flex gap-4">
104-
<.button variant="secondary" phx-click="close_share_drawer" type="button">
105-
Cancel
106-
</.button>
107-
<.button type="submit">
108-
Share Bounty <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
109-
</.button>
117+
def bounty_form_wrapper(assigns) do
118+
~H"""
119+
<%= if @has_fresh_token? do %>
120+
{render_slot(@inner_block)}
121+
<% else %>
122+
<div class="relative">
123+
<div class="absolute inset-0 z-10 bg-background/50" />
124+
<div class="pointer-events-none saturate-0">
125+
{render_slot(@inner_block)}
126+
</div>
127+
<.alert
128+
variant="default"
129+
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"
130+
>
131+
<.alert_title>Let's get you started</.alert_title>
132+
<.alert_description>
133+
Connect your GitHub account to create a bounty
134+
</.alert_description>
135+
<.button type="submit" href={Algora.Github.authorize_url()}>
136+
Connect GitHub <.icon name="tabler-arrow-right" class="-mr-1 ml-2 h-4 w-4" />
137+
</.button>
138+
</.alert>
110139
</div>
111-
</.form>
140+
<% end %>
112141
"""
113142
end
114143
end

lib/algora_web/live/org/nav.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule AlgoraWeb.Org.Nav do
66
import Ecto.Changeset
77
import Phoenix.LiveView
88

9+
alias Algora.Accounts
910
alias Algora.Bounties
1011
alias Algora.Organizations
1112
alias Algora.Organizations.Member
@@ -35,6 +36,7 @@ defmodule AlgoraWeb.Org.Nav do
3536
{:cont,
3637
socket
3738
|> assign(:screenshot?, not is_nil(params["screenshot"]))
39+
|> assign(:has_fresh_token?, Accounts.has_fresh_token?(current_user))
3840
|> assign(:main_bounty_form, main_bounty_form)
3941
|> assign(:main_bounty_form_open?, false)
4042
|> assign(:main_contract_form, main_contract_form)

lib/algora_web/live/org/preview_nav.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ defmodule AlgoraWeb.Org.PreviewNav do
2020

2121
{:cont,
2222
socket
23+
|> assign(:has_fresh_token?, Accounts.has_fresh_token?(user))
2324
|> assign(:main_bounty_form, to_form(BountyForm.changeset(%BountyForm{}, %{})))
2425
|> assign(:main_bounty_form_open?, false)
2526
|> assign(:main_contract_form, to_form(ContractForm.changeset(%ContractForm{}, %{})))
@@ -45,6 +46,7 @@ defmodule AlgoraWeb.Org.PreviewNav do
4546

4647
socket =
4748
socket
49+
|> assign(:has_fresh_token?, false)
4850
|> assign(:main_bounty_form, to_form(BountyForm.changeset(%BountyForm{}, %{})))
4951
|> assign(:main_bounty_form_open?, false)
5052
|> assign(:main_contract_form, to_form(ContractForm.changeset(%ContractForm{}, %{})))

lib/algora_web/live/org/repo_nav.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule AlgoraWeb.Org.RepoNav do
66
import Ecto.Changeset
77
import Phoenix.LiveView
88

9+
alias Algora.Accounts
910
alias Algora.Bounties
1011
alias Algora.Organizations
1112
alias Algora.Organizations.Member
@@ -26,6 +27,7 @@ defmodule AlgoraWeb.Org.RepoNav do
2627

2728
{:cont,
2829
socket
30+
|> assign(:has_fresh_token?, Accounts.has_fresh_token?(current_user))
2931
|> assign(:screenshot?, not is_nil(params["screenshot"]))
3032
|> assign(:main_bounty_form, main_bounty_form)
3133
|> assign(:main_bounty_form_open?, false)

0 commit comments

Comments
 (0)