@campxdev/campx-web-utils 0.6.0 → 1.0.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.
- package/dist/README.md +46 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/src/App.d.ts +1 -0
- package/dist/cjs/types/src/AppContent.d.ts +2 -0
- package/dist/cjs/types/src/components/ActivityLog.d.ts +13 -0
- package/dist/cjs/types/src/components/ChangePassword.d.ts +9 -0
- package/dist/cjs/types/src/config/axios.d.ts +12 -0
- package/dist/cjs/types/src/context/ConfirmDialogProvider.d.ts +4 -0
- package/dist/cjs/types/src/context/ErrorBoundary/ErrorBoundary.d.ts +5 -0
- package/dist/cjs/types/src/context/ErrorBoundary/Login.d.ts +17 -0
- package/dist/cjs/types/src/context/Providers.d.ts +9 -0
- package/dist/cjs/types/src/context/SnackbarProvider.d.ts +6 -0
- package/dist/cjs/types/src/context/application-store.d.ts +65 -0
- package/dist/cjs/types/src/hooks/useConfirm.d.ts +8 -0
- package/dist/cjs/types/src/index.d.ts +1 -0
- package/dist/cjs/types/src/layout/AppLayout/AppLayout.d.ts +23 -0
- package/dist/cjs/types/src/layout/AppLayout/components/HelpDocs.d.ts +11 -0
- package/dist/cjs/types/src/reportWebVitals.d.ts +3 -0
- package/dist/cjs/types/src/routes/main.d.ts +13 -0
- package/dist/cjs/types/src/selectors/BatchSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/CourseSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/DepartmentSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/EmployeesSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/FeeTypeSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/HostelFloorSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/HostelRoomSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/PrintFormatSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/ProgramSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/RegulationSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/SemesterSelector.d.ts +2 -0
- package/dist/cjs/types/src/selectors/YearRangeSelector.d.ts +7 -0
- package/dist/cjs/types/src/selectors/utils.d.ts +9 -0
- package/dist/cjs/types/src/setupTests.d.ts +1 -0
- package/dist/cjs/types/src/utils/constants.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/src/App.d.ts +1 -0
- package/dist/esm/types/src/AppContent.d.ts +2 -0
- package/dist/esm/types/src/components/ActivityLog.d.ts +13 -0
- package/dist/esm/types/src/components/ChangePassword.d.ts +9 -0
- package/dist/esm/types/src/config/axios.d.ts +12 -0
- package/dist/esm/types/src/context/ConfirmDialogProvider.d.ts +4 -0
- package/dist/esm/types/src/context/ErrorBoundary/ErrorBoundary.d.ts +5 -0
- package/dist/esm/types/src/context/ErrorBoundary/Login.d.ts +17 -0
- package/dist/esm/types/src/context/Providers.d.ts +9 -0
- package/dist/esm/types/src/context/SnackbarProvider.d.ts +6 -0
- package/dist/esm/types/src/context/application-store.d.ts +65 -0
- package/dist/esm/types/src/context/export.d.ts +5 -0
- package/dist/esm/types/src/hooks/export.d.ts +1 -0
- package/dist/esm/types/src/hooks/useConfirm.d.ts +8 -0
- package/dist/esm/types/src/index.d.ts +1 -0
- package/dist/esm/types/src/layout/AppLayout/AppLayout.d.ts +23 -0
- package/dist/esm/types/src/layout/AppLayout/components/HelpDocs.d.ts +11 -0
- package/dist/esm/types/src/reportWebVitals.d.ts +3 -0
- package/dist/esm/types/src/routes/main.d.ts +13 -0
- package/dist/esm/types/src/selectors/BatchSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/CourseSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/DepartmentSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/EmployeesSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/FeeTypeSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/HostelFloorSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/HostelRoomSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/PrintFormatSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/ProgramSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/RegulationSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/SemesterSelector.d.ts +2 -0
- package/dist/esm/types/src/selectors/YearRangeSelector.d.ts +7 -0
- package/dist/esm/types/src/selectors/export.d.ts +12 -0
- package/dist/esm/types/src/selectors/utils.d.ts +9 -0
- package/dist/esm/types/src/setupTests.d.ts +1 -0
- package/dist/esm/types/src/utils/constants.d.ts +4 -0
- package/dist/index.d.ts +193 -0
- package/package.json +50 -17
- package/.prettierrc +0 -7
- package/craco.config.js +0 -22
- package/export.ts +0 -7
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/src/App.css +0 -38
- package/src/App.tsx +0 -16
- package/src/AppContent.tsx +0 -30
- package/src/components/ActivityLog.tsx +0 -96
- package/src/components/ChangePassword.tsx +0 -169
- package/src/config/axios.ts +0 -92
- package/src/context/ConfirmDialogProvider.tsx +0 -78
- package/src/context/ErrorBoundary/ErrorBoundary.tsx +0 -131
- package/src/context/ErrorBoundary/Login.tsx +0 -202
- package/src/context/Providers.tsx +0 -64
- package/src/context/SnackbarProvider.tsx +0 -42
- package/src/context/application-store.ts +0 -87
- package/src/hooks/useConfirm.ts +0 -57
- package/src/index.css +0 -13
- package/src/index.tsx +0 -19
- package/src/layout/AppLayout/AppLayout.tsx +0 -151
- package/src/layout/AppLayout/components/HelpDocs.tsx +0 -123
- package/src/logo.svg +0 -1
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/routes/main.tsx +0 -27
- package/src/selectors/BatchSelector.tsx +0 -15
- package/src/selectors/CourseSelector.tsx +0 -16
- package/src/selectors/DepartmentSelector.tsx +0 -19
- package/src/selectors/EmployeesSelector.tsx +0 -20
- package/src/selectors/FeeTypeSelector.tsx +0 -15
- package/src/selectors/HostelFloorSelector.tsx +0 -19
- package/src/selectors/HostelRoomSelector.tsx +0 -20
- package/src/selectors/PrintFormatSelector.tsx +0 -17
- package/src/selectors/ProgramSelector.tsx +0 -16
- package/src/selectors/RegulationSelector.tsx +0 -19
- package/src/selectors/SemesterSelector.tsx +0 -16
- package/src/selectors/YearRangeSelector.tsx +0 -26
- package/src/selectors/utils.tsx +0 -39
- package/src/setupTests.ts +0 -5
- package/src/utils/constants.ts +0 -18
- package/tsconfig.json +0 -22
- /package/{src/context/export.ts → dist/cjs/types/src/context/export.d.ts} +0 -0
- /package/{src/hooks/export.ts → dist/cjs/types/src/hooks/export.d.ts} +0 -0
- /package/{src/selectors/export.ts → dist/cjs/types/src/selectors/export.d.ts} +0 -0
- /package/{types → dist/types}/theme.d.ts +0 -0
package/src/App.css
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
.App {
|
|
2
|
-
text-align: center;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.App-logo {
|
|
6
|
-
height: 40vmin;
|
|
7
|
-
pointer-events: none;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
@media (prefers-reduced-motion: no-preference) {
|
|
11
|
-
.App-logo {
|
|
12
|
-
animation: App-logo-spin infinite 20s linear;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.App-header {
|
|
17
|
-
background-color: #282c34;
|
|
18
|
-
min-height: 100vh;
|
|
19
|
-
display: flex;
|
|
20
|
-
flex-direction: column;
|
|
21
|
-
align-items: center;
|
|
22
|
-
justify-content: center;
|
|
23
|
-
font-size: calc(10px + 2vmin);
|
|
24
|
-
color: white;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.App-link {
|
|
28
|
-
color: #61dafb;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@keyframes App-logo-spin {
|
|
32
|
-
from {
|
|
33
|
-
transform: rotate(0deg);
|
|
34
|
-
}
|
|
35
|
-
to {
|
|
36
|
-
transform: rotate(360deg);
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/App.tsx
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useRoutes } from 'react-router-dom';
|
|
2
|
-
|
|
3
|
-
import { Providers } from './context/export';
|
|
4
|
-
import { mainRoutes } from './routes/main';
|
|
5
|
-
|
|
6
|
-
export default function App() {
|
|
7
|
-
return (
|
|
8
|
-
<Providers>
|
|
9
|
-
<AppRouter />
|
|
10
|
-
</Providers>
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
const AppRouter = () => {
|
|
14
|
-
const app = useRoutes(mainRoutes);
|
|
15
|
-
return app;
|
|
16
|
-
};
|
package/src/AppContent.tsx
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Button, TextField } from '@campxdev/react-blueprint';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { EmployeesSelector } from './selectors/EmployeesSelector';
|
|
4
|
-
import { PrintFormatSelector } from './selectors/export';
|
|
5
|
-
|
|
6
|
-
function AppContent() {
|
|
7
|
-
const [value, setValue] = useState('63b810ee995d6d64f4a248de');
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
<>
|
|
11
|
-
<Button variant="contained" onClick={() => {}}>
|
|
12
|
-
Confirm
|
|
13
|
-
</Button>
|
|
14
|
-
<EmployeesSelector
|
|
15
|
-
fullWidth
|
|
16
|
-
value={value}
|
|
17
|
-
onChange={(value: any) => {
|
|
18
|
-
setValue(value);
|
|
19
|
-
}}
|
|
20
|
-
/>
|
|
21
|
-
<div style={{ height: '300px' }}></div>
|
|
22
|
-
|
|
23
|
-
<TextField />
|
|
24
|
-
|
|
25
|
-
<PrintFormatSelector onChange={() => {}} />
|
|
26
|
-
</>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default AppContent;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { ActivityLogView } from '@campxdev/react-blueprint';
|
|
2
|
-
import { Store } from 'pullstate';
|
|
3
|
-
import { useEffect, useState } from 'react';
|
|
4
|
-
import { useInfiniteQuery } from 'react-query';
|
|
5
|
-
import { axios } from '../config/axios';
|
|
6
|
-
|
|
7
|
-
function formatDate(date: Date): string {
|
|
8
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type ActivityLogType = {
|
|
12
|
-
activitiesData: any[];
|
|
13
|
-
lastTimestamp: number | null;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type ActivityLogStoreType = {
|
|
17
|
-
[logType: string]: ActivityLogType;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const ActivityLogStore = new Store<ActivityLogStoreType>({});
|
|
21
|
-
|
|
22
|
-
export default function ActivityLog({
|
|
23
|
-
apiEndpoint,
|
|
24
|
-
params,
|
|
25
|
-
}: {
|
|
26
|
-
apiEndpoint: string;
|
|
27
|
-
params: Record<string, any>;
|
|
28
|
-
}) {
|
|
29
|
-
const [fromDate, setFromDate] = useState<Date | null>(null);
|
|
30
|
-
const [toDate, setToDate] = useState<Date | null>(null);
|
|
31
|
-
|
|
32
|
-
const { activitiesData } = ActivityLogStore.useState(
|
|
33
|
-
(s) => s[params.logType] || { activitiesData: [], lastTimestamp: null },
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const fetchActivities = async ({ pageParam = null }) => {
|
|
37
|
-
const response = await axios.get(apiEndpoint, {
|
|
38
|
-
params: {
|
|
39
|
-
...params,
|
|
40
|
-
lastTimestamp: pageParam,
|
|
41
|
-
...(fromDate && { fromDate: formatDate(fromDate) }),
|
|
42
|
-
...(toDate && { toDate: formatDate(toDate) }),
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
return response.data;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const { fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } =
|
|
49
|
-
useInfiniteQuery(
|
|
50
|
-
['activities', params.logType, fromDate, toDate],
|
|
51
|
-
fetchActivities,
|
|
52
|
-
{
|
|
53
|
-
getNextPageParam: (lastPage) =>
|
|
54
|
-
lastPage?.length
|
|
55
|
-
? new Date(lastPage[lastPage.length - 1]?.timestamp).getTime()
|
|
56
|
-
: null,
|
|
57
|
-
onSuccess: (data) => {
|
|
58
|
-
ActivityLogStore.update((s) => {
|
|
59
|
-
const currentData = s[params.logType] || {
|
|
60
|
-
activitiesData: [],
|
|
61
|
-
lastTimestamp: null,
|
|
62
|
-
};
|
|
63
|
-
currentData.activitiesData = data.pages.flatMap(
|
|
64
|
-
(page) => page ?? [],
|
|
65
|
-
);
|
|
66
|
-
currentData.lastTimestamp = data.pages[data.pages.length - 1]
|
|
67
|
-
?.timestamp
|
|
68
|
-
? new Date(data.pages[data.pages.length - 1].timestamp).getTime()
|
|
69
|
-
: null;
|
|
70
|
-
s[params.logType] = currentData;
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
enabled: activitiesData.length === 0 || !!fromDate || !!toDate,
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (fromDate || toDate) {
|
|
79
|
-
fetchNextPage();
|
|
80
|
-
}
|
|
81
|
-
}, [fromDate, toDate, fetchNextPage]);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<ActivityLogView
|
|
85
|
-
activitiesData={activitiesData}
|
|
86
|
-
isFetchingNextPage={isFetchingNextPage}
|
|
87
|
-
fetchNextPage={fetchNextPage}
|
|
88
|
-
hasNextPage={hasNextPage}
|
|
89
|
-
fromDate={fromDate}
|
|
90
|
-
toDate={toDate}
|
|
91
|
-
isLoading={isLoading}
|
|
92
|
-
setFromDate={setFromDate}
|
|
93
|
-
setToDate={setToDate}
|
|
94
|
-
/>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CircularProgress,
|
|
3
|
-
IconButton,
|
|
4
|
-
InputAdornment,
|
|
5
|
-
Stack,
|
|
6
|
-
} from '@mui/material';
|
|
7
|
-
import { useState } from 'react';
|
|
8
|
-
import { useForm } from 'react-hook-form';
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
Button,
|
|
12
|
-
DialogButton,
|
|
13
|
-
FormControlWrapper,
|
|
14
|
-
TextField,
|
|
15
|
-
} from '@campxdev/react-blueprint';
|
|
16
|
-
import { StyledMenuItem } from '@campxdev/react-blueprint/src/components/Navigation/DropDownMenu/styles';
|
|
17
|
-
import { Visibility, VisibilityOff } from '@mui/icons-material';
|
|
18
|
-
import { toast } from 'react-toastify';
|
|
19
|
-
import { axios } from '../config/axios';
|
|
20
|
-
import { isDevelopment } from '../utils/constants';
|
|
21
|
-
|
|
22
|
-
interface PasswordVisibilityState {
|
|
23
|
-
oldPassword: boolean;
|
|
24
|
-
newPassword: boolean;
|
|
25
|
-
confirmPassword: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface FormData {
|
|
29
|
-
oldPassword: string;
|
|
30
|
-
newPassword: string;
|
|
31
|
-
confirmPassword: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface Field {
|
|
35
|
-
label: string;
|
|
36
|
-
name: keyof PasswordVisibilityState;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface ChangePasswordProps {
|
|
40
|
-
close: () => void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function ChangePassword({ close }: ChangePasswordProps) {
|
|
44
|
-
const [showPassword, setShowPassword] = useState<PasswordVisibilityState>({
|
|
45
|
-
oldPassword: false,
|
|
46
|
-
newPassword: false,
|
|
47
|
-
confirmPassword: false,
|
|
48
|
-
});
|
|
49
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
50
|
-
|
|
51
|
-
const { handleSubmit, control, reset } = useForm<FormData>();
|
|
52
|
-
|
|
53
|
-
const onSubmit = async (formData: any) => {
|
|
54
|
-
setIsLoading(true);
|
|
55
|
-
const { oldPassword, newPassword, confirmPassword } = formData;
|
|
56
|
-
if (newPassword === confirmPassword) {
|
|
57
|
-
try {
|
|
58
|
-
await axios.post(
|
|
59
|
-
isDevelopment
|
|
60
|
-
? 'https://api.campx.dev/auth-server/auth/change-password'
|
|
61
|
-
: 'https://api.campx.in/auth-server/auth/change-password',
|
|
62
|
-
{
|
|
63
|
-
oldPassword,
|
|
64
|
-
newPassword,
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
toast.success('Password Changed Successfully');
|
|
68
|
-
setIsLoading(false);
|
|
69
|
-
reset();
|
|
70
|
-
close();
|
|
71
|
-
} catch (error) {
|
|
72
|
-
console.log(error, 'this is error');
|
|
73
|
-
// axiosErrorToast(error);
|
|
74
|
-
setIsLoading(false);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
toast.error('New Password, Confirm Password must be same');
|
|
78
|
-
setIsLoading(false);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const fields: Field[] = [
|
|
83
|
-
{ label: 'Old Password', name: 'oldPassword' },
|
|
84
|
-
{ label: 'New Password', name: 'newPassword' },
|
|
85
|
-
{ label: 'Confirm Password', name: 'confirmPassword' },
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<form onSubmit={handleSubmit(onSubmit)}>
|
|
90
|
-
<FormControlWrapper control={control}>
|
|
91
|
-
<Stack gap={1} direction="column">
|
|
92
|
-
{fields.map((item) => {
|
|
93
|
-
return (
|
|
94
|
-
<>
|
|
95
|
-
<TextField
|
|
96
|
-
label={item.label}
|
|
97
|
-
name={item.name}
|
|
98
|
-
type={showPassword[item.name] ? 'text' : 'password'}
|
|
99
|
-
required
|
|
100
|
-
InputProps={{
|
|
101
|
-
endAdornment: (
|
|
102
|
-
<InputAdornment position="end">
|
|
103
|
-
<IconButton
|
|
104
|
-
size="small"
|
|
105
|
-
onClick={() =>
|
|
106
|
-
setShowPassword((prev: any) => ({
|
|
107
|
-
...prev,
|
|
108
|
-
[item.name]: !prev[item.name],
|
|
109
|
-
}))
|
|
110
|
-
}
|
|
111
|
-
edge="end"
|
|
112
|
-
>
|
|
113
|
-
{showPassword[item.name] ? (
|
|
114
|
-
<Visibility />
|
|
115
|
-
) : (
|
|
116
|
-
<VisibilityOff />
|
|
117
|
-
)}
|
|
118
|
-
</IconButton>
|
|
119
|
-
</InputAdornment>
|
|
120
|
-
),
|
|
121
|
-
}}
|
|
122
|
-
/>
|
|
123
|
-
</>
|
|
124
|
-
);
|
|
125
|
-
})}
|
|
126
|
-
|
|
127
|
-
<Stack direction={'row'} gap={2} sx={{ marginTop: '15px' }}>
|
|
128
|
-
<Button variant="outlined" onClick={close}>
|
|
129
|
-
Cancel
|
|
130
|
-
</Button>
|
|
131
|
-
<Button
|
|
132
|
-
type="submit"
|
|
133
|
-
variant="contained"
|
|
134
|
-
endIcon={
|
|
135
|
-
isLoading && (
|
|
136
|
-
<CircularProgress
|
|
137
|
-
style={{ color: 'white' }}
|
|
138
|
-
size="30px"
|
|
139
|
-
thickness={1.7}
|
|
140
|
-
/>
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
>
|
|
144
|
-
Submit
|
|
145
|
-
</Button>
|
|
146
|
-
</Stack>
|
|
147
|
-
</Stack>
|
|
148
|
-
</FormControlWrapper>
|
|
149
|
-
</form>
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export const ChangePasswordDialog: React.FC = () => (
|
|
154
|
-
<>
|
|
155
|
-
<DialogButton
|
|
156
|
-
anchor={({ open }) => (
|
|
157
|
-
<StyledMenuItem
|
|
158
|
-
onClick={() => {
|
|
159
|
-
open();
|
|
160
|
-
}}
|
|
161
|
-
>
|
|
162
|
-
Change Password
|
|
163
|
-
</StyledMenuItem>
|
|
164
|
-
)}
|
|
165
|
-
content={({ close }) => <ChangePassword close={close} />}
|
|
166
|
-
title="Change Password"
|
|
167
|
-
/>
|
|
168
|
-
</>
|
|
169
|
-
);
|
package/src/config/axios.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import Axios, { InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import Cookies from 'js-cookie';
|
|
3
|
-
import { ApplicationStore } from '../context/application-store';
|
|
4
|
-
import { institutionCode, isDevelopment, tenantCode } from '../utils/constants';
|
|
5
|
-
|
|
6
|
-
export const formatParams = (params: any) => {
|
|
7
|
-
return Object.fromEntries(
|
|
8
|
-
Object.entries(params ?? {})?.map((i) => [
|
|
9
|
-
i[0],
|
|
10
|
-
i[1] === '__empty__' ? '' : i[1],
|
|
11
|
-
]),
|
|
12
|
-
);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const axios = Axios.create({
|
|
16
|
-
baseURL: process.env.REACT_APP_API_HOST,
|
|
17
|
-
withCredentials: true,
|
|
18
|
-
headers: {
|
|
19
|
-
'x-tenant-id': tenantCode,
|
|
20
|
-
'x-institution-code': institutionCode,
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
axios.interceptors.request.use(
|
|
25
|
-
function (config: InternalAxiosRequestConfig) {
|
|
26
|
-
const params = formatParams(config?.params);
|
|
27
|
-
|
|
28
|
-
const sessionKey = Cookies.get('campx_session_key');
|
|
29
|
-
const openPaymentsKey = Cookies.get('campx_open_payments_key');
|
|
30
|
-
const studentSessionKey = Cookies.get('campx_student_key');
|
|
31
|
-
|
|
32
|
-
if (isDevelopment && sessionKey) {
|
|
33
|
-
config.headers.set('campx_session_key', sessionKey);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (isDevelopment && studentSessionKey) {
|
|
37
|
-
config.headers.set('campx_student_key', studentSessionKey);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (openPaymentsKey) {
|
|
41
|
-
config.headers.set('campx_open_payments_key', openPaymentsKey);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
...config,
|
|
46
|
-
params,
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
function (error) {
|
|
50
|
-
return Promise.reject(error);
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
axios.interceptors.response.use(
|
|
55
|
-
function (response) {
|
|
56
|
-
if (
|
|
57
|
-
response.config.method &&
|
|
58
|
-
['put', 'post', 'delete', 'patch'].includes(response.config.method) &&
|
|
59
|
-
[200, 201, 202].includes(response.status)
|
|
60
|
-
) {
|
|
61
|
-
ApplicationStore.update((s) => {
|
|
62
|
-
s.snackbar.open = true;
|
|
63
|
-
s.snackbar.message = response.data.message;
|
|
64
|
-
s.snackbar.severity = 'success';
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return response;
|
|
69
|
-
},
|
|
70
|
-
function (err) {
|
|
71
|
-
if ([400, 422].includes(err.response.status)) {
|
|
72
|
-
ApplicationStore.update((s) => {
|
|
73
|
-
s.snackbar.open = true;
|
|
74
|
-
s.snackbar.message = err.response.data.message || 'Bad Request';
|
|
75
|
-
s.snackbar.severity = 'error';
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (
|
|
79
|
-
err.response.config.method &&
|
|
80
|
-
['put', 'post', 'delete', 'patch'].includes(err.response.config.method) &&
|
|
81
|
-
[404].includes(err.response.status)
|
|
82
|
-
) {
|
|
83
|
-
ApplicationStore.update((s) => {
|
|
84
|
-
s.snackbar.open = true;
|
|
85
|
-
s.snackbar.message = err.response.data.message;
|
|
86
|
-
s.snackbar.severity = 'error';
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return Promise.reject(err);
|
|
91
|
-
},
|
|
92
|
-
);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ConfirmDialog, ConfirmDialogType } from '@campxdev/react-blueprint';
|
|
2
|
-
import { createContext, ReactNode } from 'react';
|
|
3
|
-
import { ApplicationStore } from './application-store';
|
|
4
|
-
|
|
5
|
-
interface ConfirmStateProps {
|
|
6
|
-
showConfirmDialog: (
|
|
7
|
-
title: string,
|
|
8
|
-
message: string,
|
|
9
|
-
onConfirm: () => void,
|
|
10
|
-
onCancel: () => void,
|
|
11
|
-
type?: ConfirmDialogType,
|
|
12
|
-
confirmButtonText?: string,
|
|
13
|
-
cancelButtonText?: string,
|
|
14
|
-
) => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const ConfirmContext = createContext<ConfirmStateProps>({
|
|
18
|
-
showConfirmDialog: () => {},
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const ConfirmDialogProvider = ({
|
|
22
|
-
children,
|
|
23
|
-
}: {
|
|
24
|
-
children: ReactNode;
|
|
25
|
-
}) => {
|
|
26
|
-
const confirmDialog = ApplicationStore.useState((s) => s.confirmDialog);
|
|
27
|
-
|
|
28
|
-
const showConfirmDialog = (
|
|
29
|
-
title: string,
|
|
30
|
-
message: string,
|
|
31
|
-
onConfirm: () => void,
|
|
32
|
-
onCancel: () => void,
|
|
33
|
-
type: ConfirmDialogType = 'confirm',
|
|
34
|
-
confirmButtonText?: string,
|
|
35
|
-
cancelButtonText?: string,
|
|
36
|
-
) => {
|
|
37
|
-
ApplicationStore.update((s) => {
|
|
38
|
-
s.confirmDialog = {
|
|
39
|
-
isOpen: true,
|
|
40
|
-
title,
|
|
41
|
-
message,
|
|
42
|
-
onConfirm,
|
|
43
|
-
onCancel,
|
|
44
|
-
type,
|
|
45
|
-
confirmButtonText,
|
|
46
|
-
cancelButtonText,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const handleCloseDialog = () => {
|
|
52
|
-
ApplicationStore.update((s) => {
|
|
53
|
-
s.confirmDialog.isOpen = false;
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<ConfirmContext.Provider value={{ showConfirmDialog }}>
|
|
59
|
-
{children}
|
|
60
|
-
<ConfirmDialog
|
|
61
|
-
isOpen={confirmDialog.isOpen}
|
|
62
|
-
title={confirmDialog.title}
|
|
63
|
-
message={confirmDialog.message}
|
|
64
|
-
type={confirmDialog.type}
|
|
65
|
-
confirmButtonText={confirmDialog.confirmButtonText}
|
|
66
|
-
cancelButtonText={confirmDialog.cancelButtonText}
|
|
67
|
-
onConfirm={() => {
|
|
68
|
-
confirmDialog.onConfirm();
|
|
69
|
-
handleCloseDialog();
|
|
70
|
-
}}
|
|
71
|
-
onCancel={() => {
|
|
72
|
-
confirmDialog.onCancel();
|
|
73
|
-
handleCloseDialog();
|
|
74
|
-
}}
|
|
75
|
-
/>
|
|
76
|
-
</ConfirmContext.Provider>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button,
|
|
3
|
-
Dialog,
|
|
4
|
-
InternalServerError,
|
|
5
|
-
NoInterneConnection,
|
|
6
|
-
PageNotFound,
|
|
7
|
-
UnAuthorized,
|
|
8
|
-
} from '@campxdev/react-blueprint';
|
|
9
|
-
import { Alert, Box, styled } from '@mui/material';
|
|
10
|
-
import Cookies from 'js-cookie';
|
|
11
|
-
import { ReactNode, useState } from 'react';
|
|
12
|
-
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary';
|
|
13
|
-
import { QueryErrorResetBoundary } from 'react-query';
|
|
14
|
-
import { useLocation, useNavigate } from 'react-router-dom';
|
|
15
|
-
import { Login } from './Login';
|
|
16
|
-
|
|
17
|
-
export type ErrorBoundaryProps = {
|
|
18
|
-
children: ReactNode;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const StyledAlert = styled(Alert)(({ theme }) => ({
|
|
22
|
-
height: '60px',
|
|
23
|
-
border: `1px solid ${theme.palette.error.main}`,
|
|
24
|
-
display: 'flex',
|
|
25
|
-
alignItems: 'center',
|
|
26
|
-
'& .MuiAlert-message': {
|
|
27
|
-
padding: 0,
|
|
28
|
-
},
|
|
29
|
-
'& .MuiTypography-root': {
|
|
30
|
-
margin: 0,
|
|
31
|
-
},
|
|
32
|
-
position: 'relative',
|
|
33
|
-
'& .retryBtn': {
|
|
34
|
-
color: '#661B2A',
|
|
35
|
-
position: 'absolute',
|
|
36
|
-
right: 8,
|
|
37
|
-
top: 8,
|
|
38
|
-
},
|
|
39
|
-
}));
|
|
40
|
-
|
|
41
|
-
export const ErrorBoundary = (props: ErrorBoundaryProps) => {
|
|
42
|
-
const location = useLocation();
|
|
43
|
-
return (
|
|
44
|
-
<QueryErrorResetBoundary>
|
|
45
|
-
{({ reset }) => (
|
|
46
|
-
<ReactErrorBoundary
|
|
47
|
-
key={location?.pathname}
|
|
48
|
-
onReset={reset}
|
|
49
|
-
FallbackComponent={ErrorFallback}
|
|
50
|
-
>
|
|
51
|
-
{props.children}
|
|
52
|
-
</ReactErrorBoundary>
|
|
53
|
-
)}
|
|
54
|
-
</QueryErrorResetBoundary>
|
|
55
|
-
);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const ErrorFallback = ({ error, resetErrorBoundary }: any) => {
|
|
59
|
-
if (error?.response?.status) {
|
|
60
|
-
switch (error?.response?.status) {
|
|
61
|
-
case 401:
|
|
62
|
-
return <UnAuth />;
|
|
63
|
-
|
|
64
|
-
case 500:
|
|
65
|
-
return <InternalServerError resetBoundary={resetErrorBoundary} />;
|
|
66
|
-
case 404:
|
|
67
|
-
return <PageNotFound />;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (error?.code === 'ERR_NETWORK') {
|
|
72
|
-
return <NoInterneConnection resetBoundary={resetErrorBoundary} />;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
<Box sx={{ marginTop: '16px', padding: '20px' }}>
|
|
77
|
-
<StyledAlert severity="error">
|
|
78
|
-
{error?.response?.data?.message ?? error?.message}
|
|
79
|
-
<Button
|
|
80
|
-
className="retryBtn"
|
|
81
|
-
onClick={() => resetErrorBoundary()}
|
|
82
|
-
size="small"
|
|
83
|
-
color="error"
|
|
84
|
-
variant="outlined"
|
|
85
|
-
>
|
|
86
|
-
Try Again
|
|
87
|
-
</Button>
|
|
88
|
-
</StyledAlert>
|
|
89
|
-
</Box>
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const UnAuth = () => {
|
|
94
|
-
const navigate = useNavigate();
|
|
95
|
-
const [isModalOpen, setModalOpen] = useState(false);
|
|
96
|
-
|
|
97
|
-
const sessionCookie = Cookies.get('campx_session_key');
|
|
98
|
-
|
|
99
|
-
const handleLoginClick = () => {
|
|
100
|
-
if (window.location.hostname === 'localhost') {
|
|
101
|
-
setModalOpen(true);
|
|
102
|
-
} else {
|
|
103
|
-
if (!sessionCookie) {
|
|
104
|
-
navigate('/auth/login');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<UnAuthorized
|
|
111
|
-
component={
|
|
112
|
-
<>
|
|
113
|
-
<Button
|
|
114
|
-
sx={{
|
|
115
|
-
marginTop: '20px',
|
|
116
|
-
}}
|
|
117
|
-
variant="contained"
|
|
118
|
-
onClick={handleLoginClick}
|
|
119
|
-
>
|
|
120
|
-
Click Here To Login
|
|
121
|
-
</Button>
|
|
122
|
-
<Dialog
|
|
123
|
-
open={isModalOpen}
|
|
124
|
-
onClose={() => setModalOpen(false)}
|
|
125
|
-
content={({ close }) => <Login close={close} />}
|
|
126
|
-
/>
|
|
127
|
-
</>
|
|
128
|
-
}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
};
|