mirror of
https://github.com/idanoo/autobrr
synced 2025-07-26 02:09:13 +00:00

* Minor cosmetic changes - Changed Feeds paragraph to include regular RSS feeds - Centered "Danger Zone" header on Settings/Releases - Added punctuations to subtitles and sublabes that were missing them - Removed some subtitles over "Create new" buttons in Settings * settings(releases) Added paragraph below header * Changed user and docs icons * Fixed Notifications table for narrow screens * Made Notifications-page dynamic like the IRC-page - Hiding notification type and events on smaller screens * Made API table look better on smaller screens - Adjusted col-spans - overflow-auto on name * overflow-hidden on name * Made Feeds dynamic like Notifications * Made Clients dynamic like Feeds and Notifications * name field will now truncate instead of span itself over multiple lines mouseovering the name will now show the full value mitigated scrollbars changes to col-span to move the name column closer to enabled switch adjusted paddings in desktop and mobile layout Co-authored-by: martylukyy <35452459+martylukyy@users.noreply.github.com>
137 lines
No EOL
5 KiB
TypeScript
137 lines
No EOL
5 KiB
TypeScript
import { queryClient } from "../../App";
|
|
import { useRef } from "react";
|
|
import { useMutation, useQuery } from "react-query";
|
|
import { KeyField } from "../../components/fields/text";
|
|
import { DeleteModal } from "../../components/modals";
|
|
import APIKeyAddForm from "../../forms/settings/APIKeyAddForm";
|
|
import Toast from "../../components/notifications/Toast";
|
|
import { APIClient } from "../../api/APIClient";
|
|
import { useToggle } from "../../hooks/hooks";
|
|
import { toast } from "react-hot-toast";
|
|
import { classNames } from "../../utils";
|
|
import { TrashIcon } from "@heroicons/react/24/outline";
|
|
import { EmptySimple } from "../../components/emptystates";
|
|
|
|
function APISettings() {
|
|
const [addFormIsOpen, toggleAddForm] = useToggle(false);
|
|
|
|
const { data } = useQuery(
|
|
["apikeys"],
|
|
() => APIClient.apikeys.getAll(),
|
|
{
|
|
retry: false,
|
|
refetchOnWindowFocus: false,
|
|
onError: err => console.log(err)
|
|
}
|
|
);
|
|
|
|
return (
|
|
<div className="divide-y divide-gray-200 dark:divide-gray-700 lg:col-span-9">
|
|
<div className="pb-6 py-6 px-4 sm:p-6 lg:pb-8">
|
|
<APIKeyAddForm isOpen={addFormIsOpen} toggle={toggleAddForm}/>
|
|
|
|
<div className="-ml-4 -mt-4 flex justify-between items-center flex-wrap sm:flex-nowrap">
|
|
<div className="ml-4 mt-4">
|
|
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-white">API keys</h3>
|
|
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
|
|
Manage API keys.
|
|
</p>
|
|
</div>
|
|
<div className="ml-4 mt-4 flex-shrink-0">
|
|
<button
|
|
type="button"
|
|
className="relative inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 dark:bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
|
|
onClick={toggleAddForm}
|
|
>
|
|
Add new
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{data && data.length > 0 ?
|
|
<section className="mt-6 light:bg-white dark:bg-gray-800 light:shadow sm:rounded-md">
|
|
<ol className="min-w-full relative">
|
|
<li className="grid grid-cols-12 gap-4 mb-2 border-b border-gray-200 dark:border-gray-700">
|
|
<div
|
|
className="col-span-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Name
|
|
</div>
|
|
<div
|
|
className="col-span-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Key
|
|
</div>
|
|
</li>
|
|
|
|
{data && data.map((k) => (
|
|
<APIListItem key={k.key} apikey={k}/>
|
|
))}
|
|
</ol>
|
|
</section>
|
|
: <EmptySimple title="No API keys" subtitle="" buttonAction={toggleAddForm}
|
|
buttonText="Create API key"/>}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface ApiKeyItemProps {
|
|
apikey: APIKey
|
|
}
|
|
|
|
function APIListItem({ apikey }: ApiKeyItemProps) {
|
|
const cancelModalButtonRef = useRef(null);
|
|
const [deleteModalIsOpen, toggleDeleteModal] = useToggle(false);
|
|
|
|
const deleteMutation = useMutation(
|
|
(key: string) => APIClient.apikeys.delete(key),
|
|
{
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries(["apikeys"]);
|
|
queryClient.invalidateQueries(["apikeys", apikey.key]);
|
|
|
|
toast.custom((t) => <Toast type="success" body={`API key ${apikey?.name} was deleted`} t={t}/>);
|
|
}
|
|
}
|
|
);
|
|
|
|
return (
|
|
<li className="text-gray-500 dark:text-gray-400">
|
|
<DeleteModal
|
|
isOpen={deleteModalIsOpen}
|
|
toggle={toggleDeleteModal}
|
|
buttonRef={cancelModalButtonRef}
|
|
deleteAction={() => {
|
|
deleteMutation.mutate(apikey.key);
|
|
toggleDeleteModal();
|
|
}}
|
|
title={`Remove API key: ${apikey.name}`}
|
|
text="Are you sure you want to remove this API key? This action cannot be undone."
|
|
/>
|
|
|
|
<div className="grid grid-cols-12 gap-4 items-center py-2">
|
|
<div className="col-span-4 overflow-auto flex items-center text-sm font-medium text-gray-900 dark:text-white">
|
|
{apikey.name}
|
|
</div>
|
|
<div className="col-span-6 flex items-center text-sm font-medium text-gray-900 dark:text-white">
|
|
<KeyField value={apikey.key}/>
|
|
</div>
|
|
|
|
<div className="col-span-2 flex items-center justify-end text-sm font-medium text-gray-900 dark:text-white">
|
|
<button
|
|
className={classNames(
|
|
"text-gray-900 dark:text-gray-300",
|
|
"font-medium group flex rounded-md items-center px-2 py-2 text-sm"
|
|
)}
|
|
onClick={toggleDeleteModal}
|
|
title="Delete key"
|
|
>
|
|
<TrashIcon
|
|
className="text-red-500 w-5 h-5"
|
|
aria-hidden="true"
|
|
/>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
export default APISettings; |