import { useEffect, useState } from "react"; import { faRotate } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { createNotification } from "@app/components/notifications"; import { Badge, Button, DeleteActionModal } from "@app/components/v2"; import { useUser } from "@app/context"; import { usePopUp } from "@app/hooks"; import { useInvalidateCache } from "@app/hooks/api"; import { useGetInvalidatingCacheStatus } from "@app/hooks/api/admin/queries"; import { CacheType } from "@app/hooks/api/admin/types"; export const CachingPageForm = () => { const { mutateAsync: invalidateCache } = useInvalidateCache(); const { user } = useUser(); const [type, setType] = useState(null); const [shouldPoll, setShouldPoll] = useState(false); const { data: invalidationStatus, isFetching, refetch } = useGetInvalidatingCacheStatus(shouldPoll); const isInvalidating = Boolean(shouldPoll && (isFetching || invalidationStatus)); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "invalidateCache" ] as const); const handleInvalidateCacheSubmit = async () => { if (!type || isInvalidating) return; try { await invalidateCache({ type }); createNotification({ text: `Began invalidating ${type} cache`, type: "success" }); setShouldPoll(true); handlePopUpClose("invalidateCache"); } catch (err) { console.error(err); createNotification({ text: `Failed to invalidate ${type} cache`, type: "error" }); } }; useEffect(() => { if (isInvalidating) return; if (shouldPoll) { setShouldPoll(false); createNotification({ text: "Successfully invalidated cache", type: "success" }); } }, [isInvalidating, shouldPoll]); useEffect(() => { refetch().then((v) => setShouldPoll(v.data || false)); }, []); return ( <>
Secrets Cache {isInvalidating && ( Invalidating Cache )}
The encrypted secrets cache encompasses all secrets stored within the system and provides a temporary, secure storage location for frequently accessed credentials.
handlePopUpToggle("invalidateCache", isOpen)} deleteKey="confirm" onDeleteApproved={handleInvalidateCacheSubmit} /> ); };