fix user bug

This commit is contained in:
Dimas Atmodjo 2024-11-25 17:00:25 +07:00
parent e176c8b5e2
commit 57849e88b8
2 changed files with 15 additions and 3 deletions

View File

@ -8,7 +8,15 @@ import useDashboards from '../hooks/useDashboards';
import { slugify } from '../../../../utils/Constant'; import { slugify } from '../../../../utils/Constant';
import Skeleton from 'react-loading-skeleton'; import Skeleton from 'react-loading-skeleton';
function validName(fullName) {
const nameArray = fullName.split(" ");
const firstTwoWords = nameArray.slice(0, 2).join(" ");
return firstTwoWords;
}
const Dashboard = () => { const Dashboard = () => {
const { username } = JSON.parse(localStorage.getItem('userData'));
const { journey, loading, error, thumbPath} = useDashboards(); const { journey, loading, error, thumbPath} = useDashboards();
const noData = () =>{ return journey.lenght > 0 ? false : true }; const noData = () =>{ return journey.lenght > 0 ? false : true };
@ -19,7 +27,7 @@ const Dashboard = () => {
return ( return (
<div className='home-page'> <div className='home-page'>
<h1 className='text-blue fw-bold mb-1'>Hi, Dimas Anhar !</h1> <h1 className='text-blue text-capitalize fw-bold mb-1'>Hi, {validName(username)} !</h1>
<p className='text-secondary'>Lets evolve together with adaptive learning tailored just for you.</p> <p className='text-secondary'>Lets evolve together with adaptive learning tailored just for you.</p>
<h4 className='text-blue mt-4 fw-bold'>Your Last Journey!</h4> <h4 className='text-blue mt-4 fw-bold'>Your Last Journey!</h4>
<Container fluid className='bg-white rounded rounded-4 p-4'> <Container fluid className='bg-white rounded rounded-4 p-4'>

View File

@ -60,8 +60,12 @@ const useHistories = () => {
} }
setHistoryData(data.payload); setHistoryData(data.payload);
} catch (error) { } catch (error) {
if (error.status == 404) {
setHistoryData([]);
}else{
console.log(error); console.log(error);
setError('Failed to fetch data'); setError(error.message);
}
} finally { } finally {
setLoading(false); setLoading(false);
} }