Skip to content

Commit

Permalink
feat: make consent form confirmable
Browse files Browse the repository at this point in the history
  • Loading branch information
MelchiorKokernoot committed Sep 26, 2024
1 parent 932860e commit b8bff56
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Systems.Assignment.ConfirmationModal do
defmodule Frameworks.Pixel.ConfirmationModal do
use CoreWeb, :live_component

@impl true
Expand Down
2 changes: 1 addition & 1 deletion core/systems/assignment/content_page_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions core/systems/assignment/gdpr_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"""
Expand Down

0 comments on commit b8bff56

Please sign in to comment.