@movalib/movalib-commons 1.60.1 → 1.62.1

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,7 +1,7 @@
1
- import { AlertColor } from "@mui/material";
2
1
  import { FunctionComponent, ReactNode } from "react";
3
- import { MovaAppType } from "./helpers/Enums";
2
+ import { AlertColor } from "@mui/material";
4
3
  import { MovaLoginForm } from "./helpers/Types";
4
+ import { MovaAppType } from "./helpers/Enums";
5
5
  /**
6
6
  * Propriétés du composant
7
7
  * movaAppType : type d'application Movalib au sein de laquelle le composant est injectée
@@ -51,26 +51,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  var jsx_runtime_1 = require("react/jsx-runtime");
54
- var Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
55
- var VisibilityOff_1 = __importDefault(require("@mui/icons-material/VisibilityOff"));
56
- var lab_1 = require("@mui/lab");
57
- var material_1 = require("@mui/material");
58
- var InputAdornment_1 = __importDefault(require("@mui/material/InputAdornment"));
59
- var libphonenumber_js_1 = require("libphonenumber-js");
60
54
  var react_1 = require("react");
61
- var react_router_dom_1 = require("react-router-dom");
62
- var DialogForgotPassword_1 = __importDefault(require("./DialogForgotPassword"));
63
- var MovaCopyright_1 = __importDefault(require("./MovaCopyright"));
64
- var leaf_green_large_png_1 = __importDefault(require("./assets/images/leaf_green_large.png"));
65
- var leaf_pink_large_png_1 = __importDefault(require("./assets/images/leaf_pink_large.png"));
66
- var logo_admin_large_png_1 = __importDefault(require("./assets/images/logo/logo_admin_large.png"));
55
+ var lab_1 = require("@mui/lab");
67
56
  var logo_large_border_png_1 = __importDefault(require("./assets/images/logo/logo_large_border.png"));
68
- var logo_large_dm_png_1 = __importDefault(require("./assets/images/logo/logo_large_dm.png"));
69
57
  var logo_pro_large_border_png_1 = __importDefault(require("./assets/images/logo/logo_pro_large_border.png"));
58
+ var logo_admin_large_png_1 = __importDefault(require("./assets/images/logo/logo_admin_large.png"));
59
+ var logo_large_dm_png_1 = __importDefault(require("./assets/images/logo/logo_large_dm.png"));
70
60
  var logo_pro_large_dm_png_1 = __importDefault(require("./assets/images/logo/logo_pro_large_dm.png"));
61
+ var leaf_green_large_png_1 = __importDefault(require("./assets/images/leaf_green_large.png"));
62
+ var leaf_pink_large_png_1 = __importDefault(require("./assets/images/leaf_pink_large.png"));
63
+ var material_1 = require("@mui/material");
64
+ var MovaCopyright_1 = __importDefault(require("./MovaCopyright"));
71
65
  var Enums_1 = require("./helpers/Enums");
72
- var Tools_1 = require("./helpers/Tools");
73
66
  var Validator_1 = require("./helpers/Validator");
67
+ var Tools_1 = require("./helpers/Tools");
68
+ var react_router_dom_1 = require("react-router-dom");
69
+ var InputAdornment_1 = __importDefault(require("@mui/material/InputAdornment"));
70
+ var Visibility_1 = __importDefault(require("@mui/icons-material/Visibility"));
71
+ var VisibilityOff_1 = __importDefault(require("@mui/icons-material/VisibilityOff"));
72
+ var DialogForgotPassword_1 = __importDefault(require("./DialogForgotPassword"));
73
+ var libphonenumber_js_1 = require("libphonenumber-js");
74
74
  // Permet de centrer le contenu de l'application
75
75
  var styles = {
76
76
  display: 'flex',
@@ -233,16 +233,14 @@ var MovaLogin = function (_a) {
233
233
  </Dialog>
234
234
  );
235
235
  } */
236
- return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: styles }, { children: [(0, jsx_runtime_1.jsx)("img", { src: leaf_green_large_png_1.default, style: {
237
- position: 'fixed',
236
+ return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: styles }, { children: [(0, jsx_runtime_1.jsx)("img", { src: leaf_green_large_png_1.default, style: { position: 'fixed',
238
237
  float: 'left',
239
238
  width: '250px',
240
239
  height: '400px',
241
240
  top: '-20%',
242
241
  left: '0%',
243
242
  opacity: '0.3',
244
- zIndex: -8
245
- }, alt: 'Feuille Verte Movalib' }), (0, jsx_runtime_1.jsxs)(material_1.Container, __assign({ component: "main", maxWidth: "xs" }, { children: [(0, jsx_runtime_1.jsx)(material_1.CssBaseline, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
243
+ zIndex: -8 }, alt: 'Feuille Verte Movalib' }), (0, jsx_runtime_1.jsxs)(material_1.Container, __assign({ component: "main", maxWidth: "xs" }, { children: [(0, jsx_runtime_1.jsx)(material_1.CssBaseline, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: {
246
244
  marginTop: 6,
247
245
  display: 'flex',
248
246
  flexDirection: 'column',
@@ -265,15 +263,13 @@ var MovaLogin = function (_a) {
265
263
  borderColor: darkMode ? 'white' : 'default', // Couleur de la bordure
266
264
  }
267
265
  } }), (0, jsx_runtime_1.jsx)(material_1.FormControlLabel, { control: (0, jsx_runtime_1.jsx)(material_1.Checkbox, { value: "remember", color: "primary" }), label: "Se souvenir de moi" }), (0, jsx_runtime_1.jsx)(lab_1.LoadingButton, __assign({ loading: loading, type: "submit", fullWidth: true, variant: "contained", sx: { mt: 3, mb: 2, backgroundColor: darkMode ? theme.palette.primary.dark : theme.palette.primary.main } }, { children: (0, jsx_runtime_1.jsx)("span", { children: "Se connecter" }) })), movaAppType === Enums_1.MovaAppType.INDIVIDUAL && (0, jsx_runtime_1.jsx)(material_1.Button, __assign({ fullWidth: true, variant: "outlined", onClick: function (e) { return handleOnClickSignUp(); }, sx: { mb: 2, color: theme.palette.primary.dark } }, { children: (0, jsx_runtime_1.jsx)("span", { children: "CR\u00C9ER MON COMPTE" }) })), alertMessage && alertSeverity && (0, jsx_runtime_1.jsx)(material_1.Alert, __assign({ severity: alertSeverity, sx: { mb: 2 } }, { children: alertMessage })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ container: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: true }, { children: (0, jsx_runtime_1.jsx)(material_1.Link, __assign({ variant: "body2", color: "text.secondary", onClick: function (e) { return handleOnClickForgotPassword(); }, sx: { cursor: 'pointer' } }, { children: "Mot de passe oubli\u00E9 ?" })) })) }))] })), (0, jsx_runtime_1.jsx)(MovaCopyright_1.default, { sx: { mt: 8, mb: 1 } }), version && (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ variant: 'body2', color: theme.palette.grey[200], sx: { textAlign: 'center' } }, { children: version })), openForgotPassword &&
