skipConfirm.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import Button from 'sentry/components/button';
  4. import ButtonBar from 'sentry/components/buttonBar';
  5. import HookOrDefault from 'sentry/components/hookOrDefault';
  6. import {t} from 'sentry/locale';
  7. import {fadeIn} from 'sentry/styles/animations';
  8. import space from 'sentry/styles/space';
  9. type Props = {
  10. children: (opts: {skip: (e: React.MouseEvent) => void}) => React.ReactNode;
  11. onSkip: () => void;
  12. };
  13. type State = {
  14. showConfirmation: boolean;
  15. };
  16. class SkipConfirm extends Component<Props, State> {
  17. state: State = {
  18. showConfirmation: false,
  19. };
  20. toggleConfirm = (e: React.MouseEvent) => {
  21. e.stopPropagation();
  22. this.setState(state => ({showConfirmation: !state.showConfirmation}));
  23. };
  24. handleSkip = (e: React.MouseEvent) => {
  25. e.stopPropagation();
  26. this.props.onSkip();
  27. };
  28. render() {
  29. const {children} = this.props;
  30. return (
  31. <Fragment>
  32. {children({skip: this.toggleConfirm})}
  33. <Confirmation
  34. visible={this.state.showConfirmation}
  35. onSkip={this.handleSkip}
  36. onDismiss={this.toggleConfirm}
  37. />
  38. </Fragment>
  39. );
  40. }
  41. }
  42. export default SkipConfirm;
  43. const SkipHelp = HookOrDefault({
  44. hookName: 'onboarding-wizard:skip-help',
  45. defaultComponent: () => (
  46. <Button priority="primary" size="xs" to="https://forum.sentry.io/" external>
  47. {t('Community Forum')}
  48. </Button>
  49. ),
  50. });
  51. type ConfirmProps = React.HTMLAttributes<HTMLDivElement> & {
  52. onDismiss: (e: React.MouseEvent) => void;
  53. onSkip: (e: React.MouseEvent) => void;
  54. visible: boolean;
  55. };
  56. const Confirmation = styled(({onDismiss, onSkip, visible: _, ...props}: ConfirmProps) => (
  57. <div onClick={onDismiss} {...props}>
  58. <p>{t("Not sure what to do? We're here for you!")}</p>
  59. <ButtonBar gap={1}>
  60. <SkipHelp />
  61. <Button size="xs" onClick={onSkip}>
  62. {t('Just skip')}
  63. </Button>
  64. </ButtonBar>
  65. </div>
  66. ))`
  67. display: ${p => (p.visible ? 'flex' : 'none')};
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. bottom: 0;
  72. right: 0;
  73. padding: 0 ${space(3)};
  74. border-radius: ${p => p.theme.borderRadius};
  75. align-items: center;
  76. flex-direction: column;
  77. justify-content: center;
  78. background: rgba(255, 255, 255, 0.9);
  79. animation: ${fadeIn} 200ms normal forwards;
  80. font-size: ${p => p.theme.fontSizeMedium};
  81. p {
  82. margin-bottom: ${space(1)};
  83. }
  84. `;