import React, { useState } from "react"; import Button from "components/buttons/Button"; // @ts-ignore import InputField from "components/forms/fields/InputField"; // @ts-ignore import FleetIcon from "components/icons/FleetIcon"; // @ts-ignore import { stringToClipboard } from "utilities/copy_text"; import { IEnrollSecret } from "interfaces/enroll_secret"; import EyeIcon from "../../../../assets/images/icon-eye-16x16@2x.png"; import EditIcon from "../../../../assets/images/icon-pencil-14x14@2x.png"; import DeleteIcon from "../../../../assets/images/icon-trash-14x14@2x.png"; const baseClass = "enroll-secrets"; interface IEnrollSecretRowProps { secret: IEnrollSecret; toggleSecretEditorModal?: () => void; toggleDeleteSecretModal?: () => void; setSelectedSecret?: React.Dispatch< React.SetStateAction >; } const EnrollSecretRow = ({ secret, toggleSecretEditorModal, toggleDeleteSecretModal, setSelectedSecret, }: IEnrollSecretRowProps): JSX.Element | null => { const [showSecret, setShowSecret] = useState(false); const [copyMessage, setCopyMessage] = useState(""); const onCopySecret = (evt: React.MouseEvent) => { evt.preventDefault(); stringToClipboard(secret.secret) .then(() => setCopyMessage("Copied!")) .catch(() => setCopyMessage("Copy failed")); // Clear message after 1 second setTimeout(() => setCopyMessage(""), 1000); return false; }; const onToggleSecret = (evt: React.MouseEvent) => { evt.preventDefault(); setShowSecret(!showSecret); return false; }; const onEditSecretClick = (evt: React.MouseEvent) => { evt.preventDefault(); if (toggleSecretEditorModal && setSelectedSecret) { setSelectedSecret(secret); toggleSecretEditorModal(); } }; const onDeleteSecretClick = (evt: React.MouseEvent) => { evt.preventDefault(); if (toggleDeleteSecretModal && setSelectedSecret) { setSelectedSecret(secret); toggleDeleteSecretModal(); } }; const renderLabel = () => { return ( {copyMessage && {`${copyMessage} `}} show/hide ); }; return (
{toggleSecretEditorModal && toggleDeleteSecretModal ? ( <> ) : null}
); }; export default EnrollSecretRow;