import React, { ReactElement, ReactNode, useState } from "react"; import { Button, ButtonVariant, Modal, ModalVariant, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; export const useConfirmDialog = ( props: ConfirmDialogProps ): [() => void, () => ReactElement] => { const [show, setShow] = useState(false); function toggleDialog() { setShow((show) => !show); } const Dialog = () => ( ); return [toggleDialog, Dialog]; }; export interface ConfirmDialogModalProps extends ConfirmDialogProps { open: boolean; toggleDialog: () => void; } export type ConfirmDialogProps = { titleKey: string; messageKey?: string; noCancelButton?: boolean; confirmButtonDisabled?: boolean; cancelButtonLabel?: string; continueButtonLabel?: string; continueButtonVariant?: ButtonVariant; variant?: ModalVariant; onConfirm: () => void; onCancel?: () => void; children?: ReactNode; }; export const ConfirmDialogModal = ({ titleKey, messageKey, noCancelButton, cancelButtonLabel, continueButtonLabel, continueButtonVariant, onConfirm, onCancel, children, open = true, variant = ModalVariant.small, toggleDialog, confirmButtonDisabled, }: ConfirmDialogModalProps) => { const { t } = useTranslation(); return ( { onConfirm(); toggleDialog(); }} > {t(continueButtonLabel || "common:continue")} , !noCancelButton && ( ), ]} > {!messageKey && children} {messageKey && t(messageKey)} ); };