deleteButton.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as Sentry from '@sentry/react';
  2. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  3. import Button from 'sentry/components/button';
  4. import Confirm from 'sentry/components/confirm';
  5. import {IconDelete} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import useApi from 'sentry/utils/useApi';
  8. import {useRouteContext} from 'sentry/utils/useRouteContext';
  9. function DeleteButton() {
  10. const api = useApi();
  11. const {params, router} = useRouteContext();
  12. const orgSlug = params.orgId;
  13. const [projectSlug, replayId] = params.replaySlug.split(':');
  14. const handleDelete = async () => {
  15. try {
  16. await api.requestPromise(
  17. `/projects/${orgSlug}/${projectSlug}/replays/${replayId}/`,
  18. {
  19. method: 'DELETE',
  20. }
  21. );
  22. router.replace(`/organizations/${orgSlug}/replays/`);
  23. } catch (err) {
  24. addErrorMessage(t('Failed to delete replay'));
  25. Sentry.captureException(err);
  26. }
  27. };
  28. return (
  29. <Confirm
  30. message={t('Are you sure you want to delete this replay?')}
  31. onConfirm={handleDelete}
  32. >
  33. <Button size="xs" icon={<IconDelete size="xs" />}>
  34. {t('Delete')}
  35. </Button>
  36. </Confirm>
  37. );
  38. }
  39. export default DeleteButton;