All files / src/components/Playbooks/steps HandleExternalLinksRender.tsx

0% Statements 0/17
0% Branches 0/15
0% Functions 0/3
0% Lines 0/16

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                                                                                                       
import { useDispatch } from "react-redux";
import {
  addExternalLinks,
  toggleExternalLinkVisibility,
} from "../../../store/features/playbook/playbookSlice";
import ExternalLinks from "./ExternalLinks";
import useIsPrefetched from "../../../hooks/playbooks/useIsPrefetched";
import useCurrentStep from "../../../hooks/playbooks/step/useCurrentStep";
 
function HandleExternalLinksRender({ id }) {
  const dispatch = useDispatch();
  const isPrefetched = useIsPrefetched();
 
  const [step] = useCurrentStep(id);
 
  const toggleExternalLinks = () => {
    dispatch(toggleExternalLinkVisibility({ id }));
  };
 
  const setLinks = (links) => {
    dispatch(addExternalLinks({ links, id }));
  };
 
  Iif (isPrefetched || !step) return;
 
  const showLinks =
    step?.ui_requirement.showExternalLinks ||
    (step?.external_links?.length ?? 0) > 0;
 
  return (
    <>
      {(step?.external_links?.length ?? 0) > 0 ? (
        <div className="mt-2 text-sm cursor-pointer text-violet-500">
          <b>External Links</b>
        </div>
      ) : (
        <div
          className="mt-2 text-sm cursor-pointer text-violet-500"
          onClick={toggleExternalLinks}>
          <b>{step?.ui_requirement.showExternalLinks ? "-" : "+"}</b> Add
          External Links
        </div>
      )}
      {showLinks && (
        <ExternalLinks links={step?.external_links} setLinks={setLinks} />
      )}
    </>
  );
}
 
export default HandleExternalLinksRender;