Require deliberate helper acceptance

This commit is contained in:
SimpleTest 2026-08-03 03:44:26 +03:00
parent 9b79f7b8de
commit c085620762
6 changed files with 264 additions and 20 deletions

View File

@ -20,6 +20,7 @@ defmodule WhoNeedHelpWeb.RequestLive.Show do
|> assign(:subscribed_assignment_id, nil) |> assign(:subscribed_assignment_id, nil)
|> assign(:tracking_presence_key, nil) |> assign(:tracking_presence_key, nil)
|> assign(:tracking_session_id, nil) |> assign(:tracking_session_id, nil)
|> assign(:accept_confirmation_open?, false)
|> assign(:native_client, native_client) |> assign(:native_client, native_client)
|> assign( |> assign(
:e2e_runtime_node, :e2e_runtime_node,
@ -142,12 +143,21 @@ defmodule WhoNeedHelpWeb.RequestLive.Show do
end end
@impl true @impl true
def handle_event("prepare-accept", _, socket) do
{:noreply, assign(socket, :accept_confirmation_open?, true)}
end
def handle_event("cancel-accept", _, socket) do
{:noreply, assign(socket, :accept_confirmation_open?, false)}
end
def handle_event("accept", _, socket) do def handle_event("accept", _, socket) do
case Help.accept_request(socket.assigns.current_scope, socket.assigns.request.id) do case Help.accept_request(socket.assigns.current_scope, socket.assigns.request.id) do
{:ok, _} -> {:ok, _} ->
{:noreply, {:noreply,
put_action_flash( socket
socket, |> assign(:accept_confirmation_open?, false)
|> put_action_flash(
:info, :info,
gettext("You accepted this request. Use private chat to coordinate safely.") gettext("You accepted this request. Use private chat to coordinate safely.")
)} )}
@ -1312,11 +1322,66 @@ defmodule WhoNeedHelpWeb.RequestLive.Show do
<%= cond do %> <%= cond do %>
<% @request.status == :open && @request.requester_id != @current_scope.user.id -> %> <% @request.status == :open && @request.requester_id != @current_scope.user.id -> %>
<p class="mt-2 text-sm opacity-70"> <p class="mt-2 text-sm opacity-70">
{gettext("Accept only if you can complete this safely and for free.")} {gettext(
"Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
)}
</p> </p>
<button phx-click="accept" class="btn btn-success mt-4 w-full"> <%= if @accept_confirmation_open? do %>
<section
id="accept-request-confirmation"
class="mt-4 rounded-2xl border border-white/20 bg-white/10 p-4"
aria-labelledby="accept-request-confirmation-title"
tabindex="-1"
phx-mounted={JS.focus()}
>
<h3 id="accept-request-confirmation-title" class="font-bold">
{gettext("Before you accept")}
</h3>
<ul class="mt-3 list-disc space-y-2 pl-5 text-sm text-neutral-content/80">
<li>
{gettext("This request will be assigned to you and private chat will open.")}
</li>
<li>
{gettext("An exact location appears only if the requester chose to share it.")}
</li>
<li>
{gettext(
"If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
)}
</li>
<li>
{gettext(
"You can withdraw later, but please tell the requester as soon as possible."
)}
</li>
</ul>
<div class="mt-4 grid gap-2">
<button
id="confirm-accept-request"
phx-click="accept"
class="btn btn-success w-full"
phx-disable-with={gettext("Accepting…")}
>
{gettext("Confirm — I can help")}
</button>
<button
id="cancel-accept-request"
phx-click="cancel-accept"
class="btn btn-ghost border-white/20 text-neutral-content hover:bg-white/10"
>
{gettext("Not now")}
</button>
</div>
</section>
<% else %>
<button
id="prepare-accept-request"
phx-click="prepare-accept"
class="btn btn-success mt-4 w-full"
>
{gettext("I can help")} {gettext("I can help")}
</button> </button>
<% end %>
<% @request.status == :open -> %> <% @request.status == :open -> %>
<p class="mt-3 text-sm opacity-70"> <p class="mt-3 text-sm opacity-70">
{gettext("Waiting for a nearby volunteer.")} {gettext("Waiting for a nearby volunteer.")}

View File

@ -141,9 +141,49 @@ msgstr ""
msgid "A signal requests human review; optional tracking absence is not proof of abuse." msgid "A signal requests human review; optional tracking absence is not proof of abuse."
msgstr "" msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1316 #: lib/who_need_help_web/live/request_live/show.ex:1325
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Accept only if you can complete this safely and for free." msgid "Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1337
#, elixir-autogen, elixir-format
msgid "Before you accept"
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1343
#, elixir-autogen, elixir-format
msgid "This request will be assigned to you and private chat will open."
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1349
#, elixir-autogen, elixir-format
msgid "An exact location appears only if the requester chose to share it."
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1355
#, elixir-autogen, elixir-format
msgid "If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1361
#, elixir-autogen, elixir-format
msgid "You can withdraw later, but please tell the requester as soon as possible."
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1372
#, elixir-autogen, elixir-format
msgid "Accepting…"
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1374
#, elixir-autogen, elixir-format
msgid "Confirm — I can help"
msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:1382
#, elixir-autogen, elixir-format
msgid "Not now"
msgstr "" msgstr ""
#: lib/who_need_help_web/live/request_live/show.ex:953 #: lib/who_need_help_web/live/request_live/show.ex:953

View File

@ -141,10 +141,50 @@ msgstr "A link to confirm your email change has been sent to the new address."
msgid "A signal requests human review; optional tracking absence is not proof of abuse." msgid "A signal requests human review; optional tracking absence is not proof of abuse."
msgstr "A signal requests human review; optional tracking absence is not proof of abuse." msgstr "A signal requests human review; optional tracking absence is not proof of abuse."
#: lib/who_need_help_web/live/request_live/show.ex:1316 #: lib/who_need_help_web/live/request_live/show.ex:1325
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Accept only if you can complete this safely and for free." msgid "Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
msgstr "Accept only if you can complete this safely and for free." msgstr "Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
#: lib/who_need_help_web/live/request_live/show.ex:1337
#, elixir-autogen, elixir-format
msgid "Before you accept"
msgstr "Before you accept"
#: lib/who_need_help_web/live/request_live/show.ex:1343
#, elixir-autogen, elixir-format
msgid "This request will be assigned to you and private chat will open."
msgstr "This request will be assigned to you and private chat will open."
#: lib/who_need_help_web/live/request_live/show.ex:1349
#, elixir-autogen, elixir-format
msgid "An exact location appears only if the requester chose to share it."
msgstr "An exact location appears only if the requester chose to share it."
#: lib/who_need_help_web/live/request_live/show.ex:1355
#, elixir-autogen, elixir-format
msgid "If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
msgstr "If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
#: lib/who_need_help_web/live/request_live/show.ex:1361
#, elixir-autogen, elixir-format
msgid "You can withdraw later, but please tell the requester as soon as possible."
msgstr "You can withdraw later, but please tell the requester as soon as possible."
#: lib/who_need_help_web/live/request_live/show.ex:1372
#, elixir-autogen, elixir-format
msgid "Accepting…"
msgstr "Accepting…"
#: lib/who_need_help_web/live/request_live/show.ex:1374
#, elixir-autogen, elixir-format
msgid "Confirm — I can help"
msgstr "Confirm — I can help"
#: lib/who_need_help_web/live/request_live/show.ex:1382
#, elixir-autogen, elixir-format
msgid "Not now"
msgstr "Not now"
#: lib/who_need_help_web/live/request_live/show.ex:953 #: lib/who_need_help_web/live/request_live/show.ex:953
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format

View File

@ -145,11 +145,50 @@ msgstr ""
"Сигнал требует проверки человеком; отсутствие необязательного отслеживания " "Сигнал требует проверки человеком; отсутствие необязательного отслеживания "
"не является доказательством злоупотребления." "не является доказательством злоупотребления."
#: lib/who_need_help_web/live/request_live/show.ex:1316 #: lib/who_need_help_web/live/request_live/show.ex:1325
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Accept only if you can complete this safely and for free." msgid "Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
msgstr "" msgstr "Принимайте заявку, только если можете помочь безопасно и добровольно. Who Need Help не обрабатывает платежи."
"Принимайте заявку, только если можете безопасно и бесплатно её выполнить."
#: lib/who_need_help_web/live/request_live/show.ex:1337
#, elixir-autogen, elixir-format
msgid "Before you accept"
msgstr "Перед принятием"
#: lib/who_need_help_web/live/request_live/show.ex:1343
#, elixir-autogen, elixir-format
msgid "This request will be assigned to you and private chat will open."
msgstr "Эта заявка будет закреплена за вами, и откроется приватный чат."
#: lib/who_need_help_web/live/request_live/show.ex:1349
#, elixir-autogen, elixir-format
msgid "An exact location appears only if the requester chose to share it."
msgstr "Точное местоположение появится, только если заявитель решил им поделиться."
#: lib/who_need_help_web/live/request_live/show.ex:1355
#, elixir-autogen, elixir-format
msgid "If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
msgstr "Если потребуется покупка или возмещение расходов, договоритесь об этом напрямую в чате до того, как потратите деньги."
#: lib/who_need_help_web/live/request_live/show.ex:1361
#, elixir-autogen, elixir-format
msgid "You can withdraw later, but please tell the requester as soon as possible."
msgstr "Позже можно отказаться, но, пожалуйста, сообщите заявителю как можно скорее."
#: lib/who_need_help_web/live/request_live/show.ex:1372
#, elixir-autogen, elixir-format
msgid "Accepting…"
msgstr "Принимаем…"
#: lib/who_need_help_web/live/request_live/show.ex:1374
#, elixir-autogen, elixir-format
msgid "Confirm — I can help"
msgstr "Подтвердить — я помогу"
#: lib/who_need_help_web/live/request_live/show.ex:1382
#, elixir-autogen, elixir-format
msgid "Not now"
msgstr "Не сейчас"
#: lib/who_need_help_web/live/request_live/show.ex:953 #: lib/who_need_help_web/live/request_live/show.ex:953
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format

View File

@ -145,11 +145,50 @@ msgstr ""
"Сигнал потребує перевірки людиною; відсутність необов’язкового відстеження " "Сигнал потребує перевірки людиною; відсутність необов’язкового відстеження "
"не є доказом зловживання." "не є доказом зловживання."
#: lib/who_need_help_web/live/request_live/show.ex:1316 #: lib/who_need_help_web/live/request_live/show.ex:1325
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Accept only if you can complete this safely and for free." msgid "Accept only if you can help safely and voluntarily. Who Need Help does not process payments."
msgstr "" msgstr "Приймайте заявку, лише якщо можете допомогти безпечно й добровільно. Who Need Help не обробляє платежі."
"Приймайте заявку, лише якщо можете безпечно й безкоштовно її виконати."
#: lib/who_need_help_web/live/request_live/show.ex:1337
#, elixir-autogen, elixir-format
msgid "Before you accept"
msgstr "Перед прийняттям"
#: lib/who_need_help_web/live/request_live/show.ex:1343
#, elixir-autogen, elixir-format
msgid "This request will be assigned to you and private chat will open."
msgstr "Цю заявку буде закріплено за вами, і відкриється приватний чат."
#: lib/who_need_help_web/live/request_live/show.ex:1349
#, elixir-autogen, elixir-format
msgid "An exact location appears only if the requester chose to share it."
msgstr "Точне місцеперебування з’явиться, лише якщо заявник вирішив ним поділитися."
#: lib/who_need_help_web/live/request_live/show.ex:1355
#, elixir-autogen, elixir-format
msgid "If a purchase or reimbursement is involved, agree on it directly in chat before spending money."
msgstr "Якщо потрібна покупка або відшкодування витрат, домовтеся про це безпосередньо в чаті до того, як витрачати гроші."
#: lib/who_need_help_web/live/request_live/show.ex:1361
#, elixir-autogen, elixir-format
msgid "You can withdraw later, but please tell the requester as soon as possible."
msgstr "Пізніше можна відмовитися, але, будь ласка, повідомте заявника якомога швидше."
#: lib/who_need_help_web/live/request_live/show.ex:1372
#, elixir-autogen, elixir-format
msgid "Accepting…"
msgstr "Приймаємо…"
#: lib/who_need_help_web/live/request_live/show.ex:1374
#, elixir-autogen, elixir-format
msgid "Confirm — I can help"
msgstr "Підтвердити — я допоможу"
#: lib/who_need_help_web/live/request_live/show.ex:1382
#, elixir-autogen, elixir-format
msgid "Not now"
msgstr "Не зараз"
#: lib/who_need_help_web/live/request_live/show.ex:953 #: lib/who_need_help_web/live/request_live/show.ex:953
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format

View File

@ -1194,7 +1194,28 @@ defmodule WhoNeedHelpWeb.MutualAidLiveTest do
) )
helper_view helper_view
|> element("button[phx-click='accept']") |> element("#prepare-accept-request")
|> render_click()
assert has_element?(helper_view, "#accept-request-confirmation")
assert has_element?(helper_view, "#confirm-accept-request")
assert has_element?(helper_view, "#cancel-accept-request")
assert is_nil(Repo.get_by(WhoNeedHelp.Help.Assignment, request_id: request.id))
helper_view
|> element("#cancel-accept-request")
|> render_click()
refute has_element?(helper_view, "#accept-request-confirmation")
assert has_element?(helper_view, "#prepare-accept-request")
assert is_nil(Repo.get_by(WhoNeedHelp.Help.Assignment, request_id: request.id))
helper_view
|> element("#prepare-accept-request")
|> render_click()
helper_view
|> element("#confirm-accept-request")
|> render_click() |> render_click()
assert render(helper_view) =~ assert render(helper_view) =~