-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathTextbooks.tsx
More file actions
140 lines (133 loc) · 4.31 KB
/
Textbooks.tsx
File metadata and controls
140 lines (133 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Breadcrumb,
Button,
Container,
Layout,
Row,
} from '@openedx/paragon';
import { Add as AddIcon } from '@openedx/paragon/icons';
import { Helmet } from 'react-helmet';
import { Link } from 'react-router-dom';
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
import { SavingErrorAlert } from '@src/generic/saving-error-alert';
import { LoadingSpinner } from '@src/generic/Loading';
import SubHeader from '@src/generic/sub-header/SubHeader';
import ConnectionErrorAlert from '@src/generic/ConnectionErrorAlert';
import EmptyPlaceholder from './empty-placeholder/EmptyPlaceholder';
import TextbookCard from './textbook-card/TextbooksCard';
import TextbookSidebar from './textbook-sidebar/TextbookSidebar';
import TextbookForm from './textbook-form/TextbookForm';
import { useTextbooks } from './hooks';
import { getTextbookFormInitialValues } from './utils';
import messages from './messages';
const Textbooks = () => {
const intl = useIntl();
const { courseDetails } = useCourseAuthoringContext();
const {
textbooks,
isLoading,
isLoadingFailed,
breadcrumbs,
mutationErrorMessage,
anyMutationFailed,
isTextbookFormOpen,
openTextbookForm,
closeTextbookForm,
handleTextbookFormSubmit,
handleTextbookEditFormSubmit,
handleTextbookDeleteSubmit,
} = useTextbooks();
if (isLoadingFailed) {
return (
<Container size="xl" className="course-unit px-4 mt-4">
<ConnectionErrorAlert />
</Container>
);
}
if (isLoading) {
return (
<Row className="m-0 mt-4 justify-content-center">
<LoadingSpinner />
</Row>
);
}
return (
<>
<Helmet>
<title>
{`${courseDetails?.name} | ${intl.formatMessage(messages.headingTitle)}`}
</title>
</Helmet>
<Container size="xl" className="px-4">
<section className="mb-4 mt-5">
<SubHeader
title={intl.formatMessage(messages.headingTitle)}
breadcrumbs={
<Breadcrumb
linkAs={Link}
ariaLabel={intl.formatMessage(messages.breadcrumbAriaLabel)}
links={breadcrumbs}
/>
}
headerActions={
<Button
iconBefore={AddIcon}
onClick={openTextbookForm}
disabled={isTextbookFormOpen}
>
{intl.formatMessage(messages.newTextbookButton)}
</Button>
}
/>
<Layout
lg={[{ span: 9 }, { span: 3 }]}
md={[{ span: 9 }, { span: 3 }]}
sm={[{ span: 12 }, { span: 12 }]}
xs={[{ span: 12 }, { span: 12 }]}
xl={[{ span: 9 }, { span: 3 }]}
>
<Layout.Element>
<article>
<section className="textbook-section">
<div className="pt-4">
{textbooks.length ?
textbooks.map((textbook, index) => (
<TextbookCard
key={textbook.id}
textbook={textbook}
onEditSubmit={handleTextbookEditFormSubmit}
onDeleteSubmit={handleTextbookDeleteSubmit}
textbookIndex={index}
/>
)) :
(
!isTextbookFormOpen && <EmptyPlaceholder onCreateNewTextbook={openTextbookForm} />
)}
{isTextbookFormOpen && (
<TextbookForm
closeTextbookForm={closeTextbookForm}
initialFormValues={getTextbookFormInitialValues()}
onSubmit={handleTextbookFormSubmit}
/>
)}
</div>
</section>
</article>
</Layout.Element>
<Layout.Element>
<TextbookSidebar />
</Layout.Element>
</Layout>
</section>
</Container>
<div className="alert-toast">
<SavingErrorAlert
isQueryFailed={anyMutationFailed}
errorMessage={mutationErrorMessage}
/>
</div>
</>
);
};
export default Textbooks;