@larisarozin/dodone-shared 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.
Files changed (66) hide show
  1. package/README.md +116 -0
  2. package/dist/api/routes.d.ts +66 -0
  3. package/dist/api/routes.js +87 -0
  4. package/dist/config/ConfigContext.d.ts +4 -0
  5. package/dist/config/ConfigContext.js +10 -0
  6. package/dist/config/ConfigProvider.d.ts +8 -0
  7. package/dist/config/ConfigProvider.js +8 -0
  8. package/dist/config/useConfig.d.ts +1 -0
  9. package/dist/config/useConfig.js +17 -0
  10. package/dist/config.d.ts +4 -0
  11. package/dist/config.js +6 -0
  12. package/dist/hooks/auth/AuthContext.d.ts +6 -0
  13. package/dist/hooks/auth/AuthContext.js +10 -0
  14. package/dist/hooks/auth/AuthProvider.d.ts +6 -0
  15. package/dist/hooks/auth/AuthProvider.js +83 -0
  16. package/dist/hooks/auth/AuthState.d.ts +20 -0
  17. package/dist/hooks/auth/AuthState.js +7 -0
  18. package/dist/hooks/auth/useAuth.d.ts +3 -0
  19. package/dist/hooks/auth/useAuth.js +17 -0
  20. package/dist/hooks/useAllowanceHistories.d.ts +9 -0
  21. package/dist/hooks/useAllowanceHistories.js +87 -0
  22. package/dist/hooks/useAllowanceHistoryTaskItems.d.ts +7 -0
  23. package/dist/hooks/useAllowanceHistoryTaskItems.js +69 -0
  24. package/dist/hooks/useGrades.d.ts +5 -0
  25. package/dist/hooks/useGrades.js +50 -0
  26. package/dist/hooks/useNotificationPreferences.d.ts +9 -0
  27. package/dist/hooks/useNotificationPreferences.js +107 -0
  28. package/dist/hooks/useTaskCategories.d.ts +7 -0
  29. package/dist/hooks/useTaskCategories.js +70 -0
  30. package/dist/hooks/useTaskComments.d.ts +7 -0
  31. package/dist/hooks/useTaskComments.js +69 -0
  32. package/dist/hooks/useTaskGroups.d.ts +7 -0
  33. package/dist/hooks/useTaskGroups.js +70 -0
  34. package/dist/hooks/useTaskItems.d.ts +7 -0
  35. package/dist/hooks/useTaskItems.js +70 -0
  36. package/dist/hooks/useTaskKinds.d.ts +7 -0
  37. package/dist/hooks/useTaskKinds.js +70 -0
  38. package/dist/hooks/useTeam.d.ts +24 -0
  39. package/dist/hooks/useTeam.js +255 -0
  40. package/dist/index.d.ts +29 -0
  41. package/dist/index.js +50 -0
  42. package/dist/types/AllowanceHistory.d.ts +66 -0
  43. package/dist/types/AllowanceHistory.js +7 -0
  44. package/dist/types/AllowanceInterval.d.ts +29 -0
  45. package/dist/types/AllowanceInterval.js +40 -0
  46. package/dist/types/ApiResponse.d.ts +7 -0
  47. package/dist/types/ApiResponse.js +7 -0
  48. package/dist/types/DeviceRegistration.d.ts +6 -0
  49. package/dist/types/DeviceRegistration.js +7 -0
  50. package/dist/types/TaskItem.d.ts +174 -0
  51. package/dist/types/TaskItem.js +16 -0
  52. package/dist/types/Team.d.ts +76 -0
  53. package/dist/types/Team.js +7 -0
  54. package/dist/types/User.d.ts +91 -0
  55. package/dist/types/User.js +7 -0
  56. package/dist/types/UserNotificationPreferences.d.ts +81 -0
  57. package/dist/types/UserNotificationPreferences.js +68 -0
  58. package/dist/utils/ApiClient.d.ts +204 -0
  59. package/dist/utils/ApiClient.js +608 -0
  60. package/dist/utils/paging.d.ts +305 -0
  61. package/dist/utils/paging.js +428 -0
  62. package/dist/utils/storage.d.ts +7 -0
  63. package/dist/utils/storage.js +37 -0
  64. package/dist/utils/utils.d.ts +0 -0
  65. package/dist/utils/utils.js +6 -0
  66. package/package.json +29 -0
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # dodone-shared Library
2
+
3
+ A shared library for task management functionality with React hooks and authentication.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install dodone-shared
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Wrap your application with both the `ConfigProvider` and `AuthProvider`:
14
+
15
+ ```tsx
16
+ import React from 'react';
17
+ import { ConfigProvider, AuthProvider } from 'dodone-shared';
18
+
19
+ function App() {
20
+ return (
21
+ <ConfigProvider config={{ baseUrl: 'https://your-api-server.com' }}>
22
+ <AuthProvider>
23
+ {/* Your app components */}
24
+ <YourAppComponents />
25
+ </AuthProvider>
26
+ </ConfigProvider>
27
+ );
28
+ }
29
+
30
+ export default App;
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Authentication
36
+
37
+ ```tsx
38
+ import { useAuth } from 'dodone-shared';
39
+
40
+ function LoginComponent() {
41
+ const { user, token, authError, authLoading, dispatch } = useAuth();
42
+
43
+ const handleLogin = (user, token) => {
44
+ dispatch({ type: 'LOGIN_SUCCESS', user, token });
45
+ };
46
+
47
+ const handleLogout = () => {
48
+ dispatch({ type: 'LOGOUT' });
49
+ };
50
+
51
+ // ... rest of your component
52
+ }
53
+ ```
54
+
55
+ ### Task Management Hooks
56
+
57
+ All hooks now automatically use the configured base URL:
58
+
59
+ ```tsx
60
+ import {
61
+ useTaskItems,
62
+ useTaskGroups,
63
+ useTaskKinds,
64
+ useTaskCategories,
65
+ useTeam
66
+ } from 'dodone-shared';
67
+
68
+ function TaskDashboard() {
69
+ const userId = 123;
70
+ const groupId = 456;
71
+ const kindId = 789;
72
+
73
+ // No need to pass baseUrl anymore!
74
+ const { taskItems, loadingTaskItems, refreshTaskItems } = useTaskItems(userId);
75
+ const { taskGroups, taskGroupsLoading, refreshTaskGroups } = useTaskGroups(userId);
76
+ const { kinds, loading: kindsLoading } = useTaskKinds(groupId);
77
+ const { groups: categories, loading: categoriesLoading } = useTaskCategories(kindId);
78
+ const { team, loading: teamLoading } = useTeam();
79
+
80
+ // ... rest of your component
81
+ }
82
+ ```
83
+
84
+ ## Configuration Options
85
+
86
+ The `ConfigProvider` accepts a config object with the following options:
87
+
88
+ - `baseUrl` (required): The base URL of your API server
89
+
90
+ Future configuration options may include:
91
+ - `timeout`: Request timeout in milliseconds
92
+ - `defaultHeaders`: Default headers to include with all requests
93
+
94
+ ## Migration from Previous Versions
95
+
96
+ If you were previously passing `baseUrl` as a parameter to hooks:
97
+
98
+ **Before:**
99
+ ```tsx
100
+ const { taskItems } = useTaskItems(userId, 'https://api.example.com');
101
+ const { taskGroups } = useTaskGroups(userId, 'https://api.example.com');
102
+ ```
103
+
104
+ **After:**
105
+ ```tsx
106
+ // In your App.tsx or root component
107
+ <ConfigProvider config={{ baseUrl: 'https://api.example.com' }}>
108
+ <AuthProvider>
109
+ {/* Your app */}
110
+ </AuthProvider>
111
+ </ConfigProvider>
112
+
113
+ // In your components
114
+ const { taskItems } = useTaskItems(userId);
115
+ const { taskGroups } = useTaskGroups(userId);
116
+ ```
@@ -0,0 +1,66 @@
1
+ export declare const API_ROUTES: {
2
+ auth: {
3
+ login: string;
4
+ register: string;
5
+ logout: string;
6
+ forgotPassword: string;
7
+ resetPassword: string;
8
+ sendPasswordResetEmail: string;
9
+ };
10
+ user: {
11
+ get: (id: number) => string;
12
+ create: string;
13
+ update: string;
14
+ delete: (id: number) => string;
15
+ };
16
+ notifications: {
17
+ register: string;
18
+ unregister: string;
19
+ };
20
+ grades: {
21
+ getList: () => string;
22
+ };
23
+ taskGroups: {
24
+ create: string;
25
+ update: string;
26
+ delete: (id: number) => string;
27
+ get: (id: number) => string;
28
+ getDetails: (id: number) => string;
29
+ getPagedList: () => string;
30
+ getPagedListDetails: () => string;
31
+ };
32
+ taskKinds: {
33
+ create: string;
34
+ update: string;
35
+ delete: (id: number) => string;
36
+ get: (id: number) => string;
37
+ getDetails: (id: number) => string;
38
+ getPagedList: () => string;
39
+ getPagedListDetails: () => string;
40
+ };
41
+ taskCategories: {
42
+ create: string;
43
+ update: string;
44
+ delete: (id: number) => string;
45
+ get: (id: number) => string;
46
+ getDetails: (id: number) => string;
47
+ getPagedList: () => string;
48
+ getPagedListDetails: () => string;
49
+ };
50
+ taskItems: {
51
+ create: string;
52
+ update: string;
53
+ copy: (id: number) => string;
54
+ archive: (id: number, archiving: boolean) => string;
55
+ archiveList: (archiving: boolean) => string;
56
+ pin: (id: number, pinning: boolean) => string;
57
+ pinList: (pinning: boolean) => string;
58
+ setActive: (id: number, activating: boolean) => string;
59
+ setActiveList: (activating: boolean) => string;
60
+ setComplete: (id: number, completing: boolean) => string;
61
+ setCompleteList: (completing: boolean) => string;
62
+ delete: (id: number) => string;
63
+ get: (id: number) => string;
64
+ getDetails: (id: number) => string;
65
+ };
66
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.API_ROUTES = void 0;
9
+ exports.API_ROUTES = {
10
+ auth: {
11
+ login: "/api/auth/login",
12
+ register: "/api/auth/register",
13
+ logout: "/api/auth/logout",
14
+ forgotPassword: "/api/auth/forgot-password",
15
+ resetPassword: "/api/auth/reset-password",
16
+ sendPasswordResetEmail: "/api/auth/send-password-reset-email",
17
+ },
18
+ user: {
19
+ get: (id) => `/api/user/${id}`,
20
+ // getMe: "/api/user/me",
21
+ // getTeam: '/api/user/team/',
22
+ create: "/api/user",
23
+ update: "/api/user",
24
+ delete: (id) => `/api/user/${id}`,
25
+ // getPagedList: () => `/api/user/team-paged-list/`,
26
+ },
27
+ notifications: {
28
+ register: "/api/userdeviceregistration/register-device",
29
+ unregister: "/api/userdeviceregistration/unregister-device",
30
+ },
31
+ grades: {
32
+ getList: () => `/api/grade/list/`,
33
+ },
34
+ taskGroups: {
35
+ create: "/api/taskgroup",
36
+ update: "/api/taskgroup",
37
+ delete: (id) => `/api/taskgroup/${id}`,
38
+ get: (id) => `/api/taskgroup/${id}`,
39
+ getDetails: (id) => `/api/taskgroup/details/${id}`,
40
+ // getList: (userId: number) => `/api/taskgroup/list/${userId}`,
41
+ // getListDetails: (userId: number) => `/api/taskgroup/list-details/${userId}`,
42
+ getPagedList: () => `/api/taskgroup/paged-list/`,
43
+ getPagedListDetails: () => `/api/taskgroup/paged-list-details/`,
44
+ },
45
+ taskKinds: {
46
+ create: "/api/taskkind",
47
+ update: "/api/taskkind",
48
+ delete: (id) => `/api/taskkind/${id}`,
49
+ get: (id) => `/api/taskkind/${id}`,
50
+ getDetails: (id) => `/api/taskkind/details/${id}`,
51
+ // getList: (groupId: number) => `/api/taskkind/list/${groupId}`,
52
+ // getListDetails: (groupId: number) => `/api/taskkind/list-details/${groupId}`,
53
+ getPagedList: () => `/api/taskkind/paged-list/`,
54
+ getPagedListDetails: () => `/api/taskkind/paged-list-details/`,
55
+ },
56
+ taskCategories: {
57
+ create: "/api/taskcategory",
58
+ update: "/api/taskcategory",
59
+ delete: (id) => `/api/taskcategory/${id}`,
60
+ get: (id) => `/api/taskcategory/${id}`,
61
+ getDetails: (id) => `/api/taskcategory/details/${id}`,
62
+ // getList: (kindId: number) => `/api/taskcategory/list/${kindId}`,
63
+ // getListDetails: (kindId: number) => `/api/taskcategory/list-details/${kindId}`,
64
+ getPagedList: () => `/api/taskcategory/paged-list/`,
65
+ getPagedListDetails: () => `/api/taskcategory/paged-list-details/`,
66
+ },
67
+ taskItems: {
68
+ create: "/api/taskitem",
69
+ update: "/api/taskitem",
70
+ copy: (id) => `/api/taskitem/copy/${id}`,
71
+ archive: (id, archiving) => `/api/taskitem/${id}/${archiving}`,
72
+ archiveList: (archiving) => `/api/taskitem/archive-list/${archiving}`,
73
+ pin: (id, pinning) => `/api/taskitem/pin/${id}/${pinning}`,
74
+ pinList: (pinning) => `/api/taskitem/pin-list/${pinning}`,
75
+ setActive: (id, activating) => `/api/taskitem/set-active/${id}/${activating}`,
76
+ setActiveList: (activating) => `/api/taskitem/set-active-list/${activating}`,
77
+ setComplete: (id, completing) => `/api/taskitem/set-complete/${id}/${completing}`,
78
+ setCompleteList: (completing) => `/api/taskitem/set-complete-list/${completing}`,
79
+ delete: (id) => `/api/taskitem/${id}`,
80
+ get: (id) => `/api/taskitem/${id}`,
81
+ getDetails: (id) => `/api/taskitem/details/${id}`,
82
+ // getList: (userId: number) => `/api/taskitem/list/${userId}`,
83
+ // getListDetails: (userId: number) => `/api/taskitem/list-details/${userId}`,
84
+ // getPagedList: (request: PagedTaskItemListRequest) => `/api/taskitem/list/${request.parentId}`,
85
+ // getPagedListDetails: (request: PagedTaskItemListRequest) => `/api/taskitem/list-details/${request.parentId}`,
86
+ },
87
+ };
@@ -0,0 +1,4 @@
1
+ export interface LibraryConfig {
2
+ baseUrl: string;
3
+ }
4
+ export declare const ConfigContext: import("react").Context<LibraryConfig | undefined>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ConfigContext = void 0;
9
+ const react_1 = require("react");
10
+ exports.ConfigContext = (0, react_1.createContext)(undefined);
@@ -0,0 +1,8 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type LibraryConfig } from './ConfigContext';
3
+ interface ConfigProviderProps {
4
+ children: ReactNode;
5
+ config: LibraryConfig;
6
+ }
7
+ export declare function ConfigProvider({ children, config }: ConfigProviderProps): import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigProvider = ConfigProvider;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const ConfigContext_1 = require("./ConfigContext");
6
+ function ConfigProvider({ children, config }) {
7
+ return ((0, jsx_runtime_1.jsx)(ConfigContext_1.ConfigContext.Provider, { value: config, children: children }));
8
+ }
@@ -0,0 +1 @@
1
+ export declare function useConfig(): import("./ConfigContext").LibraryConfig;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.useConfig = useConfig;
9
+ const react_1 = require("react");
10
+ const ConfigContext_1 = require("./ConfigContext");
11
+ function useConfig() {
12
+ const context = (0, react_1.useContext)(ConfigContext_1.ConfigContext);
13
+ if (!context) {
14
+ throw new Error('useConfig must be used within a ConfigProvider. Make sure to wrap your app with <ConfigProvider config={{ baseUrl: "your-api-url" }}>');
15
+ }
16
+ return context;
17
+ }
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ API_BASE_URL: string;
3
+ };
4
+ export default _default;
package/dist/config.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const API_BASE_URL = "http://192.168.1.126:5214";
4
+ exports.default = {
5
+ API_BASE_URL,
6
+ };
@@ -0,0 +1,6 @@
1
+ import { type AuthState, type AuthAction } from "./AuthState";
2
+ type AuthContextType = AuthState & {
3
+ dispatch: React.Dispatch<AuthAction>;
4
+ };
5
+ export declare const AuthContext: import("react").Context<AuthContextType | undefined>;
6
+ export {};
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.AuthContext = void 0;
9
+ const react_1 = require("react");
10
+ exports.AuthContext = (0, react_1.createContext)(undefined);
@@ -0,0 +1,6 @@
1
+ import { type ReactNode } from 'react';
2
+ interface AuthProviderProps {
3
+ children: ReactNode;
4
+ }
5
+ export declare function AuthProvider({ children }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AuthProvider = AuthProvider;
16
+ const jsx_runtime_1 = require("react/jsx-runtime");
17
+ /*
18
+ * Copyright (c) 2025 Larisa Rozin
19
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
20
+ * All rights reserved.
21
+ */
22
+ const react_1 = require("react");
23
+ const AuthContext_1 = require("./AuthContext");
24
+ const storage_1 = __importDefault(require("../../utils/storage"));
25
+ const USER_KEY = 'auth_user';
26
+ const TOKEN_KEY = 'auth_token';
27
+ function authReducer(state, action) {
28
+ switch (action.type) {
29
+ case 'LOGIN_SUCCESS':
30
+ return Object.assign(Object.assign({}, state), { user: action.user, token: action.token, authError: '', authLoading: false });
31
+ case 'LOGOUT':
32
+ return Object.assign(Object.assign({}, state), { user: null, token: null, authError: '', authLoading: false });
33
+ case 'SET_ERROR':
34
+ return Object.assign(Object.assign({}, state), { authError: action.error, authLoading: false });
35
+ case 'SET_LOADING':
36
+ return Object.assign(Object.assign({}, state), { authLoading: action.loading });
37
+ default:
38
+ return state;
39
+ }
40
+ }
41
+ const initialState = {
42
+ user: null,
43
+ token: null,
44
+ authError: '',
45
+ authLoading: false,
46
+ };
47
+ function AuthProvider({ children }) {
48
+ const [state, dispatch] = (0, react_1.useReducer)(authReducer, initialState);
49
+ (0, react_1.useEffect)(() => {
50
+ (() => __awaiter(this, void 0, void 0, function* () {
51
+ const storedUser = yield storage_1.default.getItem(USER_KEY);
52
+ const storedToken = yield storage_1.default.getItem(TOKEN_KEY);
53
+ if (storedUser && storedToken) {
54
+ dispatch({
55
+ type: 'LOGIN_SUCCESS',
56
+ user: JSON.parse(storedUser),
57
+ token: storedToken,
58
+ });
59
+ }
60
+ }))();
61
+ }, []);
62
+ (0, react_1.useEffect)(() => {
63
+ if (state.user) {
64
+ storage_1.default.setItem(USER_KEY, JSON.stringify(state.user));
65
+ // Store user_id separately for easy access (e.g., for celebration checks)
66
+ storage_1.default.setItem('user_id', state.user.id.toString());
67
+ }
68
+ else {
69
+ storage_1.default.removeItem(USER_KEY);
70
+ storage_1.default.removeItem('user_id');
71
+ }
72
+ }, [state.user]);
73
+ (0, react_1.useEffect)(() => {
74
+ if (state.token) {
75
+ storage_1.default.setItem(TOKEN_KEY, state.token);
76
+ }
77
+ else {
78
+ storage_1.default.removeItem(TOKEN_KEY);
79
+ }
80
+ }, [state.token]);
81
+ const value = (0, react_1.useMemo)(() => (Object.assign(Object.assign({}, state), { dispatch })), [state]);
82
+ return ((0, jsx_runtime_1.jsx)(AuthContext_1.AuthContext.Provider, { value: value, children: children }));
83
+ }
@@ -0,0 +1,20 @@
1
+ import { type User } from "../../types/User";
2
+ export type AuthState = {
3
+ user: User | null;
4
+ token: string | null;
5
+ authError: string;
6
+ authLoading: boolean;
7
+ };
8
+ export type AuthAction = {
9
+ type: 'LOGIN_SUCCESS';
10
+ user: User;
11
+ token: string;
12
+ } | {
13
+ type: 'LOGOUT';
14
+ } | {
15
+ type: 'SET_ERROR';
16
+ error: string;
17
+ } | {
18
+ type: 'SET_LOADING';
19
+ loading: boolean;
20
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export declare function useAuth(): import("./AuthState").AuthState & {
2
+ dispatch: React.Dispatch<import("./AuthState").AuthAction>;
3
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.useAuth = useAuth;
9
+ const react_1 = require("react");
10
+ const AuthContext_1 = require("./AuthContext");
11
+ function useAuth() {
12
+ const context = (0, react_1.useContext)(AuthContext_1.AuthContext);
13
+ if (!context) {
14
+ throw new Error('useAuth must be used within an AuthProvider');
15
+ }
16
+ return context;
17
+ }
@@ -0,0 +1,9 @@
1
+ import { PagedListResponse } from "../utils/paging";
2
+ import { AllowanceHistoryApprovalRequest, AllowanceHistoryClaimRequest, AllowanceHistoryResponse, PagedAllowanceHistoriesListRequest } from "../types/AllowanceHistory";
3
+ export declare function useAllowanceHistories(request: PagedAllowanceHistoriesListRequest): {
4
+ pagedAllowanceHistories: PagedListResponse<AllowanceHistoryResponse> | undefined;
5
+ loadingAllowanceHistories: boolean;
6
+ refreshAllowanceHistories: (request: PagedAllowanceHistoriesListRequest) => void;
7
+ approveAllowance: (request: AllowanceHistoryApprovalRequest) => Promise<AllowanceHistoryResponse>;
8
+ claimAllowance: (request: AllowanceHistoryClaimRequest) => Promise<AllowanceHistoryResponse>;
9
+ };
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025 Larisa Rozin
4
+ * dodone-shared - Task Management, Allowance & Bonus Tracking Application Package
5
+ * All rights reserved.
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.useAllowanceHistories = useAllowanceHistories;
18
+ const react_1 = require("react");
19
+ const useAuth_1 = require("./auth/useAuth");
20
+ const useConfig_1 = require("../config/useConfig");
21
+ const ApiClient_1 = require("../utils/ApiClient");
22
+ function useAllowanceHistories(request) {
23
+ const { token } = (0, useAuth_1.useAuth)();
24
+ const { baseUrl } = (0, useConfig_1.useConfig)();
25
+ const [pagedListRequest, setPagedListRequest] = (0, react_1.useState)(request);
26
+ const [pagedAllowanceHistories, setPagedAllowanceHistories] = (0, react_1.useState)();
27
+ const [loadingAllowanceHistories, setLoadingAllowanceHistories] = (0, react_1.useState)(true);
28
+ const fetchAllowanceHistories = (0, react_1.useCallback)((requestToUse) => __awaiter(this, void 0, void 0, function* () {
29
+ const requestToFetch = requestToUse || pagedListRequest;
30
+ if (!token) {
31
+ setLoadingAllowanceHistories(false);
32
+ return;
33
+ }
34
+ if (!requestToFetch) {
35
+ console.error("No request available for fetching allowance histories");
36
+ setLoadingAllowanceHistories(false);
37
+ return;
38
+ }
39
+ setLoadingAllowanceHistories(true);
40
+ try {
41
+ const apiClient = (0, ApiClient_1.createApiClient)(baseUrl, token);
42
+ const data = yield apiClient.allowanceHistories.getPagedList(requestToFetch);
43
+ if (!data || data.success === false) {
44
+ console.error("Failed to fetch allowance histories:", (data === null || data === void 0 ? void 0 : data.message) || "Unknown error");
45
+ setLoadingAllowanceHistories(false);
46
+ return;
47
+ }
48
+ setPagedAllowanceHistories(data);
49
+ }
50
+ catch (err) {
51
+ console.error("Error fetching allowance histories:", err);
52
+ }
53
+ finally {
54
+ setLoadingAllowanceHistories(false);
55
+ }
56
+ }), [token, baseUrl]);
57
+ function refreshAllowanceHistories(request) {
58
+ setPagedListRequest(request);
59
+ // Pass the request directly to fetchAllowanceHistories to avoid state timing issues
60
+ fetchAllowanceHistories(request);
61
+ }
62
+ function approveAllowance(request) {
63
+ if (!baseUrl || !token) {
64
+ throw new Error("Missing baseUrl or token for API client");
65
+ }
66
+ const apiClient = (0, ApiClient_1.createApiClient)(baseUrl, token);
67
+ const data = apiClient.allowanceHistories.approveAllowance(request);
68
+ // refreshAllowanceHistories(pagedListRequest);
69
+ return data;
70
+ }
71
+ function claimAllowance(request) {
72
+ if (!baseUrl || !token) {
73
+ throw new Error("Missing baseUrl or token for API client");
74
+ }
75
+ const apiClient = (0, ApiClient_1.createApiClient)(baseUrl, token);
76
+ const data = apiClient.allowanceHistories.claimAllowance(request);
77
+ // refreshAllowanceHistories(pagedListRequest);
78
+ return data;
79
+ }
80
+ (0, react_1.useEffect)(() => {
81
+ // Only fetch on initial load if we have a valid request
82
+ if (pagedListRequest) {
83
+ fetchAllowanceHistories(pagedListRequest);
84
+ }
85
+ }, [fetchAllowanceHistories]);
86
+ return { pagedAllowanceHistories, loadingAllowanceHistories, refreshAllowanceHistories, approveAllowance, claimAllowance };
87
+ }
@@ -0,0 +1,7 @@
1
+ import { PagedListResponse } from "../utils/paging";
2
+ import { AllowanceHistoryTaskItemResponse, PagedAllowanceHistoryTaskItemsListRequest } from "../types/AllowanceHistory";
3
+ export declare function useAllowanceHistoryTaskItems(request: PagedAllowanceHistoryTaskItemsListRequest): {
4
+ pagedAllowanceHistoryTaskItems: PagedListResponse<AllowanceHistoryTaskItemResponse> | undefined;
5
+ loadingAllowanceHistoryTaskItems: boolean;
6
+ refreshAllowanceHistoryTaskItems: (request: PagedAllowanceHistoryTaskItemsListRequest) => void;
7
+ };