268
- (0, jsx_runtime_1.jsx)(DialogForgotPassword_1.default, { openForgotPassword: openForgotPassword, setOpenForgotPassword: setOpenForgotPassword, movaAppType: movaAppType, form: form, handleInputChange: handleInputChange, handleSubmitForgotPassword: handleSubmitForgotPassword })] })), (0, jsx_runtime_1.jsx)("img", { src: leaf_pink_large_png_1.default, style: {
269
- position: 'fixed',
266
+ (0, jsx_runtime_1.jsx)(DialogForgotPassword_1.default, { openForgotPassword: openForgotPassword, setOpenForgotPassword: setOpenForgotPassword, movaAppType: movaAppType, form: form, handleInputChange: handleInputChange, handleSubmitForgotPassword: handleSubmitForgotPassword })] })), (0, jsx_runtime_1.jsx)("img", { src: leaf_pink_large_png_1.default, style: { position: 'fixed',
270
267
  float: 'right',
271
268
  width: '250px',
272
269
  height: '400px',
273
270
  bottom: '-20%',
274
271
  right: '0%',
275
272
  opacity: '0.3',
276
- zIndex: '-10'
277
- }, alt: 'Feuille Rose Movalib' })] })));
273
+ zIndex: '-10' }, alt: 'Feuille Rose Movalib' })] })));
278
274
  };
279
275
  exports.default = MovaLogin;
@@ -1,4 +1,4 @@
1
- import '../../style/QRCode.css';
1
+ import "../../style/QRCode.css";
2
2
  export declare const getPdfDocument: (url: string) => import("pdfjs-dist/types/src/display/api").PDFDocumentLoadingTask;
