// This file is part of Coog. The COPYRIGHT file at the top level of // this repository contains the full copyright notices and license terms. import React, { FC, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'; import cn from 'classnames'; import ConfirmationButton from '../ConfirmationButton'; import Select from '../Select'; import { DuplicateButtonProps } from './DuplicateButton.types'; import './DuplicateButton.scss'; /** * DuplicateButton component * @param props * @returns {XML} * @constructor */ const DuplicateButton: FC = ({ label, validateLabel = 'Valider', cancelLabel = 'Annuler', isLoadingValidate = false, disabled = false, selection = [], eventEmitter, styleSelect = {}, placeholder = undefined, }: DuplicateButtonProps): JSX.Element => { const [btnState, setBtnState] = useState(false); const [localValue, setLocalValue] = useState(); const [hasValidated, setHasValidated] = useState(false); const [canResetState, setCanResetState] = useState(false); if (hasValidated && isLoadingValidate) { setCanResetState(true); setHasValidated(false); } else if (canResetState && !isLoadingValidate) { setCanResetState(false); setBtnState(false); setLocalValue(null); } const clickMainButton = () => { setBtnState(true); }; const clickCancel = () => { setLocalValue(null); setBtnState(false); }; const clickValidate = () => { eventEmitter(localValue); setHasValidated(true); }; return (
<>