|
| 1 | +import { |
| 2 | + Button, |
| 3 | + Card, |
| 4 | + Container, |
| 5 | + Layout, |
| 6 | + Stack, |
| 7 | +} from '@openedx/paragon'; |
| 8 | +import { Add } from '@openedx/paragon/icons'; |
| 9 | +import { Helmet } from 'react-helmet'; |
| 10 | + |
| 11 | +import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n'; |
| 12 | +import NotFoundAlert from '@src/generic/NotFoundAlert'; |
| 13 | +import Loading from '@src/generic/Loading'; |
| 14 | +import SubHeader from '@src/generic/sub-header/SubHeader'; |
| 15 | +import Header from '@src/header'; |
| 16 | + |
| 17 | +import { useLibraryContext } from '../common/context/LibraryContext'; |
| 18 | +import { useContentLibrary, useCourseMigrations } from '../data/apiHooks'; |
| 19 | +import { HelpSidebar } from './HelpSidebar'; |
| 20 | +import { MigratedCourseCard } from './MigratedCourseCard'; |
| 21 | +import messages from './messages'; |
| 22 | + |
| 23 | +const EmptyState = () => ( |
| 24 | + <Container size="md" className="py-6"> |
| 25 | + <Card> |
| 26 | + <Stack direction="horizontal" gap={3} className="my-6 justify-content-center"> |
| 27 | + <FormattedMessage {...messages.emptyStateText} /> |
| 28 | + <Button iconBefore={Add} disabled> |
| 29 | + <FormattedMessage {...messages.emptyStateButtonText} /> |
| 30 | + </Button> |
| 31 | + </Stack> |
| 32 | + </Card> |
| 33 | + </Container> |
| 34 | +); |
| 35 | + |
| 36 | +export const CourseImportHomePage = () => { |
| 37 | + const intl = useIntl(); |
| 38 | + const { libraryId } = useLibraryContext(); |
| 39 | + const { data: libraryData } = useContentLibrary(libraryId); |
| 40 | + const { data: courseMigrations } = useCourseMigrations(libraryId); |
| 41 | + |
| 42 | + if (!courseMigrations) { |
| 43 | + return <Loading />; |
| 44 | + } |
| 45 | + |
| 46 | + if (!libraryData) { |
| 47 | + return <NotFoundAlert />; |
| 48 | + } |
| 49 | + |
| 50 | + return ( |
| 51 | + <div className="d-flex"> |
| 52 | + <div className="flex-grow-1"> |
| 53 | + <Helmet> |
| 54 | + <title>{libraryData.title} | {process.env.SITE_NAME}</title> |
| 55 | + </Helmet> |
| 56 | + <Header |
| 57 | + number={libraryData.slug} |
| 58 | + title={libraryData.title} |
| 59 | + org={libraryData.org} |
| 60 | + contextId={libraryId} |
| 61 | + isLibrary |
| 62 | + containerProps={{ |
| 63 | + size: undefined, |
| 64 | + }} |
| 65 | + /> |
| 66 | + <Container className="px-0 mt-4 mb-5 library-authoring-page"> |
| 67 | + <div className="px-4 bg-light-200 border-bottom"> |
| 68 | + <SubHeader |
| 69 | + title={intl.formatMessage(messages.pageTitle)} |
| 70 | + subtitle={intl.formatMessage(messages.pageSubtitle)} |
| 71 | + hideBorder |
| 72 | + /> |
| 73 | + </div> |
| 74 | + <Layout xs={[{ span: 9 }, { span: 3 }]}> |
| 75 | + <Layout.Element> |
| 76 | + {courseMigrations.length ? ( |
| 77 | + <Stack gap={3} className="pl-4 mt-4"> |
| 78 | + <h3>Previous Imports</h3> |
| 79 | + {courseMigrations.map((courseMigration) => ( |
| 80 | + <MigratedCourseCard |
| 81 | + key={courseMigration.source.key} |
| 82 | + courseMigration={courseMigration} |
| 83 | + /> |
| 84 | + ))} |
| 85 | + </Stack> |
| 86 | + ) : (<EmptyState />)} |
| 87 | + </Layout.Element> |
| 88 | + <Layout.Element> |
| 89 | + <HelpSidebar /> |
| 90 | + </Layout.Element> |
| 91 | + </Layout> |
| 92 | + </Container> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + ); |
| 96 | +}; |
0 commit comments