diff --git a/core/systems/assignment/confirmation_modal.ex b/core/frameworks/pixel/components/confirmation_modal.ex similarity index 96% rename from core/systems/assignment/confirmation_modal.ex rename to core/frameworks/pixel/components/confirmation_modal.ex index 2a7abb07a..3738c155b 100644 --- a/core/systems/assignment/confirmation_modal.ex +++ b/core/frameworks/pixel/components/confirmation_modal.ex @@ -1,4 +1,4 @@ -defmodule Systems.Assignment.ConfirmationModal do +defmodule Frameworks.Pixel.ConfirmationModal do use CoreWeb, :live_component @impl true diff --git a/core/systems/assignment/content_page_form.ex b/core/systems/assignment/content_page_form.ex index b0e2a9ef9..4e80cadcb 100644 --- a/core/systems/assignment/content_page_form.ex +++ b/core/systems/assignment/content_page_form.ex @@ -67,7 +67,7 @@ defmodule Systems.Assignment.ContentPageForm do @impl true def compose(:confirmation_modal, %{page_ref: page_ref}) do %{ - module: Systems.Assignment.ConfirmationModal, + module: Pixel.ConfirmationModal, params: %{ assigns: %{ page_ref: page_ref diff --git a/core/systems/assignment/gdpr_form.ex b/core/systems/assignment/gdpr_form.ex index ff3a4c66f..e71f00526 100644 --- a/core/systems/assignment/gdpr_form.ex +++ b/core/systems/assignment/gdpr_form.ex @@ -55,6 +55,18 @@ defmodule Systems.Assignment.GdprForm do } end + @impl true + def compose(:confirmation_modal, %{entity: %{consent_agreement: consent_agreement}}) do + %{ + module: Pixel.ConfirmationModal, + params: %{ + assigns: %{ + consent_agreement: consent_agreement + } + } + } + end + @impl true def handle_event( "update", @@ -71,15 +83,32 @@ defmodule Systems.Assignment.GdprForm do end @impl true - def handle_event("update", %{status: :off}, %{assigns: %{entity: assignment}} = socket) do - {:ok, _} = Assignment.Public.update_consent_agreement(assignment, nil) - + def handle_event("update", %{status: :off}, socket) do { :noreply, socket + |> compose_child(:confirmation_modal) + |> show_modal(:confirmation_modal, :dialog) } end + @impl true + def handle_event("cancelled", %{source: %{name: :confirmation_modal}}, socket) do + {:noreply, + socket + |> hide_modal(:confirmation_modal)} + end + + @impl true + def handle_event( + "confirmed", + %{source: %{name: :confirmation_modal}}, + %{assigns: %{entity: assignment}} = socket + ) do + {:ok, _} = Assignment.Public.update_consent_agreement(assignment, nil) + {:noreply, socket |> hide_modal(:confirmation_modal)} + end + @impl true def render(assigns) do ~H"""