@campxdev/campx-web-utils 1.3.7 → 2.0.0-alpha.1

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 (34) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/types/src/context/Providers.d.ts +1 -2
  3. package/dist/cjs/types/src/index.d.ts +1 -1
  4. package/dist/esm/index.js +2 -2
  5. package/dist/esm/types/src/context/Providers.d.ts +1 -2
  6. package/dist/esm/types/src/index.d.ts +1 -1
  7. package/dist/index.d.ts +5 -51
  8. package/dist/styles.css +4941 -0
  9. package/export.ts +0 -3
  10. package/package.json +12 -12
  11. package/src/AppContent.tsx +1 -15
  12. package/src/context/ErrorBoundary/ErrorBoundary.tsx +11 -37
  13. package/src/context/ErrorBoundary/Login.tsx +57 -67
  14. package/src/context/Providers.tsx +3 -12
  15. package/src/index.tsx +1 -1
  16. package/src/routes/main.tsx +5 -4
  17. package/src/styles/index.css +4 -0
  18. package/src/utils/constants.ts +2 -0
  19. package/types/prettier.d.ts +2 -0
  20. package/dist/cjs/types/src/components/ActivityLog.d.ts +0 -13
  21. package/dist/cjs/types/src/components/ChangePassword.d.ts +0 -9
  22. package/dist/cjs/types/src/layout/AppLayout/AppLayout.d.ts +0 -23
  23. package/dist/cjs/types/src/layout/AppLayout/components/HelpDocs.d.ts +0 -11
  24. package/dist/esm/types/src/components/ActivityLog.d.ts +0 -13
  25. package/dist/esm/types/src/components/ChangePassword.d.ts +0 -9
  26. package/dist/esm/types/src/layout/AppLayout/AppLayout.d.ts +0 -23
  27. package/dist/esm/types/src/layout/AppLayout/components/HelpDocs.d.ts +0 -11
  28. package/dist/types/theme.d.ts +0 -63
  29. package/src/App.css +0 -38
  30. package/src/components/ActivityLog.tsx +0 -96
  31. package/src/components/ChangePassword.tsx +0 -183
  32. package/src/index.css +0 -13
  33. package/src/layout/AppLayout/AppLayout.tsx +0 -155
  34. package/src/layout/AppLayout/components/HelpDocs.tsx +0 -121
