linking.stories.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import useFetchMock from '../hooks/use-fetch-mock'
  2. import LinkingSection from '../../js/features/settings/components/linking-section'
  3. import { setDefaultMeta, defaultSetupMocks } from './helpers/linking'
  4. import { UserProvider } from '../../js/shared/context/user-context'
  5. import { SSOProvider } from '../../js/features/settings/context/sso-context'
  6. import { ScopeDecorator } from '../decorators/scope'
  7. import { useEffect } from 'react'
  8. import { useMeta } from '../hooks/use-meta'
  9. const MOCK_DELAY = 1000
  10. export const Section = args => {
  11. useFetchMock(defaultSetupMocks)
  12. setDefaultMeta()
  13. return (
  14. <UserProvider>
  15. <SSOProvider>
  16. <LinkingSection {...args} />
  17. </SSOProvider>
  18. </UserProvider>
  19. )
  20. }
  21. export const SectionAllUnlinked = args => {
  22. useFetchMock(defaultSetupMocks)
  23. useMeta({
  24. 'ol-thirdPartyIds': {},
  25. 'ol-user': {
  26. features: { github: true, dropbox: true, mendeley: true, zotero: true },
  27. refProviders: {
  28. mendeley: false,
  29. zotero: false,
  30. },
  31. },
  32. 'ol-github': { enabled: false },
  33. 'ol-dropbox': { registered: false },
  34. })
  35. useEffect(() => {
  36. setDefaultMeta()
  37. }, [])
  38. return (
  39. <UserProvider>
  40. <SSOProvider>
  41. <LinkingSection {...args} />
  42. </SSOProvider>
  43. </UserProvider>
  44. )
  45. }
  46. export const SectionSSOErrors = args => {
  47. useFetchMock(fetchMock =>
  48. fetchMock.post('/user/oauth-unlink', 500, { delay: MOCK_DELAY })
  49. )
  50. setDefaultMeta()
  51. window.metaAttributesCache.set('integrationLinkingWidgets', [])
  52. window.metaAttributesCache.set('referenceLinkingWidgets', [])
  53. window.metaAttributesCache.set(
  54. 'ol-ssoErrorMessage',
  55. 'Account already linked to another Overleaf user'
  56. )
  57. return (
  58. <UserProvider>
  59. <SSOProvider>
  60. <LinkingSection {...args} />
  61. </SSOProvider>
  62. </UserProvider>
  63. )
  64. }
  65. export const SectionProjetSyncSuccess = args => {
  66. useFetchMock(defaultSetupMocks)
  67. setDefaultMeta()
  68. window.metaAttributesCache.set('ol-github', { enabled: true })
  69. window.metaAttributesCache.set(
  70. 'ol-projectSyncSuccessMessage',
  71. 'Thanks, we’ve successfully linked your GitHub account to Overleaf. You can now export your Overleaf projects to GitHub, or import projects from your GitHub repositories.'
  72. )
  73. return (
  74. <UserProvider>
  75. <SSOProvider>
  76. <LinkingSection {...args} />
  77. </SSOProvider>
  78. </UserProvider>
  79. )
  80. }
  81. export default {
  82. title: 'Account Settings / Linking',
  83. component: LinkingSection,
  84. decorators: [ScopeDecorator],
  85. }