Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/assets/stylesheets/components/_sweetalert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
background-color: transparent;
}

.swal-content {
input {
color: inherit;
background: transparent;
border: 1px solid rgba(150, 150, 150, 0.4);
border-radius: var(--radius-md, 6px);
padding: 8px 12px;
width: 100%;
}
}

.swal-button {
@extend .btn;
}
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ def transaction
elsif @canonical_transaction.amount_cents.abs >= 5_000_00 # $5k
"Are you really really sure you want to map this transaction? 🤔 it seems like a big one :)"
end

# If this transaction was already mapped a while ago, remapping it annoys Sierra's accounting system.

if @canonical_transaction.canonical_event_mapping.present? &&
@canonical_transaction.canonical_event_mapping.created_at < 12.hours.ago
@stale_remap = true
@remap_confirm_msg = "⚠️ This transaction was already mapped to \"#{@canonical_transaction.event&.name}\" #{helpers.time_ago_in_words(@canonical_transaction.canonical_event_mapping.created_at)} ago. Remapping it now may disrupt our accounting. Are you absolutely sure you want to remap this transaction?"
@remap_confirm_phrase = "REMAP #{@canonical_transaction.id}"
@remap_after_message = "Please contact Sierra and the HCB Ops team right away to let them know you remapped transaction ##{@canonical_transaction.id}."
@remap_warning_tooltip = "This transaction was already mapped #{helpers.time_ago_in_words(@canonical_transaction.canonical_event_mapping.created_at)} ago — remapping it requires extra confirmation."
end
end

def events
Expand Down
55 changes: 55 additions & 0 deletions app/javascript/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,69 @@ function showConfirm(
}).then(v => !!v)
}

async function showTypeToConfirm(
message,
phrase,
{ title = 'Are you sure?', afterMessage = null } = {}
) {
const warned = await swal({
title,
text: message,
icon: 'warning',
buttons: ['Cancel', "Yes, I'm sure"],
dangerMode: true,
})
if (!warned) return false

const typed = await swal({
title: 'Confirm by typing',
text: `Type "${phrase}" below to confirm:`,
content: {
element: 'input',
attributes: {
placeholder: phrase,
type: 'text',
},
},
buttons: ['Cancel', 'Confirm'],
dangerMode: true,
})
if (typed?.trim() !== phrase) {
if (typed !== null) {
await swal('Not confirmed', 'What you typed did not match.', 'error')
}
return false
}

if (afterMessage) {
await swal('One more thing', afterMessage, 'info')
}

return true
}

Turbo.config.forms.confirm = (message, formElement, submitter) => {
const dangerMode = Boolean(
submitter?.hasAttribute('data-turbo-confirm-danger') ||
formElement?.hasAttribute('data-turbo-confirm-danger')
)

const phrase =
submitter?.getAttribute('data-turbo-confirm-type-phrase') ||
formElement?.getAttribute('data-turbo-confirm-type-phrase')

if (phrase) {
const afterMessage =
submitter?.getAttribute('data-turbo-confirm-after-message') ||
formElement?.getAttribute('data-turbo-confirm-after-message')

return showTypeToConfirm(message, phrase, { afterMessage })
}

return showConfirm(message, { dangerMode })
}
window.showConfirm = showConfirm
window.showTypeToConfirm = showTypeToConfirm
window.swal = swal

export default showConfirm
10 changes: 9 additions & 1 deletion app/views/admin/transaction.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

<h1>Transaction <%= @canonical_transaction.id %></h1>

<% remap_confirm_data = @stale_remap ? {
"turbo-confirm-danger": true,
"turbo-confirm-type-phrase": @remap_confirm_phrase,
"turbo-confirm-after-message": @remap_after_message,
} : {} %>
<% remap_warning_icon = @stale_remap ? content_tag(:span, "⚠️", class: "tooltipped tooltipped--n ml-1", style: "cursor: help;", "aria-label": @remap_warning_tooltip) : "".html_safe %>

<table class="no-stripes <%= "admin-bg-pending" unless @canonical_transaction.canonical_event_mapping %>">
<tbody>
<tr>
Expand Down Expand Up @@ -85,7 +92,8 @@
<div class="flex flex-row gap-2">
<%= form_with model: false, local: true, url: set_event_path(@canonical_transaction), method: :post do |form| %>
<%= combobox_tag :event_id, event_search_admin_index_path, placeholder: "Select event", class: "!max-w-full !min-w-72", value: @canonical_transaction.event&.to_combobox_display %>
<%= form.submit "Set", data: { "turbo-confirm": @mapping_confirm_msg } %>
<%= form.submit "Set", data: remap_confirm_data.merge("turbo-confirm": @stale_remap ? @remap_confirm_msg : @mapping_confirm_msg) %>
<%= remap_warning_icon %>
<% end %>
</div>
<%= form_with url: set_event_path(@canonical_transaction), method: :post do |form| %>
Expand Down