Skip to content

Commit

Permalink
Implement user notes in CRM and HelpScout integration (plausible#4611)
Browse files Browse the repository at this point in the history
* Implement user notes in CRM and HelpScout integration

* Update HS tests

* Make slight markup and styling changes
  • Loading branch information
zoldar authored Sep 25, 2024
1 parent e11fd15 commit 9d997a7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions extra/lib/plausible/help_scout.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ defmodule Plausible.HelpScout do
{:ok,
%{
email: user.email,
notes: user.notes,
status_label: status_label(user),
status_link:
Routes.kaffy_resource_url(PlausibleWeb.Endpoint, :show, :auth, :user, user.id),
Expand Down
15 changes: 15 additions & 0 deletions extra/lib/plausible_web/views/help_scout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ defmodule PlausibleWeb.HelpScoutView do
<p class="label">
Owner of <b><a href={@sites_link} target="_blank"><%= @sites_count %> sites</a></b>
</p>
<p class="value"></p>
</div>
<div :if={@notes} class="notes">
<p class="label">
<b>Notes</b>
</p>
<div class="value">
<%= Phoenix.HTML.Format.text_to_html(@notes, escape: true) %>
</div>
</div>
<% end %>
</.layout>
Expand Down Expand Up @@ -140,6 +151,10 @@ defmodule PlausibleWeb.HelpScoutView do
margin-bottom: 1.25em;
font-weight: bold;
}
.notes .value {
font-weight: normal;
}
</style>
</head>
Expand Down
6 changes: 5 additions & 1 deletion lib/plausible/auth/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ defmodule Plausible.Auth.User do
field :previous_email, :string
field :accept_traffic_until, :date

# Field for purely informational purposes in CRM context
field :notes, :string

# A field only used as a manual override - allow subscribing
# to any plan, even when exceeding its pageview limit
field :allow_next_upgrade_override, :boolean
Expand Down Expand Up @@ -113,7 +116,8 @@ defmodule Plausible.Auth.User do
:theme,
:trial_expiry_date,
:allow_next_upgrade_override,
:accept_traffic_until
:accept_traffic_until,
:notes
])
|> validate_required([:email, :name, :email_verified])
|> maybe_bump_accept_traffic_until()
Expand Down
3 changes: 2 additions & 1 deletion lib/plausible/auth/user_admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ defmodule Plausible.Auth.UserAdmin do
allow_next_upgrade_override: nil,
accept_traffic_until: %{
help_text: "Change will take up to 15 minutes to propagate"
}
},
notes: %{type: :textarea, rows: 6}
]
end

Expand Down
8 changes: 5 additions & 3 deletions test/plausible_web/controllers/help_scout_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
end
end

describe "shows/2" do
describe "show/2" do
test "returns details on success", %{conn: conn} do
user = insert(:user, email: "[email protected]")
user = insert(:user, email: "[email protected]", notes: "Some note\nwith new line")

conn =
conn
Expand All @@ -115,7 +115,9 @@ defmodule PlausibleWeb.HelpScoutControllerTest do
"/helpscout/show?conversation_id=123&customer_id=500&[email protected]"
)

assert html_response(conn, 200) =~ "/crm/auth/user/#{user.id}"
assert html = html_response(conn, 200)
assert html =~ "/crm/auth/user/#{user.id}"
assert html =~ "Some note<br>\nwith new line"
end

test "returns error when cookie is missing", %{conn: conn} do
Expand Down

0 comments on commit 9d997a7

Please sign in to comment.