@movalib/movalib-commons 1.68.27 → 1.68.29

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.
@@ -21,7 +21,12 @@ type TMovaTable<T> = {
21
21
  onRowDoubleClick?: (data: T) => void;
22
22
  filterChildren?: React.ReactNode;
23
23
  asSearchSection?: boolean;
24
+ cardRenderer?: ComponentType<{
25
+ element: T;
26
+ onClick?: () => void;
27
+ }>;
28
+ forceCardRender?: boolean;
24
29
  placeHolderNoData?: React.ReactNode;
25
30
  };
26
- export default function MovaTableBack<T>({ useDataHook, displayedColumns, pagination, compact, onRowClick, onRowRightClick, onRowDoubleClick, isClickable, filterChildren, asSearchSection, placeHolderNoData, }: TMovaTable<T>): import("react/jsx-runtime").JSX.Element;
31
+ export default function MovaTableBack<T>({ useDataHook, displayedColumns, pagination, compact, onRowClick, onRowRightClick, onRowDoubleClick, isClickable, filterChildren, asSearchSection, placeHolderNoData, cardRenderer, forceCardRender, }: TMovaTable<T>): import("react/jsx-runtime").JSX.Element;
27
32
  export {};
@@ -9,13 +9,18 @@ var icons_material_1 = require("@mui/icons-material");
9
9
  var Search_1 = __importDefault(require("@mui/icons-material/Search"));
10
10
  var material_1 = require("@mui/material");
11
11
  var react_1 = require("react");
