Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error message when coach is not connected to any students #83

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions client/src/Lessons/LessonsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function LessonsPage() {
const [addCardsWithImages, setAddCardsWithImages] = useState<ICard[]>([]);
const [lessonNumber, setLessonNumber] = useState<string>('');
const [loading, setLoading] = useState<boolean>(true);
const [errorMessage, setErrorMessage] = useState<string>('');

useEffect(() => {
const fetchResources = async () => {
Expand All @@ -49,6 +50,17 @@ function LessonsPage() {
resources = await getData(`coach/resources/${id}`);
}

if (resources.error) {
if (
resources.error.data.message.includes('connected to any students')
) {
setErrorMessage('Coach is not connected to any students.');
return;
}
setErrorMessage(resources.error.data.message);
return;
}

const lessonResources = resources?.data.resources || [];
const addResources = resources?.data.additional_resources || [];
const num = resources?.data.lesson_level || '';
Expand Down Expand Up @@ -94,6 +106,29 @@ function LessonsPage() {
fetchResources();
}, [role, id]);

if (errorMessage) {
return (
<Box
sx={{
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100vh',
}}
>
<Typography
variant="h2"
sx={{
textAlign: 'center',
}}
>
{errorMessage}
</Typography>
</Box>
);
}

if (loading) {
return (
<Box
Expand Down
Loading