izen-react-starter 2.3.9 → 2.4.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/README.md CHANGED
@@ -763,6 +763,45 @@ function UsersScreen() {
763
763
  }
764
764
  ```
765
765
 
766
+ ### Utility helpers (payload, time, HTML)
767
+
768
+ These utilities are exported from `izen-react-starter/lib`:
769
+
770
+ - `formatPayloadForEndpoint` (alias: `formatAxiosData`) — normalize payloads per endpoint (e.g., multipart for file-heavy routes, boolean fixes, role permissions, employee shifts).
771
+ - `buildMultipartFormData`, `buildRolePermissionsFormData`, `buildEmployeeShiftFormData` — helpers used by `formatPayloadForEndpoint` that you can also call directly.
772
+ - `removeHtmlTags` — strip HTML tags from strings.
773
+ - Time helpers: `parseTimeToMilliseconds`, `diffHoursFromTimestamps` (alias: `TimeDiffHours`), `subtractTimeStrings`, `sumTimeStrings`, `formatSecondsToHms` (aliases: `secondsToTime`, `formatTimeStr`).
774
+ - Date helpers: `toUTCDateString`/`toUTCDateTimeString`, `getWeekRange` (alias: `getWeekBounds`).
775
+
776
+ Example payload formatting:
777
+
778
+ ```ts
779
+ import { formatPayloadForEndpoint } from 'izen-react-starter/lib';
780
+
781
+ // Multipart for file upload endpoints
782
+ const payload = { name: 'Test', image: myFile };
783
+ const body = formatPayloadForEndpoint(payload, '/lessons');
784
+ await axios.post('/lessons', body);
785
+
786
+ // Role permissions (only true values become permissions[])
787
+ const roleBody = formatPayloadForEndpoint({ name: 'admin', manage_users: true }, '/roles');
788
+ await axios.post('/roles', roleBody);
789
+
790
+ // Employee shifts schedule
791
+ const shiftBody = formatPayloadForEndpoint({ employeeShifts: { mon: { start: '09:00', end: '17:00' } } }, '/employee-shifts/schedule-update');
792
+ await axios.post('/employee-shifts/schedule-update', shiftBody);
793
+ ```
794
+
795
+ Example time helpers:
796
+
797
+ ```ts
798
+ import { parseTimeToMilliseconds, subtractTimeStrings, formatSecondsToHms } from 'izen-react-starter/lib';
799
+
800
+ const ms = parseTimeToMilliseconds('09:30'); // 34200000
801
+ const diff = subtractTimeStrings('10:30', '09:00'); // "01:30:00"
802
+ const pretty = formatSecondsToHms(3661); // "01:01:01"
803
+ ```
804
+
766
805
  ### Role-Based Access Control (RBAC)
767
806
 
768
807
  The RBAC system is now fully configurable! Define your own roles, resources, and rules.
@@ -1,4 +1,4 @@
1
- export { cn, capitalize, convertToHourMinuteString, formatErrorToList, formatDate, dateFromat, createChangeEvent, appendFormData, debounce, throttle } from './utils';
1
+ export { cn, capitalize, convertToHourMinuteString, formatErrorToList, formatDate, dateFromat, createChangeEvent, appendFormData, buildMultipartFormData, buildRolePermissionsFormData, buildEmployeeShiftFormData, formatPayloadForEndpoint, formatAxiosData, removeHtmlTags, toUTCDateString, toUTCDateTimeString, parseTimeToMilliseconds, diffHoursFromTimestamps, subtractTimeStrings, sumTimeStrings, formatSecondsToHms, getWeekRange, debounce, throttle, } from './utils';
2
2
  export { handleEditCache, handleSingleEditCache } from './cache-util';
3
3
  export type { CacheEditOptions } from './cache-util';
4
4
  export * from './api';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtK,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,cAAc,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,EAAE,EACF,UAAU,EACV,yBAAyB,EACzB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,4BAA4B,EAC5B,0BAA0B,EAC1B,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,QAAQ,EACR,QAAQ,GACR,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,cAAc,OAAO,CAAC"}
@@ -3,6 +3,12 @@ import { ChangeEvent } from 'react';
3
3
  export declare function cn(...inputs: ClassValue[]): string;
4
4
  export declare function capitalize(str: string): string;
5
5
  export declare function convertToHourMinuteString(hours: number): string;
6
+ /**
7
+ * Format payloads for specific endpoints (multipart, boolean fixes, etc.).
8
+ * This is the library-friendly replacement for the old formatAxiosData.
9
+ */
10
+ export declare function formatPayloadForEndpoint(payload: any, endpoint: string): any;
11
+ export declare const formatAxiosData: typeof formatPayloadForEndpoint;
6
12
  export declare function formatErrorToList(str: string[] | string): string;
7
13
  export declare function formatDate(date: Date | string, formatStr?: string): string;
8
14
  /**
@@ -19,6 +25,9 @@ export declare function formatDate(date: Date | string, formatStr?: string): str
19
25
  * ```
