Dashboard Render Fix
Dashboard Render Fix
fix all error which prevent my dashbord page to render well in the browser , and this error in my
prowser console "Destroy " isn't a function this description don"t come of this script but when i run
it , it"s display in my browser please fix it also : import React, { memo, useCallback, useContext,
useEffect, useId, useLayoutEffect, useState } from 'react';
import Header from './Header'
import NavUser from "./NavUser"
import { Badge, Button, Checkbox, IconButton, Rating, TextareaAutosize, Tooltip } from
'@mui/material'
import styled from 'styled-components';
import EventNoteRoundedIcon from '@mui/icons-material/EventNoteRounded';
import AccessTimeRoundedIcon from '@mui/icons-material/AccessTimeRounded';
import VideoLibraryRoundedIcon from '@mui/icons-material/VideoLibraryRounded';
import KeyboardArrowRightOutlinedIcon from '@mui/icons-material/KeyboardArrowRightOutlined';
import CancelOutlinedIcon from '@mui/icons-material/CancelOutlined';
import ThumbsUpDownRoundedIcon from '@mui/icons-material/ThumbsUpDownRounded';
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
import toast from 'react-hot-toast'
import DialogBox from './DialogBox';
import DisclaimerText from "./DisclaimerText";
import VideoThumbnail from './VideoThumbnail';
import ArticleContent from "../ArticleComponents/ArticleContent"
import { BsArrowUpRight, BsCheckCircle, BsCheckCircleFill, BsChevronRight, BsCircle, BsCircleFill,
BsEnvelope, BsFillArchiveFill, BsFillRocketTakeoffFill, BsRocket, BsRocketFill, BsRocketTakeoff } from
'react-icons/bs';
import ThemeHandler, { ThemeContext } from './ThemeHandler';
import { useMutation, useQueries, useQuery } from '@tanstack/react-query';
import apiClient from '../axios_handling/ApiClient';
import Loader from './Loader';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '../store/useAuthStore'
import { MessageCircleMoreIcon } from 'lucide-react';
import ChatContainer from '../RealChat/components/ChatContainer';
import { useChatStore } from '../../src_1/store/useChatStore';
import { useForm } from 'react-hook-form';
const para = `Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium asperiores
laborum repudiandae quidem eligendi suscipit quaerat iusto a, officiis, deleniti impedit magnam,
vero rerum voluptas? Possimus voluptatum doloribus expedita est.`;
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/13
border-radius: 4px;
overflow: hidden;
z-index: 5;
&::before {
content: '';
z-index: -1;
position: absolute;
height: 100%;
background: conic-gradient(#0f0f ,3.6deg, #0f0f 0deg);
transition: .5s ease-in-out;
top: 0;
left: 0;
height: 100%;
width: ${props => props.width || '0%'};
}
`;
`
function Dashboad() {
const [UserName, setUserName] = useState("Junior");
const [token, setToken] = useState(0);
const [SkillsLength, setSkillsLength] = useState(0);
const [RatingView, setRatingView] = useState(false);
const [showDialog, setShowDialog] = useState(false);
const [showMessage, setshowMessage] = useState(false);
await sendMessage({
text: data.text.trim()
});
MessageForm.reset()
} catch (error) {
toast.error("Failed to send message");
}
}
const SwitchMedia = () => {
setMediaQuery(!MediaQuery)
}
const OpenMessage = () => {
setshowMessage(!showMessage)
}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/13
const OpenDisclaimer = () => {
setShowDialog(!showDialog);
}
const { isDarkMode, toggleTheme } = ThemeContext
const Playlists = []
const Videos=[
{
useFulLinks: [
{ title: "Youtube", link: "www.youtube.com/feed/downloads" },
{ title: "Youtube", link: "www.youtube.com/feed/downloads" },
{ title: "Youtube", link: "www.youtube.com/feed/downloads" }
],
theme: "Hacking",
title: "Introduction au Hacking",
level: "Débutant",
tag: "",
link: 'https://www.youtube.com/watch?v=lTRiuFIWV54',
thumbnail: "https://img.youtube.com/vi/lTRiuFIWV54/hqdefault.jpg",
childrenVideo: (<><ArticleContent content={para} label={"Yann"}></ArticleContent> </>)
},
{
theme: "Sécurité Réseaux",
title: "Sécurité des Réseaux",
level: "Intermédiaire",
tag: "",
link: 'https://www.youtube.com/watch?v=8q5mc1AEtYo',
thumbnail: "https://img.youtube.com/vi/8q5mc1AEtYo/hqdefault.jpg",
childrenVideo: (<><ArticleContent content={para} label={"VONVON"}></ArticleContent> </>)
},
{
theme: "Cryptographie",
title: "Bases de la Cryptographie",
level: "Avancé",
tag: "",
link: "https://www.youtube.com/watch?v=5qap5aO4i9A",
thumbnail: "https://img.youtube.com/vi/5qap5aO4i9A/hqdefault.jpg",
childrenVideo: (<><p>Yann Ubarne</p></>)
},
];
// const {
// data: EventData,
// isLoading: EventLoading,
// isError: isEventError,
// error: EventError,
// } = useQuery({
// queryFn: async () => {
// const { data } = await apiClient.get('/api/user/events');
// return data
// },
// queryKey: ["New_Event"],
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/13
// refetchInterval: 1000,
// enabled: truehorloge,
// staleTime: 1,
// });
useEffect(() => {
checkAuth()
console.log(authUser)
}, [checkAuth,authUser]);
// useEffect(() => {
// if (isEventError) {
// console.error( EventError?.message);
// }
// }, [ isEventError, EventError])
// console.log(Events)
// if (EventLoading) {
// return <Loader />;
// }
// console.log(Events)
return (
<ThemeHandler>
<>
<Header MediaQuery={MediaQuery}></Header>
<div className="dashboard-parent">
<div className="dashboard">
<div className="dashboard-content">
<DashboardHeader UserName={UserName} OpenDisclaimer={OpenDisclaimer} />
<DashboardSecondPart token={token} SkillsLength={SkillsLength} ProgressBar=
{ProgressBar} />
<UserRequest SendMessage={SendMessage} Chats={Chats} OpenMessage={OpenMessage}
MessageForm={MessageForm}/>
<EventHandling Events={Events} />
<VideoSuggestion Videos={Videos} />
<RatingBtn setRatingView={setRatingView} />
</div>
</div>
<RatingHandling
RatingView={RatingView}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/13
setRatingView={setRatingView}
seRatingValue={seRatingValue}
RatingValue={RatingValue}
/>
</div>
<DialogBox show={showMessage} onClose={OpenMessage} title={"Messages"} content={
<div style={{height:'100%'}}>
<div id='user-chat-bg' style={{ display: "flex",alignItems: "center",justifyContent: "center"}}>
<div style={{borderRadius: "0.5rem",width: "100%",maxWidth: "72rem",height: "calc(100vh -
8rem /* 128px */)"}} >
<div style={{display: "flex",height: "100%",borderRadius: "0.5rem",overflow: "hidden"}}>
<ChatContainer />
</div>
</div>
</div>
</div>
} />
<DialogBox
show={showDialog}
onClose={OpenDisclaimer}
title={"Disclaimer"}
content={<DisclaimerText />}
/>
<NavUser
SwitchMedia={SwitchMedia}
// User={User}
/>
<Loader />
</>
</ThemeHandler>
);
};
<div className="three-part-dashboard">
<form action="" className="ask-form">
<TextareaAutosize
{...MessageForm.register('text',{required:true})}
className='ask-user-area'
aria-label="minimum height"
minRows={5}
placeholder="Posez moi vos questions" />
<div className="ask-btn-handler">
<Button variant='contained' className='send-ask' onClick=
{MessageForm.handleSubmit(SendMessage)}>Envoyer</Button>
{Chats.length > 0 && <Tooltip title="Nouveau Message">
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/13
<IconButton color='inherit' onClick={OpenMessage}>
<Badge badgeContent={Chats.length} max={9} color='error'>
<MessageCircleMoreIcon className='new-message' />
</Badge>
</IconButton>
</Tooltip>}
<Tooltip title="Vos questions sont répondu dans un délai de moins de 24h, PS: Si le système
détecte des spams votre adresse IP sera bloquer">
<ErrorOutlineIcon className='warning-spam-and-more'></ErrorOutlineIcon>
</Tooltip>
</div>
</form>
</div>
));
/>
</li>
))}
{/* {Videos?.map((tutorial, index) => (
<li key={index}>
<VideoThumbnail
thumbnail={tutorial?.thumbnail}
childrenVideo={tutorial?.childrenVideo}
link={tutorial?.link}
title={tutorial?.title}
theme={tutorial?.theme}
level={tutorial?.level}
/>
</li>
))} */}
</ul>
}
</div>
</div>
));
The code you provided is quite comprehensive but contains multiple issues that need fixing. Here's how
to address the key problems, including the "Destroy" is not a function error:
jsx
jsx
const {
data: EventData,
isLoading: EventLoading,
isError: isEventError,
error: EventError,
} = useQuery({
queryFn: async () => {
const { data } = await apiClient.get('/api/user/events');
return data;
},
queryKey: ["New_Event"],
refetchInterval: 1000,
});
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/13
4. Handle Missing Styles:
Ensure all class names (e.g., `.dashboard-parent`, `.dashboard-content`) are styled in your CSS
or styled-components.
5. Chat Store State:
Verify the `useChatStore` implementation. Ensure the `sendMessage` and `messages` properties
are correctly defined and used:
jsx
jsx
Updated Code
jsx
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/13
width: 100%;
background: #c7d0dd;
height: 10px;
border-radius: 4px;
overflow: hidden;
&::before {
content: '';
position: absolute;
height: 100%;
background: linear-gradient(90deg, #0f0, #f00);
width: ${(props) => props.width || '0%'};
transition: 0.5s ease-in-out;
}
`;
function Dashboad() {
const { authUser, checkAuth } = useAuthStore();
const { messages: Chats, sendMessage } = useChatStore();
const { register, handleSubmit, reset } = useForm();
const { isDarkMode } = useContext(ThemeContext);
useEffect(() => {
checkAuth();
if (authUser) {
const { username, token, skillsLength } = authUser;
setUserName(username || '');
setToken(token || 0);
setSkillsLength(skillsLength || 0);
}
}, [authUser, checkAuth]);
return (
<div className={`dashboard ${isDarkMode ? 'dark-mode' : ''}`}>
<Header />
<DialogBox
show={showDialog}
onClose={() => setShowDialog(false)}
title="Disclaimer"
content={<DisclaimerText />}
/>
<NavUser />
<form onSubmit={handleSubmit(handleSendMessage)}>
<textarea {...register('text')} />
<button type="submit">Send</button>
</form>
<ProgressBar width={`${SkillsLength * 0.5}%`} />
<ChatContainer Chats={Chats} />
</div>
);
}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/13
export default Dashboad;
Next Steps:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/13