Pārlūkot izejas kodu

no message

master
[email protected] pirms 1 mēnesi
vecāks
revīzija
c38aca6509
2 mainītis faili ar 1184 papildinājumiem un 174 dzēšanām
  1. +1116
    -119
      src/pages/client/ClientMaintainPage/ClientForm.js
  2. +68
    -55
      src/pages/pdf/PdfMaintainPage/index.js

+ 1116
- 119
src/pages/client/ClientMaintainPage/ClientForm.js
Failā izmaiņas netiks attēlotas, jo tās ir par lielu
Parādīt failu


+ 68
- 55
src/pages/pdf/PdfMaintainPage/index.js Parādīt failu

@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from 'react';
import { Button, Grid, InputLabel, TextField } from '@mui/material';
import { GeneralConfirmWindow, notifySaveSuccess } from "../../../utils/CommonFunction";
import axios from 'axios';
import {apiPath, adobeAPIKey} from "../../../auth/utils";
import {appURL, apiPath, adobeAPIKey} from "../../../auth/utils";
import {
GET_PDF_TEMPLATE_PATH,
GET_PDF_PATH,
@@ -37,55 +37,55 @@ function PDF() {
const refId = queryParams.get("refId");

const loadPdfForm = async (id, templateId = 0, clientId = 0) => {
if (!pdfLoaded) {
if (id > 0) {
// axios.get(`${apiPath}${GET_PDF_TEMPLATE_PATH}`, {
axios.get(`${apiPath}${GET_PDF_PATH}/${id}`, {
// responseType: 'arraybuffer', // Essential for binary data
})
.then((response) => {
if (response.status === 200) {
const res = response.data;
setRecord({ // WIP - allow to update all record
id : res.id,
clientId: res.clientId,
templateId: res.templateId,
})
setFormName(res.filename);
if (id > 0) {
// axios.get(`${apiPath}${GET_PDF_TEMPLATE_PATH}`, {
axios.get(`${apiPath}${GET_PDF_PATH}/${id}`, {
// responseType: 'arraybuffer', // Essential for binary data
})
.then((response) => {
if (response.status === 200) {
const res = response.data;
setRecord({ // WIP - allow to update all record
id : res.id,
clientId: res.clientId,
templateId: res.templateId,
})
setFormName(res.filename);

//Convert Base64 to binary data
handlePdfUrl(base64ToBinary(res.blobValue));
setPdfLoaded(true);
}
})
.catch(error => {
console.log(error);
return false;
});
//Convert Base64 to binary data
handlePdfUrl(base64ToBinary(res.blobValue));
setPdfLoaded(true);
}
})
.catch(error => {
console.log(error);
return false;
});

} else {
axios.get(`${apiPath}${GET_PDF_TEMPLATE_PATH}`, {
// responseType: 'arraybuffer', // Essential for binary data
params: {
templateId: templateId,
clientId: clientId,
},
})
.then((response) => {
if (response.status === 200) {
const res = response.data;
setFormName(res.filename);
//Convert Base64 to binary data
handlePdfUrl(base64ToBinary(res.blobValue));
setPdfLoaded(true);
}
})
.catch(error => {
console.log(error);
return false;
});
}
} else {
axios.get(`${apiPath}${GET_PDF_TEMPLATE_PATH}`, {
// responseType: 'arraybuffer', // Essential for binary data
params: {
templateId: templateId,
clientId: clientId,
},
})
.then((response) => {
if (response.status === 200) {
const res = response.data;
setFormName(res.filename);
//Convert Base64 to binary data
handlePdfUrl(base64ToBinary(res.blobValue));
setPdfLoaded(true);
}
})
.catch(error => {
console.log(error);
return false;
});
}
};

const handlePdfUrl = (pdfBytes) => {
@@ -134,7 +134,7 @@ function PDF() {
).catch(error => {
console.error('Preview error:', error);
setError('Failed to load PDF: ' + error.message);
// setError('Failed to load PDF: ' + error.message); // Commented out 'setError' since it's not defined
}).then(instance => {
URL.revokeObjectURL(pdfUrl);
@@ -151,7 +151,7 @@ function PDF() {
console.log("viewer: ", DCViewer);
} else {
console.error('AdobeDC not available');
setError('Adobe SDK not loaded');
// setError('Adobe SDK not loaded'); // Commented out 'setError' since it's not defined
}
};

@@ -191,29 +191,42 @@ function PDF() {
const handleSavePdf = async (metaData, content, options) => {
try {
const filledPdfBlob = new Blob([content], { type: 'application/pdf' });
// Create FormData to send the file to Spring Boot
const formData = new FormData();
formData.append('file', filledPdfBlob, 'filled_form.pdf');
formData.append('record', JSON.stringify(record));
setIsSaving(true);
// Send the filled PDF to your Spring Boot backend's save endpoint
await axios.post(`${apiPath}${POST_PDF_PATH}`, formData, {
headers: {
'Content-Type': 'multipart/form-data' // Important for file uploads
'Content-Type': 'multipart/form-data'
},
})
.then(response => {
setIsSaving(false);
console.log('PDF saved on server:', response.data);
const newId = response.data.data.id;
setRecord({
id: response.data.data.id,
id: newId,
clientId: record.clientId,
templateId: record.templateId
});
notifySaveSuccess()});
notifySaveSuccess();

/*
if(response.data.data.reload){
setPdfLoaded(false);
setViewerLoaded(false);
setAdobeDCView(null);
navigate(`/pdf/maintain/${newId}`, { replace: false });
}
*/
});
return {
code: window.AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
data: { metaData } // Return metaData to prevent t.data undefined
data: { metaData }
};
} catch (error) {
console.error('Error saving PDF:', error);


Notiek ielāde…
Atcelt
Saglabāt