/* ============================================================================ * Copyright (c) Cloud Annotations * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React, { useState } from "react"; import clsx from "clsx"; import FormItem from "../FormItem"; import FormSelect from "../FormSelect"; import FormTextInput from "../FormTextInput"; import { useTypedDispatch, useTypedSelector } from "../hooks"; import styles from "../styles.module.css"; import { AuthState, Scheme, setAuthData, setSelectedAuth } from "./slice"; type Props = { mode: "locked" | "unlocked"; } & JSX.IntrinsicElements["button"]; function LockButton({ mode, children, style, ...rest }: Props) { return ( ); } function validateData(selectedAuth: Scheme[], data: AuthState["data"]) { for (const scheme of selectedAuth) { if (data[scheme.key] === undefined) { return false; } const hasMissingKeys = Object.values(data[scheme.key]).includes(undefined); if (hasMissingKeys) { return false; } } return true; } function Authorization() { const [editing, setEditing] = useState(false); const data = useTypedSelector((state) => state.auth.data); const options = useTypedSelector((state) => state.auth.options); const selected = useTypedSelector((state) => state.auth.selected); const dispatch = useTypedDispatch(); if (selected === undefined) { return null; } const selectedAuth = options[selected]; const authenticated = validateData(selectedAuth, data); const optionKeys = Object.keys(options); if (editing) { return (