3
3
  export declare const QrCodePLVContainer: ({ data }: {
4
4
  data: string;
@@ -79,16 +79,16 @@ var icons_material_1 = require("@mui/icons-material");
79
79
  var material_1 = require("@mui/material");
80
80
  require("../../style/QRCode.css");
81
81
  var html2canvas_1 = __importDefault(require("html2canvas"));
82
+ var pdf_lib_1 = require("pdf-lib");
83
+ var pdfjsLib = __importStar(require("pdfjs-dist"));
82
84
  var qr_code_styling_1 = __importDefault(require("qr-code-styling"));
83
85
  var react_1 = require("react");
84
86
  var react_to_print_1 = require("react-to-print");
85
87
  var DownloadedQRCode_1 = require("../../DownloadedQRCode");
86
88
  var leaf_yellow_small_png_1 = __importDefault(require("../../assets/images/leaf_yellow_small.png"));
87
89
  var Tools_1 = require("../../helpers/Tools");
88
- var pdf_lib_1 = require("pdf-lib");
89
90
  var PLVComponent_1 = require("./PLVComponent");
90
- var pdfjsLib = __importStar(require("pdfjs-dist"));
91
- pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';
91
+ pdfjsLib.GlobalWorkerOptions.workerSrc = "/pdf.worker.min.mjs";
92
92
  var getPdfDocument = function (url) {
93
93
  return pdfjsLib.getDocument(url);
94
94
  };
@@ -96,26 +96,26 @@ exports.getPdfDocument = getPdfDocument;
96
96
  var QrCodePLVContainer = function (_a) {
97
97
  var data = _a.data;
98
98
  var _b = (0, react_1.useState)(null), selectedChoice = _b[0], setSelectedChoice = _b[1];
99
- var _c = (0, react_1.useState)(''), urlA4 = _c[0], setUrlA4 = _c[1];
100
- var _d = (0, react_1.useState)(''), urlA3 = _d[0], setUrlA3 = _d[1];
99
+ var _c = (0, react_1.useState)(""), urlA4 = _c[0], setUrlA4 = _c[1];
100
+ var _d = (0, react_1.useState)(""), urlA3 = _d[0], setUrlA3 = _d[1];
101
101
  var _e = (0, react_1.useState)(false), isReady = _e[0], setIsReady = _e[1];
102
102
  var qrCodeRef = (0, react_1.useRef)(null);
103
103
  var theme = (0, material_1.useTheme)();
104
104
  var PLVrefA4 = (0, react_1.useRef)(null);
105
105
  var PLVrefA3 = (0, react_1.useRef)(null);
106
- //si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
106
+ //si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
107
107
  //il faut modifier la width et height, imageSize du qrCodeOptions et mettre les mêmes valeurs que dans le optionQrcode de la fonction printPLV
108
108
  var qrCodeOptions = (0, react_1.useMemo)(function () { return ({
109
109
  width: 300,
110
110
  height: 300,
111
- type: 'canvas',
111
+ type: "canvas",
112
112
  data: data,
113
113
  image: leaf_yellow_small_png_1.default,
114
114
  margin: 10,
115
115
  qrOptions: {
116
116
  typeNumber: 0,
117
- mode: 'Byte',
118
- errorCorrectionLevel: 'Q',
117
+ mode: "Byte",
118
+ errorCorrectionLevel: "Q",
119
119
  },
120
120
  imageOptions: {
121
121
  hideBackgroundDots: true,
@@ -124,18 +124,18 @@ var QrCodePLVContainer = function (_a) {
124
124
  },
125
125
  dotsOptions: {
126
126
  color: (0, material_1.darken)(theme.palette.primary.main, 0.4),
127
- type: 'square',
127
+ type: "square",
128
128
  },
129
129
  backgroundOptions: {
130
- color: 'white',
130
+ color: "white",
131
131
  },
132
132
  cornersSquareOptions: {
133
133
  color: (0, material_1.darken)(theme.palette.secondary.main, 0.2),
134
- type: 'square',
134
+ type: "square",
135
135
  },
136
136
  cornersDotOptions: {
137
137
  color: (0, material_1.darken)(theme.palette.secondary.main, 0.2),
138
- type: 'square',
138
+ type: "square",
139
139
  },
140
140
  }); }, [data, theme.palette]);
141
141
  var qrCode = (0, react_1.useMemo)(function () { return new qr_code_styling_1.default(qrCodeOptions); }, [qrCodeOptions]);
@@ -145,7 +145,7 @@ var QrCodePLVContainer = function (_a) {
145
145
  }
146
146
  }, [qrCode]);
147
147
  (0, react_1.useEffect)(function () {
148
- var urlA4 = printPLV('A4').then(function (url) {
148
+ var urlA4 = printPLV("A4").then(function (url) {
149
149
  setUrlA4(url);
150
150
  });
151
151
  }, [data]);
@@ -179,12 +179,12 @@ var QrCodePLVContainer = function (_a) {
179
179
  firstPage = pages[0];
180
180
  _a = firstPage.getSize(), width = _a.width, height = _a.height;
181
181
  optionQrcode = {};
182
- if (format === 'A3') {
182
+ if (format === "A3") {
183
183
  optionQrcode = {
184
184
  x: width - 427,
185
185
  y: 88,
186
186
  width: 349,
187
- height: 349
187
+ height: 349,
188
188
  };
189
189
  }
190
190
  else {
@@ -200,7 +200,7 @@ var QrCodePLVContainer = function (_a) {
200
200
  return [4 /*yield*/, pdfDoc.save()];
201
201
  case 7:
202
202
  modifiedPdfBytes = _b.sent();
203
- blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
203
+ blob = new Blob([modifiedPdfBytes], { type: "application/pdf" });
204
204
  url = URL.createObjectURL(blob);
205
205
  loadingTask = (0, exports.getPdfDocument)(url);
206
206
  return [4 /*yield*/, loadingTask.promise];
@@ -209,8 +209,8 @@ var QrCodePLVContainer = function (_a) {
209
209
  return [4 /*yield*/, pdf.getPage(1)];
210
210
  case 9:
211
211
  page = _b.sent();
212
- canvas = document.createElement('canvas');
213
- context = canvas.getContext('2d');
212
+ canvas = document.createElement("canvas");
213
+ context = canvas.getContext("2d");
214
214
  viewport = page.getViewport({ scale: 3 });
215
215
  canvas.width = viewport.width;
216
216
  canvas.height = viewport.height;
@@ -221,7 +221,7 @@ var QrCodePLVContainer = function (_a) {
221
221
  return [4 /*yield*/, page.render(renderContext).promise];
222
222
  case 10:
223
223
  _b.sent();
224
- imageUrl = canvas.toDataURL('image/png');
224
+ imageUrl = canvas.toDataURL("image/png");
225
225
  setIsReady(true);
226
226
  return [2 /*return*/, imageUrl];
227
227
  }
@@ -230,31 +230,31 @@ var QrCodePLVContainer = function (_a) {
230
230
  }
231
231
  var downloadQRCodeHeadless = (0, react_1.useCallback)(function () {
232
232
  qrCode.download({
233
- extension: 'png',
234
- name: 'movalib-qr-code',
233
+ extension: "png",
234
+ name: "movalib-qr-code",
235
235
  });
236
236
  }, [qrCode.download]);
237
237
  var downloadQrCodeWithCTA = (0, react_1.useCallback)(function () {
238
238
  // Check if we have everything we need
239
- var qrCodeContainer = document.querySelector('#qr-code-container');
240
- var qrCodeDiv = qrCodeContainer === null || qrCodeContainer === void 0 ? void 0 : qrCodeContainer.querySelector('.qr-code');
241
- var qrCodeCanva = qrCodeDiv === null || qrCodeDiv === void 0 ? void 0 : qrCodeDiv.querySelector('canvas');
242
- var downloadedDiv = document.getElementById('qr-code-downloaded-container');
239
+ var qrCodeContainer = document.querySelector("#qr-code-container");
240
+ var qrCodeDiv = qrCodeContainer === null || qrCodeContainer === void 0 ? void 0 : qrCodeContainer.querySelector(".qr-code");
241
+ var qrCodeCanva = qrCodeDiv === null || qrCodeDiv === void 0 ? void 0 : qrCodeDiv.querySelector("canvas");
242
+ var downloadedDiv = document.getElementById("qr-code-downloaded-container");
243
243
  // If we don't have the QR Code, we can't download it
244
244
  if (!(qrCodeContainer && qrCodeDiv && qrCodeCanva && downloadedDiv)) {
245
245
  return;
246
246
  }
247
247
  var tmpRendered = downloadedDiv.cloneNode(true);
248
- tmpRendered.style.display = 'flex';
249
- var downloadedQrCodeImgContainer = tmpRendered.querySelector('#qr-code-img-container');
248
+ tmpRendered.style.display = "flex";
249
+ var downloadedQrCodeImgContainer = tmpRendered.querySelector("#qr-code-img-container");
250
250
  downloadedQrCodeImgContainer.append(qrCodeCanva);
251
251
  // add it to the document to be able to download it
252
252
  document.body.append(tmpRendered);
253
253
  // create the canva of the tmpRendered div and download it
254
254
  (0, html2canvas_1.default)(tmpRendered).then(function (canvas) {
255
- var a = document.createElement('a');
256
- a.download = 'movalib-qr-code.png';
257
- a.href = canvas.toDataURL('image/png');
255
+ var a = document.createElement("a");
256
+ a.download = "movalib-qr-code.png";
257
+ a.href = canvas.toDataURL("image/png");
258
258
  a.click();
259
259
  });
260
260
  // remove the tmpRendered div
@@ -263,8 +263,8 @@ var QrCodePLVContainer = function (_a) {
263
263
  qrCode.append(qrCodeRef.current);
264
264
  }, [qrCode.append]);
265
265
  var onChangeSelectedChoice = function (e) {
266
- if (e.target.value === 'A3' && !urlA3) {
267
- printPLV('A3').then(function (url) {
266
+ if (e.target.value === "A3" && !urlA3) {
267
+ printPLV("A3").then(function (url) {
268
268
  setUrlA3(url);
269
269
  });
270
270
  }
@@ -272,30 +272,43 @@ var QrCodePLVContainer = function (_a) {
272
272
  };
273
273
  var printA3PLV = (0, react_to_print_1.useReactToPrint)({
274
274
  content: function () { return PLVrefA3.current; },
275
- documentTitle: 'Movalib_PLV_A3',
275
+ documentTitle: "Movalib_PLV_A3",
276
276
  });
277
277
  var printA4PLV = (0, react_to_print_1.useReactToPrint)({
278
278
  content: function () { return PLVrefA4.current; },
279
- documentTitle: 'Movalib_PLV_A4',
279
+ documentTitle: "Movalib_PLV_A4",
280
280
  });
281
281
  var onClickDownload = (0, react_1.useMemo)(function () {
282
282
  switch (selectedChoice) {
283
- case 'A3':
283
+ case "A3":
284
284
  return printA3PLV;
285
- case 'A4':
285
+ case "A4":
286
286
  return printA4PLV;
287
- case 'QR_Headless':
287
+ case "QR_Headless":
288
288
  return downloadQRCodeHeadless;
289
- case 'QR_Google':
289
+ case "QR_Google":
290
290
  return downloadQrCodeWithCTA;
291
291
  default:
292
292
  return function () { };
293
293
  }
294
- }, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA, printA3PLV, printA4PLV]);
295
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px' }, { children: [urlA4 && (0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA4, url: urlA4, printSize: PLVComponent_1.PrintSize.A4 }), urlA3 && (0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA3, url: urlA3, printSize: PLVComponent_1.PrintSize.A3 }), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, justifyContent: 'center', alignItems: 'center' }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 7 }, { children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true, size: 'small' }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: 'qrcode-plv-select' }, { children: "Choisissez votre support" })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ labelId: 'qrcode-plv-select', label: 'Choisissez votre support', id: 'qrcode-plv-select', onChange: onChangeSelectedChoice, value: selectedChoice }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A4' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A4" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'A3' }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A3" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Google' }, { children: "QR Code format GoogleMyBusiness" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: 'QR_Headless' }, { children: "QR Code seul" }))] }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4, marginLeft: 3 }, { children: (selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady ? ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, {})) : ((0, jsx_runtime_1.jsx)(material_1.Button, __assign({ startIcon: selectedChoice === 'A3' || selectedChoice === 'A4' ? (0, jsx_runtime_1.jsx)(icons_material_1.DocumentScanner, {}) : (0, jsx_runtime_1.jsx)(icons_material_1.QrCode2, {}), onClick: onClickDownload, variant: 'outlined', disabled: !selectedChoice || ((selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady), sx: { color: (0, material_1.darken)(theme.palette.primary.main, 0.2), borderRadius: '10rem' } }, { children: selectedChoice === 'A3' || selectedChoice === 'A4' ? 'Imprimer' : 'Télécharger' }))) }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ id: 'qr-code-container', style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)("div", { ref: qrCodeRef, style: {
296
- height: '300px',
297
- width: '300px',
298
- maxWidth: '300px !important',
299
- }, className: 'qr-code' }) })), (0, jsx_runtime_1.jsx)(DownloadedQRCode_1.DownloadedQRCode, {})] })));
294
+ }, [
295
+ selectedChoice,
296
+ downloadQRCodeHeadless,
297
+ downloadQrCodeWithCTA,
298
+ printA3PLV,
299
+ printA4PLV,
300
+ ]);
301
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: "flex", flexDirection: "column", alignItems: "center", gap: "24px" }, { children: [urlA4 && ((0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA4, url: urlA4, printSize: PLVComponent_1.PrintSize.A4 })), urlA3 && ((0, jsx_runtime_1.jsx)(PLVComponent_1.PLVComponentV2, { ref: PLVrefA3, url: urlA3, printSize: PLVComponent_1.PrintSize.A3 })), (0, jsx_runtime_1.jsxs)(material_1.Grid, __assign({ container: true, justifyContent: "center", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 7 }, { children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, __assign({ fullWidth: true, size: "small" }, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, __assign({ id: "qrcode-plv-select" }, { children: "Choisissez votre support" })), (0, jsx_runtime_1.jsxs)(material_1.Select, __assign({ labelId: "qrcode-plv-select", label: "Choisissez votre support", id: "qrcode-plv-select", onChange: onChangeSelectedChoice, value: selectedChoice }, { children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "A4" }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A4" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "A3" }, { children: "\uD83E\uDDFE\u00A0\u00A0PLV format A3" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "QR_Google" }, { children: "QR Code format GoogleMyBusiness" })), (0, jsx_runtime_1.jsx)(material_1.MenuItem, __assign({ value: "QR_Headless" }, { children: "QR Code seul" }))] }))] })) })), (0, jsx_runtime_1.jsx)(material_1.Grid, __assign({ item: true, xs: 4, marginLeft: 3 }, { children: (selectedChoice === "A3" || selectedChoice === "A4") && !isReady ? ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, {})) : ((0, jsx_runtime_1.jsx)(material_1.Button, __assign({ startIcon: selectedChoice === "A3" || selectedChoice === "A4" ? ((0, jsx_runtime_1.jsx)(icons_material_1.DocumentScanner, {})) : ((0, jsx_runtime_1.jsx)(icons_material_1.QrCode2, {})), onClick: onClickDownload, variant: "outlined", disabled: !selectedChoice ||
302
+ ((selectedChoice === "A3" || selectedChoice === "A4") &&
303
+ !isReady), sx: {
304
+ color: (0, material_1.darken)(theme.palette.primary.main, 0.2),
305
+ borderRadius: "10rem",
306
+ } }, { children: selectedChoice === "A3" || selectedChoice === "A4"
307
+ ? "Imprimer"
308
+ : "Télécharger" }))) }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ id: "qr-code-container", style: Tools_1.flexCenter }, { children: (0, jsx_runtime_1.jsx)("div", { ref: qrCodeRef, style: {
309
+ height: "300px",
310
+ width: "300px",
311
+ maxWidth: "300px !important",
312
+ }, className: "qr-code" }) })), (0, jsx_runtime_1.jsx)(DownloadedQRCode_1.DownloadedQRCode, {})] })));
300
313
  };
