@@ -5,8 +5,10 @@ defmodule AlgoraWeb.Org.JobsLive do
55 import AlgoraWeb.Components.ModalVideo
66
77 alias Algora.Accounts
8+ alias Algora.Activities
89 alias Algora.Jobs
910 alias Algora.Markdown
11+ alias Algora.Matches
1012
1113 require Logger
1214
@@ -17,7 +19,7 @@ defmodule AlgoraWeb.Org.JobsLive do
1719
1820 { :ok ,
1921 socket
20- |> assign ( :page_title , "Jobs" )
22+ |> assign ( :page_title , socket . assigns . current_org . name )
2123 |> assign ( :jobs , jobs )
2224 |> assign ( :media , media )
2325 |> assign_user_applications ( ) }
@@ -35,7 +37,7 @@ defmodule AlgoraWeb.Org.JobsLive do
3537 } />
3638 < div class = {
3739 classes ( [
38- "mx-auto max-w-7xl px-4 md:px-6 lg:px-8" ,
40+ "mx-auto max-w-6xl px-4 md:px-6 lg:px-8" ,
3941 if ( ! @ current_user , do: "py-8" , else: "py-4 md:py-6 lg:py-8" )
4042 ] )
4143 } >
@@ -78,7 +80,7 @@ defmodule AlgoraWeb.Org.JobsLive do
7880 Engineering at { @ current_org . name }
7981 </ h2 >
8082 < p class = "pt-1 font-medium text-base text-muted-foreground " >
81- Open software engineering positions at { @ current_org . name }
83+ Open engineering positions at { @ current_org . name }
8284 </ p >
8385 < div class = "pt-2 flex gap-2 items-center justify-center " >
8486 <%= for { platform , icon } <- social_icons ( ) ,
@@ -92,7 +94,7 @@ defmodule AlgoraWeb.Org.JobsLive do
9294 </ div >
9395
9496 <%= if not Enum . empty? ( @ media ) do %>
95- < div class = "max-w-4xl mx-auto mt-8 flex flex-row justify-center gap-4 " >
97+ < div class = "max-w-6xl mx-auto mt-8 flex flex-row justify-center gap-4 " >
9698 <%= for media <- @ media |> Enum . take ( 3 ) do %>
9799 < div class = "w-1/3 aspect-video rounded-lg overflow-hidden " >
98100 <%= if Algora.Accounts . youtube_url? ( media . url ) do %>
@@ -131,15 +133,13 @@ defmodule AlgoraWeb.Org.JobsLive do
131133 < div >
132134 < div class = "flex items-center gap-2 " >
133135 < . link
134- navigate = { ~p " /#{ @ current_org . handle } /job/#{ job . id } " }
136+ navigate = { "/#{ @ current_org . handle } /job/#{ job . id } " }
135137 class = "text-lg font-semibold "
136138 >
137139 < span class = "underline " > { job . title } </ span >
138- <%= if @ current_user && @ current_user . is_admin do %>
139- < span class = "text-xs font-muted-foreground " >
140- { job . location } - { job . compensation }
141- </ span >
142- <% end %>
140+ < span class = "text-xs font-muted-foreground " >
141+ { job . location } < span :if = { job . compensation } > - { job . compensation } </ span >
142+ </ span >
143143 </ . link >
144144 <%= if job . id in [ "b4sFSeJvb2rteUEX" , "M9yTwVXFjvQM2WJf" ] do %>
145145 < . badge variant = "success " > Contract to Hire</ . badge >
@@ -174,15 +174,9 @@ defmodule AlgoraWeb.Org.JobsLive do
174174 <% end %>
175175 </ div >
176176 </ div >
177- <%= if MapSet . member? ( @ user_applications , job . id ) do %>
178- < . button disabled class = "opacity-50 " size = "lg " >
179- < . icon name = "tabler-check " class = "h-6 w-6 mr-2 -ml-1 " /> Applied
180- </ . button >
181- <% else %>
182- < . button phx-click = "apply_job " phx-value-job-id = { job . id } size = "lg " >
183- < . icon name = "github " class = "h-6 w-6 mr-2 " /> Apply with GitHub
184- </ . button >
185- <% end %>
177+ < . button phx-click = "apply_job " phx-value-job-id = { job . id } >
178+ I'm interested
179+ </ . button >
186180 </ div >
187181 <% end %>
188182 </ div >
@@ -206,26 +200,65 @@ defmodule AlgoraWeb.Org.JobsLive do
206200
207201 @ impl true
208202 def handle_event ( "apply_job" , % { "job-id" => job_id } , socket ) do
209- if socket . assigns [ :current_user ] do
210- if Accounts . has_fresh_token? ( socket . assigns . current_user ) do
211- case Jobs . create_application ( job_id , socket . assigns . current_user ) do
212- { :ok , _application } ->
213- { :noreply , assign_user_applications ( socket ) }
203+ current_user = socket . assigns [ :current_user ]
204+ org = socket . assigns . current_org
214205
215- { :error , _changeset } ->
216- { :noreply , put_flash ( socket , :error , "Failed to submit application. Please try again." ) }
217- end
218- else
219- { :noreply ,
220- redirect ( socket ,
221- external: Algora.Github . authorize_url ( % { return_to: "/#{ socket . assigns . current_org . handle } /jobs" } )
222- ) }
206+ if current_user do
207+ # Try to get job match
208+ job_match = Matches . get_job_match ( current_user . id , job_id )
209+
210+ case job_match do
211+ nil ->
212+ # No match exists, create one
213+ match_attrs = % {
214+ user_id: current_user . id ,
215+ job_posting_id: job_id ,
216+ status: :automatched ,
217+ is_draft: true ,
218+ candidate_approved_at: DateTime . utc_now ( )
219+ }
220+
221+ case Matches . create_job_match ( match_attrs ) do
222+ { :ok , _created_match } ->
223+ { :ok , job } = Jobs . get_job_posting ( job_id )
224+ company_name = job . company_name || org . name
225+ user_name = current_user . name
226+ Activities . alert ( "⏱️ #{ user_name } is interested in chatting with #{ company_name } " , :critical )
227+
228+ { :noreply , push_navigate ( socket , to: "/#{ org . handle } /job/#{ job_id } /apply" ) }
229+
230+ { :error , _changeset } ->
231+ { :noreply ,
232+ socket
233+ |> put_flash ( :error , "Failed to create match" )
234+ |> push_navigate ( to: "/#{ org . handle } /job/#{ job_id } /apply" ) }
235+ end
236+
237+ match ->
238+ # Match exists, update it before redirecting
239+ { :ok , job } = Jobs . get_job_posting ( job_id )
240+
241+ case Matches . update_job_match ( match , % {
242+ candidate_approved_at: DateTime . utc_now ( ) ,
243+ candidate_discarded_at: nil
244+ } ) do
245+ { :ok , _updated_match } ->
246+ company_name = job . company_name || org . name
247+ user_name = current_user . name
248+ Activities . alert ( "⏱️ #{ user_name } is interested in chatting with #{ company_name } " , :critical )
249+
250+ { :noreply , push_navigate ( socket , to: "/#{ org . handle } /job/#{ job_id } /apply" ) }
251+
252+ { :error , _changeset } ->
253+ { :noreply ,
254+ socket
255+ |> put_flash ( :error , "Failed to update match" )
256+ |> push_navigate ( to: "/#{ org . handle } /job/#{ job_id } /apply" ) }
257+ end
223258 end
224259 else
225- { :noreply ,
226- redirect ( socket ,
227- external: Algora.Github . authorize_url ( % { return_to: "/#{ socket . assigns . current_org . handle } /jobs" } )
228- ) }
260+ # Not logged in, just redirect
261+ { :noreply , push_navigate ( socket , to: "/#{ org . handle } /job/#{ job_id } /apply" ) }
229262 end
230263 end
231264
0 commit comments