featureFeedback.stories.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {Fragment} from 'react';
  2. import {BrowserClient} from '@sentry/react';
  3. import {FeatureFeedback} from 'sentry/components/featureFeedback';
  4. import TextField from 'sentry/components/forms/fields/textField';
  5. import GlobalModal from 'sentry/components/globalModal';
  6. import IndicatorContainer from 'sentry/components/indicators';
  7. import {RouteContext} from 'sentry/views/routeContext';
  8. export default {
  9. title: 'Components/Feature Feedback',
  10. };
  11. export const _FeatureFeedback = () => {
  12. const router = {
  13. location: {
  14. query: {},
  15. pathname: '/mock-pathname/',
  16. },
  17. routes: [],
  18. params: {orgId: 'org-slug'},
  19. };
  20. // A workaround for this story to not send feedback events to Sentry
  21. // TODO: Check if there is a way to mock this in Storybook
  22. BrowserClient.prototype.captureEvent = () => {};
  23. return (
  24. <RouteContext.Provider
  25. value={{
  26. router,
  27. location: router.location,
  28. params: {},
  29. routes: [],
  30. }}
  31. >
  32. <div className="section">
  33. <h3>Default</h3>
  34. <FeatureFeedback featureName="test" />
  35. </div>
  36. <div className="section">
  37. <h3>Custom</h3>
  38. <FeatureFeedback
  39. featureName="test"
  40. initialData={{step: 0, name: null, surname: null}}
  41. >
  42. {({Header, Body, Footer, state, onFieldChange}) => {
  43. if (state.step === 0) {
  44. return (
  45. <Fragment>
  46. <Header>First Step</Header>
  47. <Body>
  48. <TextField
  49. inline={false}
  50. stacked
  51. flexibleControlStateSize
  52. label="Name"
  53. value={state.name}
  54. name="name"
  55. onChange={value => onFieldChange('name', value)}
  56. />
  57. </Body>
  58. <Footer onNext={() => onFieldChange('step', 1)} />
  59. </Fragment>
  60. );
  61. }
  62. return (
  63. <Fragment>
  64. <Header>Last Step</Header>
  65. <Body>
  66. <TextField
  67. required
  68. inline={false}
  69. stacked
  70. flexibleControlStateSize
  71. label="Surname"
  72. value={state.surname}
  73. name="surname"
  74. onChange={value => onFieldChange('surname', value)}
  75. />
  76. </Body>
  77. <Footer
  78. onBack={() => onFieldChange('step', 0)}
  79. primaryDisabled={!state.surname?.trim()}
  80. submitEventData={{message: 'Feedback: test'}}
  81. />
  82. </Fragment>
  83. );
  84. }}
  85. </FeatureFeedback>
  86. </div>
  87. <GlobalModal />
  88. <IndicatorContainer />
  89. </RouteContext.Provider>
  90. );
  91. };
  92. _FeatureFeedback.storyName = 'FeatureFeedback';
  93. _FeatureFeedback.parameters = {
  94. docs: {
  95. description: {
  96. story:
  97. 'It includes a button that, when clicked, opens a modal that the user can use to send feedback to sentry',
  98. },
  99. },
  100. };