2021-10-19 15:56:52 +02:00
|
|
|
/* eslint-disable @typescript-eslint/camelcase */
|
|
|
|
import { h, VNode } from "preact";
|
2021-10-22 06:31:46 +02:00
|
|
|
import { useAnastasisContext } from "../../context/anastasis";
|
|
|
|
import { AnastasisClientFrame } from "./index";
|
2021-11-01 20:10:49 +01:00
|
|
|
import { authMethods, KnownAuthMethods } from "./authMethodSetup";
|
2021-10-22 06:31:46 +02:00
|
|
|
|
|
|
|
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>
|
|
|
|
}
|
2021-11-01 20:10:49 +01:00
|
|
|
const configuredAuthMethods = reducer.currentReducerState.authentication_methods ?? [];
|
2021-10-22 06:31:46 +02:00
|
|
|
const policies = reducer.currentReducerState.policies ?? [];
|
2021-10-19 15:56:52 +02:00
|
|
|
|
2021-11-01 20:10:49 +01:00
|
|
|
const errors = policies.length < 1 ? 'Need more policies' : undefined
|
2021-10-19 15:56:52 +02:00
|
|
|
return (
|
2021-11-01 20:10:49 +01:00
|
|
|
<AnastasisClientFrame hideNext={errors} title="Backup: Review Recovery Policies">
|
|
|
|
{policies.length > 0 && <p class="block">
|
|
|
|
Based on your configured authentication method you have created, some policies
|
|
|
|
have been configured. In order to recover your secret you have to solve all the
|
|
|
|
challenges of at least one policy.
|
|
|
|
</p> }
|
|
|
|
{policies.length < 1 && <p class="block">
|
|
|
|
No policies had been created. Go back and add more authentication methods.
|
|
|
|
</p> }
|
2021-10-22 06:31:46 +02:00
|
|
|
{policies.map((p, policy_index) => {
|
|
|
|
const methods = p.methods
|
2021-11-01 20:10:49 +01:00
|
|
|
.map(x => configuredAuthMethods[x.authentication_method] && ({ ...configuredAuthMethods[x.authentication_method], provider: x.provider }))
|
2021-10-22 06:31:46 +02:00
|
|
|
.filter(x => !!x)
|
|
|
|
|
|
|
|
const policyName = methods.map(x => x.type).join(" + ");
|
|
|
|
|
2021-10-19 15:56:52 +02:00
|
|
|
return (
|
2021-11-01 20:10:49 +01:00
|
|
|
<div key={policy_index} class="box" style={{ display: 'flex', justifyContent: 'space-between' }}>
|
|
|
|
<div>
|
|
|
|
<h3 class="subtitle">
|
|
|
|
Policy #{policy_index + 1}: {policyName}
|
|
|
|
</h3>
|
|
|
|
{!methods.length && <p>
|
|
|
|
No auth method found
|
|
|
|
</p>}
|
2021-10-22 06:31:46 +02:00
|
|
|
{methods.map((m, i) => {
|
2021-10-19 15:56:52 +02:00
|
|
|
return (
|
2021-11-01 20:10:49 +01:00
|
|
|
<p key={i} class="block" style={{display:'flex', alignItems:'center'}}>
|
|
|
|
<span class="icon">
|
|
|
|
{authMethods[m.type as KnownAuthMethods]?.icon}
|
|
|
|
</span>
|
|
|
|
<span>
|
|
|
|
{m.instructions} recovery provided by <a href={m.provider}>{m.provider}</a>
|
|
|
|
</span>
|
|
|
|
</p>
|
2021-10-19 15:56:52 +02:00
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
2021-11-01 20:10:49 +01:00
|
|
|
<div style={{ marginTop: 'auto', marginBottom: 'auto' }}><button class="button is-danger" onClick={() => reducer.transition("delete_policy", { policy_index })}>Delete</button></div>
|
2021-10-19 15:56:52 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</AnastasisClientFrame>
|
|
|
|
);
|
|
|
|
}
|