All files / src/components/Workflows WorkflowActionOverlay.tsx

0% Statements 0/14
0% Branches 0/5
0% Functions 0/3
0% Lines 0/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60                                                                                                                       
/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from "react";
import Overlay from "../Overlay/index.js";
import { CircularProgress } from "@mui/material";
import { useDeleteWorkflowMutation } from "../../store/features/workflow/api/deleteWorkflowApi.ts";
 
const WorkflowActionOverlay = ({
  workflow,
  isOpen,
  toggleOverlay,
  refreshTable,
}) => {
  const [deleteWorkflow, { isLoading, isSuccess, status }] =
    useDeleteWorkflowMutation();
  const handleSuccess = () => {
    deleteWorkflow(workflow.id);
  };
 
  useEffect(() => {
    Iif (isSuccess) {
      toggleOverlay();
      refreshTable();
    }
  }, [status]);
 
  return (
    <>
      {isOpen && (
        <Overlay close={toggleOverlay} visible={isOpen}>
          <div className="bg-white p-5 rounded w-[400px] min-h-[100px] max-h-[500px] overflow-scroll">
            <header className="text-gray-500">Delete {workflow.name}?</header>
            <div className="flex gap-2 mt-4 mb-2">
              <button
                className="rounded border border-violet-500 text-violet-500 hover:text-white hover:bg-violet-500 transition-all p-1"
                onClick={toggleOverlay}>
                Cancel
              </button>
              <button
                className="rounded border border-violet-500 text-violet-500 hover:text-white hover:bg-violet-500 transition-all p-1"
                onClick={handleSuccess}>
                Yes
              </button>
              {isLoading && (
                <CircularProgress
                  style={{
                    marginLeft: "12px",
                  }}
                  size={20}
                />
              )}
            </div>
          </div>
        </Overlay>
      )}
    </>
  );
};
 
export default WorkflowActionOverlay;