2023-08-01 10:24:57 +03:00
|
|
|
/* eslint-disable max-lines */
|
2023-07-26 00:12:46 +03:00
|
|
|
"use client";
|
|
|
|
|
2023-10-05 18:50:02 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-11-19 20:46:12 +03:00
|
|
|
import { FaCopy } from "react-icons/fa";
|
2023-10-05 18:50:02 +03:00
|
|
|
|
2023-07-26 00:12:46 +03:00
|
|
|
import Button from "@/lib/components/ui/Button";
|
2023-08-01 10:24:57 +03:00
|
|
|
import Field from "@/lib/components/ui/Field";
|
2023-07-26 00:12:46 +03:00
|
|
|
|
|
|
|
import { useApiKeyConfig } from "./hooks/useApiKeyConfig";
|
|
|
|
|
|
|
|
export const ApiKeyConfig = (): JSX.Element => {
|
2023-08-01 10:24:57 +03:00
|
|
|
const {
|
|
|
|
apiKey,
|
|
|
|
handleCopyClick,
|
|
|
|
handleCreateClick,
|
2023-11-19 20:46:12 +03:00
|
|
|
|
2023-08-01 10:24:57 +03:00
|
|
|
} = useApiKeyConfig();
|
2023-10-05 18:50:02 +03:00
|
|
|
const { t } = useTranslation(["config"]);
|
2023-07-26 00:12:46 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-10-05 18:50:02 +03:00
|
|
|
<h3 className="font-semibold mb-2">Quivr {t("apiKey")}</h3>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
{apiKey === "" ? (
|
|
|
|
<Button
|
|
|
|
data-testid="create-new-key"
|
|
|
|
variant="secondary"
|
|
|
|
onClick={() => void handleCreateClick()}
|
|
|
|
>
|
|
|
|
Create New Key
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
<Field name="quivrApiKey" disabled={true} value={apiKey} />
|
|
|
|
<button data-testid="copy-api-key-button" onClick={handleCopyClick}>
|
|
|
|
<FaCopy />
|
|
|
|
</button>
|
2023-07-26 00:12:46 +03:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-11-19 20:46:12 +03:00
|
|
|
|
2023-07-26 00:12:46 +03:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|