chore(portal): Show support options on the billing page and remove features table (#4559)

Closes https://github.com/firezone/gtm/issues/237

<img width="1728" alt="Screenshot 2024-04-09 at 12 15 53"
src="https://github.com/firezone/firezone/assets/1877644/594a765d-363e-424d-bd70-0d9e1b1f50fa">
This commit is contained in:
Andrew Dryga
2024-04-09 14:42:48 -06:00
committed by GitHub
parent 3de0140fc1
commit 0b1ffd1339
8 changed files with 111 additions and 47 deletions

View File

@@ -17,6 +17,7 @@ defmodule Domain.Accounts.Account do
field :subscription_id, :string
field :product_name, :string
field :billing_email, :string
field :support_type, :string
end
end

View File

@@ -89,7 +89,13 @@ defmodule Domain.Accounts.Account.Changeset do
def stripe_metadata_changeset(stripe \\ %Account.Metadata.Stripe{}, attrs) do
stripe
|> cast(attrs, [:customer_id, :subscription_id, :product_name, :billing_email])
|> cast(attrs, [
:customer_id,
:subscription_id,
:product_name,
:billing_email,
:support_type
])
end
def validate_account_id_or_slug(account_id_or_slug) do

View File

@@ -176,12 +176,9 @@ defmodule Domain.Billing.EventHandler do
}} = Billing.fetch_product(product_id)
attrs =
account_update_attrs(quantity, product_metadata, subscription_metadata)
|> Map.put(:metadata, %{
stripe: %{
subscription_id: subscription_id,
product_name: product_name
}
account_update_attrs(quantity, product_metadata, subscription_metadata, %{
"subscription_id" => subscription_id,
"product_name" => product_name
})
|> Map.put(:disabled_at, nil)
|> Map.put(:disabled_reason, nil)
@@ -333,10 +330,16 @@ defmodule Domain.Billing.EventHandler do
end
end
defp account_update_attrs(quantity, product_metadata, subscription_metadata) do
defp account_update_attrs(
quantity,
product_metadata,
subscription_metadata,
stripe_metadata_overrides
) do
limit_fields = Accounts.Limits.__schema__(:fields) |> Enum.map(&to_string/1)
metadata_fields = ["support_type"]
features_and_limits =
params =
Map.merge(product_metadata, subscription_metadata)
|> Enum.flat_map(fn
{feature, "true"} ->
@@ -346,21 +349,28 @@ defmodule Domain.Billing.EventHandler do
[{feature, false}]
{key, value} ->
if key in limit_fields do
[{key, cast_limit(value)}]
else
[]
cond do
key in limit_fields ->
[{key, cast_limit(value)}]
key in metadata_fields ->
[{key, value}]
true ->
[]
end
end)
|> Enum.into(%{})
{users_count, features_and_limits} = Map.pop(features_and_limits, "users_count", quantity)
{limits, features} = Map.split(features_and_limits, limit_fields)
{users_count, params} = Map.pop(params, "users_count", quantity)
{metadata, params} = Map.split(params, metadata_fields)
{limits, features} = Map.split(params, limit_fields)
limits = Map.merge(limits, %{"users_count" => users_count})
%{
features: features,
limits: limits
limits: limits,
metadata: %{stripe: Map.merge(metadata, stripe_metadata_overrides)}
}
end

View File

@@ -41,7 +41,8 @@ account =
customer_id: "cus_PZKIfcHB6SSBA4",
subscription_id: "sub_1OkGm2ADeNU9NGxvbrCCw6m3",
product_name: "Enterprise",
billing_email: "fin@firez.one"
billing_email: "fin@firez.one",
support_type: "email"
}
},
limits: %{

View File

@@ -765,7 +765,7 @@ defmodule Domain.BillingTest do
assert account.disabled_reason == nil
end
test "updates account features and limits on subscription update", %{
test "updates account on subscription update", %{
account: account,
customer_id: customer_id
} do
@@ -778,7 +778,8 @@ defmodule Domain.BillingTest do
"monthly_active_users_count" => "15",
"service_accounts_count" => "unlimited",
"gateway_groups_count" => 1,
"users_count" => 14
"users_count" => 14,
"support_type" => "email"
}
})
@@ -804,6 +805,7 @@ defmodule Domain.BillingTest do
assert account.metadata.stripe.customer_id == customer_id
assert account.metadata.stripe.subscription_id
assert account.metadata.stripe.product_name == "Enterprise"
assert account.metadata.stripe.support_type == "email"
assert account.limits == %Domain.Accounts.Limits{
monthly_active_users_count: 15,

View File

@@ -1108,25 +1108,31 @@ defmodule Web.CoreComponents do
def feature_name(%{feature: :flow_activities} = assigns) do
~H"""
See detailed flow activities <span>(beta)</span>
See detailed Resource access logs
"""
end
def feature_name(%{feature: :multi_site_resources} = assigns) do
~H"""
Define globally-distributed resources <span>(beta)</span>
Define globally-distributed resources
"""
end
def feature_name(%{feature: :traffic_filters} = assigns) do
~H"""
Filter traffic using protocol and port rules <span>(beta)</span>
Restrict access based on port and protocol rules
"""
end
def feature_name(%{feature: :self_hosted_relays} = assigns) do
~H"""
Host your own relays <span>(beta)</span>
Host your own relays
"""
end
def feature_name(%{feature: :rest_api} = assigns) do
~H"""
REST API
"""
end

View File

@@ -84,7 +84,19 @@ defmodule Web.Settings.Billing do
<%= @account.metadata.stripe.billing_email %>
</:value>
</.vertical_table_row>
</.vertical_table>
</:content>
</.section>
<.section>
<:title>
Limits
</:title>
<:help>
Upgrade your plan to increase the limits below.
</:help>
<:content>
<.vertical_table id="billing-limits">
<.vertical_table_row :if={not is_nil(@account.limits.users_count)}>
<:label>
<p>Users</p>
@@ -166,32 +178,51 @@ defmodule Web.Settings.Billing do
<.section>
<:title>
Enabled Enterprise Features
Support
</:title>
<:help>
For further details on enrolling in beta features, reach out to your account manager
</:help>
<:content>
<.vertical_table id="features">
<.vertical_table_row :for={
{key, _value} <- Map.delete(Map.from_struct(@account.features), :limits)
}>
<:label><.feature_name feature={key} /></:label>
<:value>
<% value = apply(Domain.Accounts, :"#{key}_enabled?", [@account]) %>
<.icon
:if={value == true}
name="hero-check"
class="inline-block w-5 h-5 mr-1 text-green-500"
/>
<.icon
:if={value == false}
name="hero-x-mark"
class="inline-block w-5 h-5 mr-1 text-red-500"
/>
</:value>
</.vertical_table_row>
</.vertical_table>
<div class="ml-4 mb-4 text-neutral-600">
<span :if={@account.metadata.stripe.support_type == "email"}>
Please send
<.link
class={link_style()}
target="_blank"
href={
mailto_support(
@account,
@subject,
"Support request: #{@account.name}"
)
}
>
an email
</.link>
and we will get back to you as soon as possible.
</span>
<span :if={@account.metadata.stripe.support_type == "email_and_slack"}>
Please send us a message in the shared Slack channel or <.link
class={link_style()}
target="_blank"
href={
mailto_support(
@account,
@subject,
"Support request: #{@account.name}"
)
}
>an email</.link>.
</span>
<span :if={@account.metadata.stripe.support_type not in ["email", "email_and_slack"]}>
Ask questions, get help from other Firezone users on
<.link class={link_style()} href="https://discourse.firez.one/">
Discourse
</.link>
or <.link class={link_style()} href="https://firez.slack.com/">Slack</.link>.
Priority email and dedicated Slack support options are available on paid plans.
</span>
</div>
</:content>
</.section>

View File

@@ -76,6 +76,13 @@ defmodule Web.Live.Settings.BillingTest do
assert rows["billing email"] =~ account.metadata.stripe.billing_email
assert rows["current plan"] =~ account.metadata.stripe.product_name
rows =
lv
|> element("#billing-limits")
|> render()
|> vertical_table_to_map()
assert rows["users"] =~ "1 used / 200 allowed"
assert rows["seats"] =~ "0 used / 100 allowed"
assert rows["sites"] =~ "0 used / 10 allowed"