summaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/pages/UnlockAccount.tsx
blob: cd801256ab046c8291a56fd142a3624fbe194704 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { TranslatedString, UnwrapKeyError } from "@gnu-taler/taler-util";
import { createNewForm, notifyError, notifyInfo, useTranslationContext } from "@gnu-taler/web-util/browser";
import { VNode, h } from "preact";

export function UnlockAccount({
  onAccountUnlocked,
  onRemoveAccount,
}: {
  onAccountUnlocked: (password: string) => Promise<void>;
  onRemoveAccount: () => void;
}): VNode {
  const { i18n } = useTranslationContext()
  const Form = createNewForm<{
    password: string;
  }>();

  return (
    <div class="flex min-h-full flex-col ">
      <div class="sm:mx-auto sm:w-full sm:max-w-md">
        <h1 class="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
          <i18n.Translate>Account locked</i18n.Translate>
        </h1>
        <p class="mt-6 text-lg leading-8 text-gray-600">
          <i18n.Translate>Your account is normally locked anytime you reload. To unlock type
            your password again.</i18n.Translate>
        </p>
      </div>

      <div class="mt-10 sm:mx-auto sm:w-full sm:max-w-[480px] ">
        <div class="bg-gray-100 px-6 py-6 shadow sm:rounded-lg sm:px-12">
          <Form.Provider
            onSubmit={async (v) => {
              try {
                await onAccountUnlocked(v.password!);
                notifyInfo("Account unlocked" as TranslatedString);
              } catch (e) {
                if (e instanceof UnwrapKeyError) {
                  notifyError(
                    "Could not unlock account" as any,
                    e.message as any,
                  );
                } else {
                  throw e;
                }
              }
            }}
          >
            <div class="mb-4">
              <Form.InputLine
                label={"Password" as TranslatedString}
                name="password"
                type="password"
                required
              />
            </div>

            <div class="mt-8">
              <button
                type="submit"
                class="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
              >
                <i18n.Translate>Unlock</i18n.Translate>
              </button>
            </div>
          </Form.Provider>
        </div>
        <button
          type="button"
          onClick={() => {
            onRemoveAccount();
          }}
          class="m-4 block rounded-md bg-red-600 px-3 py-2 text-center text-sm  text-white shadow-sm hover:bg-red-500 "
        >
          <i18n.Translate>Forget account</i18n.Translate>
        </button>
      </div>
    </div>
  );
}