icleafreportui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/.env +7 -0
  2. package/README.md +70 -0
  3. package/package.json +55 -0
  4. package/public/favicon.ico +0 -0
  5. package/public/images/EResourcesImg.png +0 -0
  6. package/public/images/courseCardImg.png +0 -0
  7. package/public/images/courseInfo.png +0 -0
  8. package/public/images/exam-options.png +0 -0
  9. package/public/images/icleaf-11.png +0 -0
  10. package/public/images/icleaf_logo.png +0 -0
  11. package/public/images/template.png +0 -0
  12. package/public/images/unnamed.png +0 -0
  13. package/public/images/user.jpg +0 -0
  14. package/public/images/young-man-studying-library-using-laptop-1.png +0 -0
  15. package/public/index.html +45 -0
  16. package/public/logo192.png +0 -0
  17. package/public/logo512.png +0 -0
  18. package/public/manifest.json +25 -0
  19. package/public/robots.txt +3 -0
  20. package/src/App.css +24 -0
  21. package/src/App.js +37 -0
  22. package/src/Login.js +159 -0
  23. package/src/Reports/CourseReport.js +209 -0
  24. package/src/Reports/ExamPackReport.js +554 -0
  25. package/src/Reports/ExamReport.js +269 -0
  26. package/src/Reports/Report.js +271 -0
  27. package/src/api/client.jsx +42 -0
  28. package/src/components/Header.css +301 -0
  29. package/src/components/Header.jsx +192 -0
  30. package/src/components/Loader.jsx +23 -0
  31. package/src/components/imagePathUrl.jsx +11 -0
  32. package/src/components/sidebar.css +947 -0
  33. package/src/components/sidebar.jsx +81 -0
  34. package/src/context/TenantProvider.jsx +22 -0
  35. package/src/fonts/210000.jpg +0 -0
  36. package/src/fonts/210001.jpg +0 -0
  37. package/src/fonts/210003.jpg +0 -0
  38. package/src/fonts/210004.jpg +0 -0
  39. package/src/fonts/210006.jpg +0 -0
  40. package/src/fonts/210018.jpg +0 -0
  41. package/src/fonts/210019.jpg +0 -0
  42. package/src/fonts/210020.jpg +0 -0
  43. package/src/fonts/210279.jpg +0 -0
  44. package/src/fonts/210280.jpg +0 -0
  45. package/src/fonts/Gilroy-Black.ttf +0 -0
  46. package/src/fonts/Gilroy-BlackItalic.ttf +0 -0
  47. package/src/fonts/Gilroy-Bold.ttf +0 -0
  48. package/src/fonts/Gilroy-BoldItalic.ttf +0 -0
  49. package/src/fonts/Gilroy-ExtraBold.ttf +0 -0
  50. package/src/fonts/Gilroy-ExtraBoldItalic.ttf +0 -0
  51. package/src/fonts/Gilroy-Heavy.ttf +0 -0
  52. package/src/fonts/Gilroy-HeavyItalic.ttf +0 -0
  53. package/src/fonts/Gilroy-Light.ttf +0 -0
  54. package/src/fonts/Gilroy-LightItalic.ttf +0 -0
  55. package/src/fonts/Gilroy-Medium.ttf +0 -0
  56. package/src/fonts/Gilroy-MediumItalic.ttf +0 -0
  57. package/src/fonts/Gilroy-Regular.ttf +0 -0
  58. package/src/fonts/Gilroy-RegularItalic.ttf +0 -0
  59. package/src/fonts/Gilroy-SemiBold.ttf +0 -0
  60. package/src/fonts/Gilroy-SemiBoldItalic.ttf +0 -0
  61. package/src/fonts/Gilroy-Thin.ttf +0 -0
  62. package/src/fonts/Gilroy-ThinItalic.ttf +0 -0
  63. package/src/fonts/Gilroy-UltraLight.ttf +0 -0
  64. package/src/fonts/Gilroy-UltraLightItalic.ttf +0 -0
  65. package/src/fonts/Help - Guide Document.pdf +0 -0
  66. package/src/fonts/License.txt +144 -0
  67. package/src/fonts/More Free Fonts on fontshmonts.com.url +2 -0
  68. package/src/fonts/cover.jpg +0 -0
  69. package/src/index.css +13 -0
  70. package/src/index.js +21 -0
  71. package/src/login.css +809 -0
  72. package/src/logo.svg +1 -0
  73. package/src/package.js +10 -0
  74. package/src/reportWebVitals.js +13 -0
  75. package/src/setupTests.js +5 -0
  76. package/src/styles.css +2026 -0
  77. package/src/theme.css +107 -0
