@selfcommunity/react-ui 0.10.2-courses.171 → 0.10.2-courses.172
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/CourseForm/CourseForm.js +24 -24
- package/lib/cjs/components/CourseForm/UploadCourseCover.d.ts +3 -8
- package/lib/cjs/components/CourseForm/UploadCourseCover.js +3 -38
- package/lib/esm/components/CourseForm/CourseForm.js +24 -24
- package/lib/esm/components/CourseForm/UploadCourseCover.d.ts +3 -8
- package/lib/esm/components/CourseForm/UploadCourseCover.js +4 -39
- package/lib/umd/react-ui.js +1 -1
- package/package.json +8 -8
|
@@ -99,7 +99,7 @@ const Root = (0, styles_1.styled)(material_1.Box, {
|
|
|
99
99
|
* @param inProps
|
|
100
100
|
*/
|
|
101
101
|
function CourseForm(inProps) {
|
|
102
|
-
var _a, _b, _c
|
|
102
|
+
var _a, _b, _c;
|
|
103
103
|
//PROPS
|
|
104
104
|
const props = (0, system_1.useThemeProps)({
|
|
105
105
|
props: inProps,
|
|
@@ -185,28 +185,28 @@ function CourseForm(inProps) {
|
|
|
185
185
|
*/
|
|
186
186
|
const handleSubmit = (0, react_1.useCallback)(() => {
|
|
187
187
|
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: true })));
|
|
188
|
+
const formData = new FormData();
|
|
189
|
+
if (field.imageOriginalFile) {
|
|
190
|
+
formData.append('image_original', field.imageOriginalFile);
|
|
191
|
+
}
|
|
192
|
+
formData.append('name', field.name);
|
|
193
|
+
formData.append('description', field.description);
|
|
194
|
+
formData.append('type', field.type);
|
|
195
|
+
if (field.privacy) {
|
|
196
|
+
formData.append('privacy', field.privacy);
|
|
197
|
+
}
|
|
198
|
+
if (field.categories) {
|
|
199
|
+
for (const key in field.categories) {
|
|
200
|
+
formData.append(key, field.categories[key]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
188
203
|
let courseService;
|
|
189
204
|
if (course) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
courseService = api_services_1.CourseService.updateCourse(course.id, data, {
|
|
193
|
-
headers: { 'Content-Type': 'application/json' }
|
|
205
|
+
courseService = api_services_1.CourseService.updateCourse(course.id, formData, {
|
|
206
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
194
207
|
});
|
|
195
208
|
}
|
|
196
209
|
else {
|
|
197
|
-
// Create
|
|
198
|
-
const formData = new FormData();
|
|
199
|
-
if (field.imageOriginalFile) {
|
|
200
|
-
formData.append('image_original', field.imageOriginalFile);
|
|
201
|
-
}
|
|
202
|
-
formData.append('name', field.name);
|
|
203
|
-
formData.append('description', field.description);
|
|
204
|
-
formData.append('type', field.type);
|
|
205
|
-
if (field.categories) {
|
|
206
|
-
for (const key in field.categories) {
|
|
207
|
-
formData.append(key, field.categories[key]);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
210
|
courseService = api_services_1.CourseService.createCourse(formData, {
|
|
211
211
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
212
212
|
});
|
|
@@ -214,18 +214,18 @@ function CourseForm(inProps) {
|
|
|
214
214
|
courseService
|
|
215
215
|
.then((data) => {
|
|
216
216
|
notifyChanges(data);
|
|
217
|
-
setField((prev) => (Object.assign(Object.assign({}, prev), {
|
|
217
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: false })));
|
|
218
218
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
219
219
|
})
|
|
220
220
|
.catch((e) => {
|
|
221
221
|
const _error = (0, api_services_1.formatHttpErrorCode)(e);
|
|
222
222
|
if (Object.values(_error)[0]['error'] === 'unique') {
|
|
223
|
-
setError(Object.assign(Object.assign({}, error), {
|
|
223
|
+
setError(Object.assign(Object.assign({}, error), { nameError: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.name.error.unique", defaultMessage: "ui.courseForm.name.error.unique" }) }));
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
226
226
|
setError(Object.assign(Object.assign({}, error), _error));
|
|
227
227
|
}
|
|
228
|
-
setField((prev) => (Object.assign(Object.assign({}, prev), {
|
|
228
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: false })));
|
|
229
229
|
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, e);
|
|
230
230
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
231
231
|
});
|
|
@@ -250,11 +250,11 @@ function CourseForm(inProps) {
|
|
|
250
250
|
/**
|
|
251
251
|
* Renders root object
|
|
252
252
|
*/
|
|
253
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: _step === Course_1.SCCourseFormStepType.GENERAL ? classes.stepOne : classes.stepTwo }, { children: [_step === Course_1.SCCourseFormStepType.GENERAL && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: Object.values(types_1.SCCourseTypologyType).map((option, index) => ((0, jsx_runtime_1.jsx)(material_1.Card, Object.assign({ className: (0, classnames_1.default)(classes.card, { [classes.selected]: option === field.type }) }, { children: (0, jsx_runtime_1.jsx)(material_1.CardActionArea, Object.assign({ onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['type']: option }))) }, { children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "subtitle2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.title`, defaultMessage: `ui.courseForm.${option}.title` }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.info`, defaultMessage: `ui.courseForm.${option}.info` }) }))] }) })) }), index))) })), _step === Course_1.SCCourseFormStepType.CUSTOMIZATION && ((0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: classes.form }, { children: [course && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5", className: classes.contrastColor }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.edit.title.general", defaultMessage: "ui.courseForm.edit.title.general" }) }))), (0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: (0, jsx_runtime_1.jsx)(UploadCourseCover_1.default, {
|
|
253
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className) }, rest, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({ className: _step === Course_1.SCCourseFormStepType.GENERAL ? classes.stepOne : classes.stepTwo }, { children: [_step === Course_1.SCCourseFormStepType.GENERAL && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: Object.values(types_1.SCCourseTypologyType).map((option, index) => ((0, jsx_runtime_1.jsx)(material_1.Card, Object.assign({ className: (0, classnames_1.default)(classes.card, { [classes.selected]: option === field.type }) }, { children: (0, jsx_runtime_1.jsx)(material_1.CardActionArea, Object.assign({ onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['type']: option }))) }, { children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "subtitle2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.title`, defaultMessage: `ui.courseForm.${option}.title` }) })), (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: `ui.courseForm.${option}.info`, defaultMessage: `ui.courseForm.${option}.info` }) }))] }) })) }), index))) })), _step === Course_1.SCCourseFormStepType.CUSTOMIZATION && ((0, jsx_runtime_1.jsxs)(material_1.FormGroup, Object.assign({ className: classes.form }, { children: [course && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "h5", className: classes.contrastColor }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.edit.title.general", defaultMessage: "ui.courseForm.edit.title.general" }) }))), (0, jsx_runtime_1.jsx)(material_1.Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: (0, jsx_runtime_1.jsx)(UploadCourseCover_1.default, { isUploading: field.isSubmitting, onChange: handleChangeCover }) })), (0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, className: (0, classnames_1.default)(classes.name, classes.contrastBgColor), placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
254
254
|
endAdornment: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: Course_1.COURSE_TITLE_MAX_LENGTH - field.name.length }))
|
|
255
255
|
}, error: Boolean(field.name.length > Course_1.COURSE_TITLE_MAX_LENGTH) || Boolean(error['nameError']), helperText: field.name.length > Course_1.COURSE_TITLE_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.name.error.maxLength", defaultMessage: "ui.courseForm.name.error.maxLength" })) : error['nameError'] ? (error['nameError']) : null }), (0, jsx_runtime_1.jsx)(material_1.TextField, { multiline: true, className: (0, classnames_1.default)(classes.description, classes.contrastBgColor), placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
256
|
-
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((
|
|
257
|
-
}, error: Boolean(((
|
|
256
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: "body2" }, { children: ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? Course_1.COURSE_DESCRIPTION_MAX_LENGTH - field.description.length : Course_1.COURSE_DESCRIPTION_MAX_LENGTH })))
|
|
257
|
+
}, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > Course_1.COURSE_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > Course_1.COURSE_DESCRIPTION_MAX_LENGTH ? ((0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: "ui.courseForm.description.error.maxLength", defaultMessage: "ui.courseForm.description.error.maxLength" })) : null }), (0, jsx_runtime_1.jsx)(CategoryAutocomplete_1.default, { defaultValue: field.categories, TextFieldProps: { label: intl.formatMessage(Object.keys(field.categories).length ? messages.category : messages.categoryEmpty) }, multiple: true, onChange: handleOnChangeCategory, className: classes.contrastBgColor }), course && ((0, jsx_runtime_1.jsx)(Edit_1.default, { course: course, onPrivacyChange: (privacy) => setField((prev) => (Object.assign(Object.assign({}, prev), { ['privacy']: privacy }))), className: classes.contrastBgColor }))] }))), (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: (0, classnames_1.default)(classes.actions, classes.contrastBgColor) }, { children: (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, Object.assign({ size: "small", loading: field.isSubmitting, disabled: _step === Course_1.SCCourseFormStepType.GENERAL
|
|
258
258
|
? !field.type || Object.keys(error).length !== 0
|
|
259
259
|
: _step === Course_1.SCCourseFormStepType.CUSTOMIZATION &&
|
|
260
260
|
(!field.name ||
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface UploadCourseCoverProps {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @default
|
|
3
|
+
* If the image is in uploadingstate
|
|
4
|
+
* @default false
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
isUploading: boolean;
|
|
7
7
|
/**
|
|
8
8
|
* On change function.
|
|
9
9
|
* @default null
|
|
@@ -14,11 +14,6 @@ export interface UploadCourseCoverProps {
|
|
|
14
14
|
* @default null
|
|
15
15
|
*/
|
|
16
16
|
className?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Prop to handle cover loading in the create course modal.
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
isCreationMode?: boolean;
|
|
22
17
|
/**
|
|
23
18
|
* Any other properties
|
|
24
19
|
*/
|
|
@@ -11,9 +11,6 @@ const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
|
11
11
|
const system_1 = require("@mui/system");
|
|
12
12
|
const constants_1 = require("./constants");
|
|
13
13
|
const lab_1 = require("@mui/lab");
|
|
14
|
-
const Errors_1 = require("../../constants/Errors");
|
|
15
|
-
const api_services_1 = require("@selfcommunity/api-services");
|
|
16
|
-
const utils_1 = require("@selfcommunity/utils");
|
|
17
14
|
const react_intl_1 = require("react-intl");
|
|
18
15
|
const messages = (0, react_intl_1.defineMessages)({
|
|
19
16
|
errorLoadImage: {
|
|
@@ -57,15 +54,12 @@ function UploadCourseCover(inProps) {
|
|
|
57
54
|
props: inProps,
|
|
58
55
|
name: constants_1.PREFIX
|
|
59
56
|
});
|
|
60
|
-
const {
|
|
57
|
+
const { isUploading = false, onChange, className = false } = props, rest = tslib_1.__rest(props, ["isUploading", "onChange", "className"]);
|
|
61
58
|
//CONTEXT
|
|
62
59
|
const scUserContext = (0, react_1.useContext)(react_core_1.SCUserContext);
|
|
63
60
|
//STATE
|
|
64
61
|
let fileInput = (0, react_1.useRef)(null);
|
|
65
|
-
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
66
62
|
const [alert, setAlert] = (0, react_1.useState)(null);
|
|
67
|
-
// INTL
|
|
68
|
-
const intl = (0, react_intl_1.useIntl)();
|
|
69
63
|
// Anonymous
|
|
70
64
|
if (!scUserContext.user) {
|
|
71
65
|
return null;
|
|
@@ -83,47 +77,18 @@ function UploadCourseCover(inProps) {
|
|
|
83
77
|
reader.onload = (e) => {
|
|
84
78
|
const img = new Image();
|
|
85
79
|
img.onload = () => {
|
|
86
|
-
|
|
87
|
-
onChange(fileInput);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
onChange(fileInput);
|
|
91
|
-
handleSave();
|
|
92
|
-
}
|
|
80
|
+
onChange(fileInput);
|
|
93
81
|
};
|
|
94
82
|
img.src = e.target.result;
|
|
95
83
|
};
|
|
96
84
|
reader.readAsDataURL(selectedFile);
|
|
97
85
|
};
|
|
98
|
-
/**
|
|
99
|
-
* Handles cover saving after upload action
|
|
100
|
-
*/
|
|
101
|
-
function handleSave() {
|
|
102
|
-
if (!fileInput) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
setLoading(true);
|
|
106
|
-
const formData = new FormData();
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
formData.append('image_original', fileInput);
|
|
110
|
-
api_services_1.CourseService.changeCourseCover(courseId, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
|
|
111
|
-
.then((data) => {
|
|
112
|
-
// onChange && onChange(data.image_medium);
|
|
113
|
-
setLoading(false);
|
|
114
|
-
})
|
|
115
|
-
.catch((error) => {
|
|
116
|
-
utils_1.Logger.error(Errors_1.SCOPE_SC_UI, error);
|
|
117
|
-
setLoading(false);
|
|
118
|
-
setAlert(intl.formatMessage(messages.errorLoadImage));
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
86
|
/**
|
|
122
87
|
* If there is an error
|
|
123
88
|
*/
|
|
124
89
|
if (alert) {
|
|
125
90
|
return ((0, jsx_runtime_1.jsx)(material_1.Alert, Object.assign({ color: "error", onClose: () => setAlert(null) }, { children: alert })));
|
|
126
91
|
}
|
|
127
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }), (0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), size: "medium", variant: "contained", disabled:
|
|
92
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }), (0, jsx_runtime_1.jsx)(Root, Object.assign({ className: (0, classnames_1.default)(classes.root, className), size: "medium", variant: "contained", disabled: isUploading, onClick: () => fileInput.current.click(), loading: isUploading }, rest, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "image" }) }))] }));
|
|
128
93
|
}
|
|
129
94
|
exports.default = UploadCourseCover;
|
|
@@ -97,7 +97,7 @@ const Root = styled(Box, {
|
|
|
97
97
|
* @param inProps
|
|
98
98
|
*/
|
|
99
99
|
export default function CourseForm(inProps) {
|
|
100
|
-
var _a, _b, _c
|
|
100
|
+
var _a, _b, _c;
|
|
101
101
|
//PROPS
|
|
102
102
|
const props = useThemeProps({
|
|
103
103
|
props: inProps,
|
|
@@ -183,28 +183,28 @@ export default function CourseForm(inProps) {
|
|
|
183
183
|
*/
|
|
184
184
|
const handleSubmit = useCallback(() => {
|
|
185
185
|
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: true })));
|
|
186
|
+
const formData = new FormData();
|
|
187
|
+
if (field.imageOriginalFile) {
|
|
188
|
+
formData.append('image_original', field.imageOriginalFile);
|
|
189
|
+
}
|
|
190
|
+
formData.append('name', field.name);
|
|
191
|
+
formData.append('description', field.description);
|
|
192
|
+
formData.append('type', field.type);
|
|
193
|
+
if (field.privacy) {
|
|
194
|
+
formData.append('privacy', field.privacy);
|
|
195
|
+
}
|
|
196
|
+
if (field.categories) {
|
|
197
|
+
for (const key in field.categories) {
|
|
198
|
+
formData.append(key, field.categories[key]);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
186
201
|
let courseService;
|
|
187
202
|
if (course) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
courseService = CourseService.updateCourse(course.id, data, {
|
|
191
|
-
headers: { 'Content-Type': 'application/json' }
|
|
203
|
+
courseService = CourseService.updateCourse(course.id, formData, {
|
|
204
|
+
headers: { 'Content-Type': 'multipart/form-data' }
|
|
192
205
|
});
|
|
193
206
|
}
|
|
194
207
|
else {
|
|
195
|
-
// Create
|
|
196
|
-
const formData = new FormData();
|
|
197
|
-
if (field.imageOriginalFile) {
|
|
198
|
-
formData.append('image_original', field.imageOriginalFile);
|
|
199
|
-
}
|
|
200
|
-
formData.append('name', field.name);
|
|
201
|
-
formData.append('description', field.description);
|
|
202
|
-
formData.append('type', field.type);
|
|
203
|
-
if (field.categories) {
|
|
204
|
-
for (const key in field.categories) {
|
|
205
|
-
formData.append(key, field.categories[key]);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
208
|
courseService = CourseService.createCourse(formData, {
|
|
209
209
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|
210
210
|
});
|
|
@@ -212,18 +212,18 @@ export default function CourseForm(inProps) {
|
|
|
212
212
|
courseService
|
|
213
213
|
.then((data) => {
|
|
214
214
|
notifyChanges(data);
|
|
215
|
-
setField((prev) => (Object.assign(Object.assign({}, prev), {
|
|
215
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: false })));
|
|
216
216
|
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
|
|
217
217
|
})
|
|
218
218
|
.catch((e) => {
|
|
219
219
|
const _error = formatHttpErrorCode(e);
|
|
220
220
|
if (Object.values(_error)[0]['error'] === 'unique') {
|
|
221
|
-
setError(Object.assign(Object.assign({}, error), {
|
|
221
|
+
setError(Object.assign(Object.assign({}, error), { nameError: _jsx(FormattedMessage, { id: "ui.courseForm.name.error.unique", defaultMessage: "ui.courseForm.name.error.unique" }) }));
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
224
|
setError(Object.assign(Object.assign({}, error), _error));
|
|
225
225
|
}
|
|
226
|
-
setField((prev) => (Object.assign(Object.assign({}, prev), {
|
|
226
|
+
setField((prev) => (Object.assign(Object.assign({}, prev), { isSubmitting: false })));
|
|
227
227
|
Logger.error(SCOPE_SC_UI, e);
|
|
228
228
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
229
229
|
});
|
|
@@ -248,11 +248,11 @@ export default function CourseForm(inProps) {
|
|
|
248
248
|
/**
|
|
249
249
|
* Renders root object
|
|
250
250
|
*/
|
|
251
|
-
return (_jsxs(Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: _jsxs(Box, Object.assign({ className: _step === SCCourseFormStepType.GENERAL ? classes.stepOne : classes.stepTwo }, { children: [_step === SCCourseFormStepType.GENERAL && (_jsx(_Fragment, { children: Object.values(SCCourseTypologyType).map((option, index) => (_jsx(Card, Object.assign({ className: classNames(classes.card, { [classes.selected]: option === field.type }) }, { children: _jsx(CardActionArea, Object.assign({ onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['type']: option }))) }, { children: _jsxs(CardContent, { children: [_jsx(Typography, Object.assign({ variant: "subtitle2" }, { children: _jsx(FormattedMessage, { id: `ui.courseForm.${option}.title`, defaultMessage: `ui.courseForm.${option}.title` }) })), _jsx(Typography, Object.assign({ variant: "body2" }, { children: _jsx(FormattedMessage, { id: `ui.courseForm.${option}.info`, defaultMessage: `ui.courseForm.${option}.info` }) }))] }) })) }), index))) })), _step === SCCourseFormStepType.CUSTOMIZATION && (_jsxs(FormGroup, Object.assign({ className: classes.form }, { children: [course && (_jsx(Typography, Object.assign({ variant: "h5", className: classes.contrastColor }, { children: _jsx(FormattedMessage, { id: "ui.courseForm.edit.title.general", defaultMessage: "ui.courseForm.edit.title.general" }) }))), _jsx(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: _jsx(UploadCourseCover, {
|
|
251
|
+
return (_jsxs(Fragment, { children: [_jsx(Root, Object.assign({ className: classNames(classes.root, className) }, rest, { children: _jsxs(Box, Object.assign({ className: _step === SCCourseFormStepType.GENERAL ? classes.stepOne : classes.stepTwo }, { children: [_step === SCCourseFormStepType.GENERAL && (_jsx(_Fragment, { children: Object.values(SCCourseTypologyType).map((option, index) => (_jsx(Card, Object.assign({ className: classNames(classes.card, { [classes.selected]: option === field.type }) }, { children: _jsx(CardActionArea, Object.assign({ onClick: () => setField((prev) => (Object.assign(Object.assign({}, prev), { ['type']: option }))) }, { children: _jsxs(CardContent, { children: [_jsx(Typography, Object.assign({ variant: "subtitle2" }, { children: _jsx(FormattedMessage, { id: `ui.courseForm.${option}.title`, defaultMessage: `ui.courseForm.${option}.title` }) })), _jsx(Typography, Object.assign({ variant: "body2" }, { children: _jsx(FormattedMessage, { id: `ui.courseForm.${option}.info`, defaultMessage: `ui.courseForm.${option}.info` }) }))] }) })) }), index))) })), _step === SCCourseFormStepType.CUSTOMIZATION && (_jsxs(FormGroup, Object.assign({ className: classes.form }, { children: [course && (_jsx(Typography, Object.assign({ variant: "h5", className: classes.contrastColor }, { children: _jsx(FormattedMessage, { id: "ui.courseForm.edit.title.general", defaultMessage: "ui.courseForm.edit.title.general" }) }))), _jsx(Paper, Object.assign({ style: _backgroundCover, classes: { root: classes.cover } }, { children: _jsx(UploadCourseCover, { isUploading: field.isSubmitting, onChange: handleChangeCover }) })), _jsx(TextField, { required: true, className: classNames(classes.name, classes.contrastBgColor), placeholder: `${intl.formatMessage(messages.name)}`, margin: "normal", value: field.name, name: "name", onChange: handleChange, InputProps: {
|
|
252
252
|
endAdornment: _jsx(Typography, Object.assign({ variant: "body2" }, { children: COURSE_TITLE_MAX_LENGTH - field.name.length }))
|
|
253
253
|
}, error: Boolean(field.name.length > COURSE_TITLE_MAX_LENGTH) || Boolean(error['nameError']), helperText: field.name.length > COURSE_TITLE_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.courseForm.name.error.maxLength", defaultMessage: "ui.courseForm.name.error.maxLength" })) : error['nameError'] ? (error['nameError']) : null }), _jsx(TextField, { multiline: true, className: classNames(classes.description, classes.contrastBgColor), placeholder: `${intl.formatMessage(messages.description)}`, margin: "normal", value: field.description, name: "description", onChange: handleChange, InputProps: {
|
|
254
|
-
endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((
|
|
255
|
-
}, error: Boolean(((
|
|
254
|
+
endAdornment: (_jsx(Typography, Object.assign({ variant: "body2" }, { children: ((_a = field.description) === null || _a === void 0 ? void 0 : _a.length) ? COURSE_DESCRIPTION_MAX_LENGTH - field.description.length : COURSE_DESCRIPTION_MAX_LENGTH })))
|
|
255
|
+
}, error: Boolean(((_b = field.description) === null || _b === void 0 ? void 0 : _b.length) > COURSE_DESCRIPTION_MAX_LENGTH), helperText: ((_c = field.description) === null || _c === void 0 ? void 0 : _c.length) > COURSE_DESCRIPTION_MAX_LENGTH ? (_jsx(FormattedMessage, { id: "ui.courseForm.description.error.maxLength", defaultMessage: "ui.courseForm.description.error.maxLength" })) : null }), _jsx(CategoryAutocomplete, { defaultValue: field.categories, TextFieldProps: { label: intl.formatMessage(Object.keys(field.categories).length ? messages.category : messages.categoryEmpty) }, multiple: true, onChange: handleOnChangeCategory, className: classes.contrastBgColor }), course && (_jsx(CourseEdit, { course: course, onPrivacyChange: (privacy) => setField((prev) => (Object.assign(Object.assign({}, prev), { ['privacy']: privacy }))), className: classes.contrastBgColor }))] }))), _jsx(Box, Object.assign({ className: classNames(classes.actions, classes.contrastBgColor) }, { children: _jsx(LoadingButton, Object.assign({ size: "small", loading: field.isSubmitting, disabled: _step === SCCourseFormStepType.GENERAL
|
|
256
256
|
? !field.type || Object.keys(error).length !== 0
|
|
257
257
|
: _step === SCCourseFormStepType.CUSTOMIZATION &&
|
|
258
258
|
(!field.name ||
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export interface UploadCourseCoverProps {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @default
|
|
3
|
+
* If the image is in uploadingstate
|
|
4
|
+
* @default false
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
isUploading: boolean;
|
|
7
7
|
/**
|
|
8
8
|
* On change function.
|
|
9
9
|
* @default null
|
|
@@ -14,11 +14,6 @@ export interface UploadCourseCoverProps {
|
|
|
14
14
|
* @default null
|
|
15
15
|
*/
|
|
16
16
|
className?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Prop to handle cover loading in the create course modal.
|
|
19
|
-
* @default false
|
|
20
|
-
*/
|
|
21
|
-
isCreationMode?: boolean;
|
|
22
17
|
/**
|
|
23
18
|
* Any other properties
|
|
24
19
|
*/
|
|
@@ -9,10 +9,7 @@ import classNames from 'classnames';
|
|
|
9
9
|
import { useThemeProps } from '@mui/system';
|
|
10
10
|
import { PREFIX } from './constants';
|
|
11
11
|
import { LoadingButton } from '@mui/lab';
|
|
12
|
-
import {
|
|
13
|
-
import { CourseService } from '@selfcommunity/api-services';
|
|
14
|
-
import { Logger } from '@selfcommunity/utils';
|
|
15
|
-
import { defineMessages, useIntl } from 'react-intl';
|
|
12
|
+
import { defineMessages } from 'react-intl';
|
|
16
13
|
const messages = defineMessages({
|
|
17
14
|
errorLoadImage: {
|
|
18
15
|
id: 'ui.changeGroupCover.button.change.alertErrorImage',
|
|
@@ -55,15 +52,12 @@ export default function UploadCourseCover(inProps) {
|
|
|
55
52
|
props: inProps,
|
|
56
53
|
name: PREFIX
|
|
57
54
|
});
|
|
58
|
-
const {
|
|
55
|
+
const { isUploading = false, onChange, className = false } = props, rest = __rest(props, ["isUploading", "onChange", "className"]);
|
|
59
56
|
//CONTEXT
|
|
60
57
|
const scUserContext = useContext(SCUserContext);
|
|
61
58
|
//STATE
|
|
62
59
|
let fileInput = useRef(null);
|
|
63
|
-
const [loading, setLoading] = useState(false);
|
|
64
60
|
const [alert, setAlert] = useState(null);
|
|
65
|
-
// INTL
|
|
66
|
-
const intl = useIntl();
|
|
67
61
|
// Anonymous
|
|
68
62
|
if (!scUserContext.user) {
|
|
69
63
|
return null;
|
|
@@ -81,46 +75,17 @@ export default function UploadCourseCover(inProps) {
|
|
|
81
75
|
reader.onload = (e) => {
|
|
82
76
|
const img = new Image();
|
|
83
77
|
img.onload = () => {
|
|
84
|
-
|
|
85
|
-
onChange(fileInput);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
onChange(fileInput);
|
|
89
|
-
handleSave();
|
|
90
|
-
}
|
|
78
|
+
onChange(fileInput);
|
|
91
79
|
};
|
|
92
80
|
img.src = e.target.result;
|
|
93
81
|
};
|
|
94
82
|
reader.readAsDataURL(selectedFile);
|
|
95
83
|
};
|
|
96
|
-
/**
|
|
97
|
-
* Handles cover saving after upload action
|
|
98
|
-
*/
|
|
99
|
-
function handleSave() {
|
|
100
|
-
if (!fileInput) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
setLoading(true);
|
|
104
|
-
const formData = new FormData();
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
formData.append('image_original', fileInput);
|
|
108
|
-
CourseService.changeCourseCover(courseId, formData, { headers: { 'Content-Type': 'multipart/form-data' } })
|
|
109
|
-
.then((data) => {
|
|
110
|
-
// onChange && onChange(data.image_medium);
|
|
111
|
-
setLoading(false);
|
|
112
|
-
})
|
|
113
|
-
.catch((error) => {
|
|
114
|
-
Logger.error(SCOPE_SC_UI, error);
|
|
115
|
-
setLoading(false);
|
|
116
|
-
setAlert(intl.formatMessage(messages.errorLoadImage));
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
84
|
/**
|
|
120
85
|
* If there is an error
|
|
121
86
|
*/
|
|
122
87
|
if (alert) {
|
|
123
88
|
return (_jsx(Alert, Object.assign({ color: "error", onClose: () => setAlert(null) }, { children: alert })));
|
|
124
89
|
}
|
|
125
|
-
return (_jsxs(_Fragment, { children: [_jsx("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }), _jsx(Root, Object.assign({ className: classNames(classes.root, className), size: "medium", variant: "contained", disabled:
|
|
90
|
+
return (_jsxs(_Fragment, { children: [_jsx("input", { type: "file", onChange: handleUpload, ref: fileInput, hidden: true, accept: ".gif,.png,.jpg,.jpeg" }), _jsx(Root, Object.assign({ className: classNames(classes.root, className), size: "medium", variant: "contained", disabled: isUploading, onClick: () => fileInput.current.click(), loading: isUploading }, rest, { children: _jsx(Icon, { children: "image" }) }))] }));
|
|
126
91
|
}
|