mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-22 10:51:46 +03:00
3529222b95
* feat: add <ApiKeyConfig/> * feat(SDK): add update brain * feat: add removeUndefined helper * feat: remove unnecessary autofocus flag * add brain settings tab * ui: add tab delimitor * feat: improve ux
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import { useAuthApi } from "@/lib/api/auth/useAuthApi";
|
|
import { useEventTracking } from "@/services/analytics/useEventTracking";
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
export const useApiKeyConfig = () => {
|
|
const [apiKey, setApiKey] = useState("");
|
|
const { track } = useEventTracking();
|
|
const { createApiKey } = useAuthApi();
|
|
|
|
const handleCreateClick = async () => {
|
|
try {
|
|
void track("CREATE_API_KEY");
|
|
const createdApiKey = await createApiKey();
|
|
setApiKey(createdApiKey);
|
|
} catch (error) {
|
|
console.error("Error creating API key: ", error);
|
|
}
|
|
};
|
|
|
|
const copyToClipboard = async (text: string) => {
|
|
try {
|
|
void track("COPY_API_KEY");
|
|
await navigator.clipboard.writeText(text);
|
|
} catch (err) {
|
|
console.error("Failed to copy:", err);
|
|
}
|
|
};
|
|
|
|
const handleCopyClick = () => {
|
|
if (apiKey !== "") {
|
|
void copyToClipboard(apiKey);
|
|
}
|
|
};
|
|
|
|
return {
|
|
handleCreateClick,
|
|
apiKey,
|
|
handleCopyClick,
|
|
};
|
|
};
|