@movalib/movalib-commons 1.55.4 → 1.55.5
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/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/dist/src/components/QrCodePLVContainer/QrCodePLVContainer.js +104 -16
- package/dist/src/helpers/ApiHelper.d.ts +1 -0
- package/dist/src/helpers/ApiHelper.js +2 -2
- package/dist/src/helpers/DateUtils.d.ts +1 -0
- package/dist/src/utils/DialogPrint.d.ts +1 -0
- package/dist/src/utils/DialogPrint.js +22 -0
- package/index.ts +3 -0
- package/movalib-movalib-commons-1.55.36.tgz +0 -0
- package/movalib-movalib-commons-1.55.37.tgz +0 -0
- package/package.json +5 -2
- package/public/Movalib_A3.pdf +0 -0
- package/public/Movalib_A4.pdf +0 -0
- package/src/components/QrCodePLVContainer/QrCodePLVContainer.tsx +58 -19
- package/src/helpers/ApiHelper.ts +6 -5
- package/src/utils/DialogPrint.tsx +18 -0
package/dist/index.d.ts
CHANGED
|
@@ -51,3 +51,4 @@ export { validatePhoneNumber, validateText, validateEmail } from './src/helpers/
|
|
|
51
51
|
export { formatDateByCountryCode, getLongFormattedDateTime } from './src/helpers/DateUtils';
|
|
52
52
|
export { request, API_BASE_URL } from './src/helpers/ApiHelper';
|
|
53
53
|
export { RoleType, MovaAppType, DayOfWeek, EventState, EventType, DocumentType, DigitalPassportIndex, DocumentState, Gender, DateFormatTypes, PartsApplicationType, ProductType, OrderPreference, OrderState, SlotAlgorithm, VehiclePlateFormat as VehiclePlateType, SubscriptionPaymentInterval, RegistrationState, PrestationType, PrestationState, CountryCode, SubscriptionState, SubscriptionType, APIMethod, } from './src/helpers/Enums';
|
|
54
|
+
export { openDialogPrint } from './src/utils/DialogPrint';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.formatFrenchVehiclePlate = exports.formatVehicleTire = exports.validateField = exports.deleteCookie = exports.readCookie = exports.VehicleTire = exports.Event = exports.Schedule = exports.Garage = exports.Document = exports.Vehicle = exports.Address = exports.Role = exports.User = exports.Customer = exports.Logger = exports.Operation = exports.Prestation = exports.Product = exports.Supplier = exports.Employee = exports.Absence = exports.Subscription = exports.PrintSize = exports.PLVComponent = exports.QrCodePLVContainer = exports.GenderSelector = exports.ConfirmationDialog = exports.MovaVehicleTireField = exports.MovaCopyright = exports.MovaSignUp = exports.MovaLogin = exports.MovaSnackbar = exports.TestButton = exports.VehiclePlateField = exports.QRCode = exports.MovaDialog = exports.Loader = exports.MovaDigitalPassport = exports.VehicleFullCard = exports.ScheduleFields = exports.AddressFields = exports.AccountValidation = exports.GaragePLV = exports.IbanInput = exports.DialogForgotPassword = exports.UserService = exports.GarageService = exports.AuthenticationService = exports.VehicleService = void 0;
|
|
8
|
-
exports.APIMethod = exports.SubscriptionType = exports.SubscriptionState = exports.CountryCode = exports.PrestationState = exports.PrestationType = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.VehiclePlateType = exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = exports.MovaAppType = exports.RoleType = exports.API_BASE_URL = exports.request = exports.getLongFormattedDateTime = exports.formatDateByCountryCode = exports.validateEmail = exports.validateText = exports.validatePhoneNumber = exports.getApplicationsShortLabels = exports.isSafariOniOS = exports.getDayOfWeekLabel = exports.findScheduleByDayOfWeek = exports.getFormattedIntervals = exports.getFormattedSchedule = exports.formatPhoneNumber = exports.flexLeftRow = exports.capitalizeFirstLetter = exports.getApplicationShortLabel = exports.isEmpty = void 0;
|
|
8
|
+
exports.openDialogPrint = exports.APIMethod = exports.SubscriptionType = exports.SubscriptionState = exports.CountryCode = exports.PrestationState = exports.PrestationType = exports.RegistrationState = exports.SubscriptionPaymentInterval = exports.VehiclePlateType = exports.SlotAlgorithm = exports.OrderState = exports.OrderPreference = exports.ProductType = exports.PartsApplicationType = exports.DateFormatTypes = exports.Gender = exports.DocumentState = exports.DigitalPassportIndex = exports.DocumentType = exports.EventType = exports.EventState = exports.DayOfWeek = exports.MovaAppType = exports.RoleType = exports.API_BASE_URL = exports.request = exports.getLongFormattedDateTime = exports.formatDateByCountryCode = exports.validateEmail = exports.validateText = exports.validatePhoneNumber = exports.getApplicationsShortLabels = exports.isSafariOniOS = exports.getDayOfWeekLabel = exports.findScheduleByDayOfWeek = exports.getFormattedIntervals = exports.getFormattedSchedule = exports.formatPhoneNumber = exports.flexLeftRow = exports.capitalizeFirstLetter = exports.getApplicationShortLabel = exports.isEmpty = void 0;
|
|
9
9
|
// Export des services
|
|
10
10
|
var VehicleService_1 = require("./src/services/VehicleService");
|
|
11
11
|
Object.defineProperty(exports, "VehicleService", { enumerable: true, get: function () { return __importDefault(VehicleService_1).default; } });
|
|
@@ -153,3 +153,6 @@ Object.defineProperty(exports, "CountryCode", { enumerable: true, get: function
|
|
|
153
153
|
Object.defineProperty(exports, "SubscriptionState", { enumerable: true, get: function () { return Enums_1.SubscriptionState; } });
|
|
154
154
|
Object.defineProperty(exports, "SubscriptionType", { enumerable: true, get: function () { return Enums_1.SubscriptionType; } });
|
|
155
155
|
Object.defineProperty(exports, "APIMethod", { enumerable: true, get: function () { return Enums_1.APIMethod; } });
|
|
156
|
+
// Export des utils
|
|
157
|
+
var DialogPrint_1 = require("./src/utils/DialogPrint");
|
|
158
|
+
Object.defineProperty(exports, "openDialogPrint", { enumerable: true, get: function () { return DialogPrint_1.openDialogPrint; } });
|
|
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
51
|
};
|
|
@@ -22,18 +58,19 @@ require("../../style/QRCode.css");
|
|
|
22
58
|
var html2canvas_1 = __importDefault(require("html2canvas"));
|
|
23
59
|
var qr_code_styling_1 = __importDefault(require("qr-code-styling"));
|
|
24
60
|
var react_1 = require("react");
|
|
25
|
-
var react_to_print_1 = require("react-to-print");
|
|
26
61
|
var DownloadedQRCode_1 = require("../../DownloadedQRCode");
|
|
27
62
|
var leaf_yellow_small_png_1 = __importDefault(require("../../assets/images/leaf_yellow_small.png"));
|
|
28
63
|
var Tools_1 = require("../../helpers/Tools");
|
|
29
|
-
var
|
|
64
|
+
var pdf_lib_1 = require("pdf-lib");
|
|
65
|
+
var DialogPrint_1 = require("../../utils/DialogPrint");
|
|
30
66
|
var QrCodePLVContainer = function (_a) {
|
|
31
67
|
var data = _a.data;
|
|
32
68
|
var _b = (0, react_1.useState)(null), selectedChoice = _b[0], setSelectedChoice = _b[1];
|
|
33
69
|
var qrCodeRef = (0, react_1.useRef)(null);
|
|
34
|
-
var PLVrefA4 = (0, react_1.useRef)(null);
|
|
35
|
-
var PLVrefA3 = (0, react_1.useRef)(null);
|
|
36
70
|
var theme = (0, material_1.useTheme)();
|
|
71
|
+
//si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
|
|
72
|
+
//il faut modifier la width et height, imageSize du qrCodeOptions et mettre les mêmes valeurs que dans le optionQrcode de la fonction printPLV
|
|
73
|
+
//
|
|
37
74
|
var qrCodeOptions = (0, react_1.useMemo)(function () { return ({
|
|
38
75
|
width: 300,
|
|
39
76
|
height: 300,
|
|
@@ -73,14 +110,65 @@ var QrCodePLVContainer = function (_a) {
|
|
|
73
110
|
qrCode.append(qrCodeRef.current);
|
|
74
111
|
}
|
|
75
112
|
}, [qrCode]);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
function printPLV(format) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
115
|
+
var pdfUrl, response, existingPdfBytes, pdfDoc, qrCodeBlob, qrImageBytes, qrImage, pages, firstPage, _a, width, height, optionQrcode, modifiedPdfBytes, blob, url;
|
|
116
|
+
return __generator(this, function (_b) {
|
|
117
|
+
switch (_b.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
pdfUrl = "/Movalib_".concat(format, ".pdf");
|
|
120
|
+
return [4 /*yield*/, fetch(pdfUrl)];
|
|
121
|
+
case 1:
|
|
122
|
+
response = _b.sent();
|
|
123
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
124
|
+
case 2:
|
|
125
|
+
existingPdfBytes = _b.sent();
|
|
126
|
+
return [4 /*yield*/, pdf_lib_1.PDFDocument.load(existingPdfBytes)];
|
|
127
|
+
case 3:
|
|
128
|
+
pdfDoc = _b.sent();
|
|
129
|
+
return [4 /*yield*/, qrCode.getRawData("png")];
|
|
130
|
+
case 4:
|
|
131
|
+
qrCodeBlob = _b.sent();
|
|
132
|
+
return [4 /*yield*/, (qrCodeBlob === null || qrCodeBlob === void 0 ? void 0 : qrCodeBlob.arrayBuffer())];
|
|
133
|
+
case 5:
|
|
134
|
+
qrImageBytes = _b.sent();
|
|
135
|
+
return [4 /*yield*/, pdfDoc.embedPng(qrImageBytes)];
|
|
136
|
+
case 6:
|
|
137
|
+
qrImage = _b.sent();
|
|
138
|
+
pages = pdfDoc.getPages();
|
|
139
|
+
firstPage = pages[0];
|
|
140
|
+
_a = firstPage.getSize(), width = _a.width, height = _a.height;
|
|
141
|
+
optionQrcode = {};
|
|
142
|
+
if (format === 'A3') {
|
|
143
|
+
optionQrcode = {
|
|
144
|
+
x: width - 427,
|
|
145
|
+
y: 88,
|
|
146
|
+
width: 349,
|
|
147
|
+
height: 349
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
optionQrcode = {
|
|
152
|
+
x: width - 303,
|
|
153
|
+
y: 54,
|
|
154
|
+
width: 245,
|
|
155
|
+
height: 245,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// AJouter le QR code à la première page du PDF
|
|
159
|
+
firstPage.drawImage(qrImage, optionQrcode);
|
|
160
|
+
return [4 /*yield*/, pdfDoc.save()];
|
|
161
|
+
case 7:
|
|
162
|
+
modifiedPdfBytes = _b.sent();
|
|
163
|
+
blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
|
|
164
|
+
url = URL.createObjectURL(blob);
|
|
165
|
+
// Ouvrir la page d'impression
|
|
166
|
+
(0, DialogPrint_1.openDialogPrint)(url);
|
|
167
|
+
return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
84
172
|
var downloadQRCodeHeadless = (0, react_1.useCallback)(function () {
|
|
85
173
|
qrCode.download({
|
|
86
174
|
extension: 'png',
|
|
@@ -121,9 +209,9 @@ var QrCodePLVContainer = function (_a) {
|
|
|
121
209
|
var onClickDownload = (0, react_1.useMemo)(function () {
|
|
122
210
|
switch (selectedChoice) {
|
|
123
211
|
case 'A3':
|
|
124
|
-
return
|
|
212
|
+
return function () { printPLV('A3'); };
|
|
125
213
|
case 'A4':
|
|
126
|
-
return
|
|
214
|
+
return function () { printPLV('A4'); };
|
|
127
215
|
case 'QR_Headless':
|
|
128
216
|
return downloadQRCodeHeadless;
|
|
129
217
|
case 'QR_Google':
|
|
@@ -131,8 +219,8 @@ var QrCodePLVContainer = function (_a) {
|
|
|
131
219
|
default:
|
|
132
220
|
return function () { };
|
|
133
221
|
}
|
|
134
|
-
}, [selectedChoice,
|
|
135
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px' }, { children: [(0, jsx_runtime_1.
|
|
222
|
+
}, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA]);
|
|
223
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '24px' }, { children: [(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: (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, 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: {
|
|
136
224
|
height: '300px',
|
|
137
225
|
width: '300px',
|
|
138
226
|
maxWidth: '300px !important',
|
|
@@ -12,14 +12,14 @@ function handleError(error) {
|
|
|
12
12
|
var msg = error.message.includes('fetch') ? "Connexion impossible" : error.message;
|
|
13
13
|
return {
|
|
14
14
|
success: false,
|
|
15
|
-
error: msg
|
|
15
|
+
error: msg,
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
function handleResponse(response) {
|
|
19
19
|
var contentType = response.headers.get("content-type");
|
|
20
20
|
var isJson = contentType && contentType.includes("application/json");
|
|
21
21
|
var dataPromise = isJson ? response.json() : response.text();
|
|
22
|
-
var location = response.headers.get('
|
|
22
|
+
var location = response.headers.get('Location');
|
|
23
23
|
return dataPromise.then(function (data) {
|
|
24
24
|
if (!response.ok) {
|
|
25
25
|
Logger_1.default.error(data);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function openDialogPrint(url: string): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openDialogPrint = void 0;
|
|
4
|
+
function openDialogPrint(url) {
|
|
5
|
+
var iframe = document.createElement('iframe');
|
|
6
|
+
iframe.style.position = 'absolute';
|
|
7
|
+
iframe.style.width = '0px';
|
|
8
|
+
iframe.style.height = '0px';
|
|
9
|
+
iframe.src = url;
|
|
10
|
+
document.body.appendChild(iframe);
|
|
11
|
+
// Ouvrir la boîte de dialogue d'impression lorsque l'iframe est chargée
|
|
12
|
+
iframe.onload = function () {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.print();
|
|
15
|
+
};
|
|
16
|
+
// Supprimer l'iframe une fois l'impression terminée
|
|
17
|
+
iframe.onclose = function () {
|
|
18
|
+
document.body.removeChild(iframe);
|
|
19
|
+
URL.revokeObjectURL(url);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.openDialogPrint = openDialogPrint;
|
package/index.ts
CHANGED
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@movalib/movalib-commons",
|
|
3
|
-
"version": "1.55.
|
|
3
|
+
"version": "1.55.5",
|
|
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",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
31
|
"html2canvas": "^1.4.1",
|
|
32
32
|
"js-cookie": "^3.0.5",
|
|
33
|
+
"pdf-lib": "^1.17.1",
|
|
33
34
|
"qr-code-styling": "^1.4.4",
|
|
34
35
|
"react": "^18.2.0",
|
|
35
36
|
"react-dom": "^18.2.0",
|
|
@@ -40,7 +41,9 @@
|
|
|
40
41
|
"typescript": "^4.9.5"
|
|
41
42
|
},
|
|
42
43
|
"eslintConfig": {
|
|
43
|
-
"extends": [
|
|
44
|
+
"extends": [
|
|
45
|
+
"react-app"
|
|
46
|
+
]
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
49
|
"@types/js-cookie": "^3.0.4",
|
|
Binary file
|
|
Binary file
|
|
@@ -21,6 +21,8 @@ import { DownloadedQRCode } from '../../DownloadedQRCode';
|
|
|
21
21
|
import QRCodeImage from '../../assets/images/leaf_yellow_small.png';
|
|
22
22
|
import { flexCenter } from '../../helpers/Tools';
|
|
23
23
|
import { PLVComponent, PrintSize } from './PLVComponent';
|
|
24
|
+
import { PDFDocument } from 'pdf-lib';
|
|
25
|
+
import { openDialogPrint } from '../../utils/DialogPrint';
|
|
24
26
|
|
|
25
27
|
type SelectChoice = null | 'A3' | 'A4' | 'QR_Headless' | 'QR_Google';
|
|
26
28
|
|
|
@@ -28,11 +30,11 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
|
|
|
28
30
|
const [selectedChoice, setSelectedChoice] = useState<SelectChoice>(null);
|
|
29
31
|
|
|
30
32
|
const qrCodeRef = useRef<HTMLDivElement>(null);
|
|
31
|
-
const PLVrefA4 = useRef<PLVComponent>(null);
|
|
32
|
-
const PLVrefA3 = useRef<PLVComponent>(null);
|
|
33
|
-
|
|
34
33
|
const theme = useTheme();
|
|
35
34
|
|
|
35
|
+
//si sur l'impression des PLV en A4 ou A3 le Qrcode est flou,
|
|
36
|
+
//il faut modifier la width et height, imageSize du qrCodeOptions et mettre les mêmes valeurs que dans le optionQrcode de la fonction printPLV
|
|
37
|
+
//
|
|
36
38
|
const qrCodeOptions: Options = useMemo(
|
|
37
39
|
() => ({
|
|
38
40
|
width: 300,
|
|
@@ -77,16 +79,56 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
|
|
|
77
79
|
qrCode.append(qrCodeRef.current);
|
|
78
80
|
}
|
|
79
81
|
}, [qrCode]);
|
|
82
|
+
async function printPLV(format: string) {
|
|
83
|
+
// Chemin du fichier PDF
|
|
84
|
+
const pdfUrl = `/Movalib_${format}.pdf`;
|
|
85
|
+
// Récupérer le fichier PDF depuis le serveur
|
|
86
|
+
const response = await fetch(pdfUrl);
|
|
87
|
+
const existingPdfBytes = await response.arrayBuffer();
|
|
88
|
+
|
|
89
|
+
// Charger le document PDF
|
|
90
|
+
const pdfDoc = await PDFDocument.load(existingPdfBytes);
|
|
91
|
+
// Convertir le Qrcode en Blob
|
|
92
|
+
const qrCodeBlob = await qrCode.getRawData("png");
|
|
93
|
+
|
|
94
|
+
// Convertir l'image QR code en un tableau de bytes
|
|
95
|
+
const qrImageBytes = await qrCodeBlob?.arrayBuffer();
|
|
96
|
+
// Intégrer l'image du QR code dans le PDF
|
|
97
|
+
const qrImage = await pdfDoc.embedPng(qrImageBytes!);
|
|
98
|
+
|
|
99
|
+
const pages = pdfDoc.getPages();
|
|
100
|
+
const firstPage = pages[0]; // Ajouter le QR code à la première page
|
|
101
|
+
const { width, height } = firstPage.getSize();
|
|
102
|
+
|
|
103
|
+
let optionQrcode = {};
|
|
104
|
+
if(format === 'A3'){
|
|
105
|
+
optionQrcode = {
|
|
106
|
+
x: width - 427,
|
|
107
|
+
y: 88,
|
|
108
|
+
width: 349,
|
|
109
|
+
height: 349
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
optionQrcode = {
|
|
113
|
+
x: width - 303,
|
|
114
|
+
y: 54,
|
|
115
|
+
width: 245,
|
|
116
|
+
height: 245,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// AJouter le QR code à la première page du PDF
|
|
120
|
+
firstPage.drawImage(qrImage, optionQrcode);
|
|
80
121
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
documentTitle: 'Movalib_PLV_A4',
|
|
84
|
-
});
|
|
122
|
+
// Enregistrer le PDF modifié en bytes
|
|
123
|
+
const modifiedPdfBytes = await pdfDoc.save();
|
|
85
124
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
125
|
+
// Convertir les bytes en Blob puis en URL
|
|
126
|
+
const blob = new Blob([modifiedPdfBytes], { type: 'application/pdf' });
|
|
127
|
+
const url = URL.createObjectURL(blob);
|
|
128
|
+
|
|
129
|
+
// Ouvrir la page d'impression
|
|
130
|
+
openDialogPrint(url);
|
|
131
|
+
}
|
|
90
132
|
|
|
91
133
|
const downloadQRCodeHeadless = useCallback(() => {
|
|
92
134
|
qrCode.download({
|
|
@@ -138,9 +180,9 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
|
|
|
138
180
|
const onClickDownload = useMemo(() => {
|
|
139
181
|
switch (selectedChoice) {
|
|
140
182
|
case 'A3':
|
|
141
|
-
return
|
|
183
|
+
return () => {printPLV('A3')};
|
|
142
184
|
case 'A4':
|
|
143
|
-
return
|
|
185
|
+
return () => {printPLV('A4')};
|
|
144
186
|
case 'QR_Headless':
|
|
145
187
|
return downloadQRCodeHeadless;
|
|
146
188
|
case 'QR_Google':
|
|
@@ -148,12 +190,9 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
|
|
|
148
190
|
default:
|
|
149
191
|
return () => {};
|
|
150
192
|
}
|
|
151
|
-
}, [selectedChoice,
|
|
193
|
+
}, [selectedChoice, downloadQRCodeHeadless, downloadQrCodeWithCTA]);
|
|
152
194
|
return (
|
|
153
195
|
<Box display='flex' flexDirection='column' alignItems='center' gap='24px'>
|
|
154
|
-
<PLVComponent ref={PLVrefA4} url={data} printSize={PrintSize.A4} />
|
|
155
|
-
<PLVComponent ref={PLVrefA3} url={data} printSize={PrintSize.A3} />
|
|
156
|
-
|
|
157
196
|
<Grid container justifyContent='center' alignItems='center'>
|
|
158
197
|
<Grid item xs={7}>
|
|
159
198
|
<FormControl fullWidth size='small'>
|
|
@@ -165,8 +204,8 @@ export const QrCodePLVContainer = ({ data }: { data: string }) => {
|
|
|
165
204
|
onChange={onChangeSelectedChoice}
|
|
166
205
|
value={selectedChoice}
|
|
167
206
|
>
|
|
168
|
-
<MenuItem value={'
|
|
169
|
-
<MenuItem value={'
|
|
207
|
+
<MenuItem value={'A4'}>🧾 PLV format A4</MenuItem>
|
|
208
|
+
<MenuItem value={'A3'}>🧾 PLV format A3</MenuItem>
|
|
170
209
|
<MenuItem value={'QR_Google'}>QR Code format GoogleMyBusiness</MenuItem>
|
|
171
210
|
<MenuItem value={'QR_Headless'}>QR Code seul</MenuItem>
|
|
172
211
|
</Select>
|
package/src/helpers/ApiHelper.ts
CHANGED
|
@@ -21,8 +21,8 @@ type APIError = {
|
|
|
21
21
|
export type APIResponse<T> = {
|
|
22
22
|
success: boolean,
|
|
23
23
|
data?: T,
|
|
24
|
-
error?: string
|
|
25
|
-
|
|
24
|
+
error?: string,
|
|
25
|
+
location?: string | null
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export type APIRequest = {
|
|
@@ -36,7 +36,7 @@ function handleError(error: Error): APIResponse<null> {
|
|
|
36
36
|
let msg = error.message.includes('fetch') ? "Connexion impossible" : error.message;
|
|
37
37
|
return {
|
|
38
38
|
success: false,
|
|
39
|
-
error: msg
|
|
39
|
+
error: msg,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -45,7 +45,8 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
|
|
|
45
45
|
const contentType = response.headers.get("content-type");
|
|
46
46
|
const isJson = contentType && contentType.includes("application/json");
|
|
47
47
|
const dataPromise = isJson ? response.json() : response.text();
|
|
48
|
-
const location = response.headers.get('
|
|
48
|
+
const location = response.headers.get('Location');
|
|
49
|
+
|
|
49
50
|
|
|
50
51
|
return dataPromise.then(data => {
|
|
51
52
|
|
|
@@ -69,7 +70,7 @@ function handleResponse(response: Response): Promise<APIResponse<any>> {
|
|
|
69
70
|
return { success: false, error: errorMsg };
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
return { success: true, data, location };
|
|
73
|
+
return { success: true, data, location: location };
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function openDialogPrint(url: string) {
|
|
2
|
+
const iframe = document.createElement('iframe');
|
|
3
|
+
iframe.style.position = 'absolute';
|
|
4
|
+
iframe.style.width = '0px';
|
|
5
|
+
iframe.style.height = '0px';
|
|
6
|
+
iframe.src = url;
|
|
7
|
+
document.body.appendChild(iframe);
|
|
8
|
+
|
|
9
|
+
// Ouvrir la boîte de dialogue d'impression lorsque l'iframe est chargée
|
|
10
|
+
iframe.onload = () => {
|
|
11
|
+
iframe?.contentWindow?.print();
|
|
12
|
+
};
|
|
13
|
+
// Supprimer l'iframe une fois l'impression terminée
|
|
14
|
+
iframe.onclose = () => {
|
|
15
|
+
document.body.removeChild(iframe);
|
|
16
|
+
URL.revokeObjectURL(url);
|
|
17
|
+
}
|
|
18
|
+
}
|