confirmDelete.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {Fragment} from 'react';
  2. import Alert from 'sentry/components/alert';
  3. import Confirm from 'sentry/components/confirm';
  4. import Field from 'sentry/components/forms/field';
  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. const ConfirmDelete = ({message, confirmInput, ...props}: Props) => (
  15. <Confirm
  16. {...props}
  17. bypass={false}
  18. disableConfirmButton
  19. renderMessage={({disableConfirmButton}) => (
  20. <Fragment>
  21. <Alert type="error">{message}</Alert>
  22. <Field
  23. flexibleControlStateSize
  24. inline={false}
  25. label={t(
  26. 'Please enter %s to confirm the deletion',
  27. <code>{confirmInput}</code>
  28. )}
  29. >
  30. <Input
  31. type="text"
  32. placeholder={confirmInput}
  33. onChange={e => disableConfirmButton(e.target.value !== confirmInput)}
  34. />
  35. </Field>
  36. </Fragment>
  37. )}
  38. />
  39. );
  40. export default ConfirmDelete;