@@ -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,183 +0,0 @@
1
- import {
2
- CircularProgress,
3
- IconButton,
4
- InputAdornment,
5
- MenuItem,
6
- Stack,
7
- styled,
8
- } from '@mui/material';
9
- import { useState } from 'react';
10
- import { useForm } from 'react-hook-form';
11
-
12
- import {
13
- Button,
14
- DialogButton,
15
- FormControlWrapper,
16
- TextField,
17
- } from '@campxdev/react-blueprint';
18
- import { Visibility, VisibilityOff } from '@mui/icons-material';
19
- import { toast } from 'react-toastify';
20
- import { axios } from '../config/axios';
21
- import { isDevelopment } from '../utils/constants';
22
-
23
- interface PasswordVisibilityState {
24
- oldPassword: boolean;
25
- newPassword: boolean;
26
- confirmPassword: boolean;
27
- }
28
-
29
- interface FormData {
30
- oldPassword: string;
31
- newPassword: string;
32
- confirmPassword: string;
33
- }
34
-
35
- interface Field {
36
- label: string;
37
- name: keyof PasswordVisibilityState;
38
- }
39
-
40
- interface ChangePasswordProps {
41
- close: () => void;
42
- }
43
-
44
- export const StyledMenuItem = styled(MenuItem)(() => ({
45
- display: 'flex',
46
- alignItems: 'center',
47
- gap: '5px',
48
- '& .MuiListItemIcon-root': {
49
- minWidth: '24px',
50
- },
51
- '& .MuiSvgIcon-root': {
52
- height: '14px',
53
- width: '14px',
54
- },
55
- }));
56
-
57
- export function ChangePassword({ close }: ChangePasswordProps) {
58
- const [showPassword, setShowPassword] = useState<PasswordVisibilityState>({
59
- oldPassword: false,
60
- newPassword: false,
61
- confirmPassword: false,
62
- });
63
- const [isLoading, setIsLoading] = useState(false);
64
-
65
- const { handleSubmit, control, reset } = useForm<FormData>();
66
-
67
- const onSubmit = async (formData: any) => {
68
- setIsLoading(true);
69
- const { oldPassword, newPassword, confirmPassword } = formData;
70
- if (newPassword === confirmPassword) {
71
- try {
72
- await axios.post(
73
- isDevelopment
74
- ? 'https://api.campx.dev/auth-server/auth/change-password'
75
- : 'https://api.campx.in/auth-server/auth/change-password',
76
- {
77
- oldPassword,
78
- newPassword,
79
- },
80
- );
81
- toast.success('Password Changed Successfully');
82
- setIsLoading(false);
83
- reset();
84
- close();
85
- } catch (error) {
86
- console.log(error, 'this is error');
87
- // axiosErrorToast(error);
88
- setIsLoading(false);
89
- }
90
- } else {
91
- toast.error('New Password, Confirm Password must be same');
92
- setIsLoading(false);
93
- }
94
- };
95
-
96
- const fields: Field[] = [
97
- { label: 'Old Password', name: 'oldPassword' },
98
- { label: 'New Password', name: 'newPassword' },
99
- { label: 'Confirm Password', name: 'confirmPassword' },
100
- ];
101
-
102
- return (
103
- <form onSubmit={handleSubmit(onSubmit)}>
104
- <FormControlWrapper control={control}>
105
- <Stack gap={1} direction="column">
106
- {fields.map((item) => {
107
- return (
108
- <>
109
- <TextField
110
- label={item.label}
111
- name={item.name}
112
- type={showPassword[item.name] ? 'text' : 'password'}
113
- required
114
- InputProps={{
115
- endAdornment: (
116
- <InputAdornment position="end">
117
- <IconButton
118
- size="small"
119
- onClick={() =>
120
- setShowPassword((prev: any) => ({
121
- ...prev,
122
- [item.name]: !prev[item.name],
123
- }))
124
- }
125
- edge="end"
126
- >
127
- {showPassword[item.name] ? (
128
- <Visibility />
129
- ) : (
130
- <VisibilityOff />
131
- )}
132
- </IconButton>
133
- </InputAdornment>
134
- ),
135
- }}
136
- />
137
- </>
138
- );
139
- })}
140
-
141
- <Stack direction={'row'} gap={2} sx={{ marginTop: '15px' }}>
142
- <Button variant="outlined" onClick={close}>
143
- Cancel
144
- </Button>
145
- <Button
146
- type="submit"
147
- variant="contained"
148
- endIcon={
149
- isLoading && (
150
- <CircularProgress
151
- style={{ color: 'white' }}
152
- size="30px"
153
- thickness={1.7}
154
- />
155
- )
156
- }
157
- >
158
- Submit
159
- </Button>
160
- </Stack>
161
- </Stack>
162
- </FormControlWrapper>
163
- </form>
164
- );
165
- }
166
-
167
- export const ChangePasswordDialog: React.FC = () => (
168
- <>
169
- <DialogButton
170
- anchor={({ open }) => (
171
- <StyledMenuItem
172
- onClick={() => {
173
- open();
174
- }}
175
- >
176
- Change Password
177
- </StyledMenuItem>
178
- )}
179
- content={({ close }) => <ChangePassword close={close} />}
180
- title="Change Password"
181
- />
182
- </>
183
- );
package/src/index.css DELETED
@@ -1,13 +0,0 @@
1
- body {
2
- margin: 0;
3
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5
- sans-serif;
6
- -webkit-font-smoothing: antialiased;
7
- -moz-osx-font-smoothing: grayscale;
8
- }
9
-
10
- code {
11
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12
- monospace;
13
- }
@@ -1,155 +0,0 @@
1
- import {
2
- AppHeader,
3
- Sidebar,
4
- SideMenuItemProps,
5
- Spinner,
6
- } from '@campxdev/react-blueprint';
7
- import { Box, Stack, styled, useMediaQuery, useTheme } from '@mui/material';
8
- import { motion } from 'framer-motion';
9
- import Cookies from 'js-cookie';
10
- import { ReactNode, Suspense, useState } from 'react';
11
- import { ChangePasswordDialog } from '../../components/ChangePassword';
12
- import { axios } from '../../config/axios';
13
- import { ErrorBoundary } from '../../context/export';
14
- import { HelpDocs } from './components/HelpDocs';
15
-
16
- type Props = {
17
- actions?: ReactNode[];
18
- profileActions?: ReactNode[];
19
- children?: ReactNode;
20
- menu: SideMenuItemProps[];
21
- mainContainerSx?: any;
22
- handleLogout?: any;
23
- userName?: string;
24
- designation?: string;
25
- clientName?: string;
26
- institutionData?: any[];
27
- defaultCollapsed?: boolean;
28
- helpDocsConfig?: Record<
29
- string,
30
- { actions: { name: string; onClick: () => void }[] }
31
- >;
32
- };
33
-
34
- export const AppLayout: React.FC<Props> = ({
35
- actions = [],
36
- profileActions = [],
37
- children,
38
- institutionData = [],
39
- menu,
40
- mainContainerSx,
41
- handleLogout,
42
- userName = '',
43
- designation = '',
44
- clientName = '',
45
- defaultCollapsed = true,
46
- helpDocsConfig,
47
- }) => {
48
- const [collapsed, setCollapsed] = useState(defaultCollapsed);
49
- const theme = useTheme();
50
- const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
51
-
52
- function logout() {
53
- axios
54
- .post('/auth-server/auth/logout')
55
- .then((res) => {
56
- Cookies.remove('campx_tenant');
57
- Cookies.remove('campx_session_key');
58
- Cookies.remove('campx_institution');
59
- window.location.href = '/';
60
- })
61
- .catch((err) => {
62
- // toast("Unable To Logout.");
63
- });
64
- }
65
-
66
- const fullPath = window.location.pathname;
67
- const pathSegments = fullPath.split('/').filter(Boolean);
68
- const actualPath = pathSegments.slice(1).join('/');
69
- const normalizedPath = actualPath.replace(/\/\d+/g, '/:id');
70
- const helpDocsActions = helpDocsConfig?.[`/${normalizedPath}`]?.actions || [];
71
-
72
- return (
73
- <AppLayoutContainer>
74
- <Sidebar menu={menu} collapsed={collapsed} setCollapsed={setCollapsed} />
75
- <motion.div
76
- animate={{
77
- width: collapsed ? 'calc(100% - 84px)' : 'calc(100% - 278px)',
78
- }}
79
- transition={{ duration: 0.3, ease: 'circOut' }}
80
- style={{
81
- margin: '12px 12px 12px 0px',
82
- width: isSmallScreen ? '100%' : 'calc(100% - 84px)',
83
- display: isSmallScreen ? 'contents' : 'block',
84
- }}
85
- >
86
- <AppHeader
87
- clientName={clientName}
88
- userFullName={userName}
89
- designation={designation}
90
- actions={actions}
91
- profileActions={[<ChangePasswordDialog />, ...profileActions]}
92
- collapsed={collapsed}
93
- showActiveDevices={false}
94
- onLogoutClick={handleLogout ?? logout}
95
- institutionsData={institutionData}
96
- {...(isSmallScreen && {
97
- profileSx: { width: 32, height: 32, fontSize: '12px' },
98
- })}
99
- />
100
- {helpDocsConfig && helpDocsActions.length > 0 && (
101
- <HelpDocs actions={helpDocsActions} />
102
- )}
103
-
104
- <OutletContainer
105
- sx={{
106
- margin: '12px 0px 0px 0px',
107
- backgroundColor: theme.palette.surface.paperBackground,
108
- ...mainContainerSx,
109
- }}
110
- onClick={() => {
111
- setCollapsed(true);
112
- }}
113
- >
114
- <Suspense fallback={<Spinner />}>
115
- <ErrorBoundary>{children}</ErrorBoundary>
116
- </Suspense>
117
- </OutletContainer>
118
- </motion.div>
119
- </AppLayoutContainer>
120
- );
121
- };
122
-
123
- const AppLayoutContainer = styled(Stack)(({ theme }: { theme?: any }) => ({
124
- flexDirection: 'row',
125
- backgroundColor: theme.palette.surface.defaultBackground,
126
-
127
- [theme.breakpoints.down('md')]: { flexWrap: 'wrap' },
128
- }));
129
-
130
- const OutletContainer = styled(Box)(({ theme }: { theme?: any }) => ({
131
- borderRadius: '8px',
132
- height: 'calc(100vh - 96px)',
133
- overflowY: 'scroll',
134
- width: '100%',
135
-
136
- '&::-webkit-scrollbar': {
137
- width: '0.5em',
138
- height: '0.2em',
139
- backgroundColor: theme.palette.surface.defaultBackground,
140
- },
141
-
142
- '&::-webkit-scrollbar-thumb': {
143
- backgroundColor: theme.palette.primary.light,
144
- borderRadius: '3px',
145
-
146
- '&:hover': { backgroundColor: theme.palette.primary.main },
147
- },
148
-
149
- [theme.breakpoints.down('md')]: {
150
- margin: '0px 12px 12px 12px',
151
- height: 'calc(100vh - 118px)',
152
-
153
- '&::-webkit-scrollbar': { display: 'none' },
154
- },
155
- }));
@@ -1,121 +0,0 @@
1
- import { Icons } from '@campxdev/react-blueprint';
2
- import { Backdrop, useTheme } from '@mui/material';
3
- import Box from '@mui/material/Box';
4
- import SpeedDial from '@mui/material/SpeedDial';
5
- import SpeedDialAction from '@mui/material/SpeedDialAction';
6
- import * as React from 'react';
7
-
8
- interface HelpDocsActionType {
9
- name: string;
10
- onClick?: () => void;
11
- backgroundColor?: string;
12
- }
13
-
14
- interface HelpDocsProps {
15
- actions: HelpDocsActionType[];
16
- }
17
-
18
- export const HelpDocs: React.FC<HelpDocsProps> = ({ actions }) => {
19
- const theme = useTheme();
20
- const [open, setOpen] = React.useState(false);
21
-
22
- const handleOpen = () => setOpen(true);
23
- const handleClose = () => setOpen(false);
24
-
25
- return (
26
- <Box
27
- sx={{
28
- position: 'fixed',
29
- bottom: 26,
30
- right: 0,
31
- zIndex: 1000,
32
- }}
33
- >
34
- <Backdrop open={open} />
35
- <SpeedDial
36
- ariaLabel="Custom Help Docs"
37
- sx={{
38
- position: 'absolute',
39
- bottom: 0,
40
- right: 40,
41
- display: 'flex',
42
- alignItems: 'flex-end',
43
- '& .MuiFab-primary': {
44
- backgroundColor: theme.palette.highlight.highlightBlue,
45
- borderRadius: '8px',
46
- width: '50px',
47
- height: '50px',
48
- display: 'flex',
49
- justifyContent: 'center',
50
- alignItems: 'center',
51
- '&:hover': {
52
- backgroundColor: theme.palette.highlight.highlightBlue,
53
- },
54
- },
55
- '& .MuiSpeedDialAction-fab': {
56
- margin: '0 0 16px 0',
57
- '&:not(:last-child)': {
58
- marginBottom: '8px',
59
- },
60
- },
61
- }}
62
- icon={<Icons.HelpDocsIcon size={20} />}
63
- onClose={handleClose}
64
- onOpen={handleOpen}
65
- open={open}
66
- direction="up"
67
- >
68
- {actions.map((action: HelpDocsActionType) => (
69
- <SpeedDialAction
70
- key={action.name}
71
- onClick={() => {
72
- action.onClick?.();
73
- handleClose();
74
- }}
75
- icon={
76
- <span
77
- style={{
78
- display: 'flex',
79
- alignItems: 'center',
80
- justifyContent: 'center',
81
- width: '100%',
82
- height: '100%',
83
- fontWeight: 'bold',
84
- whiteSpace: 'nowrap',
85
- overflow: 'hidden',
86
- textOverflow: 'ellipsis',
87
- }}
88
- >
89
- {action.name}
90
- </span>
91
- }
92
- FabProps={{
93
- sx: {
94
- width: 'auto',
95
- minWidth: '180px',
96
- maxWidth: '280px',
97
- padding: '8px 12px',
98
- boxShadow: 'none',
99
- height: '40px',
100
- borderRadius: '8px',
101
- backgroundColor: theme.palette.surface.defaultBackground,
102
- color: theme.palette.text.primary,
103
- fontWeight: 500,
104
- fontFamily: 'Heebo',
105
- fontSize: '12px',
106
- whiteSpace: 'nowrap',
107
- textAlign: 'right',
108
- display: 'flex',
109
- justifyContent: 'flex-end',
110
- alignItems: 'center',
111
- '&:hover': {
112
- backgroundColor: theme.palette.surface.defaultBackground,
113
- },
114
- },
115
- }}
116
- />
117
- ))}
118
- </SpeedDial>
119
- </Box>
120
- );
121
- };