@movalib/movalib-commons 1.59.0 → 1.59.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.
@@ -1,4 +1,5 @@
1
1
  import '../../style/QRCode.css';
2
+ export declare const getPdfDocument: (url: string) => import("pdfjs-dist/types/src/display/api").PDFDocumentLoadingTask;
2
3
  export declare const QrCodePLVContainer: ({ data }: {
3
4
  data: string;
4
5
  }) => import("react/jsx-runtime").JSX.Element;
@@ -73,7 +73,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
- exports.QrCodePLVContainer = void 0;
76
+ exports.QrCodePLVContainer = exports.getPdfDocument = void 0;
77
77
  var jsx_runtime_1 = require("react/jsx-runtime");
78
78
  var icons_material_1 = require("@mui/icons-material");
79
79
  var material_1 = require("@mui/material");
@@ -88,7 +88,11 @@ var Tools_1 = require("../../helpers/Tools");
88
88
  var pdf_lib_1 = require("pdf-lib");
89
89
  var PLVComponent_1 = require("./PLVComponent");
90
90
  var pdfjsLib = __importStar(require("pdfjs-dist"));
91
- pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.mjs';
91
+ pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';
92
+ var getPdfDocument = function (url) {
93
+ return pdfjsLib.getDocument(url);
94
+ };
95
+ exports.getPdfDocument = getPdfDocument;
92
96
  var QrCodePLVContainer = function (_a) {
93
97
  var data = _a.data;
94
98
  var _b = (0, react_1.useState)(null), selectedChoice = _b[0], setSelectedChoice = _b[1];
@@ -144,24 +148,14 @@ var QrCodePLVContainer = function (_a) {
144
148
  var urlA4 = printPLV('A4').then(function (url) {
145
149
  setUrlA4(url);
146
150
  });
147
- var urlA3 = printPLV('A3').then(function (url) {
148
- setUrlA3(url);
149
- });
150
151
  }, [data]);
