This repository was archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddProjectButton.tsx
71 lines (65 loc) · 1.99 KB
/
AddProjectButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use client";
import {useTranslation} from "react-i18next";
import {Button, Typography, Skeleton} from "@mui/material";
import {getUserData, UserData} from "@lib/api";
import {useState, useEffect} from "react";
interface EditCourseButtonProps{
course_id:number
}
const AddProjectButton = ({course_id}: EditCourseButtonProps) => {
/*
* Specific add project button component
* @param course_id: The id of the course to which the project will be added
* */
const {t} = useTranslation();
const [user, setUser] = useState<UserData | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchUser = async () => {
try {
setUser(await getUserData());
} catch (error) {
console.error("There was an error fetching the user data:", error);
}
}
setLoading(false);
fetchUser();
}, [])
return (
loading ?
<Skeleton
variant='rectangular'
width={150}
height={45}
sx={{
borderRadius: '8px'
}}
/> :
<>
{user?.role !== 3 && ( // If the user is not a student
<Button
variant="contained"
color="secondary"
sx={{
width: 'fit-content',
height: 'fit-content',
}}
href={`/course/${course_id}/add_project/`}
>
<Typography
variant="subtitle1"
sx={{
color: 'secondary.contrastText',
display: 'inline-block',
whiteSpace: 'nowrap',
width: 'fit-content',
}}
>
{t("add_project")}
</Typography>
</Button>
)}
</>
)
}
export default AddProjectButton