12
+ var material_2 = require("@mui/material");
12
13
  function MovaTableBack(_a) {
13
- var useDataHook = _a.useDataHook, displayedColumns = _a.displayedColumns, pagination = _a.pagination, compact = _a.compact, onRowClick = _a.onRowClick, onRowRightClick = _a.onRowRightClick, onRowDoubleClick = _a.onRowDoubleClick, isClickable = _a.isClickable, filterChildren = _a.filterChildren, _b = _a.asSearchSection, asSearchSection = _b === void 0 ? true : _b, placeHolderNoData = _a.placeHolderNoData;
14
- var _c = (0, react_1.useState)(0), currentPageIndex = _c[0], setCurrentPageIndex = _c[1];
15
- var _d = (0, react_1.useState)(25), rowsPerPage = _d[0], setRowsPerPage = _d[1];
16
- var _e = (0, react_1.useState)(""), search = _e[0], setSearch = _e[1];
14
+ var useDataHook = _a.useDataHook, displayedColumns = _a.displayedColumns, pagination = _a.pagination, compact = _a.compact, onRowClick = _a.onRowClick, onRowRightClick = _a.onRowRightClick, onRowDoubleClick = _a.onRowDoubleClick, isClickable = _a.isClickable, filterChildren = _a.filterChildren, _b = _a.asSearchSection, asSearchSection = _b === void 0 ? true : _b, placeHolderNoData = _a.placeHolderNoData, cardRenderer = _a.cardRenderer, _c = _a.forceCardRender, forceCardRender = _c === void 0 ? false : _c;
15
+ var _d = (0, react_1.useState)(0), currentPageIndex = _d[0], setCurrentPageIndex = _d[1];
16
+ var _e = (0, react_1.useState)(25), rowsPerPage = _e[0], setRowsPerPage = _e[1];
17
+ var _f = (0, react_1.useState)(""), search = _f[0], setSearch = _f[1];
17
18
  var clickTimeout = (0, react_1.useRef)(null);
18
- var _f = useDataHook(currentPageIndex, rowsPerPage, search), data = _f.data, totalElements = _f.totalElements, isLoading = _f.isLoading, refresh = _f.refresh;
19
+ var theme = (0, material_2.useTheme)();
20
+ var isMobile = (0, material_2.useMediaQuery)(theme.breakpoints.down("md"));
21
+ var showCards = (isMobile || forceCardRender) && !!cardRenderer;
22
+ var CardComponent = cardRenderer;
23
+ var _g = useDataHook(currentPageIndex, rowsPerPage, search), data = _g.data, totalElements = _g.totalElements, isLoading = _g.isLoading, refresh = _g.refresh;
19
24
  var handleDoubleClick = (0, react_1.useCallback)(function (element) {
20
25
  if (!onRowDoubleClick)
21
26
  return;
@@ -61,7 +66,7 @@ function MovaTableBack(_a) {
61
66
  gap: 2,
62
67
  }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { size: "small", type: "search", onChange: handleSearchChange, inputProps: {
63
68
  startAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "start", children: (0, jsx_runtime_1.jsx)(Search_1.default, {}) })),
64
- }, sx: { width: "100%" }, placeholder: "Rechercher" }), refresh && ((0, jsx_runtime_1.jsx)(material_1.Button, { size: "small", onClick: refresh, variant: "contained", children: (0, jsx_runtime_1.jsx)(icons_material_1.Refresh, {}) }))] }), filterChildren && filterChildren, (0, jsx_runtime_1.jsx)(material_1.TableContainer, { sx: { height: "100%" }, component: material_1.Paper, children: (0, jsx_runtime_1.jsxs)(material_1.Table, { size: compact ? "small" : "medium", sx: { height: "100%" }, stickyHeader: true, children: [(0, jsx_runtime_1.jsx)(material_1.TableHead, { children: (0, jsx_runtime_1.jsx)(material_1.TableRow, { children: displayedColumns.map(function (column, index) { return ((0, jsx_runtime_1.jsx)(material_1.TableCell, { children: column.displayName }, index)); }) }) }), (0, jsx_runtime_1.jsxs)(material_1.TableBody, { sx: { overflowY: "auto" }, children: [isLoading && ((0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, { colSpan: 5, sx: { padding: 0 }, children: (0, jsx_runtime_1.jsx)(material_1.LinearProgress, {}) }) })), !isLoading && (data === null || data === void 0 ? void 0 : data.length) === 0 && placeHolderNoData && ((0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, { colSpan: displayedColumns.length, sx: { textAlign: "center", color: "grey.400" }, children: placeHolderNoData }) })), (data === null || data === void 0 ? void 0 : data.length) !== 0 &&
69
+ }, sx: { width: "100%" }, placeholder: "Rechercher" }), refresh && ((0, jsx_runtime_1.jsx)(material_1.Button, { size: "small", onClick: refresh, variant: "contained", children: (0, jsx_runtime_1.jsx)(icons_material_1.Refresh, {}) }))] }), filterChildren && filterChildren, showCards ? ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { flex: 1, minHeight: 0, overflow: "auto", display: "flex", flexDirection: "column", gap: 1, p: 1 }, children: [isLoading && (0, jsx_runtime_1.jsx)(material_1.LinearProgress, {}), !isLoading && (data === null || data === void 0 ? void 0 : data.length) === 0 && placeHolderNoData, data === null || data === void 0 ? void 0 : data.map(function (element, index) { return ((0, jsx_runtime_1.jsx)(CardComponent, { element: element, onClick: function () { return onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(element); } }, index)); })] }), pagination && pagination.length > 0 && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { flexShrink: 0, borderTop: 1, borderColor: "divider", backgroundColor: "white" }, children: (0, jsx_runtime_1.jsx)(material_1.TablePagination, { sx: { minHeight: "52px" }, component: "div", count: totalElements, onPageChange: handlePageChange, page: currentPageIndex, rowsPerPage: rowsPerPage, labelRowsPerPage: "Par page :", onRowsPerPageChange: handleRowsPerPageChange, rowsPerPageOptions: pagination }) }))] })) : ((0, jsx_runtime_1.jsx)(material_1.TableContainer, { sx: { height: "100%" }, component: material_1.Paper, children: (0, jsx_runtime_1.jsxs)(material_1.Table, { size: compact ? "small" : "medium", sx: { height: "100%" }, stickyHeader: true, children: [(0, jsx_runtime_1.jsx)(material_1.TableHead, { children: (0, jsx_runtime_1.jsx)(material_1.TableRow, { children: displayedColumns.map(function (column, index) { return ((0, jsx_runtime_1.jsx)(material_1.TableCell, { children: column.displayName }, index)); }) }) }), (0, jsx_runtime_1.jsxs)(material_1.TableBody, { sx: { overflowY: "auto" }, children: [isLoading && ((0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, { colSpan: 5, sx: { padding: 0 }, children: (0, jsx_runtime_1.jsx)(material_1.LinearProgress, {}) }) })), !isLoading && (data === null || data === void 0 ? void 0 : data.length) === 0 && placeHolderNoData && ((0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TableCell, { colSpan: displayedColumns.length, sx: { textAlign: "center", color: "grey.400" }, children: placeHolderNoData }) })), (data === null || data === void 0 ? void 0 : data.length) !== 0 &&
65
70
  (data === null || data === void 0 ? void 0 : data.map(function (element, index) { return ((0, jsx_runtime_1.jsx)(material_1.TableRow, { onDoubleClick: function () {
66
71
  handleDoubleClick(element);
67
72
  }, onClick: function () { return handleRowClick(element); }, onContextMenu: function (event) {
@@ -80,5 +85,5 @@ function MovaTableBack(_a) {
80
85
  width: "1%",
81
86
  maxWidth: "fit-content",
82
87
  }
83
- : {}, children: column.component && ((0, jsx_runtime_1.jsx)(column.component, { element: element })) }, index)); }) }, index)); })), (0, jsx_runtime_1.jsx)(material_1.TableRow, { sx: { height: "100%" } })] }), pagination && pagination.length > 0 && ((0, jsx_runtime_1.jsx)(material_1.TableFooter, { sx: { position: "sticky", bottom: 0, backgroundColor: "white" }, children: (0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TablePagination, { count: totalElements, onPageChange: handlePageChange, page: currentPageIndex, rowsPerPage: rowsPerPage, labelRowsPerPage: "Lignes par page :", onRowsPerPageChange: handleRowsPerPageChange, rowsPerPageOptions: pagination }) }) }))] }) })] }));
88
+ : {}, children: column.component && ((0, jsx_runtime_1.jsx)(column.component, { element: element })) }, index)); }) }, index)); })), (0, jsx_runtime_1.jsx)(material_1.TableRow, { sx: { height: "100%" } })] }), pagination && pagination.length > 0 && ((0, jsx_runtime_1.jsx)(material_1.TableFooter, { sx: { position: "sticky", bottom: 0, backgroundColor: "white" }, children: (0, jsx_runtime_1.jsx)(material_1.TableRow, { children: (0, jsx_runtime_1.jsx)(material_1.TablePagination, { count: totalElements, onPageChange: handlePageChange, page: currentPageIndex, rowsPerPage: rowsPerPage, labelRowsPerPage: "Lignes par page :", onRowsPerPageChange: handleRowsPerPageChange, rowsPerPageOptions: pagination }) }) }))] }) }))] }));
84
89
  }