151
- (0, react_1.useEffect)(function () {
152
- if (PLVrefA4.current || PLVrefA3.current) {
153
- setIsReady(true);
154
- }
155
- else {
156
- setIsReady(false);
157
- }
158
- }, [PLVrefA4.current, PLVrefA3.current]);
159
152
  function printPLV(format) {
160
153
  return __awaiter(this, void 0, void 0, function () {
161
154
  var pdfUrl, response, existingPdfBytes, pdfDoc, qrCodeBlob, qrImageBytes, qrImage, pages, firstPage, _a, width, height, optionQrcode, modifiedPdfBytes, blob, url, loadingTask, pdf, page, canvas, context, viewport, renderContext, imageUrl;
162
155
  return __generator(this, function (_b) {
163
156
  switch (_b.label) {
164
157
  case 0:
158
+ setIsReady(false);
165
159
  pdfUrl = "/Movalib_".concat(format, ".pdf");
166
160
  return [4 /*yield*/, fetch(pdfUrl)];
167
161
  case 1:
@@ -208,7 +202,7 @@ var QrCodePLVContainer = function (_a) {
208
202
  modifiedPdfBytes = _b.sent();
209
203
  blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
210
204
  url = URL.createObjectURL(blob);
211
- loadingTask = pdfjsLib.getDocument(url);
205
+ loadingTask = (0, exports.getPdfDocument)(url);
212
206
  return [4 /*yield*/, loadingTask.promise];
213
207
  case 8:
214
208
  pdf = _b.sent();
@@ -228,6 +222,7 @@ var QrCodePLVContainer = function (_a) {
228
222
  case 10:
229
223
  _b.sent();
230
224
  imageUrl = canvas.toDataURL('image/png');
225
+ setIsReady(true);
231
226
  return [2 /*return*/, imageUrl];
232
227
  }
233
228
  });
@@ -268,6 +263,11 @@ var QrCodePLVContainer = function (_a) {
268
263
  qrCode.append(qrCodeRef.current);
269
264
  }, [qrCode.append]);
270
265
  var onChangeSelectedChoice = function (e) {
266
+ if (e.target.value === 'A3' && !urlA3) {
267
+ printPLV('A3').then(function (url) {
268
+ setUrlA3(url);
269
+ });
270
+ }
271
271
  setSelectedChoice(e.target.value);
272
272
  };
273
273
  var printA3PLV = (0, react_to_print_1.useReactToPrint)({
@@ -59,6 +59,7 @@ export default class Event {
59
59
  otherReason?: string;
60
60
  repairOrderNumber?: number;
61
61
  orderComment?: string;
62
+ vehicleReceived?: boolean;
62
63
  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);
63
64
  static getPrestationsList(event: Event): string[];
64
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.59.0",
3
+ "version": "1.59.2",
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",
@@ -24,8 +24,10 @@ import { flexCenter } from '../../helpers/Tools';
24
24
  import { PDFDocument } from 'pdf-lib';
25
25
  import { PLVComponentV2, PrintSize } from './PLVComponent';
26
26
  import * as pdfjsLib from 'pdfjs-dist';
27
- pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.mjs';
28
-
27
+ pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';
28
+ export const getPdfDocument = (url: string) => {
29
+ return pdfjsLib.getDocument(url);
30
+ };
29
31
  type SelectChoice = null | 'A3' | 'A4' | 'QR_Headless' | 'QR_Google';
30
32
  export const QrCodePLVContainer = ({ data }: { data: string }) => {
31
33
  const [selectedChoice, setSelectedChoice] = useState<SelectChoice>(null);
@@ -88,20 +90,13 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
88
90
  const urlA4 = printPLV('A4').then((url) => {
89
91
  setUrlA4(url);
90
92
  });
91
- const urlA3 = printPLV('A3').then((url) => {
92
- setUrlA3(url);
93
- });
94
93
  }, [data]);
95
94
 
96
- useEffect(() => {
97
- if (PLVrefA4.current || PLVrefA3.current) {
98
- setIsReady(true);
99
- } else {
100
- setIsReady(false);
101
- }
102
- }, [PLVrefA4.current, PLVrefA3.current]);
95
+
103
96
 
104
97
  async function printPLV(format: string) {
98
+ setIsReady(false);
99
+
105
100
  // Chemin du fichier PDF
106
101
  const pdfUrl = `/Movalib_${format}.pdf`;
107
102
  // Récupérer le fichier PDF depuis le serveur
@@ -156,7 +151,7 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
156
151
 
157
152
 
158
153
  // Convertir le PDF en image
159
- const loadingTask = pdfjsLib.getDocument(url);
154
+ const loadingTask = getPdfDocument(url);
160
155
  const pdf = await loadingTask.promise;
161
156
 
162
157
  // Récupérer la première page
@@ -179,6 +174,7 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
179
174
 
180
175
  // Convertir le canvas en URL d'image (data URL)
181
176
  const imageUrl = canvas.toDataURL('image/png');
177
+ setIsReady(true);
182
178
  return imageUrl;
183
179
  }
184
180
 
@@ -226,6 +222,11 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
226
222
  }, [qrCode.append]);
227
223
 
228
224
  const onChangeSelectedChoice: SelectProps<SelectChoice>['onChange'] = (e) => {
225
+ if(e.target.value === 'A3' && !urlA3){
226
+ printPLV('A3').then((url) => {
227
+ setUrlA3(url);
228
+ });
229
+ }
229
230
  setSelectedChoice(e.target.value as SelectChoice);
230
231
  };
231
232
 
@@ -256,7 +257,7 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
256
257
  return (
257
258
  <Box display='flex' flexDirection='column' alignItems='center' gap='24px'>
258
259
  {urlA4 && <PLVComponentV2 ref={PLVrefA4} url={urlA4} printSize={PrintSize.A4} />}
259
- {urlA3 &&<PLVComponentV2 ref={PLVrefA3} url={urlA3} printSize={PrintSize.A3} />}
260
+ {urlA3 && <PLVComponentV2 ref={PLVrefA3} url={urlA3} printSize={PrintSize.A3} />}
260
261
 
261
262
  <Grid container justifyContent='center' alignItems='center'>
262
263
  <Grid item xs={7}>
@@ -66,6 +66,7 @@ export default class Event {
66
66
 
67
67
  repairOrderNumber?: number;
68
68
  orderComment?: string;
69
+ vehicleReceived?: boolean;
69
70
 
70
71
  constructor(id: string, ownerId: number, type : EventType, title: string, garageName: string, garageId: number,color: string,
71
72
  state: EventState, garageAddress?: Address, start?: Date, end?: Date, prestations?: Prestation[], operations?: Operation[], products?: Product[],