settings.stories.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import EmailsSection from '../js/features/settings/components/emails-section'
  2. import useFetchMock from './hooks/use-fetch-mock'
  3. const MOCK_DELAY = 1000
  4. window.metaAttributesCache = window.metaAttributesCache || new Map()
  5. function defaultSetupMocks(fetchMock) {
  6. fetchMock.post(
  7. /\/user\/emails\/resend_confirmation/,
  8. (path, req) => {
  9. return 200
  10. },
  11. {
  12. delay: MOCK_DELAY,
  13. }
  14. )
  15. }
  16. const fakeUsersData = [
  17. {
  18. affiliation: {
  19. institution: {
  20. confirmed: true,
  21. name: 'Overleaf',
  22. },
  23. licence: 'pro_plus',
  24. },
  25. confirmedAt: '2022-03-09T10:59:44.139Z',
  26. email: 'foo@overleaf.com',
  27. default: true,
  28. },
  29. {
  30. confirmedAt: '2022-03-10T10:59:44.139Z',
  31. email: 'bar@overleaf.com',
  32. default: false,
  33. },
  34. {
  35. affiliation: {
  36. institution: {
  37. confirmed: true,
  38. name: 'Overleaf',
  39. },
  40. licence: 'pro_plus',
  41. department: 'Art & Art History',
  42. role: 'Reader',
  43. },
  44. email: 'baz@overleaf.com',
  45. default: false,
  46. },
  47. {
  48. email: 'qux@overleaf.com',
  49. default: false,
  50. },
  51. ]
  52. export const EmailsList = args => {
  53. useFetchMock(defaultSetupMocks)
  54. window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
  55. return <EmailsSection {...args} />
  56. }
  57. export const NetworkErrors = args => {
  58. useFetchMock(defaultSetupMocks)
  59. window.metaAttributesCache.set('ol-userEmails', fakeUsersData)
  60. useFetchMock(fetchMock => {
  61. fetchMock.post(
  62. /\/user\/emails\/resend_confirmation/,
  63. () => {
  64. return 503
  65. },
  66. {
  67. delay: MOCK_DELAY,
  68. }
  69. )
  70. })
  71. return <EmailsSection {...args} />
  72. }
  73. export default {
  74. title: 'Emails and Affiliations',
  75. component: EmailsSection,
  76. }