@@ -10,6 +10,7 @@ export type APIRequest = {
10
10
  method: APIMethod;
11
11
  appType?: MovaAppType;
12
12
  body?: string | FormData;
13
+ headers?: any;
13
14
  };
14
15
  /**
15
16
  * ATTENTION : cela signifie que toutes les requêtes du Front seront de type "preflight"
@@ -72,9 +72,15 @@ var request = function (options) {
72
72
  }
73
73
  break;
74
74
  }
75
+ if (options.headers) {
76
+ Object.entries(options.headers).forEach(function (_a) {
77
+ var key = _a[0], value = _a[1];
78
+ headers.set(key, value);
79
+ });
80
+ }
75
81
  // On intègre les headers aux options
76
82
  var defaults = { headers: headers };
77
- options = Object.assign({}, defaults, options);
83
+ options = Object.assign({}, defaults, options, { headers: headers });
78
84
  Logger_1.default.info(options);
79
85
  // Appel API
80
86
  return fetch(options.url, options)
@@ -107,7 +107,8 @@ export default class Event {
107
107
  quoteFirstSendingTime?: Date;
108
108
  lastQuoteCreationDate?: Date;
109
109
  urgent?: boolean;
110
- constructor(id: string, ownerId: number, type: EventType, title: string, garageName: string, garageId: number, color: string, state: EventState, garageAddress?: Address, start?: Date, end?: Date, prestations?: Prestation[], operations?: Operation[], products?: Product[], guestsId?: string[], vehicleId?: number, quoteId?: number, notes?: string, vehicleAvailableNotified?: boolean, editable?: boolean, resourceId?: number, garageVehicleId?: number, garageVehicleRequest?: boolean, vehicleAvailableNotificationTime?: Date, interventionEndTime?: Date, quoteLastSendingTime?: Date, invoiceSendingDate?: Date, orders?: Order[], creationDate?: Date, updatedDate?: Date, lastQuoteCreationDate?: Date, quoteFirstSendingTime?: Date, urgent?: boolean, garageVehicleBookings?: LoanVehicle[], goodForAgreement?: boolean);
110
+ schedulable?: boolean;
111
+ constructor(id: string, ownerId: number, type: EventType, title: string, garageName: string, garageId: number, color: string, state: EventState, garageAddress?: Address, start?: Date, end?: Date, prestations?: Prestation[], operations?: Operation[], products?: Product[], guestsId?: string[], vehicleId?: number, quoteId?: number, notes?: string, vehicleAvailableNotified?: boolean, editable?: boolean, resourceId?: number, garageVehicleId?: number, garageVehicleRequest?: boolean, vehicleAvailableNotificationTime?: Date, interventionEndTime?: Date, quoteLastSendingTime?: Date, invoiceSendingDate?: Date, orders?: Order[], creationDate?: Date, updatedDate?: Date, lastQuoteCreationDate?: Date, quoteFirstSendingTime?: Date, urgent?: boolean, garageVehicleBookings?: LoanVehicle[], goodForAgreement?: boolean, schedulable?: boolean);
111
112
  static getPrestationsList(event: Event): string[];
112
113
  static getCurrentQuote(event: Event): Document | null;
113
114
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var Enums_1 = require("../helpers/Enums");
4
4
  var Event = /** @class */ (function () {
5
- function Event(id, ownerId, type, title, garageName, garageId, color, state, garageAddress, start, end, prestations, operations, products, guestsId, vehicleId, quoteId, notes, vehicleAvailableNotified, editable, resourceId, garageVehicleId, garageVehicleRequest, vehicleAvailableNotificationTime, interventionEndTime, quoteLastSendingTime, invoiceSendingDate, orders, creationDate, updatedDate, lastQuoteCreationDate, quoteFirstSendingTime, urgent, garageVehicleBookings, goodForAgreement) {
5
+ function Event(id, ownerId, type, title, garageName, garageId, color, state, garageAddress, start, end, prestations, operations, products, guestsId, vehicleId, quoteId, notes, vehicleAvailableNotified, editable, resourceId, garageVehicleId, garageVehicleRequest, vehicleAvailableNotificationTime, interventionEndTime, quoteLastSendingTime, invoiceSendingDate, orders, creationDate, updatedDate, lastQuoteCreationDate, quoteFirstSendingTime, urgent, garageVehicleBookings, goodForAgreement, schedulable) {
6
6
  this.id = id;
7
7
  this.notes = notes;
8
8
  this.ownerId = ownerId;
@@ -50,6 +50,7 @@ var Event = /** @class */ (function () {
50
50
  this.urgent = urgent;
51
51
  this.garageVehicleBookings = garageVehicleBookings;
52
52
  this.goodForAgreement = goodForAgreement;
53
+ this.schedulable = schedulable;
53
54
  }
54
55
  Event.getPrestationsList = function (event) {
55
56
  if (event && event.prestations) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.68.27",
3
+ "version": "1.68.29",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,6 +25,7 @@ import {
25
25
  useRef,
26
26
  useState,
27
27
  } from "react";
28
+ import { useMediaQuery, useTheme } from "@mui/material";
28
29
 
29
30
  type TMovaTable<T> = {
30
31
  useDataHook: (
@@ -50,6 +51,8 @@ type TMovaTable<T> = {
50
51
  onRowDoubleClick?: (data: T) => void;
51
52
  filterChildren?: React.ReactNode;
52
53
  asSearchSection?: boolean;
54
+ cardRenderer?: ComponentType<{ element: T; onClick?: () => void }>;
55
+ forceCardRender?:boolean;
53
56
  placeHolderNoData?: React.ReactNode;
54
57
  };
55
58
 
@@ -65,12 +68,17 @@ export default function MovaTableBack<T>({
65
68
  filterChildren,
66
69
  asSearchSection = true,
67
70
  placeHolderNoData,
71
+ cardRenderer,
72
+ forceCardRender = false,
68
73
  }: TMovaTable<T>) {
69
74
  const [currentPageIndex, setCurrentPageIndex] = useState<number>(0);
70
75
  const [rowsPerPage, setRowsPerPage] = useState<number>(25);
71
76
  const [search, setSearch] = useState("");
72
77
  const clickTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
73
-
78
+ const theme = useTheme();
79
+ const isMobile = useMediaQuery(theme.breakpoints.down("md"));
80
+ const showCards = (isMobile || forceCardRender) && !!cardRenderer;
81
+ const CardComponent = cardRenderer as ComponentType<{ element: T; onClick?: () => void }>;
74
82
  const { data, totalElements, isLoading, refresh } = useDataHook(
75
83
  currentPageIndex,
76
84
  rowsPerPage,
@@ -161,6 +169,38 @@ export default function MovaTableBack<T>({
161
169
  )}
162
170
  </Box>}
163
171
  {filterChildren && filterChildren}
172
+
173
+ {showCards ? (
174
+ <Box sx={{ flex: 1, minHeight: 0, display: "flex", flexDirection: "column" }}>
175
+ {/* Zone scrollable */}
176
+ <Box sx={{ flex: 1, minHeight: 0, overflow: "auto", display: "flex", flexDirection: "column", gap: 1, p: 1 }}>
177
+ {isLoading && <LinearProgress />}
178
+ {!isLoading && data?.length === 0 && placeHolderNoData}
179
+ {data?.map((element, index) => (
180
+ <CardComponent key={index} element={element} onClick={() => onRowClick?.(element)} />
181
+ ))}
182
+ </Box>
183
+
184
+ {/* Pagination fixe en bas */}
185
+ {pagination && pagination.length > 0 && (
186
+ <Box sx={{ flexShrink: 0, borderTop: 1, borderColor: "divider", backgroundColor: "white" }}>
187
+ <TablePagination
188
+ sx={{ minHeight: "52px" }}
189
+ component="div"
190
+ count={totalElements}
191
+ onPageChange={handlePageChange}
192
+ page={currentPageIndex}
193
+ rowsPerPage={rowsPerPage}
194
+ labelRowsPerPage="Par page :"
195
+ onRowsPerPageChange={handleRowsPerPageChange}
196
+ rowsPerPageOptions={pagination}
197
+ />
198
+ </Box>
199
+ )}
200
+ </Box>
201
+ ) : (
202
+
203
+
164
204
  <TableContainer sx={{ height: "100%" }} component={Paper}>
165
205
  <Table
166
206
  size={compact ? "small" : "medium"}
@@ -258,6 +298,7 @@ export default function MovaTableBack<T>({
258
298
  )}
259
299
  </Table>
260
300
  </TableContainer>
301
+ )}
261
302
  </div>
262
303
  );
263
304
  }
@@ -28,7 +28,8 @@ export type APIRequest = {
28
28
  url: string,
29
29
  method: APIMethod,
30
30
  appType?: MovaAppType,
31
- body?: string | FormData
31
+ body?: string | FormData,
32
+ headers?: any,
32
33
  }
33
34
 
34
35
  function handleError(error: Error): APIResponse<null> {
@@ -107,9 +108,16 @@ export const request = (options:APIRequest): Promise<APIResponse<any>> => {
107
108
  break;
108
109
  }
109
110
 
111
+ if (options.headers) {
112
+ Object.entries(options.headers).forEach(([key, value]) => {
113
+ headers.set(key, value as string);
114
+ });
115
+ }
116
+
110
117
  // On intègre les headers aux options
111
- const defaults = {headers: headers};
112
- options = Object.assign({}, defaults, options);
118
+ const defaults = { headers: headers };
119
+ options = Object.assign({}, defaults, options, { headers: headers });
120
+
113
121
 
114
122
  Logger.info(options);
115
123
 
@@ -122,6 +122,7 @@ export default class Event {
122
122
  quoteFirstSendingTime?: Date;
123
123
  lastQuoteCreationDate?: Date;
124
124
  urgent?: boolean;
125
+ schedulable?:boolean;
125
126
  constructor(
126
127
  id: string,
127
128
  ownerId: number,
@@ -158,6 +159,7 @@ export default class Event {
158
159
  urgent?: boolean,
159
160
  garageVehicleBookings?: LoanVehicle[],
160
161
  goodForAgreement?:boolean,
162
+ schedulable?:boolean
161
163
  ) {
162
164
  this.id = id;
163
165
  this.notes = notes;
@@ -207,6 +209,7 @@ export default class Event {
207
209
  this.urgent = urgent;
208
210
  this.garageVehicleBookings = garageVehicleBookings;
209
211
  this.goodForAgreement = goodForAgreement;
212
+ this.schedulable = schedulable;
210
213
  }
211
214
 
212
215
  static getPrestationsList(event: Event): string[] {