1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useEffect , useState , ChangeEvent } from "react" ;
2
2
import { useNavigate } from "react-router-dom" ;
3
3
import { getAllBlogs , getBlogsByAuthor } from "../../redux/actions/blogActions" ;
4
4
import { createBlogAction } from "../../redux/actions/blogActions" ;
@@ -9,6 +9,9 @@ import { handleBlogImageUpload } from "../../utils/imageUploadUtil";
9
9
import { useAppDispatch , useAppSelector } from "../../hooks/hooks" ;
10
10
import AllBlogsSkeleton from "../../skeletons/allBlogsSkeleton" ;
11
11
import SingleBlogSkeleton from "skeletons/singleBlogSkeleton" ;
12
+ import ReactQuill from 'react-quill' ;
13
+ import 'react-quill/dist/quill.snow.css' ;
14
+ import { AiOutlineClose } from 'react-icons/ai' ;
12
15
import HideUnhideButton from "../../components/hideBlog"
13
16
14
17
interface Comment {
@@ -67,6 +70,7 @@ const AllBlogs = () => {
67
70
const [ addingBlog , setAddingBlog ] = useState ( false ) ;
68
71
const [ manyImaages , setManyImages ] = useState ( false ) ;
69
72
const [ tags , setTags ] = useState ( '' ) ;
73
+ const [ content , setContent ] = useState ( '' ) ;
70
74
const [ submitData , setSubmitData ] = useState < SubmitData > ( {
71
75
title : "" ,
72
76
content : "" ,
@@ -226,20 +230,62 @@ const AllBlogs = () => {
226
230
await dispatch ( createBlogAction ( obj ) ) ;
227
231
setAddingBlog ( false ) ;
228
232
removeModal ( ) ;
229
- dispatch ( getBlogsByAuthor ( String ( userId ) ) ) ;
233
+
234
+ if ( role == "applicant" || role == "trainee" ) {
235
+ dispatch ( getBlogsByAuthor ( String ( userId ) ) ) ;
236
+ } else {
237
+ dispatch ( getAllBlogs ( ) ) ;
238
+ }
239
+
230
240
} catch ( error ) {
231
241
console . log ( error ) ;
232
242
} finally {
233
243
setIsUploading ( false ) ;
234
244
}
235
245
} ;
246
+
247
+ const modules = {
248
+ toolbar : [
249
+ [ { 'header' : [ 1 , 2 , 3 , 4 , 5 , 6 , false ] } ] ,
250
+ [ 'bold' , 'italic' , 'underline' , 'strike' ] ,
251
+ [ { 'list' : 'ordered' } , { 'list' : 'bullet' } ] ,
252
+ [ 'link' ] ,
253
+ [ { 'align' : [ ] } ] ,
254
+ [ { 'color' : [ ] } , { 'background' : [ ] } ] ,
255
+ [ 'clean' ]
256
+ ]
257
+ } ;
258
+
259
+ const formats = [
260
+ 'header' ,
261
+ 'bold' , 'italic' , 'underline' , 'strike' ,
262
+ 'list' , 'bullet' ,
263
+ 'link' , 'image' ,
264
+ 'align' ,
265
+ 'color' , 'background'
266
+ ] ;
267
+
268
+ const handleContentChange = ( value : string ) => {
269
+ setContent ( value ) ;
270
+
271
+ // Simulate an event object to match the expected input of handleInputChange
272
+ const syntheticEvent = {
273
+ target : {
274
+ name : 'content' ,
275
+ value : value
276
+ }
277
+ } as ChangeEvent < HTMLTextAreaElement > ;
278
+
279
+ handleInputChange ( syntheticEvent ) ;
280
+ } ;
281
+
236
282
237
283
238
284
return (
239
285
< div className = "min-h-screen bg-white w-full dark:bg-slate-900 dark:text-white p-6" >
240
286
{ addNewBlogModal && (
241
287
< div className = "fixed inset-0 mt-16 p-0 flex items-center justify-center bg-black bg-opacity-20 dark:bg-opacity-40" >
242
- < div className = "bg-white dark:bg-dark-bg w-11/12 md:w-3/5 lg:w-2/5 rounded-lg p-6" >
288
+ < div className = "bg-white dark:bg-dark-bg w-11/12 md:w-3/5 lg:w-2/5 rounded-lg p-6 max-h-[600px] overflow-y-scroll " >
243
289
< div className = "w-full flex mb-2 items-center justify-between" >
244
290
< h3 className = "font-bold text-m dark:text-white " >
245
291
CREATE A NEW BLOG
@@ -267,13 +313,14 @@ const AllBlogs = () => {
267
313
</ div >
268
314
< div className = "flex flex-col" >
269
315
< label className = "font-semibold text-sm" > Blog Content</ label >
270
- < textarea
271
- name = "content"
272
- value = { submitData . content }
273
- onChange = { handleInputChange }
274
- className = "border rounded focus:ring-2 focus:ring-white dark:bg-black px-4 py-2 h-24"
316
+ < ReactQuill
317
+ value = { content }
318
+ onChange = { handleContentChange }
319
+ modules = { modules }
320
+ formats = { formats }
321
+ theme = "snow"
322
+ className = "border rounded dark:bg-black"
275
323
placeholder = "Enter Blog Content"
276
- maxLength = { 2000 }
277
324
/>
278
325
{ errors . content && (
279
326
< span className = "text-red-500 text-xs" > { errors . content } </ span >
@@ -361,19 +408,18 @@ const AllBlogs = () => {
361
408
< div className = "max-w-6xl mt-2 mx-auto" >
362
409
< div className = "mb-6 w-full flex items-center justify-between" >
363
410
< h1 className = "text-2xl font-semibold" > All Blogs</ h1 >
364
- { userId && role && ( role == "applicant" || role == "trainee" ) && (
365
- < div className = "w-full sm:w-auto" >
366
- < button
367
- disabled = { isLoading }
368
- onClick = { Open }
369
- className = { `flex items-center justify-center w-full sm:w-auto ${
370
- isLoading ? "bg-emerald-300" : "bg-primary dark:bg-[#56C870]"
371
- } rounded-md py-2 px-4 text-white font-medium cursor-pointer hover:opacity-90 transition-opacity`}
372
- >
373
- < icons . AiOutlinePlus className = "mr-2" /> Blog
374
- </ button >
375
- </ div >
376
- ) }
411
+
412
+ < div className = "w-full sm:w-auto" >
413
+ < button
414
+ disabled = { isLoading }
415
+ onClick = { Open }
416
+ className = { `flex items-center justify-center w-full sm:w-auto ${
417
+ isLoading ? "bg-emerald-300" : "bg-primary dark:bg-[#56C870]"
418
+ } rounded-md py-2 px-4 text-white font-medium cursor-pointer hover:opacity-90 transition-opacity`}
419
+ >
420
+ < icons . AiOutlinePlus className = "mr-2" /> Blog
421
+ </ button >
422
+ </ div >
377
423
</ div >
378
424
379
425
< div className = "space-y-4" >
@@ -397,9 +443,10 @@ const AllBlogs = () => {
397
443
< p className = "text-lg font-medium break-words whitespace-normal overflow-wrap-break-word transition-colors" >
398
444
{ blog . title }
399
445
</ p >
400
- < p className = "dark:text-slate-400 text-slate-800 break break-words text-sm line-clamp-2" >
401
- { blog . content }
402
- </ p >
446
+ < div
447
+ className = "dark:text-slate-400 text-slate-800 break break-words text-sm line-clamp-2"
448
+ dangerouslySetInnerHTML = { { __html : blog . content } }
449
+ > </ div >
403
450
</ div >
404
451
< div className = "w-1/6 flex flex-col items-end text-sm dar:text-slate-400" >
405
452
< span > { `${ blog . author . firstname } ${ blog . author . lastname } ` } </ span >
@@ -408,10 +455,7 @@ const AllBlogs = () => {
408
455
</ span >
409
456
</ div >
410
457
{ role === "admin" || role === "superAdmin" ? (
411
- < HideUnhideButton
412
- blogId = { blog . id }
413
- isHidden = { blog . isHidden }
414
- />
458
+ < HideUnhideButton blogId = { blog . id } isHidden = { blog . isHidden } />
415
459
) : null }
416
460
</ div >
417
461
) )
0 commit comments