From b8bff5641f031244e7e1c200465268e7d7b4e22d Mon Sep 17 00:00:00 2001 From: MelchiorKokernoot Date: Thu, 26 Sep 2024 16:11:19 +0200 Subject: [PATCH] feat: make consent form confirmable --- .../pixel/components}/confirmation_modal.ex | 2 +- core/systems/assignment/content_page_form.ex | 2 +- core/systems/assignment/gdpr_form.ex | 35 +++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) rename core/{systems/assignment => frameworks/pixel/components}/confirmation_modal.ex (96%) 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"""