1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useState , ChangeEvent } from "react" ;
22import { useNavigate } from "react-router-dom" ;
33import { getAllBlogs , getBlogsByAuthor } from "../../redux/actions/blogActions" ;
44import { createBlogAction } from "../../redux/actions/blogActions" ;
@@ -9,6 +9,9 @@ import { handleBlogImageUpload } from "../../utils/imageUploadUtil";
99import { useAppDispatch , useAppSelector } from "../../hooks/hooks" ;
1010import AllBlogsSkeleton from "../../skeletons/allBlogsSkeleton" ;
1111import 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' ;
1215import HideUnhideButton from "../../components/hideBlog"
1316
1417 interface Comment {
@@ -67,6 +70,7 @@ const AllBlogs = () => {
6770 const [ addingBlog , setAddingBlog ] = useState ( false ) ;
6871 const [ manyImaages , setManyImages ] = useState ( false ) ;
6972 const [ tags , setTags ] = useState ( '' ) ;
73+ const [ content , setContent ] = useState ( '' ) ;
7074 const [ submitData , setSubmitData ] = useState < SubmitData > ( {
7175 title : "" ,
7276 content : "" ,
@@ -226,20 +230,62 @@ const AllBlogs = () => {
226230 await dispatch ( createBlogAction ( obj ) ) ;
227231 setAddingBlog ( false ) ;
228232 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+
230240 } catch ( error ) {
231241 console . log ( error ) ;
232242 } finally {
233243 setIsUploading ( false ) ;
234244 }
235245 } ;
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+
236282
237283
238284 return (
239285 < div className = "min-h-screen bg-white w-full dark:bg-slate-900 dark:text-white p-6" >
240286 { addNewBlogModal && (
241287 < 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 " >
243289 < div className = "w-full flex mb-2 items-center justify-between" >
244290 < h3 className = "font-bold text-m dark:text-white " >
245291 CREATE A NEW BLOG
@@ -267,13 +313,14 @@ const AllBlogs = () => {
267313 </ div >
268314 < div className = "flex flex-col" >
269315 < 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"
275323 placeholder = "Enter Blog Content"
276- maxLength = { 2000 }
277324 />
278325 { errors . content && (
279326 < span className = "text-red-500 text-xs" > { errors . content } </ span >
@@ -361,19 +408,18 @@ const AllBlogs = () => {
361408 < div className = "max-w-6xl mt-2 mx-auto" >
362409 < div className = "mb-6 w-full flex items-center justify-between" >
363410 < 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 >
377423 </ div >
378424
379425 < div className = "space-y-4" >
@@ -397,9 +443,10 @@ const AllBlogs = () => {
397443 < p className = "text-lg font-medium break-words whitespace-normal overflow-wrap-break-word transition-colors" >
398444 { blog . title }
399445 </ 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 >
403450 </ div >
404451 < div className = "w-1/6 flex flex-col items-end text-sm dar:text-slate-400" >
405452 < span > { `${ blog . author . firstname } ${ blog . author . lastname } ` } </ span >
@@ -408,10 +455,7 @@ const AllBlogs = () => {
408455 </ span >
409456 </ div >
410457 { role === "admin" || role === "superAdmin" ? (
411- < HideUnhideButton
412- blogId = { blog . id }
413- isHidden = { blog . isHidden }
414- />
458+ < HideUnhideButton blogId = { blog . id } isHidden = { blog . isHidden } />
415459 ) : null }
416460 </ div >
417461 ) )
0 commit comments