diff --git a/api/src/controllers/newsController.js b/api/src/controllers/newsController.js
index ace3a6066..7cbe0d0eb 100644
--- a/api/src/controllers/newsController.js
+++ b/api/src/controllers/newsController.js
@@ -44,11 +44,11 @@ const addNews = (req, res) => {
if (req.file) {
filename = req.file.filename
}
+
const {
title, message, docType, readTime, language, creator, textDetail, imageDetail, videoDetail, category
} = req.body
db.News.create({
- // _attachments: 'uploads/' + req.file.filename,
_attachments: 'news/' + filename,
title,
message,
@@ -62,7 +62,7 @@ const addNews = (req, res) => {
category,
communityId: req.params.id
})
- .then(() => res.json({ message: 'News Created !!!' }).status(200))
+ .then((data) => res.json({ data }).status(200))
.catch((err) => res.json({ error: err.message }).status(400))
}
@@ -140,7 +140,17 @@ const getNewsById = (req, res) => {
model: db.Community,
attributes: [],
where: { id: req.params.id }
- }]
+ },
+ {
+ model: db.Text,
+ },
+ {
+ model: db.Photo,
+ },
+ {
+ model: db.Video,
+ }
+ ]
})
.then(news => {
if (news) {
diff --git a/api/src/controllers/photoController.js b/api/src/controllers/photoController.js
index 2e81b0513..a942b94aa 100644
--- a/api/src/controllers/photoController.js
+++ b/api/src/controllers/photoController.js
@@ -54,30 +54,33 @@ const addphoto = async (req, res) => {
})
}
-const deletePhoto = async (req, res) => {
- const { id } = req.params
- const photo = await db.Photo.destroy({ where: { id } })
- if (!photo) {
- throw new NotFoundError()
+const updatePhoto = async (req, res) => {
+ let lessonImg = ''
+
+ const singlePhoto = await db.Photo.findOne({where: {id: req.params.id}});
+ if (req.file) {
+ lessonImg = req.file.filename
+ } else {
+ lessonImg = singlePhoto.dataValues.lessonImg
}
- res.status(202).json({
+
+ const photo = await db.Photo.update({ ...req.body, lessonImg }, {where: {id: req.params.id}})
+ res.status(201).json({
status: true,
- message: 'Lesson photo deleted successfully',
+ message: 'photo updated successfully',
data: photo
})
}
-const updatePhoto = async (req, res) => {
+const deletePhoto = async (req, res) => {
const { id } = req.params
- const photo = await db.Photo.update(req.body, {
- where: { id }
- })
+ const photo = await db.Photo.destroy({ where: { id } })
if (!photo) {
throw new NotFoundError()
}
res.status(202).json({
status: true,
- message: 'Lesson photo updated successfully',
+ message: 'Lesson photo deleted successfully',
data: photo
})
}
diff --git a/api/src/controllers/textController.js b/api/src/controllers/textController.js
index c70a0cde8..c4e05a122 100644
--- a/api/src/controllers/textController.js
+++ b/api/src/controllers/textController.js
@@ -37,14 +37,10 @@ const addText = async (req, res) => {
const deleteText = async (req, res) => {
const { id } = req.params
- const text = await db.Text.destroy({ where: { id } })
- if (!text) {
- throw new NotFoundError()
- }
+ await db.Text.destroy({ where: { id } })
res.status(202).json({
status: true,
message: 'Lesson text deleted successfully',
- data: text
})
}
diff --git a/api/src/controllers/videoController.js b/api/src/controllers/videoController.js
index 5be669be9..175d17c62 100644
--- a/api/src/controllers/videoController.js
+++ b/api/src/controllers/videoController.js
@@ -52,7 +52,7 @@ const addVideo = async (req, res) => {
videoResource = req.files.videoResource[0].filename
}
}
- // console.log(req)
+
const video = await db.Video.create({
...req.body,
videoCover,
@@ -78,13 +78,30 @@ const deleteVideo = async (req, res) => {
const updateVideo = async (req, res) => {
const { id } = req.params
- const video = await db.Video.update(req.body, {
+ const video = await db.Video.findOne({
where: { id }
})
+
+ let videoCover = ''
+ let videoResource = ''
+
+ if(req.files.videoCover === undefined) {
+ videoCover = video.dataValues.videoCover
+ videoResource = video.dataValues.videoResource
+ } else {
+ if (req.files.videoCover) {
+ videoCover = req.files.videoCover[0].filename
+ }
+ if (req.files.videoResource) {
+ videoResource = req.files.videoResource[0].filename
+ }
+ }
+
+ await db.Video.update({...req.body, videoCover, videoResource}, {where: {id}})
+
res.status(202).json({
status: true,
message: 'Video updated successfully',
- data: video
})
}
diff --git a/api/src/helpers/filehelpers.js b/api/src/helpers/filehelpers.js
index 2305758df..440b83085 100644
--- a/api/src/helpers/filehelpers.js
+++ b/api/src/helpers/filehelpers.js
@@ -53,38 +53,42 @@ const resizeImage = (req, res, next) => {
const { format, height, width } = { format: 'webp', ...req.body }
try {
// user might not send image sometimes
- if (!req.file) return next()
+ if (!req.file) {
+ return next()
- const filename = path
- .basename(req.file.path)
- .split('.')
- .slice(0, -1)
- .join('.')
- let dir = path.join(
- path.dirname(__dirname),
- '..',
- 'files',
- `${req.file.fieldname}`,
- filename
- )
- let newImage = sharp(req.file.path)
- if (width) {
- newImage = newImage.resize(parseInt(width))
- dir = dir + '-' + width + 'x' + height
}
- if (req.body.render) {
- newImage.toBuffer().then((data) => {
- // To display the image
- res.writeHead(200, {
- 'Content-Type': 'image/webp',
- 'Content-Length': data.length
+ else {
+ const filename = path
+ .basename(req.file.path)
+ .split('.')
+ .slice(0, -1)
+ .join('.')
+ let dir = path.join(
+ path.dirname(__dirname),
+ '..',
+ 'files',
+ `${req.file.fieldname}`,
+ filename
+ )
+ let newImage = sharp(req.file.path)
+ if (width) {
+ newImage = newImage.resize(parseInt(width))
+ dir = dir + '-' + width + 'x' + height
+ }
+ if (req.body.render) {
+ newImage.toBuffer().then((data) => {
+ // To display the image
+ res.writeHead(200, {
+ 'Content-Type': 'image/webp',
+ 'Content-Length': data.length
+ })
+ return res.end(data)
})
- return res.end(data)
- })
- } else {
- const savePath = dir + '.' + format
- newImage = newImage.toFile(savePath)
- return next(null, true)
+ } else {
+ const savePath = dir + '.' + format
+ newImage = newImage.toFile(savePath)
+ return next(null, true)
+ }
}
} catch (error) {
throw error
diff --git a/api/src/migrations/20210805052503-alter-videos-texts-photos-tbl-newsId.js b/api/src/migrations/20210805052503-alter-videos-texts-photos-tbl-newsId.js
new file mode 100644
index 000000000..1b1e5aaf9
--- /dev/null
+++ b/api/src/migrations/20210805052503-alter-videos-texts-photos-tbl-newsId.js
@@ -0,0 +1,33 @@
+'use strict'
+
+module.exports = {
+ up: async (queryInterface, Sequelize) => {
+ await queryInterface.addColumn('photos', 'newsId', {
+ type: Sequelize.INTEGER,
+ references: {
+ model: 'news',
+ key: 'id'
+ }
+ })
+ await queryInterface.addColumn('videos', 'newsId', {
+ type: Sequelize.INTEGER,
+ references: {
+ model: 'news',
+ key: 'id'
+ }
+ })
+ await queryInterface.addColumn('texts', 'newsId', {
+ type: Sequelize.INTEGER,
+ references: {
+ model: 'news',
+ key: 'id'
+ }
+ })
+ },
+
+ down: async (queryInterface, Sequelize) => {
+ await queryInterface.removeColumn('photos', 'newsId')
+ await queryInterface.removeColumn('videos', 'newsId')
+ await queryInterface.removeColumn('texts', 'newsId')
+ }
+}
diff --git a/api/src/models/newsModel.js b/api/src/models/newsModel.js
index 16ab72926..8d401df14 100644
--- a/api/src/models/newsModel.js
+++ b/api/src/models/newsModel.js
@@ -53,6 +53,9 @@ module.exports = (sequelize, DataTypes) => {
// association
News.associate = (models) => {
News.belongsTo(models.Community, { foreignKey: 'communityId' })
+ News.hasMany(models.Video, { foreignKey: 'newsId' })
+ News.hasMany(models.Text, { foreignKey: 'newsId' })
+ News.hasMany(models.Photo, { foreignKey: 'newsId' })
}
return News
}
diff --git a/api/src/models/photoModel.js b/api/src/models/photoModel.js
index 3d0fadce1..9fe964df9 100644
--- a/api/src/models/photoModel.js
+++ b/api/src/models/photoModel.js
@@ -14,6 +14,9 @@ module.exports = (sequelize, DataTypes) => {
isImgDesc: {
type: DataTypes.BOOLEAN
},
+ newsId: {
+ type: DataTypes.INTEGER
+ },
createdAt: {
type: DataTypes.DATE
},
@@ -24,6 +27,7 @@ module.exports = (sequelize, DataTypes) => {
{ timestamps: true })
Photo.associate = (models) => {
Photo.belongsTo(models.Lesson, { constraints: true, foreignKey: 'lessonId' })
+ Photo.belongsTo(models.News, { constraints: true, foreignKey: 'newsId' })
}
return Photo
}
diff --git a/api/src/models/textModel.js b/api/src/models/textModel.js
index ae81de3ea..7c1d831bb 100644
--- a/api/src/models/textModel.js
+++ b/api/src/models/textModel.js
@@ -13,6 +13,9 @@ module.exports = (sequelize, DataTypes) => {
textDescription: {
type: DataTypes.TEXT
},
+ newsId: {
+ type: DataTypes.INTEGER
+ },
createdAt: {
type: DataTypes.DATE
},
@@ -27,6 +30,10 @@ module.exports = (sequelize, DataTypes) => {
constraints: true,
foreignKey: 'lessonId'
})
+ Text.belongsTo(models.News, {
+ constraints: true,
+ foreignKey: 'newsId'
+ })
}
return Text
}
diff --git a/api/src/models/videoModel.js b/api/src/models/videoModel.js
index 7902736d9..6be13b684 100644
--- a/api/src/models/videoModel.js
+++ b/api/src/models/videoModel.js
@@ -20,6 +20,9 @@ module.exports = (sequelize, DataTypes) => {
videoResource: {
type: DataTypes.STRING
},
+ newsId: {
+ type: DataTypes.INTEGER
+ },
createdAt: {
type: DataTypes.DATE
},
@@ -30,6 +33,7 @@ module.exports = (sequelize, DataTypes) => {
{ timestamps: true })
Video.associate = (models) => {
Video.belongsTo(models.Lesson, { constraints: true, foreignKey: 'lessonId' })
+ Video.belongsTo(models.News, { constraints: true, foreignKey: 'newsId' })
}
return Video
diff --git a/api/src/routes/photoRouter.js b/api/src/routes/photoRouter.js
index 1f7251346..dd4461dc8 100644
--- a/api/src/routes/photoRouter.js
+++ b/api/src/routes/photoRouter.js
@@ -12,7 +12,7 @@ const {
} = require('../controllers/photoController')
router.route('/').get(getPhotos)
-router.route('/add').post(upload.single('lessonImg'), resizeImage, addphoto)
-router.route('/:id').get(getPhotoById).delete(deletePhoto).put(updatePhoto)
+router.route('/add').post(upload.single('img'), resizeImage, addphoto)
+router.route('/:id').get(getPhotoById).delete(deletePhoto).put(upload.single('img'), resizeImage, updatePhoto)
module.exports = router
diff --git a/api/src/routes/videoRouter.js b/api/src/routes/videoRouter.js
index e4eff0837..7bca6b4f7 100644
--- a/api/src/routes/videoRouter.js
+++ b/api/src/routes/videoRouter.js
@@ -13,8 +13,13 @@ const {
// get image file middleware
const fileChanger = (req, _res, next) => {
- req.file = req.files.videoCover[0]
- next()
+ if(req.files.videoCover === undefined) {
+ req.file = ''
+ next()
+ } else {
+ req.file = req.files.videoCover[0]
+ next()
+ }
}
router.route('/').get(getVideos)
@@ -26,6 +31,10 @@ router
resizeImage,
addVideo
)
-router.route('/:id').get(getVideosById).delete(deleteVideo).put(updateVideo)
+router.route('/:id').get(getVideosById).delete(deleteVideo).put(
+ upload.fields([{ name: 'videoCover' }, { name: 'videoResource' }]),
+ fileChanger,
+ resizeImage,
+ updateVideo)
module.exports = router
diff --git a/api/src/server.js b/api/src/server.js
index c4ae43f28..6730477a1 100644
--- a/api/src/server.js
+++ b/api/src/server.js
@@ -56,8 +56,8 @@ app.use('/api/groups-users', groupUsersRoutes)
app.use('/api/enterprises-users', enterpriseUsersRoutes)
app.use('/api/resizer', resizerRoutes)
app.use('/api/videos', videoRouter)
-app.use('/api/lesson-photos', photoRouter)
-app.use('/api/lesson-text', textRouter)
+app.use('/api/photos', photoRouter)
+app.use('/api/texts', textRouter)
app.use('/api/materials', materialRouter)
app.use('/api/tests', testRouter)
app.use('/api/questions', questionRouter)
diff --git a/src/App.jsx b/src/App.jsx
index 632f307fc..98cebccd5 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -74,8 +74,9 @@ function App () {
-
-
+
+
+
diff --git a/src/actions/lessonActions.js b/src/actions/lessonActions.js
index 7ed75dd09..09daf8f50 100644
--- a/src/actions/lessonActions.js
+++ b/src/actions/lessonActions.js
@@ -49,13 +49,15 @@ export const createLesson =
const lessonId = data?.data?.id
for (let i = 0; i < lessonData.length; i++) {
if (lessonData[i]?.videoLink || lessonData[i]?.videoResource) {
- await addVideo({ lessonData: lessonData[i], lessonId, dispatch })
+ await addVideo({ data: lessonData[i], lessonId, dispatch })
}
if (lessonData[i]?.lessonImg) {
- await addImage({ lessonData: lessonData[i], lessonId, dispatch })
+ console.log('hi')
+ await addImage({ data: lessonData[i], lessonId, dispatch })
}
if (lessonData[i]?.textHeading || lessonData[i]?.textDescription) {
- await addText({ lessonData: lessonData[i], lessonId, dispatch })
+ console.log('hello')
+ await addText({ data: lessonData[i], lessonId, dispatch })
}
}
for (let i = 0; i < material.length; i++) {
diff --git a/src/actions/newsActions.js b/src/actions/newsActions.js
index 8705a7a04..67b04b2d8 100644
--- a/src/actions/newsActions.js
+++ b/src/actions/newsActions.js
@@ -23,6 +23,9 @@ import {
} from '../constants/newsConstants'
import { logout } from './userAction'
+import { addVideo } from '../screens/courseManager/addLesson/addVideo'
+import { addImage } from '../screens/courseManager/addLesson/addImage'
+import { addText } from '../screens/courseManager/addLesson/addText'
// fetching current community
const currentCommunity = localStorage.getItem('currentCommunity')
@@ -67,18 +70,41 @@ export const searchNews = (search) => async (dispatch) => {
}
}
-export const createNews = (newNews) => async (dispatch, getState) => {
+export const createNews = (newNews, newsCover) => async (dispatch, getState) => {
const formData = new FormData()
- formData.append('news', newNews.file)
- formData.append('title', newNews.title)
- formData.append('category', newNews.category)
- formData.append('imageDetail', newNews.imageDetail)
+ formData.append('title', newNews[0].title)
+ formData.append('category', newNews[0].category)
+ formData.append('news', newsCover)
try {
+
+ const configFunc = () => {
+ const userdata = window.localStorage.getItem('userInfo')
+ const token = JSON.parse(userdata).token
+ const headers = { 'Content-Type': 'multipart/form-data' }
+ headers.Authorization = token && `Bearer ${token}`
+ return { headers }
+ }
+
dispatch({ type: NEWS_CREATE_REQUEST })
const { userLogin: { userInfo } } = getState()
const { data } = await postApi(dispatch, `${process.env.REACT_APP_API_BASE_URL}/api/news/add/community/${currentCommunity.id}`, formData)
dispatch({ type: NEWS_CREATE_SUCCESS, payload: data })
+
+ const newsId = data?.data?.id
+ for (let i = 0; i < newNews.length; i++) {
+ if (newNews[i]?.videoLink || newNews[i]?.videoResource) {
+ await addVideo({ data: newNews[i], lessonId: null, newsId, dispatch })
+ }
+ if (newNews[i]?.lessonImg) {
+ await addImage({ data: newNews[i], lessonId: null, newsId, dispatch })
+ }
+ if (newNews[i]?.textHeading || newNews[i]?.textDescription) {
+ await addText({ data: newNews[i], lessonId: null, newsId, dispatch })
+ }
+ }
+
dispatch({ type: NEWS_CLEAR, payload: data })
+ document.location.href = `/community-page-news/${currentCommunity.slug}`
} catch (error) {
const message =
error.response && error.response.data.message
@@ -130,19 +156,41 @@ export const savevideoDetail = (data) => (dispatch) => {
})
}
-export const newsUpdate = (newNews) => async (dispatch) => {
+export const newsUpdate = (news, newNews) => async (dispatch) => {
+ const formData = new FormData()
+ formData.append('title', news.title)
+ formData.append('category', news.category)
+ formData.append('news', news.newsCover)
try {
dispatch({ type: NEWS_UPDATE_REQUEST })
- const { id, title, description, category, file } = newNews
+ const { id } = news
const config = configFunc()
const data = await axios.put(
`${process.env.REACT_APP_API_BASE_URL}/api/news/${id}/community/${currentCommunity.id}`,
- { title, description, file, category }, config
+ formData, config
)
+
dispatch({
type: NEWS_UPDATE_SUCCESS,
payload: data
})
+
+ //adding new content
+ for (let i = 0; i < newNews.length; i++) {
+ if (newNews[i]?.videoLink || newNews[i]?.videoResource) {
+ await addVideo({ data: newNews[i], lessonId: null, newsId: id, dispatch })
+ }
+ if (newNews[i]?.lessonImg) {
+ await addImage({ data: newNews[i], lessonId: null, newsId: id, dispatch })
+ }
+ if (newNews[i]?.textHeading || newNews[i]?.textDescription) {
+ await addText({ data: newNews[i], lessonId: null, newsId: id, dispatch })
+ }
+ }
+
+ dispatch({ type: NEWS_CLEAR, payload: data })
+ document.location.href = `/community-page-news/${currentCommunity.slug}`
+
} catch (error) {
const message = error.response && error.response.data.message
? error.response.data.message
diff --git a/src/actions/photoActions.js b/src/actions/photoActions.js
index 34077a87d..f78ce1716 100644
--- a/src/actions/photoActions.js
+++ b/src/actions/photoActions.js
@@ -1,22 +1,32 @@
-import { ADD_LESSON_PHOTO } from '../utils/urlConstants'
+import {
+ Axios,
+ ADD_LESSON_PHOTO,
+ GET_LESSON_PHOTO
+} from '../utils/urlConstants'
import { postApi } from '../utils/apiFunc'
import {
- LESSSON_PHOTO_CREATE_REQUEST,
- LESSSON_PHOTO_CREATE_SUCCESS,
- LESSSON_PHOTO_CREATE_FAIL
+ PHOTO_CREATE_REQUEST,
+ PHOTO_CREATE_SUCCESS,
+ PHOTO_CREATE_FAIL,
+ PHOTO_UPDATE_REQUEST,
+ PHOTO_UPDATE_SUCCESS,
+ PHOTO_UPDATE_FAIL,
+ PHOTO_DELETE_REQUEST,
+ PHOTO_DELETE_SUCCESS,
+ PHOTO_DELETE_FAIL
} from '../constants/photoConstants'
export const createLessonImg =
- (lessonImg, photoDescription, isImgDesc, lessonId) => async (dispatch) => {
+ (lessonImg, photoDescription, isImgDesc, lessonId, newsId) => async (dispatch) => {
const lessonImgData = new FormData()
- lessonImgData.append('lessonImg', lessonImg)
+ lessonImgData.append('img', lessonImg)
lessonImgData.append('photoDescription', photoDescription)
lessonImgData.append('isImgDesc', isImgDesc)
- lessonImgData.append('lessonId', lessonId)
+ newsId ? lessonImgData.append('newsId', newsId) : lessonImgData.append('lessonId', lessonId)
try {
- dispatch({ type: LESSSON_PHOTO_CREATE_REQUEST })
+ dispatch({ type: PHOTO_CREATE_REQUEST })
const config = {
headers: {
'Content-Type': 'multipart/form-data'
@@ -28,10 +38,10 @@ export const createLessonImg =
lessonImgData,
config
)
- dispatch({ type: LESSSON_PHOTO_CREATE_SUCCESS, payload: data })
+ dispatch({ type: PHOTO_CREATE_SUCCESS, payload: data })
} catch (error) {
dispatch({
- type: LESSSON_PHOTO_CREATE_FAIL,
+ type: PHOTO_CREATE_FAIL,
payload:
error.response && error.response.data.message
? error.response.data.message
@@ -39,3 +49,54 @@ export const createLessonImg =
})
}
}
+
+export const updatePhoto =
+ (id, lessonImg, photoDescription, isImgDesc, setEditPhotoModel) =>
+ async (dispatch) => {
+ const lessonImgData = new FormData()
+
+ lessonImgData.append('img', lessonImg)
+ lessonImgData.append('photoDescription', photoDescription)
+ lessonImgData.append('isImgDesc', isImgDesc)
+
+ try {
+ dispatch({ type: PHOTO_UPDATE_REQUEST })
+ const config = {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ }
+ const { data } = await Axios.put(
+ GET_LESSON_PHOTO + `/${id}`,
+ lessonImgData,
+ config
+ )
+ dispatch({ type: PHOTO_UPDATE_SUCCESS, payload: data })
+ setEditPhotoModel(false)
+ } catch (error) {
+ dispatch({
+ type: PHOTO_UPDATE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+ }
+
+export const deletePhoto = (id, refetch) => async (dispatch) => {
+ try {
+ dispatch({ type: PHOTO_DELETE_REQUEST })
+ const { data } = await Axios.delete(GET_LESSON_PHOTO + `/${id}`)
+ dispatch({ type: PHOTO_DELETE_SUCCESS, payload: data })
+ refetch()
+ } catch (error) {
+ dispatch({
+ type: PHOTO_DELETE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+}
diff --git a/src/actions/textActions.js b/src/actions/textActions.js
index e99393265..70fd3bd82 100644
--- a/src/actions/textActions.js
+++ b/src/actions/textActions.js
@@ -1,27 +1,33 @@
-import { ADD_LESSON_TEXT } from '../utils/urlConstants'
+import { Axios, GET_LESSON_TEXT, ADD_LESSON_TEXT } from '../utils/urlConstants'
import { postApi } from '../utils/apiFunc'
import {
- LESSSON_TEXT_CREATE_REQUEST,
- LESSSON_TEXT_CREATE_SUCCESS,
- LESSSON_TEXT_CREATE_FAIL
+ TEXT_CREATE_REQUEST,
+ TEXT_CREATE_SUCCESS,
+ TEXT_CREATE_FAIL,
+ TEXT_UPDATE_REQUEST,
+ TEXT_UPDATE_SUCCESS,
+ TEXT_UPDATE_FAIL,
+ TEXT_DELETE_REQUEST,
+ TEXT_DELETE_SUCCESS,
+ TEXT_DELETE_FAIL
} from '../constants/textConstants'
export const createText =
- (textHeading, textDescription, lessonId) => async (dispatch) => {
- const textData = { textHeading, textDescription, lessonId }
+ (textHeading, textDescription, lessonId, newsId) => async (dispatch) => {
+ const textData = { textHeading, textDescription, lessonId, newsId }
try {
- dispatch({ type: LESSSON_TEXT_CREATE_REQUEST })
+ dispatch({ type: TEXT_CREATE_REQUEST })
const { data } = await postApi(
dispatch,
ADD_LESSON_TEXT,
textData
)
- dispatch({ type: LESSSON_TEXT_CREATE_SUCCESS, payload: data })
+ dispatch({ type: TEXT_CREATE_SUCCESS, payload: data })
} catch (error) {
dispatch({
- type: LESSSON_TEXT_CREATE_FAIL,
+ type: TEXT_CREATE_FAIL,
payload:
error.response && error.response.data.message
? error.response.data.message
@@ -29,3 +35,51 @@ export const createText =
})
}
}
+
+export const updateText =
+ (textId, textHeading, textDescription, setEditTextModel) =>
+ async (dispatch) => {
+ const textData = { textHeading, textDescription }
+
+ try {
+ dispatch({ type: TEXT_UPDATE_REQUEST })
+ const config = {
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ }
+ const { data } = await Axios.put(
+ GET_LESSON_TEXT + `/${textId}`,
+ textData,
+ config
+ )
+ dispatch({ type: TEXT_UPDATE_SUCCESS, payload: data })
+ // refetch()
+ setEditTextModel(false)
+ } catch (error) {
+ dispatch({
+ type: TEXT_UPDATE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+ }
+
+export const deleteText = (id, refetch) => async (dispatch) => {
+ try {
+ dispatch({ type: TEXT_DELETE_REQUEST })
+ const { data } = await Axios.delete(GET_LESSON_TEXT + `/${id}`)
+ dispatch({ type: TEXT_DELETE_SUCCESS, payload: data })
+ refetch()
+ } catch (error) {
+ dispatch({
+ type: TEXT_DELETE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+}
diff --git a/src/actions/videoActions.js b/src/actions/videoActions.js
index 10238bfe0..a44679c7a 100644
--- a/src/actions/videoActions.js
+++ b/src/actions/videoActions.js
@@ -1,10 +1,16 @@
-import { ADD_VIDEOS } from '../utils/urlConstants'
+import { Axios, ADD_VIDEOS, GET_VIDEOS } from '../utils/urlConstants'
import { postApi } from '../utils/apiFunc'
import {
VIDEO_CREATE_REQUEST,
VIDEO_CREATE_SUCCESS,
- VIDEO_CREATE_FAIL
+ VIDEO_CREATE_FAIL,
+ VIDEO_UPDATE_REQUEST,
+ VIDEO_UPDATE_SUCCESS,
+ VIDEO_UPDATE_FAIL,
+ VIDEO_DELETE_REQUEST,
+ VIDEO_DELETE_SUCCESS,
+ VIDEO_DELETE_FAIL
} from '../constants/videoConstants'
export const createVideo =
@@ -14,7 +20,8 @@ export const createVideo =
videoDescription,
videoLink,
videoResource,
- lessonId
+ lessonId,
+ newsId
) =>
async (dispatch) => {
const videoData = new FormData()
@@ -23,7 +30,7 @@ export const createVideo =
videoData.append('videoDescription', videoDescription)
videoData.append('videoLink', videoLink)
videoData.append('videoResource', videoResource)
- videoData.append('lessonId', lessonId)
+ newsId ? videoData.append('newsId', newsId) : videoData.append('lessonId', lessonId)
try {
dispatch({ type: VIDEO_CREATE_REQUEST })
@@ -44,3 +51,60 @@ export const createVideo =
})
}
}
+
+export const updateVideo =
+ (
+ id,
+ videoCover,
+ videoTitle,
+ videoDescription,
+ videoLink,
+ videoResource,
+ setEditVideoModel,
+ refetch
+ ) =>
+ async (dispatch) => {
+ const videoData = new FormData()
+ videoData.append('videoCover', videoCover)
+ videoData.append('videoTitle', videoTitle)
+ videoData.append('videoDescription', videoDescription)
+ videoData.append('videoLink', videoLink)
+ videoData.append('videoResource', videoResource)
+
+ try {
+ dispatch({ type: VIDEO_UPDATE_REQUEST })
+ const config = {
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ }
+ }
+ const { data } = await Axios.put(GET_VIDEOS + `/${id}`, videoData, config)
+ dispatch({ type: VIDEO_UPDATE_SUCCESS, payload: data })
+ setEditVideoModel(false)
+ } catch (error) {
+ dispatch({
+ type: VIDEO_UPDATE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+ }
+
+export const deleteVideo = (id, refetch) => async (dispatch) => {
+ try {
+ dispatch({ type: VIDEO_DELETE_REQUEST })
+ const { data } = await Axios.delete(GET_VIDEOS + `/${id}`)
+ dispatch({ type: VIDEO_DELETE_SUCCESS, payload: data })
+ refetch()
+ } catch (error) {
+ dispatch({
+ type: VIDEO_DELETE_FAIL,
+ payload:
+ error.response && error.response.data.message
+ ? error.response.data.message
+ : error.message
+ })
+ }
+}
diff --git a/src/components/contentAdd/ContentAdd.jsx b/src/components/contentAdd/ContentAdd.jsx
new file mode 100644
index 000000000..7d4f0813f
--- /dev/null
+++ b/src/components/contentAdd/ContentAdd.jsx
@@ -0,0 +1,42 @@
+import React from 'react'
+import Text from '../../screens/courseManager/addLesson/Text'
+import Image from '../lessonImage/Image'
+import Video from '../videoPlayer/Video'
+
+const ContentAdd = ({data, setVideoModal, setImageModal, setTextModal, textModal}) => {
+ return (
+ <>
+ {
+ data.length > 0 &&
+ data.map((vid, index) => (
+
+
+
+
+
+ ))
+ }
+
+
+
+
+
+ >
+ )
+}
+
+export default ContentAdd
diff --git a/src/components/contentAdd/ContentAdd.scss b/src/components/contentAdd/ContentAdd.scss
new file mode 100644
index 000000000..e69de29bb
diff --git a/src/components/editContent/EditContent.jsx b/src/components/editContent/EditContent.jsx
new file mode 100644
index 000000000..50f2791d7
--- /dev/null
+++ b/src/components/editContent/EditContent.jsx
@@ -0,0 +1,99 @@
+import { useState, useEffect } from 'react'
+import { GET_VIDEO, VIDEO_COVER, LESSON_IMG } from '../../utils/urlConstants'
+import Text from '../../screens/courseManager/addLesson/Text'
+import Image from '../lessonImage/Image'
+import Video from '../videoPlayer/Video'
+
+const EditContent = ({
+ data,
+ newLessonData,
+ setEditTextModel,
+ setEditPhotoModel,
+ setEditVideoModel,
+ removeTextItem,
+ removePhoto,
+ removeVideo,
+ removeLocalData,
+ editImageFunc,
+ editVideoFunc,
+ editTextFunc
+}) => {
+ const [allLessonData, setAllLessonData] = useState([])
+
+ useEffect(() => {
+ setAllLessonData(data, newLessonData)
+ }, [data, newLessonData])
+
+ function video (data) {
+ if (typeof data?.videoResource === 'string') {
+ return `${GET_VIDEO}${data?.videoResource}`
+ } else {
+ return data?.videoResource?.preview
+ }
+ }
+
+ return (
+ <>{
+ data && <>
+ {
+ data?.photos && data?.photos.map(item => {
+ return
+ })
+ }
+
+ {
+ data?.texts && data?.texts.map(item => {
+ return
+ })
+ }
+
+ {
+ data?.videos && data?.videos.map(item => {
+ return
+ })
+ }
+ >
+ }
+ >
+ )
+}
+
+export default EditContent
diff --git a/src/components/formUI/FormUI.jsx b/src/components/formUI/FormUI.jsx
index dc3c8944d..64276f6b4 100644
--- a/src/components/formUI/FormUI.jsx
+++ b/src/components/formUI/FormUI.jsx
@@ -86,10 +86,11 @@ export const SubmitButton = (props) => {
}
export const TextArea = React.forwardRef(
- ({ className, placeholder, name, rows, cols, onChange, disabled }, ref) => {
+ ({ className, placeholder, name, rows, cols, onChange, disabled, defaultValue }, ref) => {
return (
<>