summaryrefslogtreecommitdiff
path: root/packages/anastasis-webui/src/pages/home/ReviewPoliciesScreen.tsx
blob: b360ccaf0d0213436031646e47a5de1c2dc92d0f (plain)
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
/* eslint-disable @typescript-eslint/camelcase */
import { h, VNode } from "preact";
import { useAnastasisContext } from "../../context/anastasis";
import { AnastasisClientFrame } from "./index";

export function ReviewPoliciesScreen(): VNode {
  const reducer = useAnastasisContext()
  if (!reducer) {
    return <div>no reducer in context</div>
  }
  if (!reducer.currentReducerState || reducer.currentReducerState.backup_state === undefined) {
    return <div>invalid state</div>
  }
  const authMethods = reducer.currentReducerState.authentication_methods ?? [];
  const policies = reducer.currentReducerState.policies ?? [];

  return (
    <AnastasisClientFrame title="Backup: Review Recovery Policies">
      {policies.map((p, policy_index) => {
        const methods = p.methods
          .map(x => authMethods[x.authentication_method] && ({ ...authMethods[x.authentication_method], provider: x.provider }))
          .filter(x => !!x)

        const policyName = methods.map(x => x.type).join(" + ");

        return (
          <div key={policy_index} class="policy">
            <h3>
              Policy #{policy_index + 1}: {policyName}
            </h3>
            Required Authentications:
            {!methods.length && <p>
              No auth method found
            </p>}
            <ul>
              {methods.map((m, i) => {
                return (
                  <li key={i}>
                    {m.type} ({m.instructions}) at provider {m.provider}
                  </li>
                );
              })}
            </ul>
            <div>
              <button
                onClick={() => reducer.transition("delete_policy", { policy_index })}
              >
                Delete Policy
              </button>
            </div>
          </div>
        );
      })}
    </AnastasisClientFrame>
  );
}