diff --git a/lib/algora_web/live/onboarding/dev.ex b/lib/algora_web/live/onboarding/dev.ex index 3a1a7b5f9..10d217c01 100644 --- a/lib/algora_web/live/onboarding/dev.ex +++ b/lib/algora_web/live/onboarding/dev.ex @@ -49,10 +49,6 @@ defmodule AlgoraWeb.Onboarding.DevLive do @impl true def mount(_params, _session, socket) do - if connected?(socket) do - Phoenix.PubSub.subscribe(Algora.PubSub, "auth:#{socket.id}") - end - context = %{ country: socket.assigns.current_country, tech_stack: [], @@ -94,6 +90,35 @@ defmodule AlgoraWeb.Onboarding.DevLive do |> assign(:signup_form, signup_form)} end + @impl true + def render(%{current_user: current_user} = assigns) when not is_nil(current_user) do + ~H""" +
+
+ + + + + + +
+
+ """ + end + @impl true def render(assigns) do ~H""" @@ -127,37 +152,37 @@ defmodule AlgoraWeb.Onboarding.DevLive do {:noreply, socket} end - @impl true - def handle_info({:authenticated, user}, socket) do - tech_stack = get_field(socket.assigns.info_form.source, :tech_stack) || [] - intentions = get_field(socket.assigns.info_form.source, :intentions) || [] - - case user - |> change( - tech_stack: tech_stack, - seeking_bounties: "bounties" in intentions, - seeking_contracts: "contracts" in intentions, - seeking_jobs: "jobs" in intentions - ) - |> Repo.update() do - {:ok, user} -> - {:noreply, redirect(socket, to: AlgoraWeb.UserAuth.generate_login_path(user.email))} - - {:error, changeset} -> - Logger.error("Failed to update user #{user.id} on onboarding: #{inspect(changeset)}") - {:noreply, put_flash(socket, :error, "Something went wrong. Please try again.")} - end - end - @impl true def handle_event("restore_settings", params, socket) do - {:noreply, LocalStore.restore(socket, params)} + socket = LocalStore.restore(socket, params) + + if user = socket.assigns[:current_user] do + tech_stack = get_field(socket.assigns.info_form.source, :tech_stack) || [] + intentions = get_field(socket.assigns.info_form.source, :intentions) || [] + + case user + |> change( + tech_stack: tech_stack, + seeking_bounties: "bounties" in intentions, + seeking_contracts: "contracts" in intentions, + seeking_jobs: "jobs" in intentions + ) + |> Repo.update() do + {:ok, user} -> + {:noreply, redirect(socket, to: AlgoraWeb.UserAuth.generate_login_path(user.email))} + + {:error, changeset} -> + Logger.error("Failed to update user #{user.id} on onboarding: #{inspect(changeset)}") + {:noreply, put_flash(socket, :error, "Something went wrong. Please try again.")} + end + else + {:noreply, socket} + end end @impl true def handle_event("sign_in_with_github", _params, socket) do - popup_url = Github.authorize_url(%{socket_id: socket.id}) - {:noreply, push_event(socket, "open_popup", %{url: popup_url})} + {:noreply, redirect(socket, external: Github.authorize_url(%{return_to: ~p"/onboarding/dev?checkpoint=1"}))} end @impl true diff --git a/lib/algora_web/router.ex b/lib/algora_web/router.ex index ed550554a..e6cf0d26d 100644 --- a/lib/algora_web/router.ex +++ b/lib/algora_web/router.ex @@ -133,7 +133,7 @@ defmodule AlgoraWeb.Router do end live_session :onboarding, - on_mount: [{AlgoraWeb.Analytics, :current_country}] do + on_mount: [{AlgoraWeb.Analytics, :current_country}, {AlgoraWeb.UserAuth, :current_user}] do live "/onboarding/org", Onboarding.OrgLive live "/onboarding/dev", Onboarding.DevLive live "/community", CommunityLive, :index