@campxdev/campx-web-utils 0.4.0 → 0.4.2
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/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@campxdev/campx-web-utils",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"main": "./export.ts",
|
|
5
5
|
"private": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@campxdev/react-blueprint": ">=1.
|
|
7
|
+
"@campxdev/react-blueprint": ">=1.7.0",
|
|
8
8
|
"@emotion/react": ">=^11.13.3",
|
|
9
9
|
"@emotion/styled": ">=^11.13.0",
|
|
10
10
|
"@mui/icons-material": ">=6.1.5",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"react-redux": "=>9.1.2"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@campxdev/react-blueprint": "1.
|
|
17
|
+
"@campxdev/react-blueprint": "1.7.0",
|
|
18
18
|
"@hookform/resolvers": "^3.9.0",
|
|
19
19
|
"@mui/x-date-pickers": "^7.22.1",
|
|
20
20
|
"axios": "^1.7.2",
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SingleSelect, SingleSelectProps } from '@campxdev/react-blueprint';
|
|
2
|
+
import { batchOptions } from './utils';
|
|
3
|
+
|
|
4
|
+
export const BatchSelector = (props: SingleSelectProps) => {
|
|
5
|
+
return (
|
|
6
|
+
<SingleSelect
|
|
7
|
+
label="Batch"
|
|
8
|
+
options={batchOptions?.map((item: { label: string; value: string }) => ({
|
|
9
|
+
label: item.label,
|
|
10
|
+
value: item.value,
|
|
11
|
+
}))}
|
|
12
|
+
{...props}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SingleSelect, SingleSelectProps } from '@campxdev/react-blueprint';
|
|
2
|
+
import { axios } from '../config/axios';
|
|
3
|
+
|
|
4
|
+
export const PrintFormatSelector = (props: SingleSelectProps) => {
|
|
5
|
+
return (
|
|
6
|
+
<SingleSelect
|
|
7
|
+
dbLabelProps={{
|
|
8
|
+
labelKey: 'name',
|
|
9
|
+
subLabelKey: 'type',
|
|
10
|
+
useSubLabelStartCase: true,
|
|
11
|
+
}}
|
|
12
|
+
{...props}
|
|
13
|
+
externalAxios={axios}
|
|
14
|
+
optionsApiEndPoint="/dropdowns/print-formats"
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
};
|
package/src/selectors/export.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export * from './BatchSelector';
|
|
1
2
|
export * from './CourseSelector';
|
|
3
|
+
export * from './DepartmentSelector';
|
|
2
4
|
export * from './EmployeesSelector';
|
|
3
|
-
export * from './SemesterSelector';
|
|
4
5
|
export * from './FeeTypeSelector';
|
|
5
6
|
export * from './HostelFloorSelector';
|
|
6
7
|
export * from './HostelRoomSelector';
|
|
8
|
+
export * from './PrintFormatSelector';
|
|
9
|
+
export * from './SemesterSelector';
|
|
7
10
|
export * from './YearRangeSelector';
|
|
8
|
-
export * from './DepartmentSelector';
|
package/src/selectors/utils.tsx
CHANGED
|
@@ -32,3 +32,8 @@ export const FeeTypes: {
|
|
|
32
32
|
export const years = Array.from({ length: 6 }, (_, i) => {
|
|
33
33
|
return new Date().getFullYear() - i;
|
|
34
34
|
});
|
|
35
|
+
|
|
36
|
+
export const batchOptions = Array.from({ length: 12 }, (_, i) => ({
|
|
37
|
+
label: `${new Date().getFullYear() - i} - ${new Date().getFullYear() - i + 1}`,
|
|
38
|
+
value: `${new Date().getFullYear() - i} - ${new Date().getFullYear() - i + 1}`,
|
|
39
|
+
}));
|