20
26
  */
21
27
  export declare const dateFromat: (date: string | Date) => string;
28
+ export declare function removeHtmlTags(input?: string): string;
29
+ export declare function toUTCDateString(date: Date): string;
30
+ export declare function toUTCDateTimeString(date: Date): string;
22
31
  /**
23
32
  * Create a synthetic change event for form inputs
24
33
  * Useful for programmatic form updates when working with custom components
@@ -37,6 +46,25 @@ export declare const dateFromat: (date: string | Date) => string;
37
46
  */
38
47
  export declare const createChangeEvent: <T extends HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>(name: string, value: string) => ChangeEvent<T>;
39
48
  export declare function appendFormData(data: Record<string, any>): FormData;
49
+ export declare const buildMultipartFormData: typeof appendFormData;
50
+ export declare function buildRolePermissionsFormData(data: any): FormData;
51
+ export declare function buildEmployeeShiftFormData(data: any): FormData;
40
52
  export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
41
53
  export declare function throttle<T extends (...args: any[]) => any>(func: T, limit: number): (...args: Parameters<T>) => void;
54
+ export declare function parseTimeToMilliseconds(timeStr?: string): number;
55
+ export declare function diffHoursFromTimestamps(endMs: number, startMs: number): string;
56
+ export declare function subtractTimeStrings(time1: string, time2: string): string;
57
+ export declare function sumTimeStrings(time1: string, time2: string): string;
58
+ export declare function formatSecondsToHms(totalSeconds: number): string;
59
+ export declare function getWeekRange(selectedDate: Date): {
60
+ startDate: Date;
61
+ endDate: Date;
62
+ };
63
+ export declare const getUTCDate: typeof toUTCDateString;
64
+ export declare const getUTCDateTime: typeof toUTCDateTimeString;
65
+ export declare const TimeDiffHours: typeof diffHoursFromTimestamps;
66
+ export declare const parseTime: typeof parseTimeToMilliseconds;
67
+ export declare const formatTimeStr: typeof formatSecondsToHms;
68
+ export declare const secondsToTime: typeof formatSecondsToHms;
69
+ export declare const getWeekBounds: typeof getWeekRange;
42
70
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAQ,MAAM,MAAM,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAEpC,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,UAErC;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,UAMtD;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,UAcvD;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,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C,EACP,KAAK,EAAE,MAAM,GACZ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAUlC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,MAAM,UAMvD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAGrE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAG/D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAG1D;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,UAKtD;AAED,wBAAgB,YAAY,CAAC,YAAY,EAAE,IAAI,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,IAAI,CAAA;CAAE,CAcnF;AAGD,eAAO,MAAM,UAAU,wBAAkB,CAAC;AAC1C,eAAO,MAAM,cAAc,4BAAsB,CAAC;AAClD,eAAO,MAAM,aAAa,gCAA0B,CAAC;AACrD,eAAO,MAAM,SAAS,gCAA0B,CAAC;AACjD,eAAO,MAAM,aAAa,2BAAqB,CAAC;AAChD,eAAO,MAAM,aAAa,2BAAqB,CAAC;AAChD,eAAO,MAAM,aAAa,qBAAe,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "izen-react-starter",
3
- "version": "2.3.9",
3
+ "version": "2.4.0",
4
4
  "description": "A React component library with UI components, layout context, and data fetching",
5
5
  "type": "module",
6
6
  "main": "./dist/react-starter.umd.cjs",