project-list-root.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import {
  2. ProjectListProvider,
  3. useProjectListContext,
  4. } from '../context/project-list-context'
  5. import { Col, Row } from 'react-bootstrap'
  6. import { useTranslation } from 'react-i18next'
  7. import useWaitForI18n from '../../../shared/hooks/use-wait-for-i18n'
  8. import CurrentPlanWidget from './current-plan-widget/current-plan-widget'
  9. import NewProjectButton from './new-project-button'
  10. import ProjectListTable from './table/project-list-table'
  11. import SidebarFilters from './sidebar/sidebar-filters'
  12. import SurveyWidget from './survey-widget'
  13. import WelcomeMessage from './welcome-message'
  14. import LoadingBranded from '../../../shared/components/loading-branded'
  15. import UserNotifications from './notifications/user-notifications'
  16. import SearchForm from './search-form'
  17. import ProjectTools from './table/project-tools/project-tools'
  18. function ProjectListRoot() {
  19. const { isReady } = useWaitForI18n()
  20. return isReady ? (
  21. <ProjectListProvider>
  22. <ProjectListPageContent />
  23. </ProjectListProvider>
  24. ) : null
  25. }
  26. function ProjectListPageContent() {
  27. const {
  28. totalProjectsCount,
  29. error,
  30. isLoading,
  31. loadProgress,
  32. setSearchText,
  33. selectedProjects,
  34. } = useProjectListContext()
  35. return isLoading ? (
  36. <div className="loading-container">
  37. <LoadingBranded loadProgress={loadProgress} />
  38. </div>
  39. ) : (
  40. <div className="project-list-row row fill">
  41. <div className="project-list-wrapper">
  42. {error ? <DashApiError /> : ''}
  43. {totalProjectsCount > 0 ? (
  44. <>
  45. <Col md={2} xs={3} className="project-list-sidebar-wrapper">
  46. <aside className="project-list-sidebar">
  47. <NewProjectButton />
  48. <SidebarFilters />
  49. </aside>
  50. <SurveyWidget />
  51. </Col>
  52. <Col md={10} xs={9} className="project-list-main">
  53. <Row>
  54. <Col xs={12}>
  55. <UserNotifications />
  56. </Col>
  57. </Row>
  58. <Row>
  59. <Col md={7} xs={12}>
  60. <SearchForm onChange={setSearchText} />
  61. </Col>
  62. <Col md={5} xs={12}>
  63. <div className="project-tools">
  64. {selectedProjects.length === 0 ? (
  65. <CurrentPlanWidget />
  66. ) : (
  67. <ProjectTools />
  68. )}
  69. </div>
  70. </Col>
  71. </Row>
  72. <Row className="row-spaced">
  73. <Col xs={12}>
  74. <ProjectListTable />
  75. </Col>
  76. </Row>
  77. </Col>
  78. </>
  79. ) : (
  80. <Row className="row-spaced">
  81. <Col
  82. xs={8}
  83. xsOffset={2}
  84. md={8}
  85. mdOffset={2}
  86. className="project-list-empty-col"
  87. >
  88. <WelcomeMessage />
  89. </Col>
  90. </Row>
  91. )}
  92. </div>
  93. </div>
  94. )
  95. }
  96. function DashApiError() {
  97. const { t } = useTranslation()
  98. return (
  99. <Row className="row-spaced">
  100. <Col xs={8} xsOffset={2} aria-live="polite" className="text-center">
  101. <div className="alert alert-danger">
  102. {t('generic_something_went_wrong')}
  103. </div>
  104. </Col>
  105. </Row>
  106. )
  107. }
  108. export default ProjectListRoot