Pereiti prie turinio

GDPR-efterlevnad

This JavaScript code is quite large, functional, but suffers heavily from **repetition** (violating the DRY principle) and **scattered logic**. You have multiple nearly identical blocks of code for handling different GDPR form submissions. The primary goal of refactoring here is to make the code more maintainable, scalable, and readable by consolidating repetitive actions into reusable functions or using event delegation. Here is a comprehensive refactored version, followed by an explanation of the improvements. --- ## 🚀 Refactored JavaScript Code ```javascript // --- Global State Variables (Keep these at the top for clarity) --- let consentGiven = false; let email = ''; let type = ''; /** * @typedef {Object} GdprRequestConfig * @property {string} buttonSelector - Selector for the trigger button. * @property {string} formId - ID of the form to slide down. * @property {string} requestType - The 'type' value passed to openVerificationModal. */ /** * Configuration array defining all GDPR requests. * This is the single source of truth for your forms. */ const gdprRequests = [ { buttonSelector: '#btn-gdpr-edit-account-request', formId: '#form-gdpr-edit-account-request', requestType: 'customer/edit' }, { buttonSelector: '#btn-gdpr-requests-request', formId: '#form-gdpr-requests-request', requestType: 'customer/requests' }, { buttonSelector: '#btn-gdpr-personal-information-request', formId: '#form-gdpr-personal-information-request', requestType: 'customer/personal_info' }, { buttonSelector: '#btn-gdpr-orders-request', formId: '#form-gdpr-orders-request', requestType: 'customer/orders' }, { buttonSelector: '#btn-gdpr-personal-data-report-request', formId: '#form-gdpr-personal-data-report-request', requestType: 'customer/report' }, { buttonSelector: '#btn-gdpr-delete-account-request', formId: '#form-gdpr-delete-account-request', requestType: 'customer/delete' } ]; // =============================================================== // CORE MODAL & UTILITY FUNCTIONS (Keep these as they are good) // =============================================================== /** * Handles the opening sequence for the verification modal. */ function openVerificationModal() { toggleFadeiSense(document.querySelector("#