
export const getCKEditorDocumentId = (documentId, userId, formType) => {
  if (documentId) return `${documentId}-${userId}-${formType}`
  return `${userId}-${formType}`
}

export function generateTokenRequest(documentId, userId, formType) {
  return () => {
    return new Promise( ( resolve, reject ) => {
        const xhr = new XMLHttpRequest();
  
        xhr.open( 'GET', '/ckeditor-token' );
  
        xhr.addEventListener( 'load', () => {
            const statusCode = xhr.status;
            const xhrResponse = xhr.response;
  
            if ( statusCode < 200 || statusCode > 299 ) {
                return reject( new Error( 'Cannot download a new token!' ) );
            }
  
            return resolve( xhrResponse );
        } );
  
        xhr.addEventListener( 'error', () => reject( new Error( 'Network error' ) ) );
        xhr.addEventListener( 'abort', () => reject( new Error( 'Abort' ) ) );
  
        if (documentId) xhr.setRequestHeader( 'document-id', documentId );
        if (userId) xhr.setRequestHeader( 'user-id', userId );
        if (formType) xhr.setRequestHeader( 'form-type', formType );
  
        xhr.send();
    } );
  }
}


export const getCKEditorDocumentId = (documentId, userId, formType) => {
  if (documentId) return `${documentId}-${formType}`
  return `${userId}-${formType}`
}

export function generateTokenRequest(documentId, userId, formType) {
  return () => {
    return new Promise( ( resolve, reject ) => {
        const xhr = new XMLHttpRequest();
  
        xhr.open( 'GET', '/ckeditor-token' );
  
        xhr.addEventListener( 'load', () => {
            const statusCode = xhr.status;
            const xhrResponse = xhr.response;
  
            if ( statusCode < 200 || statusCode > 299 ) {
                return reject( new Error( 'Cannot download a new token!' ) );
            }
  
            return resolve( xhrResponse );
        } );
  
        xhr.addEventListener( 'error', () => reject( new Error( 'Network error' ) ) );
        xhr.addEventListener( 'abort', () => reject( new Error( 'Abort' ) ) );
  
        if (documentId) xhr.setRequestHeader( 'document-id', documentId );
        if (userId) xhr.setRequestHeader( 'user-id', userId );
        if (formType) xhr.setRequestHeader( 'form-type', formType );
  
        xhr.send();
    } );
  }
}

Fix editor document id creation
Fix editor document id creation
