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 = {
|
||||
documentFile: null as File | null,
|
||||
certificateFile: null as File | null
|
||||
certificateJson: null as Record<string, any> | null
|
||||
};
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
@ -38,19 +38,34 @@ export function getDocumentValidation(container: HTMLElement) {
|
||||
cursor: pointer;
|
||||
background: #fafafa;
|
||||
`;
|
||||
box.textContent = `Drop ${label} PDF here`;
|
||||
box.textContent = `Drop ${label} here`;
|
||||
box.ondragover = e => { e.preventDefault(); box.style.background = '#eee'; };
|
||||
box.ondragleave = () => { box.style.background = '#fafafa'; };
|
||||
box.ondrop = e => {
|
||||
box.ondrop = async e => {
|
||||
e.preventDefault();
|
||||
const file = e.dataTransfer?.files?.[0];
|
||||
if (file && file.type === 'application/pdf') {
|
||||
onDrop(file);
|
||||
box.textContent = `${label} uploaded: ${file.name}`;
|
||||
box.style.borderColor = 'green';
|
||||
box.style.background = '#e6ffed';
|
||||
} else {
|
||||
alert('Please drop a valid PDF file.');
|
||||
if (!file) return;
|
||||
if (label === 'Document') {
|
||||
if (file.type === 'application/pdf') {
|
||||
onDrop(file);
|
||||
box.textContent = `${label} uploaded: ${file.name}`;
|
||||
box.style.borderColor = 'green';
|
||||
box.style.background = '#e6ffed';
|
||||
} else {
|
||||
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;
|
||||
@ -62,7 +77,6 @@ export function getDocumentValidation(container: HTMLElement) {
|
||||
});
|
||||
|
||||
const certBox = createDropBox('Certificate', file => {
|
||||
state.certificateFile = file;
|
||||
checkSuccess();
|
||||
});
|
||||
|
||||
@ -73,7 +87,7 @@ export function getDocumentValidation(container: HTMLElement) {
|
||||
container.appendChild(wrapper);
|
||||
|
||||
function checkSuccess() {
|
||||
if (state.documentFile && state.certificateFile) {
|
||||
if (state.documentFile && state.certificateJson) {
|
||||
showSuccessScreen();
|
||||
}
|
||||
}
|
||||
@ -108,7 +122,7 @@ export function getDocumentValidation(container: HTMLElement) {
|
||||
successWrapper.appendChild(docLabel);
|
||||
|
||||
const certLabel = document.createElement('div');
|
||||
certLabel.textContent = `Certificate: ${state.certificateFile!.name}`;
|
||||
certLabel.textContent = `Certificate: ${state.certificateJson!.name}`;
|
||||
successWrapper.appendChild(certLabel);
|
||||
|
||||
// === Mocked verification data ===
|
||||
|
Loading…
x
Reference in New Issue
Block a user