diff --git a/assets/css/components/field.css b/assets/css/components/field.css index 6a2f958f..48f1291e 100644 --- a/assets/css/components/field.css +++ b/assets/css/components/field.css @@ -129,7 +129,7 @@ /* Text */ .safira-text-input { - @apply block w-full rounded-md text-dark border border-lightShade placeholder:text-darkMuted focus:outline-2 focus:border-lightShade ring-0 focus:outline-dark focus:outline-offset-2 dark:outline-darkShade dark:bg-dark dark:text-light dark:placeholder-lightMuted dark:focus:border-darkShade dark:border-darkShade focus:ring-0 dark:focus:outline-light; + @apply block w-full rounded-md text-dark border border-lightShade placeholder:text-darkMuted focus:outline-2 focus:border-lightShade ring-0 focus:outline-dark focus:outline-offset-2 dark:outline-darkShade dark:bg-dark dark:text-light dark:placeholder-lightMuted dark:focus:border-darkShade dark:border-darkShade focus:ring-0 dark:focus:outline-light dark:[color-scheme:dark]; } /* Code */ diff --git a/lib/safira/activities/activity.ex b/lib/safira/activities/activity.ex index c3749e15..de18cf45 100644 --- a/lib/safira/activities/activity.ex +++ b/lib/safira/activities/activity.ex @@ -5,11 +5,22 @@ defmodule Safira.Activities.Activity do use Safira.Schema @required_fields ~w(title date time_start time_end)a - @optional_fields ~w(description category_id location has_enrolments)a + @optional_fields ~w(description category_id location has_enrolments max_enrolments)a @derive { Flop.Schema, - filterable: [:title], sortable: [:title, :date], default_limit: 11 + filterable: [:title], + sortable: [:timestamp], + default_limit: 11, + adapter_opts: [ + compound_fields: [ + timestamp: [:date, :time_start] + ] + ], + default_order: %{ + order_by: [:timestamp], + order_directions: [:asc] + } } schema "activities" do @@ -20,6 +31,7 @@ defmodule Safira.Activities.Activity do field :time_start, :time field :time_end, :time field :has_enrolments, :boolean, default: false + field :max_enrolments, :integer, default: 0 belongs_to :category, Safira.Activities.ActivityCategory diff --git a/lib/safira_web/live/backoffice/schedule_live/form_component.ex b/lib/safira_web/live/backoffice/schedule_live/form_component.ex index 180a0057..2eeacdc4 100644 --- a/lib/safira_web/live/backoffice/schedule_live/form_component.ex +++ b/lib/safira_web/live/backoffice/schedule_live/form_component.ex @@ -45,20 +45,39 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.FormComponent do wrapper_class="col-span-1" /> + <.field + field={@form[:category_id]} + type="select" + label="Category" + options={categories_options(@categories)} + wrapper_class="w-full" + />
- <.field - field={@form[:category_id]} - type="select" - label="Category" - options={categories_options(@categories)} - wrapper_class="w-full" - /> - <.field - field={@form[:has_enrolments]} - type="checkbox" - label="Requires enrolment" - wrapper_class="w-full" - /> +
+
+ <.label> + <%= gettext("Enrolments") %> + +

+ <%= gettext( + "Enable enrolments to allow participants to sign up for this activity." + ) %> +

+ <.field + field={@form[:has_enrolments]} + type="switch" + label="" + wrapper_class="w-full pt-3" + /> +
+ <.field + :if={@enrolments_active} + field={@form[:max_enrolments]} + type="number" + label="Max enrolments" + wrapper_class="w-full" + /> +
<:actions> @@ -80,6 +99,7 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.FormComponent do {:ok, socket |> assign(assigns) + |> assign(:enrolments_active, activity.has_enrolments) |> assign_new(:form, fn -> to_form(Activities.change_activity(activity)) end)} @@ -88,7 +108,12 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.FormComponent do @impl true def handle_event("validate", %{"activity" => activity_params}, socket) do changeset = Activities.change_activity(socket.assigns.activity, activity_params) - {:noreply, assign(socket, form: to_form(changeset, action: :validate))} + + {:noreply, + assign(socket, + form: to_form(changeset, action: :validate), + enrolments_active: activity_params["has_enrolments"] != "false" + )} end def handle_event("save", %{"activity" => activity_params}, socket) do diff --git a/lib/safira_web/live/backoffice/schedule_live/index.html.heex b/lib/safira_web/live/backoffice/schedule_live/index.html.heex index bef2ac0d..ad87abf8 100644 --- a/lib/safira_web/live/backoffice/schedule_live/index.html.heex +++ b/lib/safira_web/live/backoffice/schedule_live/index.html.heex @@ -29,10 +29,10 @@ <:col :let={{_id, activity}} sortable field={:title} label="Title"> <%= activity.title %> - <:col :let={{_id, activity}} sortable field={:date} label="Date"> + <:col :let={{_id, activity}} sortable field={:timestamp} label="Date"> <%= Timex.format!(activity.date, "{D}/{M}/{YYYY}") %> - <:col :let={{_id, activity}} sortable field={:time} label="Time"> + <:col :let={{_id, activity}} field={:time} label="Time"> <%= formatted_activity_times(activity) %> <:col :let={{_id, activity}} field={:category} label="Category"> diff --git a/priv/repo/migrations/20241028131718_create_activities.exs b/priv/repo/migrations/20241028131718_create_activities.exs index 19b37b5f..0542d29e 100644 --- a/priv/repo/migrations/20241028131718_create_activities.exs +++ b/priv/repo/migrations/20241028131718_create_activities.exs @@ -5,12 +5,13 @@ defmodule Safira.Repo.Migrations.CreateActivities do create table(:activities, primary_key: false) do add :id, :binary_id, primary_key: true add :title, :string, null: false - add :description, :string + add :description, :text add :location, :string add :date, :date, null: false add :time_start, :time, null: false add :time_end, :time, null: false add :has_enrolments, :boolean, default: false, null: false + add :max_enrolments, :integer, default: 0, null: false add :category_id, references(:activity_categories, on_delete: :nothing, type: :binary_id) timestamps(type: :utc_datetime)