301
314
  exports.QrCodePLVContainer = QrCodePLVContainer;
@@ -193,7 +193,8 @@ export declare enum EventType {
193
193
  UNAVAILABILITY = "UNAVAILABILITY",
194
194
  NOTE = "NOTE",
195
195
  PENDING_APPOINTMENT = "PENDING_APPOINTMENT",
196
- WAITING_VEHICLE = "WAITING_VEHICLE"
196
+ WAITING_VEHICLE = "WAITING_VEHICLE",
197
+ QUOTE = "QUOTE"
197
198
  }
198
199
  export declare enum DayOfWeek {
199
200
  MONDAY = "MONDAY",
@@ -209,6 +210,12 @@ export declare enum DocumentState {
209
210
  APPROVED = "APPROVED",
210
211
  REJECTED = "REJECTED"
211
212
  }
213
+ export declare enum QuoteState {
214
+ QUOTE_DRAFT = "QUOTE_DRAFT",
215
+ QUOTE_SENT = "QUOTE_SENT",
216
+ QUOTE_ACCEPTED = "QUOTE_ACCEPTED",
217
+ QUOTE_REJECTED = "QUOTE_REJECTED"
218
+ }
212
219
  export declare enum DocumentType {
213
220
  USER_BANK_DETAILS = "USER_BANK_DETAILS",
214
221
  USER_APPOINTMENT_QUOTE = "USER_APPOINTMENT_QUOTE",
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoleType = exports.MovaAppType = exports.DocumentType = exports.DocumentState = exports.DayOfWeek = exports.EventType = exports.EventState = exports.DigitalPassportIndex = exports.Gender = exports.DateFormatTypes = exports.APIMethod = exports.PartsApplicationType = exports.ProductType = exports.OrderPreference = exports.OrderState = exports.SlotAlgorithm = exports.VehiclePlateFormat = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.PrestationType = exports.PrestationState = exports.CountryCode = exports.SubscriptionState = exports.SubscriptionType = exports.CustomerType = void 0;
3
+ exports.RoleType = exports.MovaAppType = exports.DocumentType = exports.QuoteState = exports.DocumentState = exports.DayOfWeek = exports.EventType = exports.EventState = exports.DigitalPassportIndex = exports.Gender = exports.DateFormatTypes = exports.APIMethod = exports.PartsApplicationType = exports.ProductType = exports.OrderPreference = exports.OrderState = exports.SlotAlgorithm = exports.VehiclePlateFormat = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.PrestationType = exports.PrestationState = exports.CountryCode = exports.SubscriptionState = exports.SubscriptionType = exports.CustomerType = void 0;
4
4
  var CustomerType;
5
5
  (function (CustomerType) {
6
6
  CustomerType["INDIVIDUAL"] = "INDIVIDUAL";
@@ -217,6 +217,7 @@ var EventType;
217
217
  EventType["NOTE"] = "NOTE";
218
218
  EventType["PENDING_APPOINTMENT"] = "PENDING_APPOINTMENT";
219
219
  EventType["WAITING_VEHICLE"] = "WAITING_VEHICLE";
220
+ EventType["QUOTE"] = "QUOTE";
220
221
  })(EventType = exports.EventType || (exports.EventType = {}));
221
222
  var DayOfWeek;
222
223
  (function (DayOfWeek) {
@@ -234,6 +235,13 @@ var DocumentState;
234
235
  DocumentState["APPROVED"] = "APPROVED";
235
236
  DocumentState["REJECTED"] = "REJECTED";
236
237
  })(DocumentState = exports.DocumentState || (exports.DocumentState = {}));
238
+ var QuoteState;
239
+ (function (QuoteState) {
240
+ QuoteState["QUOTE_DRAFT"] = "QUOTE_DRAFT";
241
+ QuoteState["QUOTE_SENT"] = "QUOTE_SENT";
242
+ QuoteState["QUOTE_ACCEPTED"] = "QUOTE_ACCEPTED";
243
+ QuoteState["QUOTE_REJECTED"] = "QUOTE_REJECTED";
244
+ })(QuoteState = exports.QuoteState || (exports.QuoteState = {}));
237
245
  var DocumentType;
238
246
  (function (DocumentType) {
239
247
  DocumentType["USER_BANK_DETAILS"] = "USER_BANK_DETAILS";
@@ -13,6 +13,10 @@ export default class Document {
13
13
  reference?: string;
14
14
  rejectReason?: string;
15
15
  validateToken?: string;
16
- constructor(id: string, ownerId: number, state: DocumentState, fileName: string, originalFileName: string, fileType: string, fileSignedUrl: string, type: DocumentType, creationDate?: Date, updateDate?: Date, reference?: string, validateToken?: string);
16
+ remindersCount?: number;
17
+ totalAmountInclVat?: number;
18
+ lastSendingTime?: Date;
19
+ firstSendingTime?: Date;
20
+ constructor(id: string, ownerId: number, state: DocumentState, fileName: string, originalFileName: string, fileType: string, fileSignedUrl: string, type: DocumentType, creationDate?: Date, updateDate?: Date, reference?: string, validateToken?: string, remindersCount?: number, totalAmountInclVat?: number, lastSendingTime?: Date, firstSendingTime?: Date);
17
21
  static findByTypeAndReference(documents: Document[], type: DocumentType, reference: string): Document | undefined;
18
22
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var Document = /** @class */ (function () {
4
- function Document(id, ownerId, state, fileName, originalFileName, fileType, fileSignedUrl, type, creationDate, updateDate, reference, validateToken) {
4
+ function Document(id, ownerId, state, fileName, originalFileName, fileType, fileSignedUrl, type, creationDate, updateDate, reference, validateToken, remindersCount, totalAmountInclVat, lastSendingTime, firstSendingTime) {
5
5
  this.id = id;
6
6
  this.state = state;
7
7
  this.ownerId = ownerId;
@@ -14,6 +14,14 @@ var Document = /** @class */ (function () {
14
14
  this.updateDate = updateDate;
15
15
  this.reference = reference;
16
16
  this.validateToken = validateToken;
17
+ this.remindersCount = remindersCount;
18
+ this.totalAmountInclVat = totalAmountInclVat;
19
+ this.lastSendingTime = lastSendingTime
20
+ ? new Date(lastSendingTime)
21
+ : undefined;
22
+ this.firstSendingTime = firstSendingTime
23
+ ? new Date(firstSendingTime)
24
+ : undefined;
17
25
  }
18
26
  Document.findByTypeAndReference = function (documents, type, reference) {
19
27
  if (documents && type && reference) {
@@ -77,7 +77,12 @@ export default class Event {
77
77
  origin?: string;
78
78
  quoteLastSendingTime?: Date;
79
79
  invoiceSendingDate?: Date;
80
- 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[]);
80
+ creationDate?: Date;
81
+ updatedDate?: Date;
82
+ quoteFirstSendingTime?: Date;
83
+ lastQuoteCreationDate?: Date;
84
+ 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);
81
85
  static getPrestationsList(event: Event): string[];
86
+ static getCurrentQuote(event: Event): Document | null;
82
87
  }
83
88
  export {};
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Enums_1 = require("../helpers/Enums");
3
4
  var Event = /** @class */ (function () {
4
- 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) {
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) {
5
6
  this.id = id;
6
7
  this.notes = notes;
7
8
  this.ownerId = ownerId;
@@ -38,6 +39,14 @@ var Event = /** @class */ (function () {
38
39
  ? new Date(invoiceSendingDate)
39
40
  : undefined;
40
41
  this.orders = orders;
42
+ this.creationDate = creationDate ? new Date(creationDate) : undefined;
43
+ this.updatedDate = updatedDate ? new Date(updatedDate) : undefined;
44
+ this.lastQuoteCreationDate = lastQuoteCreationDate
45
+ ? new Date(lastQuoteCreationDate)
46
+ : undefined;
47
+ this.quoteFirstSendingTime = quoteFirstSendingTime
48
+ ? new Date(quoteFirstSendingTime)
49
+ : undefined;
41
50
  }
42
51
  Event.getPrestationsList = function (event) {
43
52
  if (event && event.prestations) {
@@ -45,6 +54,34 @@ var Event = /** @class */ (function () {
45
54
  }
46
55
  return [];
47
56
  };
57
+ Event.getCurrentQuote = function (event) {
58
+ var _a, _b, _c, _d;
59
+ if (event.documents) {
60
+ var quoteDocument = event.documents.filter(function (doc) { return doc.type === Enums_1.DocumentType.USER_APPOINTMENT_QUOTE; });
61
+ if (event.type === Enums_1.EventType.QUOTE) {
62
+ var state = event.state;
63
+ if (state === Enums_1.QuoteState.QUOTE_DRAFT ||
64
+ state === Enums_1.QuoteState.QUOTE_SENT) {
65
+ return ((_a = quoteDocument.find(function (doc) { return doc.state === Enums_1.DocumentState.PENDING; })) !== null && _a !== void 0 ? _a : null);
66
+ }
67
+ else if (state === Enums_1.QuoteState.QUOTE_REJECTED) {
68
+ return ((_b = quoteDocument
69
+ .filter(function (doc) { return doc.state === Enums_1.DocumentState.REJECTED; })
70
+ .sort(function (a, b) {
71
+ return new Date(b.creationDate).getTime() -
72
+ new Date(a.creationDate).getTime();
73
+ })[0]) !== null && _b !== void 0 ? _b : null);
74
+ }
75
+ else if (state === Enums_1.QuoteState.QUOTE_ACCEPTED) {
76
+ return ((_c = quoteDocument.find(function (doc) { return doc.state === Enums_1.DocumentState.APPROVED; })) !== null && _c !== void 0 ? _c : null);
77
+ }
78
+ }
79
+ else {
80
+ return ((_d = quoteDocument.find(function (doc) { return doc.state === Enums_1.DocumentState.APPROVED; })) !== null && _d !== void 0 ? _d : null);
81
+ }
82
+ }
83
+ return null;
84
+ };
48
85
  return Event;
49
86
  }());
50
87
  exports.default = Event;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.60.1",
3
+ "version": "1.62.1",
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",
@@ -1,4 +1,4 @@
1
- import { DocumentScanner, QrCode2 } from '@mui/icons-material';
1
+ import { DocumentScanner, QrCode2 } from "@mui/icons-material";
2
2
  import {
3
3
  Box,
4
4
  Button,
@@ -11,48 +11,48 @@ import {
11
11
  type SelectProps,
12
12
  darken,
13
13
  useTheme,
14
- } from '@mui/material';
15
- import '../../style/QRCode.css';
16
-
17
- import html2canvas from 'html2canvas';
18
- import QRCodeStyling, { type Options } from 'qr-code-styling';
19
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
- import { useReactToPrint } from 'react-to-print';
21
- import { DownloadedQRCode } from '../../DownloadedQRCode';
22
- import QRCodeImage from '../../assets/images/leaf_yellow_small.png';
23
- import { flexCenter } from '../../helpers/Tools';
24
- import { PDFDocument } from 'pdf-lib';
25
- import { PLVComponentV2, PrintSize } from './PLVComponent';
26
- import * as pdfjsLib from 'pdfjs-dist';
27
- pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';
14
+ } from "@mui/material";
15
+ import "../../style/QRCode.css";
16
+
17
+ import html2canvas from "html2canvas";
18
+ import { PDFDocument } from "pdf-lib";
19
+ import * as pdfjsLib from "pdfjs-dist";
20
+ import QRCodeStyling, { type Options } from "qr-code-styling";
21
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
+ import { useReactToPrint } from "react-to-print";
23
+ import { DownloadedQRCode } from "../../DownloadedQRCode";
24
+ import QRCodeImage from "../../assets/images/leaf_yellow_small.png";
25
+ import { flexCenter } from "../../helpers/Tools";
26
+ import { PLVComponentV2, PrintSize } from "./PLVComponent";
27
+ pdfjsLib.GlobalWorkerOptions.workerSrc = "/pdf.worker.min.mjs";
28
28
  export const getPdfDocument = (url: string) => {
29
29
  return pdfjsLib.getDocument(url);
30
30
  };
31
- type SelectChoice = null | 'A3' | 'A4' | 'QR_Headless' | 'QR_Google';
31
+ type SelectChoice = null | "A3" | "A4" | "QR_Headless" | "QR_Google";
32
32
  export const QrCodePLVContainer = ({ data }: { data: string }) => {
33
33
  const [selectedChoice, setSelectedChoice] = useState<SelectChoice>(null);
34
- const [urlA4, setUrlA4] = useState<string>('');
35
- const [urlA3, setUrlA3] = useState<string>('');
34
+ const [urlA4, setUrlA4] = useState<string>("");
35
+ const [urlA3, setUrlA3] = useState<string>("");
36
36
  const [isReady, setIsReady] = useState(false);
37
37
 
38
38
  const qrCodeRef = useRef<HTMLDivElement>(null);
39
39
  const theme = useTheme();
40
40
  const PLVrefA4 = useRef<PLVComponentV2>(null);
41
41
  const PLVrefA3 = useRef<PLVComponentV2>(null);
42
- //si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
42
+ //si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
43
43
  //il faut modifier la width et height, imageSize du qrCodeOptions et mettre les mêmes valeurs que dans le optionQrcode de la fonction printPLV
44
44
  const qrCodeOptions: Options = useMemo(
45
45
  () => ({
46
46
  width: 300,
47
47
  height: 300,
48
- type: 'canvas',
48
+ type: "canvas",
49
49
  data: data,
50
50
  image: QRCodeImage,
51
51
  margin: 10,
52
52
  qrOptions: {
53
53
  typeNumber: 0,
54
- mode: 'Byte',
55
- errorCorrectionLevel: 'Q',
54
+ mode: "Byte",
55
+ errorCorrectionLevel: "Q",
56
56
  },
57
57
  imageOptions: {
58
58
  hideBackgroundDots: true,
@@ -61,24 +61,27 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
61
61
  },
62
62
  dotsOptions: {
63
63
  color: darken(theme.palette.primary.main, 0.4),
64
- type: 'square',
64
+ type: "square",
65
65
  },
66
66
  backgroundOptions: {
67
- color: 'white',
67
+ color: "white",
68
68
  },
69
69
  cornersSquareOptions: {
70
70
  color: darken(theme.palette.secondary.main, 0.2),
71
- type: 'square',
71
+ type: "square",
72
72
  },
73
73
  cornersDotOptions: {
74
74
  color: darken(theme.palette.secondary.main, 0.2),
75
- type: 'square',
75
+ type: "square",
76
76
  },
77
77
  }),
78
- [data, theme.palette],
78
+ [data, theme.palette]
79
79
  );
80
80
 
81
- const qrCode = useMemo(() => new QRCodeStyling(qrCodeOptions), [qrCodeOptions]);
81
+ const qrCode = useMemo(
82
+ () => new QRCodeStyling(qrCodeOptions),
83
+ [qrCodeOptions]
84
+ );
82
85
 
83
86
  useEffect(() => {
84
87
  if (qrCodeRef.current) {
@@ -87,18 +90,16 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
87
90
  }, [qrCode]);
88
91
 
89
92
  useEffect(() => {
90
- const urlA4 = printPLV('A4').then((url) => {
93
+ const urlA4 = printPLV("A4").then((url) => {
91
94
  setUrlA4(url);
92
95
  });
93
96
  }, [data]);
94
97
 
95
-
96
-
97
98
  async function printPLV(format: string) {
98
99
  setIsReady(false);
99
100
 
100
101
  // Chemin du fichier PDF
101
- const pdfUrl = `/Movalib_${format}.pdf`;
102
+ const pdfUrl = `/Movalib_${format}.pdf`;
102
103
  // Récupérer le fichier PDF depuis le serveur
103
104
  const response = await fetch(pdfUrl);
104
105
  const existingPdfBytes = await response.arrayBuffer();
@@ -118,20 +119,20 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
118
119
  const { width, height } = firstPage.getSize();
119
120
 
120
121
  let optionQrcode = {};
121
- if(format === 'A3'){
122
+ if (format === "A3") {
122
123
  optionQrcode = {
123
- x: width - 427,
124
+ x: width - 427,
124
125
  y: 88,
125
126
  width: 349,
126
- height: 349
127
- }
127
+ height: 349,
128
+ };
128
129
  } else {
129
130
  optionQrcode = {
130
131
  x: width - 303,
131
132
  y: 54,
132
133
  width: 245,
133
134
  height: 245,
134
- }
135
+ };
135
136
  }
136
137
  // AJouter le QR code à la première page du PDF
137
138
  firstPage.drawImage(qrImage, optionQrcode);
@@ -140,7 +141,7 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
140
141
  const modifiedPdfBytes = await pdfDoc.save();
141
142
 
142
143
  // Convertir les bytes en Blob puis en URL
143
- const blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
144
+ const blob = new Blob([modifiedPdfBytes], { type: "application/pdf" });
144
145
  const url = URL.createObjectURL(blob);
145
146
 
146
147
  // étape nécesssaire pour utiliser reactToPrint pour pouvoir nommer le document
@@ -148,49 +149,51 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
148
149
  // donc il faut convertir le PDF en image
149
150
  // puis convertir l'image en URL
150
151
  // et enfin integrer l'image dans le HTML via la balise <img>
151
-
152
152
 
153
153
  // Convertir le PDF en image
154
154
  const loadingTask = getPdfDocument(url);
155
155
  const pdf = await loadingTask.promise;
156
-
156
+
157
157
  // Récupérer la première page
158
158
  const page = await pdf.getPage(1);
159
-
159
+
160
160
  // Créer un canvas pour afficher la page
161
- const canvas = document.createElement('canvas');
162
- const context = canvas.getContext('2d');
163
-
164
- const viewport = page.getViewport({ scale: 3});
161
+ const canvas = document.createElement("canvas");
162
+ const context = canvas.getContext("2d");
163
+
164
+ const viewport = page.getViewport({ scale: 3 });
165
165
  canvas.width = viewport.width;
166
166
  canvas.height = viewport.height;
167
-
167
+
168
168
  // Rendu de la page dans le canvas
169
169
  const renderContext = {
170
170
  canvasContext: context!,
171
171
  viewport: viewport,
172
172
  };
173
173
  await page.render(renderContext).promise;
174
-
174
+
175
175
  // Convertir le canvas en URL d'image (data URL)
176
- const imageUrl = canvas.toDataURL('image/png');
176
+ const imageUrl = canvas.toDataURL("image/png");
177
177
  setIsReady(true);
178
178
  return imageUrl;
179
179
  }
180
180
 
181
181
  const downloadQRCodeHeadless = useCallback(() => {
182
182
  qrCode.download({
183
- extension: 'png',
184
- name: 'movalib-qr-code',
183
+ extension: "png",
184
+ name: "movalib-qr-code",
185
185
  });
186
186
  }, [qrCode.download]);
187
187
 
188
188
  const downloadQrCodeWithCTA = useCallback(() => {
189
189
  // Check if we have everything we need
190
- const qrCodeContainer = document.querySelector<HTMLElement>('#qr-code-container');
191
- const qrCodeDiv = qrCodeContainer?.querySelector<HTMLElement>('.qr-code');
192
- const qrCodeCanva = qrCodeDiv?.querySelector('canvas');
193
- const downloadedDiv = document.getElementById('qr-code-downloaded-container');
190
+ const qrCodeContainer =
191
+ document.querySelector<HTMLElement>("#qr-code-container");
192
+ const qrCodeDiv = qrCodeContainer?.querySelector<HTMLElement>(".qr-code");
193
+ const qrCodeCanva = qrCodeDiv?.querySelector("canvas");
194
+ const downloadedDiv = document.getElementById(
195
+ "qr-code-downloaded-container"
196
+ );
194
197
 
195
198
  // If we don't have the QR Code, we can't download it
196
199
  if (!(qrCodeContainer && qrCodeDiv && qrCodeCanva && downloadedDiv)) {
@@ -198,9 +201,11 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
198
201
  }
199
202
 
200
203
  const tmpRendered = downloadedDiv.cloneNode(true) as HTMLElement;
201
- tmpRendered.style.display = 'flex';
204
+ tmpRendered.style.display = "flex";
202
205
 
203
- const downloadedQrCodeImgContainer = tmpRendered.querySelector<HTMLElement>('#qr-code-img-container')!;
206
+ const downloadedQrCodeImgContainer = tmpRendered.querySelector<HTMLElement>(
207
+ "#qr-code-img-container"
208
+ )!;
204
209
 
205
210
  downloadedQrCodeImgContainer.append(qrCodeCanva);
206
211
  // add it to the document to be able to download it
@@ -208,9 +213,9 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
208
213
 
209
214
  // create the canva of the tmpRendered div and download it
210
215
  html2canvas(tmpRendered).then((canvas) => {
211
- const a = document.createElement('a');
212
- a.download = 'movalib-qr-code.png';
213
- a.href = canvas.toDataURL('image/png');
216
+ const a = document.createElement("a");
217
+ a.download = "movalib-qr-code.png";
218
+ a.href = canvas.toDataURL("image/png");
214
219
  a.click();
215
220
  });
216
221
 
@@ -221,89 +226,116 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
221
226
  qrCode.append(qrCodeRef.current!);
222
227
  }, [qrCode.append]);
223
228
 
224
- const onChangeSelectedChoice: SelectProps<SelectChoice>['onChange'] = (e) => {
225
- if(e.target.value === 'A3' && !urlA3){
226
- printPLV('A3').then((url) => {
229
+ const onChangeSelectedChoice: SelectProps<SelectChoice>["onChange"] = (e) => {
230
+ if (e.target.value === "A3" && !urlA3) {
231
+ printPLV("A3").then((url) => {
227
232
  setUrlA3(url);
228
233
  });
229
234
  }
230
235
  setSelectedChoice(e.target.value as SelectChoice);
231
236
  };
232
-
237
+
233
238
  const printA3PLV = useReactToPrint({
234
239
  content: () => PLVrefA3.current,
235
- documentTitle: 'Movalib_PLV_A3',
240
+ documentTitle: "Movalib_PLV_A3",
236
241
  });
237
242
 
238
243
  const printA4PLV = useReactToPrint({
239
244
  content: () => PLVrefA4.current,
240
- documentTitle: 'Movalib_PLV_A4',
245
+ documentTitle: "Movalib_PLV_A4",
241
246
  });
242
247
 
243
248
  const onClickDownload = useMemo(() => {
244
249
  switch (selectedChoice) {
245
- case 'A3':
250
+ case "A3":
246
251
  return printA3PLV;
247
- case 'A4':
252
+ case "A4":
248
253
  return printA4PLV;
249
- case 'QR_Headless':
254
+ case "QR_Headless":
250
255
  return downloadQRCodeHeadless;
251
- case 'QR_Google':
256
+ case "QR_Google":
252
257
  return downloadQrCodeWithCTA;
253
258
  default:
254
259
  return () => {};
255
260
  }
256
- }, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA, printA3PLV, printA4PLV]);
261
+ }, [
262
+ selectedChoice,
263
+ downloadQRCodeHeadless,
264
+ downloadQrCodeWithCTA,
265
+ printA3PLV,
266
+ printA4PLV,
267
+ ]);
257
268
  return (
258
- <Box display='flex' flexDirection='column' alignItems='center' gap='24px'>
259
- {urlA4 && <PLVComponentV2 ref={PLVrefA4} url={urlA4} printSize={PrintSize.A4} />}
260
- {urlA3 && <PLVComponentV2 ref={PLVrefA3} url={urlA3} printSize={PrintSize.A3} />}
261
-
262
- <Grid container justifyContent='center' alignItems='center'>
269
+ <Box display="flex" flexDirection="column" alignItems="center" gap="24px">
270
+ {urlA4 && (
271
+ <PLVComponentV2 ref={PLVrefA4} url={urlA4} printSize={PrintSize.A4} />
272
+ )}
273
+ {urlA3 && (
274
+ <PLVComponentV2 ref={PLVrefA3} url={urlA3} printSize={PrintSize.A3} />
275
+ )}
276
+
277
+ <Grid container justifyContent="center" alignItems="center">
263
278
  <Grid item xs={7}>
264
- <FormControl fullWidth size='small'>
265
- <InputLabel id='qrcode-plv-select'>Choisissez votre support</InputLabel>
279
+ <FormControl fullWidth size="small">
280
+ <InputLabel id="qrcode-plv-select">
281
+ Choisissez votre support
282
+ </InputLabel>
266
283
  <Select
267
- labelId='qrcode-plv-select'
268
- label='Choisissez votre support'
269
- id='qrcode-plv-select'
284
+ labelId="qrcode-plv-select"
285
+ label="Choisissez votre support"
286
+ id="qrcode-plv-select"
270
287
  onChange={onChangeSelectedChoice}
271
288
  value={selectedChoice}
272
289
  >
273
- <MenuItem value={'A4'}>🧾&nbsp;&nbsp;PLV format A4</MenuItem>
274
- <MenuItem value={'A3'}>🧾&nbsp;&nbsp;PLV format A3</MenuItem>
275
- <MenuItem value={'QR_Google'}>QR Code format GoogleMyBusiness</MenuItem>
276
- <MenuItem value={'QR_Headless'}>QR Code seul</MenuItem>
290
+ <MenuItem value={"A4"}>🧾&nbsp;&nbsp;PLV format A4</MenuItem>
291
+ <MenuItem value={"A3"}>🧾&nbsp;&nbsp;PLV format A3</MenuItem>
292
+ <MenuItem value={"QR_Google"}>
293
+ QR Code format GoogleMyBusiness
294
+ </MenuItem>
295
+ <MenuItem value={"QR_Headless"}>QR Code seul</MenuItem>
277
296
  </Select>
278
297
  </FormControl>
279
298
  </Grid>
280
299
  <Grid item xs={4} marginLeft={3}>
281
-
282
- {(selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady ? (
283
- <CircularProgress />
284
- ) : (
285
- <Button
286
- startIcon={selectedChoice === 'A3' || selectedChoice === 'A4' ? <DocumentScanner /> : <QrCode2 />}
287
- onClick={onClickDownload}
288
- variant='outlined'
289
- disabled={!selectedChoice || ((selectedChoice === 'A3' || selectedChoice === 'A4') && !isReady)}
290
- sx={{ color: darken(theme.palette.primary.main, 0.2), borderRadius: '10rem' }}
291
- >
292
- {selectedChoice === 'A3' || selectedChoice === 'A4' ? 'Imprimer' : 'Télécharger'}
300
+ {(selectedChoice === "A3" || selectedChoice === "A4") && !isReady ? (
301
+ <CircularProgress />
302
+ ) : (
303
+ <Button
304
+ startIcon={
305
+ selectedChoice === "A3" || selectedChoice === "A4" ? (
306
+ <DocumentScanner />
307
+ ) : (
308
+ <QrCode2 />
309
+ )
310
+ }
311
+ onClick={onClickDownload}
312
+ variant="outlined"
313
+ disabled={
314
+ !selectedChoice ||
315
+ ((selectedChoice === "A3" || selectedChoice === "A4") &&
316
+ !isReady)
317
+ }
318
+ sx={{
319
+ color: darken(theme.palette.primary.main, 0.2),
320
+ borderRadius: "10rem",
321
+ }}
322
+ >
323
+ {selectedChoice === "A3" || selectedChoice === "A4"
324
+ ? "Imprimer"
325
+ : "Télécharger"}
293
326
  </Button>
294
- )}
295
-
327
+ )}
296
328
  </Grid>
297
329
  </Grid>
298
- <div id='qr-code-container' style={flexCenter}>
330
+ <div id="qr-code-container" style={flexCenter}>
299
331
  <div
300
332
  ref={qrCodeRef}
301
333
  style={{
302
- height: '300px',
303
- width: '300px',
304
- maxWidth: '300px !important',
334
+ height: "300px",
335
+ width: "300px",
336
+ maxWidth: "300px !important",
305
337
  }}
306
- className='qr-code'
338
+ className="qr-code"
307
339
  />
308
340
  </div>
309
341
  <DownloadedQRCode />
@@ -213,6 +213,7 @@ export enum EventType {
213
213
  NOTE = "NOTE",
214
214
  PENDING_APPOINTMENT = "PENDING_APPOINTMENT",
215
215
  WAITING_VEHICLE = "WAITING_VEHICLE",
216
+ QUOTE = "QUOTE",
216
217
  }
217
218
 
218
219
  export enum DayOfWeek {
@@ -231,6 +232,13 @@ export enum DocumentState {
231
232
  REJECTED = "REJECTED",
232
233
  }
233
234
 
235
+ export enum QuoteState {
236
+ QUOTE_DRAFT = "QUOTE_DRAFT",
237
+ QUOTE_SENT = "QUOTE_SENT",
238
+ QUOTE_ACCEPTED = "QUOTE_ACCEPTED",
239
+ QUOTE_REJECTED = "QUOTE_REJECTED",
240
+ }
241
+
234
242
  export enum DocumentType {
235
243
  USER_BANK_DETAILS = "USER_BANK_DETAILS",
236
244
  USER_APPOINTMENT_QUOTE = "USER_APPOINTMENT_QUOTE",
@@ -15,7 +15,10 @@ export default class Document {
15
15
  reference?: string;
16
16
  rejectReason?: string;
17
17
  validateToken?: string;
18
-
18
+ remindersCount?: number;
19
+ totalAmountInclVat?: number;
20
+ lastSendingTime?: Date;
21
+ firstSendingTime?: Date;
19
22
  constructor(
20
23
  id: string,
21
24
  ownerId: number,
@@ -28,7 +31,11 @@ export default class Document {
28
31
  creationDate?: Date,
29
32
  updateDate?: Date,
30
33
  reference?: string,
31
- validateToken?: string
34
+ validateToken?: string,
35
+ remindersCount?: number,
36
+ totalAmountInclVat?: number,
37
+ lastSendingTime?: Date,
38
+ firstSendingTime?: Date
32
39
  ) {
33
40
  this.id = id;
34
41
  this.state = state;
@@ -42,6 +49,14 @@ export default class Document {
42
49
  this.updateDate = updateDate;
43
50
  this.reference = reference;
44
51
  this.validateToken = validateToken;
52
+ this.remindersCount = remindersCount;
53
+ this.totalAmountInclVat = totalAmountInclVat;
54
+ this.lastSendingTime = lastSendingTime
55
+ ? new Date(lastSendingTime)
56
+ : undefined;
57
+ this.firstSendingTime = firstSendingTime
58
+ ? new Date(firstSendingTime)
59
+ : undefined;
45
60
  }
46
61
 
47
62
  static findByTypeAndReference(
@@ -1,4 +1,11 @@
1
- import { EventState, EventType, OrderPreference } from "../helpers/Enums";
1
+ import {
2
+ DocumentState,
3
+ DocumentType,
4
+ EventState,
5
+ EventType,
6
+ OrderPreference,
7
+ QuoteState,
8
+ } from "../helpers/Enums";
2
9
  import Address from "./Address";
3
10
  import Customer from "./Customer";
4
11
  import Document from "./Document";
@@ -82,7 +89,10 @@ export default class Event {
82
89
  origin?: string;
83
90
  quoteLastSendingTime?: Date;
84
91
  invoiceSendingDate?: Date;
85
-
92
+ creationDate?: Date;
93
+ updatedDate?: Date;
94
+ quoteFirstSendingTime?: Date;
95
+ lastQuoteCreationDate?: Date;
86
96
  constructor(
87
97
  id: string,
88
98
  ownerId: number,
@@ -111,7 +121,11 @@ export default class Event {
111
121
  interventionEndTime?: Date,
112
122
  quoteLastSendingTime?: Date,
113
123
  invoiceSendingDate?: Date,
114
- orders?: order[]
124
+ orders?: order[],
125
+ creationDate?: Date,
126
+ updatedDate?: Date,
127
+ lastQuoteCreationDate?: Date,
128
+ quoteFirstSendingTime?: Date
115
129
  ) {
116
130
  this.id = id;
117
131
  this.notes = notes;
@@ -149,6 +163,14 @@ export default class Event {
149
163
  ? new Date(invoiceSendingDate)
150
164
  : undefined;
151
165
  this.orders = orders;
166
+ this.creationDate = creationDate ? new Date(creationDate) : undefined;
167
+ this.updatedDate = updatedDate ? new Date(updatedDate) : undefined;
168
+ this.lastQuoteCreationDate = lastQuoteCreationDate
169
+ ? new Date(lastQuoteCreationDate)
170
+ : undefined;
171
+ this.quoteFirstSendingTime = quoteFirstSendingTime
172
+ ? new Date(quoteFirstSendingTime)
173
+ : undefined;
152
174
  }
153
175
 
154
176
  static getPrestationsList(event: Event): string[] {
@@ -158,4 +180,44 @@ export default class Event {
158
180
 
159
181
  return [];
160
182
  }
183
+ static getCurrentQuote(event: Event): Document | null {
184
+ if (event.documents) {
185
+ const quoteDocument = event.documents.filter(
186
+ (doc) => doc.type === DocumentType.USER_APPOINTMENT_QUOTE
187
+ );
188
+ if (event.type === EventType.QUOTE) {
189
+ const state = event.state as unknown as QuoteState;
190
+ if (
191
+ state === QuoteState.QUOTE_DRAFT ||
192
+ state === QuoteState.QUOTE_SENT
193
+ ) {
194
+ return (
195
+ quoteDocument.find((doc) => doc.state === DocumentState.PENDING) ??
196
+ null
197
+ );
198
+ } else if (state === QuoteState.QUOTE_REJECTED) {
199
+ return (
200
+ quoteDocument
201
+ .filter((doc) => doc.state === DocumentState.REJECTED)
202
+ .sort(
203
+ (a, b) =>
204
+ new Date(b.creationDate!).getTime() -
205
+ new Date(a.creationDate!).getTime()
206
+ )[0] ?? null
207
+ );
208
+ } else if (state === QuoteState.QUOTE_ACCEPTED) {
209
+ return (
210
+ quoteDocument.find((doc) => doc.state === DocumentState.APPROVED) ??
211
+ null
212
+ );
213
+ }
214
+ } else {
215
+ return (
216
+ quoteDocument.find((doc) => doc.state === DocumentState.APPROVED) ??
217
+ null
218
+ );
219
+ }
220
+ }
221
+ return null;
222
+ }
161
223
  }