Add showConfirmationModal
This commit is contained in:
parent
ecba13594b
commit
37bdb3dad3
@ -171,37 +171,56 @@ export default class ModalService {
|
|||||||
if (this.modal) this.modal.style.display = 'none';
|
if (this.modal) this.modal.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
// async confirmPairing() {
|
async showConfirmationModal(options: ConfirmationModalOptions): Promise<boolean> {
|
||||||
// const service = await Services.getInstance();
|
// Create modal element
|
||||||
// if (this.modal) this.modal.style.display = 'none';
|
const modalElement = document.createElement('div');
|
||||||
|
modalElement.id = 'confirmation-modal';
|
||||||
|
modalElement.innerHTML = `
|
||||||
|
<div class="modal-overlay">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2>${options.title}</h2>
|
||||||
|
<div class="modal-body">
|
||||||
|
${options.content}
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button id="cancel-button" class="btn btn-secondary">${options.cancelText || 'Annuler'}</button>
|
||||||
|
<button id="confirm-button" class="btn btn-primary">${options.confirmText || 'Confirmer'}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
// // We send the prd update
|
// Add modal to document
|
||||||
// if (this.stateId && this.processId) {
|
document.body.appendChild(modalElement);
|
||||||
// try {
|
|
||||||
// const createPrdUpdateReturn = service.createPrdUpdate(this.processId, this.stateId);
|
|
||||||
// await service.handleApiReturn(createPrdUpdateReturn);
|
|
||||||
// } catch (e) {
|
|
||||||
// throw e;
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// throw new Error('No currentPcdCommitment');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// try {
|
// Return promise that resolves with user choice
|
||||||
// const approveChangeReturn = await service.approveChange(this.processId!, this.stateId!);
|
return new Promise((resolve) => {
|
||||||
// await service.handleApiReturn(approveChangeReturn);
|
const confirmButton = modalElement.querySelector('#confirm-button');
|
||||||
|
const cancelButton = modalElement.querySelector('#cancel-button');
|
||||||
|
const modalOverlay = modalElement.querySelector('.modal-overlay');
|
||||||
|
|
||||||
// service.pairDevice(this.paired_addresses, this.processId);
|
const cleanup = () => {
|
||||||
// this.paired_addresses = [];
|
modalElement.remove();
|
||||||
// this.processId = null;
|
};
|
||||||
// this.stateId = null;
|
|
||||||
// const newDevice = service.dumpDeviceFromMemory();
|
confirmButton?.addEventListener('click', () => {
|
||||||
// console.log(newDevice);
|
cleanup();
|
||||||
// await service.saveDeviceInDatabase(newDevice);
|
resolve(true);
|
||||||
// } catch (e) {
|
});
|
||||||
// throw e;
|
|
||||||
// }
|
cancelButton?.addEventListener('click', () => {
|
||||||
// }
|
cleanup();
|
||||||
|
resolve(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
modalOverlay?.addEventListener('click', (e) => {
|
||||||
|
if (e.target === modalOverlay) {
|
||||||
|
cleanup();
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async closeConfirmationModal() {
|
async closeConfirmationModal() {
|
||||||
const service = await Services.getInstance();
|
const service = await Services.getInstance();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user