package/.env ADDED
@@ -0,0 +1,7 @@
1
+ # REACT_APP_BASE_URL=https://icleaf.infocareerindia.com/icleafreport/
2
+ # REACT_APP_BASE_URL=http://192.168.3.107:8082/icleafreport/
3
+ REACT_APP_BASE_URL=http://192.168.2.203:8080/icleafreport
4
+ # REACT_APP_BASE_URL=http://localhost:8082/icleafreport/
5
+
6
+
7
+ GENERATE_SOURCEMAP=false
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Getting Started with Create React App
2
+
3
+ This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4
+
5
+ ## Available Scripts
6
+
7
+ In the project directory, you can run:
8
+
9
+ ### `npm start`
10
+
11
+ Runs the app in the development mode.\
12
+ Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13
+
14
+ The page will reload when you make changes.\
15
+ You may also see any lint errors in the console.
16
+
17
+ ### `npm test`
18
+
19
+ Launches the test runner in the interactive watch mode.\
20
+ See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21
+
22
+ ### `npm run build`
23
+
24
+ Builds the app for production to the `build` folder.\
25
+ It correctly bundles React in production mode and optimizes the build for the best performance.
26
+
27
+ The build is minified and the filenames include the hashes.\
28
+ Your app is ready to be deployed!
29
+
30
+ See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31
+
32
+ ### `npm run eject`
33
+
34
+ **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35
+
36
+ If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37
+
38
+ Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39
+
40
+ You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41
+
42
+ ## Learn More
43
+
44
+ You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45
+
46
+ To learn React, check out the [React documentation](https://reactjs.org/).
47
+
48
+ ### Code Splitting
49
+
50
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51
+
52
+ ### Analyzing the Bundle Size
53
+
54
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55
+
56
+ ### Making a Progressive Web App
57
+
58
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59
+
60
+ ### Advanced Configuration
61
+
62
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63
+
64
+ ### Deployment
65
+
66
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67
+
68
+ ### `npm run build` fails to minify
69
+
70
+ This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "icleafreportui",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "main": "src/package.js",
6
+ "homepage": "/reports",
7
+ "dependencies": {
8
+ "@emotion/react": "^11.11.4",
9
+ "@emotion/styled": "^11.11.5",
10
+ "@mui/icons-material": "^6.4.5",
11
+ "@mui/material": "^5.15.20",
12
+ "@mui/x-data-grid": "^7.27.1",
13
+ "@testing-library/jest-dom": "^5.17.0",
14
+ "@testing-library/react": "^13.4.0",
15
+ "@testing-library/user-event": "^13.5.0",
16
+ "antd": "^5.18.3",
17
+ "axios": "^1.7.2",
18
+ "bootstrap": "^5.3.3",
19
+ "file-saver": "^2.0.5",
20
+ "react": "^18.3.1",
21
+ "react-bootstrap": "^2.10.3",
22
+ "react-custom-scrollbars": "^4.2.1",
23
+ "react-dom": "^18.3.1",
24
+ "react-icons": "^5.2.1",
25
+ "react-loader-spinner": "^6.1.6",
26
+ "react-router-dom": "^6.24.0",
27
+ "react-scripts": "5.0.1",
28
+ "web-vitals": "^2.1.4",
29
+ "xlsx": "^0.18.5"
30
+ },
31
+ "scripts": {
32
+ "start": "react-scripts start",
33
+ "build": "react-scripts build",
34
+ "test": "react-scripts test",
35
+ "eject": "react-scripts eject"
36
+ },
37
+ "eslintConfig": {
38
+ "extends": [
39
+ "react-app",
40
+ "react-app/jest"
41
+ ]
42
+ },
43
+ "browserslist": {
44
+ "production": [
45
+ ">0.2%",
46
+ "not dead",
47
+ "not op_mini all"
48
+ ],
49
+ "development": [
50
+ "last 1 chrome version",
51
+ "last 1 firefox version",
52
+ "last 1 safari version"
53
+ ]
54
+ }
55
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,45 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="theme-color" content="#000000" />
8
+ <meta
9
+ name="description"
10
+ content="Web site created using create-react-app"
11
+ />
12
+ <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13
+ <!--
14
+ manifest.json provides metadata used when your web app is installed on a
15
+ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16
+ -->
17
+ <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18
+ <!--
19
+ Notice the use of %PUBLIC_URL% in the tags above.
20
+ It will be replaced with the URL of the `public` folder during the build.
21
+ Only files inside the `public` folder can be referenced from the HTML.
22
+
23
+ Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24
+ work correctly both with client-side routing and a non-root public URL.
25
+ Learn how to configure a non-root public URL by running `npm run build`.
26
+ -->
27
+ <title>Icleaf</title>
28
+ </head>
29
+ <body>
30
+ <noscript>You need to enable JavaScript to run this app.</noscript>
31
+ <div id="root"></div>
32
+ <script src="https://www.jdoodle.com/assets/jdoodle-pym.min.js" type="text/javascript"></script>
33
+
34
+ <!--
35
+ This HTML file is a template.
36
+ If you open it directly in the browser, you will see an empty page.
37
+
38
+ You can add webfonts, meta tags, or analytics to this file.
39
+ The build step will place the bundled scripts into the <body> tag.
40
+
41
+ To begin the development, run `npm start` or `yarn start`.
42
+ To create a production bundle, use `npm run build` or `yarn build`.
43
+ -->
44
+ </body>
45
+ </html>
Binary file
Binary file
@@ -0,0 +1,25 @@
1
+ {
2
+ "short_name": "Icleaf",
3
+ "name": "Create React App Sample",
4
+ "icons": [
5
+ {
6
+ "src": "favicon.ico",
7
+ "sizes": "64x64 32x32 24x24 16x16",
8
+ "type": "image/x-icon"
9
+ },
10
+ {
11
+ "src": "logo192.png",
12
+ "type": "image/png",
13
+ "sizes": "192x192"
14
+ },
15
+ {
16
+ "src": "logo512.png",
17
+ "type": "image/png",
18
+ "sizes": "512x512"
19
+ }
20
+ ],
21
+ "start_url": ".",
22
+ "display": "standalone",
23
+ "theme_color": "#000000",
24
+ "background_color": "#ffffff"
25
+ }
@@ -0,0 +1,3 @@
1
+ # https://www.robotstxt.org/robotstxt.html
2
+ User-agent: *
3
+ Disallow:
package/src/App.css ADDED
@@ -0,0 +1,24 @@
1
+
2
+ .select-class {
3
+ width: 20% !important;
4
+ margin: 30px 0px;
5
+
6
+ /* margin-left: 20px; */
7
+ border: 2px solid blue;
8
+ border-radius: 4px;
9
+ font-size: 15px;
10
+ display: block;
11
+ background-color: azure;
12
+ }
13
+
14
+ .select-class1 {
15
+ width: 17% !important;
16
+ margin-top: 40px;
17
+ margin-left: 20px;
18
+ padding: 15px 20px;
19
+ border: 1px solid black;
20
+ border-radius: 4px;
21
+ font-size: 15px;
22
+ display: block;
23
+ background-color: azure;
24
+ }
package/src/App.js ADDED
@@ -0,0 +1,37 @@
1
+ import React, { useState } from 'react';
2
+ import Login from './Login';
3
+ import Report from './Reports/Report';
4
+ import { HashRouter, Route, Routes } from 'react-router-dom';
5
+ import CourseReport from './Reports/CourseReport';
6
+ import ExamReport from './Reports/ExamReport';
7
+ import ExamPackReport from './Reports/ExamPackReport';
8
+ import { TenantProvider } from './context/TenantProvider'; // ADD THIS
9
+
10
+ const App = () => {
11
+ const userToken = localStorage.getItem("token")
12
+
13
+ // Configuration for API calls
14
+ const config = {
15
+ baseURL: process.env.REACT_APP_BASE_URL || 'http://192.168.2.203:8080/icleafreport',
16
+ tenantToken: 'tn_852cf0d3242a11f19d84005056575b50' // Your test token
17
+ };
18
+
19
+ return (
20
+ <TenantProvider config={config}>
21
+ <div className="App">
22
+ <HashRouter>
23
+ <Routes>
24
+ <Route path="/" element={userToken != null ? <Report /> : <Login />} />
25
+ <Route path="/login" element={userToken != null ? <Report /> : <Login />} />
26
+ <Route path="/report" element={<Report />} />
27
+ <Route path="/coursereport" element={<CourseReport />} />
28
+ <Route path="/examReport" element={<ExamReport />} />
29
+ <Route path="/examPackReport" element={<ExamPackReport />} />
30
+ </Routes>
31
+ </HashRouter>
32
+ </div>
33
+ </TenantProvider>
34
+ );
35
+ };
36
+
37
+ export default App;
package/src/Login.js ADDED
@@ -0,0 +1,159 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import axios from 'axios';
3
+ import { useHistory, useNavigate } from 'react-router-dom'; // Correct import statement for useHistory
4
+ import { logo, youngMan } from './components/imagePathUrl';
5
+ import { RiMailLine, RiLockLine, RiEyeOffLine } from 'react-icons/ri';
6
+ import { AiOutlineEyeInvisible, AiOutlineEye } from 'react-icons/ai';
7
+ import 'bootstrap/dist/css/bootstrap.css';
8
+ import './login.css';
9
+ import { Alert, Button, Snackbar } from '@mui/material';
10
+
11
+ const Login = () => {
12
+ const [username, setUsername] = useState('');
13
+ const [password, setPassword] = useState('');
14
+ const [showPassword, setShowPassword] = useState(false);
15
+ const [error, setError] = useState('');
16
+ const [openAlert, setOpenAlert] = useState(false);
17
+ const navigate = useNavigate(); // Initialize useHistory
18
+
19
+
20
+ // const getSubDomain = () => {
21
+ // const hostname = window.location.hostname;
22
+ // const parts = hostname.split('.');
23
+ // if (parts.length > 2) {
24
+ // return parts [0];
25
+ // }
26
+ // }
27
+
28
+ const getSubDomain = () => {
29
+ const hostname = window.location.hostname;
30
+ console.log("Hostname:", hostname); // debug
31
+
32
+ // For localhost without subdomain
33
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
34
+ return "icleaf";
35
+ }
36
+
37
+ const parts = hostname.split('.');
38
+ if (parts.length > 2) {
39
+ return parts[0]; // Returns subdomain
40
+ }
41
+
42
+ // If no subdomain found
43
+ return "icleaf";
44
+ };
45
+
46
+ const baseURL = process.env.REACT_APP_BASE_URL;
47
+
48
+ const handleLogin = async (e) => {
49
+ e.preventDefault();
50
+
51
+ const subdomain = getSubDomain();
52
+ try {
53
+ // const response = await axios.get(`${baseURL}` + "api/login?userName=" + username + "&password=" + password);
54
+ const response = await axios.get(
55
+ `${baseURL}api/login?userName=${username}&password=${password}&subdomain=${subdomain}`
56
+ );
57
+ console.log(response, "response")
58
+ if (response.data) {
59
+ var res = response.data;
60
+ if (res == "User Not Found") {
61
+ setError(res);
62
+ setOpenAlert(true);
63
+ } else if (res == "UserName or Password cannot be empty") {
64
+ setError(res);
65
+ setOpenAlert(true);
66
+ } else {
67
+ localStorage.setItem("token", response.data);
68
+ localStorage.setItem("subdomain", subdomain);
69
+ navigate('/Report');
70
+
71
+ }
72
+ }
73
+
74
+ } catch (error) {
75
+ setError('User Not Found');
76
+ setOpenAlert(true);
77
+ }
78
+ };
79
+
80
+ const togglePasswordVisibility = () => {
81
+ setShowPassword(!showPassword);
82
+ };
83
+
84
+ return (
85
+ <>
86
+ <div className="row page_container">
87
+ <div className="col-6 login_container1">
88
+ <img className='login_img' src={youngMan} />
89
+ </div>
90
+ <div className="col-6 login_container2_bg">
91
+ <div className='login_form_container'>
92
+ <div className='logo_container'>
93
+ <img className='logo_img' src={logo} alt="Login logo Image" />
94
+ </div>
95
+ <text className="welcome_text">Welcome</text>
96
+ <form onSubmit={handleLogin}>
97
+ <label className='login_label'>Username</label>
98
+ <div className='input_contanier'>
99
+ <div className="input_icons">
100
+ <RiMailLine />
101
+ </div>
102
+ <input
103
+ type="username"
104
+ id="username"
105
+ name="username"
106
+ className='input_box'
107
+ placeholder="Username"
108
+ // onBlur={(e) => validateForm(e.target.value, language.enterUsername, "userName")}
109
+ value={username}
110
+ onChange={(e) => {
111
+ setUsername(e.target.value);
112
+ // validateForm(e.target.value, language.enterUsername, "userName")
113
+ }}
114
+ />
115
+ </div>
116
+ <label className='login_label'>Password</label>
117
+ <div className='input_contanier'>
118
+ <div className="input_icons">
119
+ <RiLockLine />
120
+ </div>
121
+ <input
122
+ type={showPassword ? "text" : "password"}
123
+ id="password"
124
+ name="password"
125
+ className='input_box'
126
+ // onBlur={(e) => validateForm(e.target.value, language.enterPass, "password")}
127
+ placeholder="Password"
128
+ value={password}
129
+ onChange={(e) => {
130
+ setPassword(e.target.value);
131
+ // validateForm(e.target.value, language.enterPass, "password")
132
+ }}
133
+ style={{ userSelect: "none" }}
134
+ />
135
+ {showPassword ? <AiOutlineEye onClick={() => togglePasswordVisibility()} className="eye-icon_login" /> : <AiOutlineEyeInvisible onClick={() => togglePasswordVisibility()} className="eye-icon_login" />}
136
+ </div>
137
+ <div className='login_btn_container'>
138
+ <Button variant="contained" style={{ width: "100%", marginTop: "15px", padding: "10px" }} type="submit">Login</Button>
139
+ </div>
140
+ </form>
141
+ </div>
142
+ </div>
143
+
144
+ <Snackbar
145
+ open={openAlert}
146
+ autoHideDuration={6000}
147
+ onClose={() => setOpenAlert(false)}
148
+ anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
149
+ >
150
+ <Alert onClose={() => setOpenAlert(false)} severity="info" sx={{ width: '30%' }}>
151
+ {error}
152
+ </Alert>
153
+ </Snackbar>
154
+ </div>
155
+ </>
156
+ );
157
+ };
158
+
159
+ export default Login;
@@ -0,0 +1,209 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import axios from 'axios';
3
+ import { Autocomplete, FormControl, Button, Grid, Box, Typography, Paper, Snackbar, Alert, CircularProgress, TextField } from '@mui/material';
4
+ import { useNavigate } from 'react-router-dom';
5
+ import Header from '../components/Header';
6
+ import Sidebar from '../components/sidebar';
7
+ import '../App.css';
8
+
9
+ function CourseReport() {
10
+ const [token, setToken] = useState(localStorage.getItem("token"));
11
+ const navigate = useNavigate();
12
+ const [subjects, setSubjects] = useState([]);
13
+ const [courses, setCourses] = useState([]);
14
+ const [selectedSubject, setSelectedSubject] = useState(null);
15
+ const [selectedCourse, setSelectedCourse] = useState(null);
16
+ const [reportTypes] = useState(['Summary', 'Daywise']);
17
+ const [selectedReportType, setSelectedReportType] = useState(null);
18
+ const [alertMessage, setAlertMessage] = useState('');
19
+ const [loading, setLoading] = useState(false);
20
+ const [alertOpen, setAlertOpen] = useState(false);
21
+
22
+ const baseURL = process.env.REACT_APP_BASE_URL
23
+
24
+ useEffect(() => {
25
+ if (token == null) {
26
+ navigate("/login");
27
+ } else {
28
+ fetchAllSubjects();
29
+ }
30
+ }, []);
31
+
32
+ const fetchAllSubjects = async () => {
33
+ try {
34
+ const response = await axios({
35
+ method: "get",
36
+ url: `${baseURL}api/showAllSubjects`,
37
+ headers: { Authorization: `Bearer ${token}` },
38
+ });
39
+ setSubjects(response.data);
40
+ } catch (error) {
41
+ console.error('Error fetching subjects:', error);
42
+ }
43
+ };
44
+
45
+ const fetchCourses = async (subjectId) => {
46
+ try {
47
+ const response = await axios({
48
+ method: "get",
49
+ params: { subjectId },
50
+ url: `${baseURL}api/getCoursesBySubject`,
51
+ headers: { Authorization: `Bearer ${token}` },
52
+ });
53
+ setCourses(response.data);
54
+ } catch (error) {
55
+ console.error('Error fetching courses:', error);
56
+ }
57
+ };
58
+
59
+ const handleSubjectChange = (event, newValue) => {
60
+ setSelectedSubject(newValue);
61
+ setSelectedCourse(null);
62
+ setCourses([]);
63
+ if (newValue) {
64
+ fetchCourses(newValue.subjectId);
65
+ }
66
+ };
67
+
68
+ const handleCourseChange = (event, newValue) => {
69
+ setSelectedCourse(newValue);
70
+ };
71
+
72
+ const handleReportTypeChange = (event, newValue) => {
73
+ setSelectedReportType(newValue);
74
+ };
75
+
76
+ const handleDownload = async () => {
77
+ setLoading(true);
78
+ try {
79
+ let url;
80
+ if (selectedReportType === 'Summary') {
81
+ url = `${baseURL}api/downloadUserCorpCourseExcel?corpCourseId=${selectedCourse.id}`;
82
+ } else if (selectedReportType === 'Daywise') {
83
+ url = `${baseURL}api/downloadUserCorpCourseExcelDayWise?corpCourseId=${selectedCourse.id}`;
84
+ }
85
+
86
+ const response = await axios.get(url, {
87
+ responseType: 'blob',
88
+ headers: {
89
+ Authorization: `Bearer ${token}`
90
+ }
91
+ });
92
+ const contentDisposition = response.headers['content-disposition'];
93
+ const text = await response.data.text();
94
+ if (text.includes('Course not configured')) {
95
+ setAlertMessage('Course not configured.');
96
+ setAlertOpen(true);
97
+ } else {
98
+ const filename = 'course_report.xlsx';
99
+ const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
100
+ const blobUrl = URL.createObjectURL(blob);
101
+ const link = document.createElement('a');
102
+ link.href = blobUrl;
103
+ link.setAttribute('download', filename);
104
+ document.body.appendChild(link);
105
+ link.click();
106
+ link.parentNode.removeChild(link);
107
+ URL.revokeObjectURL(blobUrl);
108
+ }
109
+ } catch (error) {
110
+ console.error('Error downloading course report:', error);
111
+ } finally {
112
+ setLoading(false);
113
+ }
114
+ };
115
+
116
+
117
+ return (
118
+ <div>
119
+ <Header />
120
+ <Sidebar />
121
+ <div style={{ padding: "100px 0px 0px 100px", marginLeft: "140px" }}>
122
+ <Box sx={{ maxWidth: 800, mx: 'auto', my: 4, p: 3, backgroundColor: '#f5f5f5', borderRadius: 2 }}>
123
+ <Paper elevation={6} sx={{ p: 5, textAlign: 'center', backgroundColor: '#fff' }}>
124
+ <Typography variant="h4" component="h1" gutterBottom sx={{ color: '#3f51b5', marginBottom: "20px" }}>
125
+ Course Report
126
+ </Typography>
127
+ <Grid container spacing={2} justifyContent="center">
128
+ <Grid item xs={12} sm={4}>
129
+ <FormControl fullWidth>
130
+ <Autocomplete
131
+ id="ddlSubject"
132
+ options={subjects}
133
+ getOptionLabel={(option) => option.subjectName}
134
+ value={selectedSubject}
135
+ onChange={handleSubjectChange}
136
+ renderInput={(params) => <TextField {...params} label="Subject" />}
137
+ />
138
+ </FormControl>
139
+ </Grid>
140
+
141
+ <Grid item xs={12} sm={4}>
142
+ <FormControl fullWidth>
143
+ <Autocomplete
144
+ id="ddlCourse"
145
+ options={courses}
146
+ getOptionLabel={(option) => option.courseName}
147
+ value={selectedCourse}
148
+ onChange={handleCourseChange}
149
+ renderInput={(params) => <TextField {...params} label="Course" />}
150
+ />
151
+ </FormControl>
152
+ </Grid>
153
+
154
+ <Grid item xs={12} sm={4}>
155
+ <FormControl fullWidth>
156
+ <Autocomplete
157
+ id="ddlReportType"
158
+ options={reportTypes}
159
+ getOptionLabel={(option) => option}
160
+ value={selectedReportType}
161
+ onChange={handleReportTypeChange}
162
+ renderInput={(params) => <TextField {...params} label="Report Type" />}
163
+ />
164
+ </FormControl>
165
+ </Grid>
166
+ </Grid>
167
+
168
+ <Box sx={{ mt: 3, position: 'relative' }}>
169
+ <Button
170
+ variant="contained"
171
+ color="primary"
172
+ onClick={handleDownload}
173
+ disabled={!selectedSubject || !selectedCourse || !selectedReportType || loading}
174
+ sx={{ width: 'auto', backgroundColor: '#3f51b5', '&:hover': { backgroundColor: '#303f9f' } }}
175
+ >
176
+ {loading ? 'Downloading...' : 'Download Report'}
177
+ </Button>
178
+ {loading && (
179
+ <CircularProgress
180
+ size={24}
181
+ sx={{
182
+ position: 'absolute',
183
+ top: '50%',
184
+ left: '50%',
185
+ marginTop: '-12px',
186
+ marginLeft: '-12px',
187
+ }}
188
+ />
189
+ )}
190
+ </Box>
191
+ </Paper>
192
+ </Box>
193
+
194
+ <Snackbar
195
+ open={alertOpen}
196
+ autoHideDuration={6000}
197
+ onClose={() => setAlertOpen(false)}
198
+ anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
199
+ >
200
+ <Alert onClose={() => setAlertOpen(false)} severity="info" sx={{ width: '100%' }}>
201
+ {alertMessage}
202
+ </Alert>
203
+ </Snackbar>
204
+ </div>
205
+ </div>
206
+ );
207
+ }
208
+
209
+ export default CourseReport;