confirmDelete.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import * as React from 'react';
  2. import Alert from 'app/components/alert';
  3. import Confirm from 'app/components/confirm';
  4. import {t} from 'app/locale';
  5. import Input from 'app/views/settings/components/forms/controls/input';
  6. import Field from 'app/views/settings/components/forms/field';
  7. type Props = Omit<React.ComponentProps<typeof Confirm>, 'renderConfirmMessage'> & {
  8. /**
  9. * The string that the user must enter to confirm the deletion
  10. */
  11. confirmInput: string;
  12. };
  13. const ConfirmDelete = ({message, confirmInput, ...props}: Props) => (
  14. <Confirm
  15. {...props}
  16. bypass={false}
  17. disableConfirmButton
  18. renderMessage={({disableConfirmButton}) => (
  19. <React.Fragment>
  20. <Alert type="error">{message}</Alert>
  21. <Field
  22. flexibleControlStateSize
  23. inline={false}
  24. label={t(
  25. 'Please enter %s to confirm the deletion',
  26. <code>{confirmInput}</code>
  27. )}
  28. >
  29. <Input
  30. type="text"
  31. placeholder={confirmInput}
  32. onChange={e => disableConfirmButton(e.target.value !== confirmInput)}
  33. />
  34. </Field>
  35. </React.Fragment>
  36. )}
  37. />
  38. );
  39. export default ConfirmDelete;