document validation takes json certificates
This commit is contained in:
parent
b828e5197a
commit
6167d59501
@ -10,7 +10,7 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
documentFile: null as File | null,
|
documentFile: null as File | null,
|
||||||
certificateFile: null as File | null
|
certificateJson: null as Record<string, any> | null
|
||||||
};
|
};
|
||||||
|
|
||||||
const wrapper = document.createElement('div');
|
const wrapper = document.createElement('div');
|
||||||
@ -38,13 +38,15 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: #fafafa;
|
background: #fafafa;
|
||||||
`;
|
`;
|
||||||
box.textContent = `Drop ${label} PDF here`;
|
box.textContent = `Drop ${label} here`;
|
||||||
box.ondragover = e => { e.preventDefault(); box.style.background = '#eee'; };
|
box.ondragover = e => { e.preventDefault(); box.style.background = '#eee'; };
|
||||||
box.ondragleave = () => { box.style.background = '#fafafa'; };
|
box.ondragleave = () => { box.style.background = '#fafafa'; };
|
||||||
box.ondrop = e => {
|
box.ondrop = async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const file = e.dataTransfer?.files?.[0];
|
const file = e.dataTransfer?.files?.[0];
|
||||||
if (file && file.type === 'application/pdf') {
|
if (!file) return;
|
||||||
|
if (label === 'Document') {
|
||||||
|
if (file.type === 'application/pdf') {
|
||||||
onDrop(file);
|
onDrop(file);
|
||||||
box.textContent = `${label} uploaded: ${file.name}`;
|
box.textContent = `${label} uploaded: ${file.name}`;
|
||||||
box.style.borderColor = 'green';
|
box.style.borderColor = 'green';
|
||||||
@ -52,6 +54,19 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
} else {
|
} else {
|
||||||
alert('Please drop a valid PDF file.');
|
alert('Please drop a valid PDF file.');
|
||||||
}
|
}
|
||||||
|
} else if (label === 'Certificate') {
|
||||||
|
try {
|
||||||
|
const text = await file.text();
|
||||||
|
const json = JSON.parse(text);
|
||||||
|
onDrop(file);
|
||||||
|
state.certificateJson = json;
|
||||||
|
box.textContent = `Certificate loaded: ${file.name}`;
|
||||||
|
box.style.borderColor = 'green';
|
||||||
|
box.style.background = '#e6ffed';
|
||||||
|
} catch (err) {
|
||||||
|
alert('Invalid certificate file. Must be valid JSON.');
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return box;
|
return box;
|
||||||
};
|
};
|
||||||
@ -62,7 +77,6 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const certBox = createDropBox('Certificate', file => {
|
const certBox = createDropBox('Certificate', file => {
|
||||||
state.certificateFile = file;
|
|
||||||
checkSuccess();
|
checkSuccess();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -73,7 +87,7 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
container.appendChild(wrapper);
|
container.appendChild(wrapper);
|
||||||
|
|
||||||
function checkSuccess() {
|
function checkSuccess() {
|
||||||
if (state.documentFile && state.certificateFile) {
|
if (state.documentFile && state.certificateJson) {
|
||||||
showSuccessScreen();
|
showSuccessScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +122,7 @@ export function getDocumentValidation(container: HTMLElement) {
|
|||||||
successWrapper.appendChild(docLabel);
|
successWrapper.appendChild(docLabel);
|
||||||
|
|
||||||
const certLabel = document.createElement('div');
|
const certLabel = document.createElement('div');
|
||||||
certLabel.textContent = `Certificate: ${state.certificateFile!.name}`;
|
certLabel.textContent = `Certificate: ${state.certificateJson!.name}`;
|
||||||
successWrapper.appendChild(certLabel);
|
successWrapper.appendChild(certLabel);
|
||||||
|
|
||||||
// === Mocked verification data ===
|
// === Mocked verification data ===
|
||||||
|
Loading…
x
Reference in New Issue
Block a user