confirmDelete.tsx 1.2 KB

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