activateModal.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {Fragment, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import Alert from 'sentry/components/alert';
  5. import Button from 'sentry/components/button';
  6. import ButtonBar from 'sentry/components/buttonBar';
  7. import CheckboxFancy from 'sentry/components/checkboxFancy/checkboxFancy';
  8. import FieldRequiredBadge from 'sentry/components/forms/field/fieldRequiredBadge';
  9. import Link from 'sentry/components/links/link';
  10. import {IconWarning} from 'sentry/icons';
  11. import {t, tct} from 'sentry/locale';
  12. import space from 'sentry/styles/space';
  13. import {SamplingRule} from 'sentry/types/sampling';
  14. import {SERVER_SIDE_SAMPLING_DOC_LINK} from '../utils';
  15. type Props = ModalRenderProps & {
  16. rule: SamplingRule;
  17. };
  18. export function ActivateModal({Header, Body, Footer, closeModal}: Props) {
  19. const [understandConsequences, setUnderstandConsequences] = useState(false);
  20. function handleActivate() {
  21. // TODO(sampling): add activation logic here
  22. try {
  23. closeModal();
  24. } catch {
  25. // to nothing
  26. }
  27. }
  28. return (
  29. <Fragment>
  30. <Header closeButton>
  31. <h4>{t('Activate Rule')}</h4>
  32. </Header>
  33. <Body>
  34. <Alert type="error" showIcon icon={<IconWarning />}>
  35. {tct(
  36. 'Applying server-side sampling without first updating the Sentry SDK versions could sharply decrease the amount of accepted transactions. [link:Resolve now].',
  37. {
  38. // TODO(sampling): Add a link to the second step of the wizard once it is implemented
  39. link: <Link to="" />,
  40. }
  41. )}
  42. </Alert>
  43. <Field>
  44. <CheckboxFancy
  45. isChecked={understandConsequences}
  46. onClick={() => setUnderstandConsequences(!understandConsequences)}
  47. aria-label={
  48. understandConsequences ? t('Uncheck to disagree') : t('Check to agree')
  49. }
  50. />
  51. <FieldLabel>{t('I understand the consequences\u2026')}</FieldLabel>
  52. <FieldRequiredBadge />
  53. </Field>
  54. </Body>
  55. <Footer>
  56. <FooterActions>
  57. <Button href={SERVER_SIDE_SAMPLING_DOC_LINK} external>
  58. {t('Read Docs')}
  59. </Button>
  60. <ButtonBar gap={1}>
  61. <Button onClick={closeModal}>{t('Cancel')}</Button>
  62. <Button
  63. priority="danger"
  64. disabled={!understandConsequences}
  65. title={
  66. !understandConsequences
  67. ? t('Required fields must be filled out')
  68. : undefined
  69. }
  70. onClick={handleActivate}
  71. >
  72. {t('Activate Rule')}
  73. </Button>
  74. </ButtonBar>
  75. </FooterActions>
  76. </Footer>
  77. </Fragment>
  78. );
  79. }
  80. const FooterActions = styled('div')`
  81. display: flex;
  82. justify-content: space-between;
  83. align-items: center;
  84. flex: 1;
  85. gap: ${space(1)};
  86. `;
  87. const Field = styled('div')`
  88. display: grid;
  89. grid-template-columns: repeat(3, max-content);
  90. align-items: flex-start;
  91. line-height: 1;
  92. `;
  93. const FieldLabel = styled('div')`
  94. margin-left: ${space(1)};
  95. /* match the height of the checkbox */
  96. line-height: 16px;
  97. `;