sharing-updates-root.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import useWaitForI18n from '@/shared/hooks/use-wait-for-i18n'
  2. import { Trans, useTranslation } from 'react-i18next'
  3. import withErrorBoundary from '@/infrastructure/error-boundary'
  4. import { GenericErrorBoundaryFallback } from '@/shared/components/generic-error-boundary-fallback'
  5. import { useCallback } from 'react'
  6. import getMeta from '@/utils/meta'
  7. import { postJSON } from '@/infrastructure/fetch-json'
  8. import { debugConsole } from '@/utils/debugging'
  9. import useAsync from '@/shared/hooks/use-async'
  10. import Notification from '@/shared/components/notification'
  11. function SharingUpdatesRoot() {
  12. const { isReady } = useWaitForI18n()
  13. const { t } = useTranslation()
  14. const { isLoading, isSuccess, isError, runAsync } = useAsync()
  15. const projectId = getMeta('ol-project_id')
  16. const joinProject = useCallback(() => {
  17. runAsync(postJSON(`/project/${projectId}/sharing-updates/join`))
  18. .then(() => {
  19. location.assign(`/project/${projectId}`)
  20. })
  21. .catch(debugConsole.error)
  22. }, [runAsync, projectId])
  23. const viewProject = useCallback(() => {
  24. runAsync(postJSON(`/project/${projectId}/sharing-updates/view`))
  25. .then(() => {
  26. location.assign(`/project/${projectId}`)
  27. })
  28. .catch(debugConsole.error)
  29. }, [runAsync, projectId])
  30. const leaveProject = useCallback(() => {
  31. runAsync(postJSON(`/project/${projectId}/leave`))
  32. .then(() => {
  33. location.assign('/project')
  34. })
  35. .catch(debugConsole.error)
  36. }, [runAsync, projectId])
  37. if (!isReady) {
  38. return null
  39. }
  40. return (
  41. <div className="container">
  42. <div className="row">
  43. <div className="col-md-6 col-md-offset-3">
  44. <div className="card sharing-updates">
  45. <div className="row">
  46. <div className="col-md-12">
  47. <h1 className="sharing-updates-h1">
  48. {t('updates_to_project_sharing')}
  49. </h1>
  50. </div>
  51. </div>
  52. <div className="row row-spaced">
  53. <div className="col-md-12">
  54. <p>
  55. <Trans
  56. i18nKey="were_making_some_changes_to_project_sharing_this_means_you_will_be_visible"
  57. components={[
  58. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  59. <a
  60. href="/blog/changes-to-project-sharing"
  61. rel="noopener noreferrer"
  62. target="_blank"
  63. />,
  64. ]}
  65. />
  66. </p>
  67. </div>
  68. </div>
  69. <div className="row row-spaced">
  70. <div className="col-md-12">
  71. <button
  72. className="btn btn-primary"
  73. onClick={() => joinProject()}
  74. disabled={isLoading}
  75. >
  76. {t('ok_continue_to_project')}
  77. </button>
  78. </div>
  79. </div>
  80. {isError && (
  81. <div className="row row-spaced">
  82. <div className="col-md-12">
  83. <Notification
  84. type="error"
  85. content={t('generic_something_went_wrong')}
  86. />
  87. </div>
  88. </div>
  89. )}
  90. <div className="row row-spaced">
  91. <div className="col-md-12">
  92. <p>
  93. <small>
  94. <Trans
  95. i18nKey="you_can_also_choose_to_view_anonymously_or_leave_the_project"
  96. components={[
  97. // eslint-disable-next-line react/jsx-key
  98. <button
  99. className="btn btn-inline-link"
  100. onClick={() => viewProject()}
  101. disabled={isLoading || isSuccess}
  102. />,
  103. // eslint-disable-next-line react/jsx-key
  104. <button
  105. className="btn btn-inline-link"
  106. onClick={() => leaveProject()}
  107. disabled={isLoading || isSuccess}
  108. />,
  109. ]}
  110. />
  111. </small>
  112. </p>
  113. </div>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. )
  120. }
  121. export default withErrorBoundary(
  122. SharingUpdatesRoot,
  123. GenericErrorBoundaryFallback
  124. )