File size: 1,407 Bytes
88211d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
defmodule PlausibleWeb.Flows do
  @moduledoc """
  Static compile-time definitions for user progress flows.
  See `PlausibleWeb.Components.FlowProgress` for rendering capabilities.
  """

  @flows %{
    review: [
      "Install Plausible",
      "Verify installation"
    ],
    domain_change: [
      "Set up new domain",
      "Install Plausible",
      "Verify installation"
    ],
    register: [
      "Add site info",
      "Install Plausible",
      "Verify installation"
    ],
    invitation: [
      "Register",
      "Activate account"
    ],
    provisioning: [
      "Add site info",
      "Install Plausible",
      "Verify installation"
    ]
  }

  @valid_values @flows
                |> Enum.flat_map(fn {_, steps} -> steps end)
                |> Enum.uniq()

  @valid_keys @flows
              |> Map.keys()
              |> Enum.map(&to_string/1)

  @spec steps(binary() | atom()) :: list(binary())
  def steps(flow) when flow in @valid_keys do
    steps(String.to_existing_atom(flow))
  end

  def steps(flow) when is_atom(flow) do
    Map.get(@flows, flow, [])
  end

  def steps(_), do: []

  @spec valid_values() :: list(binary())
  def valid_values(), do: @valid_values

  @spec valid_values() :: list(binary())
  def valid_keys(), do: @valid_keys

  for {flow, _} <- @flows do
    @spec unquote(flow)() :: binary()
    def unquote(flow)(), do: unquote(to_string(flow))
  end
end