icleafreportui 0.2.5 → 0.2.7

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.
package/dist/App.js CHANGED
@@ -12,7 +12,7 @@ const App = () => {
12
12
 
13
13
  // Configuration for API calls
14
14
  const config = {
15
- baseURL: process.env.REACT_APP_BASE_URL || 'http://192.168.2.203:8080/icleafreport',
15
+ baseURL: process.env.REACT_APP_BASE_URL || 'http://192.168.2.203:8080/icleafreport/',
16
16
  tenantToken: 'tn_96ef3426276611f19d84005056575b50'
17
17
  };
18
18
  return /*#__PURE__*/_jsx(TenantProvider, {
@@ -5,6 +5,7 @@ import { useNavigate } from 'react-router-dom';
5
5
  import Header from '../components/Header';
6
6
  import Sidebar from '../components/sidebar';
7
7
  import '../App.css';
8
+ import { useTenant } from '../context/TenantProvider';
8
9
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
10
  function CourseReport() {
10
11
  const [token, setToken] = useState(localStorage.getItem("token"));
@@ -19,6 +20,9 @@ function CourseReport() {
19
20
  const [loading, setLoading] = useState(false);
20
21
  const [alertOpen, setAlertOpen] = useState(false);
21
22
  const baseURL = process.env.REACT_APP_BASE_URL;
23
+ const {
24
+ apiClient
25
+ } = useTenant();
22
26
  useEffect(() => {
23
27
  if (token == null) {
24
28
  navigate("/login");
@@ -26,33 +30,32 @@ function CourseReport() {
26
30
  fetchAllSubjects();
27
31
  }
28
32
  }, []);
33
+
34
+ // const fetchAllSubjects = async () => {
35
+ // try {
36
+ // const response = await axios({
37
+ // method: "get",
38
+ // url: `${baseURL}api/showAllSubjects`,
39
+ // headers: { Authorization: `Bearer ${token}` },
40
+ // });
41
+ // setSubjects(response.data);
42
+ // } catch (error) {
43
+ // console.error('Error fetching subjects:', error);
44
+ // }
45
+ // };
46
+
29
47
  const fetchAllSubjects = async () => {
30
48
  try {
31
- const response = await axios({
32
- method: "get",
33
- url: `${baseURL}api/showAllSubjects`,
34
- headers: {
35
- Authorization: `Bearer ${token}`
36
- }
37
- });
38
- setSubjects(response.data);
49
+ const data = await apiClient.get('/api/showAllSubjects');
50
+ setSubjects(data);
39
51
  } catch (error) {
40
52
  console.error('Error fetching subjects:', error);
41
53
  }
42
54
  };
43
55
  const fetchCourses = async subjectId => {
44
56
  try {
45
- const response = await axios({
46
- method: "get",
47
- params: {
48
- subjectId
49
- },
50
- url: `${baseURL}api/getCoursesBySubject`,
51
- headers: {
52
- Authorization: `Bearer ${token}`
53
- }
54
- });
55
- setCourses(response.data);
57
+ const data = await apiClient.get(`/api/getCoursesBySubject?subjectId=${subjectId}`);
58
+ setCourses(data);
56
59
  } catch (error) {
57
60
  console.error('Error fetching courses:', error);
58
61
  }
@@ -71,35 +74,75 @@ function CourseReport() {
71
74
  const handleReportTypeChange = (event, newValue) => {
72
75
  setSelectedReportType(newValue);
73
76
  };
77
+
78
+ // const handleDownload = async () => {
79
+ // setLoading(true);
80
+ // try {
81
+ // let url;
82
+ // if (selectedReportType === 'Summary') {
83
+ // url = `${baseURL}api/downloadUserCorpCourseExcel?corpCourseId=${selectedCourse.id}`;
84
+ // } else if (selectedReportType === 'Daywise') {
85
+ // url = `${baseURL}api/downloadUserCorpCourseExcelDayWise?corpCourseId=${selectedCourse.id}`;
86
+ // }
87
+
88
+ // const response = await axios.get(url, {
89
+ // responseType: 'blob',
90
+ // headers: {
91
+ // Authorization: `Bearer ${token}`
92
+ // }
93
+ // });
94
+ // const contentDisposition = response.headers['content-disposition'];
95
+ // const text = await response.data.text();
96
+ // if (text.includes('Course not configured')) {
97
+ // setAlertMessage('Course not configured.');
98
+ // setAlertOpen(true);
99
+ // } else {
100
+ // const filename = 'course_report.xlsx';
101
+ // const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
102
+ // const blobUrl = URL.createObjectURL(blob);
103
+ // const link = document.createElement('a');
104
+ // link.href = blobUrl;
105
+ // link.setAttribute('download', filename);
106
+ // document.body.appendChild(link);
107
+ // link.click();
108
+ // link.parentNode.removeChild(link);
109
+ // URL.revokeObjectURL(blobUrl);
110
+ // }
111
+ // } catch (error) {
112
+ // console.error('Error downloading course report:', error);
113
+ // } finally {
114
+ // setLoading(false);
115
+ // }
116
+ // };
117
+
74
118
  const handleDownload = async () => {
75
119
  setLoading(true);
76
120
  try {
77
121
  let url;
78
122
  if (selectedReportType === 'Summary') {
79
- url = `${baseURL}api/downloadUserCorpCourseExcel?corpCourseId=${selectedCourse.id}`;
123
+ url = '/api/downloadUserCorpCourseExcel';
80
124
  } else if (selectedReportType === 'Daywise') {
81
- url = `${baseURL}api/downloadUserCorpCourseExcelDayWise?corpCourseId=${selectedCourse.id}`;
125
+ url = '/api/downloadUserCorpCourseExcelDayWise';
82
126
  }
83
- const response = await axios.get(url, {
84
- responseType: 'blob',
127
+ const fullUrl = `${url}?corpCourseId=${selectedCourse.id}`;
128
+ const response = await fetch(`${baseURL}${fullUrl}`, {
85
129
  headers: {
86
- Authorization: `Bearer ${token}`
130
+ 'X-Tenant-Token': apiClient.tenantToken
87
131
  }
88
132
  });
89
- const contentDisposition = response.headers['content-disposition'];
90
- const text = await response.data.text();
133
+ const blob = await response.blob();
134
+ const text = await blob.text();
91
135
  if (text.includes('Course not configured')) {
92
136
  setAlertMessage('Course not configured.');
93
137
  setAlertOpen(true);
94
138
  } else {
95
- const filename = 'course_report.xlsx';
96
- const blob = new Blob([response.data], {
139
+ const downloadBlob = new Blob([blob], {
97
140
  type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
98
141
  });
99
- const blobUrl = URL.createObjectURL(blob);
142
+ const blobUrl = URL.createObjectURL(downloadBlob);
100
143
  const link = document.createElement('a');
101
144
  link.href = blobUrl;
102
- link.setAttribute('download', filename);
145
+ link.setAttribute('download', 'course_report.xlsx');
103
146
  document.body.appendChild(link);
104
147
  link.click();
105
148
  link.parentNode.removeChild(link);
@@ -0,0 +1,213 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { Autocomplete, FormControl, Button, Grid, Box, Typography, Paper, Snackbar, Alert, CircularProgress, TextField } from '@mui/material';
3
+ import { useTenant } from '../context/TenantProvider';
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ function CourseReportContent() {
6
+ const {
7
+ apiClient
8
+ } = useTenant();
9
+ const [subjects, setSubjects] = useState([]);
10
+ const [courses, setCourses] = useState([]);
11
+ const [selectedSubject, setSelectedSubject] = useState(null);
12
+ const [selectedCourse, setSelectedCourse] = useState(null);
13
+ const [reportTypes] = useState(['Summary', 'Daywise']);
14
+ const [selectedReportType, setSelectedReportType] = useState(null);
15
+ const [alertMessage, setAlertMessage] = useState('');
16
+ const [loading, setLoading] = useState(false);
17
+ const [alertOpen, setAlertOpen] = useState(false);
18
+ useEffect(() => {
19
+ fetchAllSubjects();
20
+ }, []);
21
+ const fetchAllSubjects = async () => {
22
+ try {
23
+ const data = await apiClient.get('/api/showAllSubjects');
24
+ setSubjects(data);
25
+ } catch (error) {
26
+ console.error('Error fetching subjects:', error);
27
+ }
28
+ };
29
+ const fetchCourses = async subjectId => {
30
+ try {
31
+ const data = await apiClient.get(`/api/getCoursesBySubject?subjectId=${subjectId}`);
32
+ setCourses(data);
33
+ } catch (error) {
34
+ console.error('Error fetching courses:', error);
35
+ }
36
+ };
37
+ const handleSubjectChange = (event, newValue) => {
38
+ setSelectedSubject(newValue);
39
+ setSelectedCourse(null);
40
+ setCourses([]);
41
+ if (newValue) {
42
+ fetchCourses(newValue.subjectId);
43
+ }
44
+ };
45
+ const handleCourseChange = (event, newValue) => {
46
+ setSelectedCourse(newValue);
47
+ };
48
+ const handleReportTypeChange = (event, newValue) => {
49
+ setSelectedReportType(newValue);
50
+ };
51
+ const handleDownload = async () => {
52
+ setLoading(true);
53
+ try {
54
+ let url;
55
+ if (selectedReportType === 'Summary') {
56
+ url = '/api/downloadUserCorpCourseExcel';
57
+ } else if (selectedReportType === 'Daywise') {
58
+ url = '/api/downloadUserCorpCourseExcelDayWise';
59
+ }
60
+ const fullUrl = `${url}?corpCourseId=${selectedCourse.id}`;
61
+ const response = await fetch(`${apiClient.baseURL}${fullUrl}`, {
62
+ headers: {
63
+ 'X-Tenant-Token': apiClient.tenantToken
64
+ }
65
+ });
66
+ const blob = await response.blob();
67
+ const text = await blob.text();
68
+ if (text.includes('Course not configured')) {
69
+ setAlertMessage('Course not configured.');
70
+ setAlertOpen(true);
71
+ } else {
72
+ const downloadBlob = new Blob([blob], {
73
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
74
+ });
75
+ const blobUrl = URL.createObjectURL(downloadBlob);
76
+ const link = document.createElement('a');
77
+ link.href = blobUrl;
78
+ link.setAttribute('download', 'course_report.xlsx');
79
+ document.body.appendChild(link);
80
+ link.click();
81
+ link.parentNode.removeChild(link);
82
+ URL.revokeObjectURL(blobUrl);
83
+ }
84
+ } catch (error) {
85
+ console.error('Error downloading course report:', error);
86
+ } finally {
87
+ setLoading(false);
88
+ }
89
+ };
90
+ return /*#__PURE__*/_jsxs(Box, {
91
+ sx: {
92
+ maxWidth: 800,
93
+ mx: 'auto',
94
+ my: 4,
95
+ p: 3,
96
+ backgroundColor: '#f5f5f5',
97
+ borderRadius: 2
98
+ },
99
+ children: [/*#__PURE__*/_jsxs(Paper, {
100
+ elevation: 6,
101
+ sx: {
102
+ p: 5,
103
+ textAlign: 'center',
104
+ backgroundColor: '#fff'
105
+ },
106
+ children: [/*#__PURE__*/_jsx(Typography, {
107
+ variant: "h4",
108
+ component: "h1",
109
+ gutterBottom: true,
110
+ sx: {
111
+ color: '#3f51b5',
112
+ marginBottom: "20px"
113
+ },
114
+ children: "Course Report"
115
+ }), /*#__PURE__*/_jsxs(Grid, {
116
+ container: true,
117
+ spacing: 2,
118
+ justifyContent: "center",
119
+ children: [/*#__PURE__*/_jsx(Grid, {
120
+ item: true,
121
+ xs: 12,
122
+ sm: 4,
123
+ children: /*#__PURE__*/_jsx(FormControl, {
124
+ fullWidth: true,
125
+ children: /*#__PURE__*/_jsx(Autocomplete, {
126
+ options: subjects,
127
+ getOptionLabel: option => option.subjectName,
128
+ value: selectedSubject,
129
+ onChange: handleSubjectChange,
130
+ renderInput: params => /*#__PURE__*/_jsx(TextField, {
131
+ ...params,
132
+ label: "Subject"
133
+ })
134
+ })
135
+ })
136
+ }), /*#__PURE__*/_jsx(Grid, {
137
+ item: true,
138
+ xs: 12,
139
+ sm: 4,
140
+ children: /*#__PURE__*/_jsx(FormControl, {
141
+ fullWidth: true,
142
+ children: /*#__PURE__*/_jsx(Autocomplete, {
143
+ options: courses,
144
+ getOptionLabel: option => option.courseName,
145
+ value: selectedCourse,
146
+ onChange: handleCourseChange,
147
+ renderInput: params => /*#__PURE__*/_jsx(TextField, {
148
+ ...params,
149
+ label: "Course"
150
+ })
151
+ })
152
+ })
153
+ }), /*#__PURE__*/_jsx(Grid, {
154
+ item: true,
155
+ xs: 12,
156
+ sm: 4,
157
+ children: /*#__PURE__*/_jsx(FormControl, {
158
+ fullWidth: true,
159
+ children: /*#__PURE__*/_jsx(Autocomplete, {
160
+ options: reportTypes,
161
+ getOptionLabel: option => option,
162
+ value: selectedReportType,
163
+ onChange: handleReportTypeChange,
164
+ renderInput: params => /*#__PURE__*/_jsx(TextField, {
165
+ ...params,
166
+ label: "Report Type"
167
+ })
168
+ })
169
+ })
170
+ })]
171
+ }), /*#__PURE__*/_jsxs(Box, {
172
+ sx: {
173
+ mt: 3,
174
+ position: 'relative'
175
+ },
176
+ children: [/*#__PURE__*/_jsx(Button, {
177
+ variant: "contained",
178
+ color: "primary",
179
+ onClick: handleDownload,
180
+ disabled: !selectedSubject || !selectedCourse || !selectedReportType || loading,
181
+ sx: {
182
+ width: 'auto',
183
+ backgroundColor: '#3f51b5'
184
+ },
185
+ children: loading ? 'Downloading...' : 'Download Report'
186
+ }), loading && /*#__PURE__*/_jsx(CircularProgress, {
187
+ size: 24,
188
+ sx: {
189
+ position: 'absolute',
190
+ top: '50%',
191
+ left: '50%',
192
+ marginTop: '-12px',
193
+ marginLeft: '-12px'
194
+ }
195
+ })]
196
+ })]
197
+ }), /*#__PURE__*/_jsx(Snackbar, {
198
+ open: alertOpen,
199
+ autoHideDuration: 6000,
200
+ onClose: () => setAlertOpen(false),
201
+ anchorOrigin: {
202
+ vertical: 'top',
203
+ horizontal: 'center'
204
+ },
205
+ children: /*#__PURE__*/_jsx(Alert, {
206
+ onClose: () => setAlertOpen(false),
207
+ severity: "info",
208
+ children: alertMessage
209
+ })
210
+ })]
211
+ });
212
+ }
213
+ export default CourseReportContent;