diff --git a/lib/shift73k/accounts.ex b/lib/shift73k/accounts.ex index 9edde8c4..199a52b3 100644 --- a/lib/shift73k/accounts.ex +++ b/lib/shift73k/accounts.ex @@ -39,6 +39,10 @@ defmodule Shift73k.Accounts do Repo.get_by(User, email: email) end + def get_user_by_calendar_slug(slug) when is_binary(slug) do + Repo.get_by(User, calendar_slug: slug) + end + @doc """ Gets a user by email and password. diff --git a/lib/shift73k_web/controllers/user_shifts_csv_controller.ex b/lib/shift73k_web/controllers/user_shifts_csv_controller.ex index 60783bfe..38a93651 100644 --- a/lib/shift73k_web/controllers/user_shifts_csv_controller.ex +++ b/lib/shift73k_web/controllers/user_shifts_csv_controller.ex @@ -5,7 +5,7 @@ defmodule Shift73kWeb.UserShiftsCsvController do alias Shift73k.Shifts.Shift def new(conn, _params) do - render(conn, "new.html", error_message: nil) + render(conn, "new.html") end def export(conn, %{"csv_export" => request_params}) do diff --git a/lib/shift73k_web/controllers/user_shifts_ics_controller.ex b/lib/shift73k_web/controllers/user_shifts_ics_controller.ex new file mode 100644 index 00000000..888a5230 --- /dev/null +++ b/lib/shift73k_web/controllers/user_shifts_ics_controller.ex @@ -0,0 +1,16 @@ +defmodule Shift73kWeb.UserShiftsIcsController do + use Shift73kWeb, :controller + + alias Shift73k.Accounts + alias Shift73k.Accounts.User + + def index(conn, %{"slug" => slug}) do + case Accounts.get_user_by_calendar_slug(slug) do + %User{} = user -> + render(conn, "index.html", slug: slug, user: user) + + _ -> + send_resp(conn, 404, "Not found") + end + end +end diff --git a/lib/shift73k_web/live/user/settings/calendar_url.ex b/lib/shift73k_web/live/user/settings/calendar_url.ex index ea621ca7..06e02ff3 100644 --- a/lib/shift73k_web/live/user/settings/calendar_url.ex +++ b/lib/shift73k_web/live/user/settings/calendar_url.ex @@ -9,24 +9,8 @@ defmodule Shift73kWeb.UserLive.Settings.CalendarUrl do |> assign(id: assigns.id) |> assign(current_user: user) |> live_okreply() - - # |> assign(form_week_start_at: user.week_start_at) end - # def week_start_options do - # week_start = Date.beginning_of_week(Date.utc_today(), hd(weekdays())) - - # week_start - # |> Date.range(Date.add(week_start, 6)) - # |> Enum.map(&Calendar.strftime(&1, "%A")) - # |> Enum.zip(weekdays()) - # end - - # @impl true - # def handle_event("changed", %{"calendar_view" => %{"week_start_at" => day}}, socket) do - # {:noreply, assign(socket, form_week_start_at: String.to_existing_atom(day))} - # end - @impl true def handle_event("save", _params, socket) do Accounts.change_user_calendar_slug(socket.assigns.current_user.id) diff --git a/lib/shift73k_web/live/user/settings/calendar_url.html.leex b/lib/shift73k_web/live/user/settings/calendar_url.html.leex index 2361caa7..a1f8b10f 100644 --- a/lib/shift73k_web/live/user/settings/calendar_url.html.leex +++ b/lib/shift73k_web/live/user/settings/calendar_url.html.leex @@ -8,26 +8,4 @@ <%= submit "Generate new", class: "btn btn-primary" %> <% end %> - <%#= form_for :calendar_view, "#", [phx_change: :changed, phx_submit: :save, phx_target: @myself], fn cvf -> %> - - <%#= label cvf, :week_start_at, class: "form-label" %> - <%#
Shifts for user: <%= @user.email %>
+Calendar slug: <%= @slug %>
+ + +