Skip to content

Commit

Permalink
Merge pull request #820 from adobecom/MWPW-158944
Browse files Browse the repository at this point in the history
MWPW-158944
  • Loading branch information
Blainegunn authored Sep 25, 2024
2 parents b7fee35 + 1dba48c commit 482d705
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
4 changes: 2 additions & 2 deletions acrobat/blocks/verb-widget/limits.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const LIMITS = {
fillsign: {
maxFileSize: 100000000, // 1 MB
maxFileSizeFriendly: '100 MB', // 1 MB
maxFileSize: 100000000, // 100 MB
maxFileSizeFriendly: '100 MB', // 100 MB
acceptedFiles: ['application/pdf'],
maxNumFiles: 1,
mobileApp: true,
Expand Down
52 changes: 29 additions & 23 deletions acrobat/blocks/verb-widget/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ const setUser = () => {
localStorage.setItem('unity.user', 'true');
};

const handleError = (err, errTxt, str, strTwo) => {
err.classList.add('verb-error');
err.classList.remove('hide');
errTxt.textContent = `${window.mph[str]} ${strTwo || ''}`;

setTimeout(() => {
err.classList.remove('verb-error');
err.classList.add('hide');
}, 5000);
};

const setDraggingClass = (widget, shouldToggle) => {
// eslint-disable-next-line chai-friendly/no-unused-expressions
shouldToggle ? widget.classList.add('dragging') : widget.classList.remove('dragging');
Expand Down Expand Up @@ -176,39 +165,56 @@ export default async function init(element) {
});

// Errors, Analytics & Logging
const handleError = (str) => {
errorState.classList.add('verb-error');
errorState.classList.remove('hide');
errorStateText.textContent = str;

setTimeout(() => {
errorState.classList.remove('verb-error');
errorState.classList.add('hide');
}, 5000);
};

window.addEventListener('unity:show-error-toast', (e) => {
// eslint-disable-next-line no-console
console.log(`⛔️ Error Code - ${e.detail?.code}`);

if (e.detail?.code === 'only_accept_one_file') {
handleError(errorState, errorStateText, 'verb-widget-error-multi');
if (e.detail?.code.includes('error_only_accept_one_file')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'unsupported_type') {
handleError(errorState, errorStateText, 'verb-widget-error-unsupported');
if (e.detail?.code.includes('error_unsupported_type')) {
handleError(e.detail?.message);
verbAnalytics('error:unsupported_type', VERB);
}

if (e.detail?.code === 'empty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-empty');
if (e.detail?.code.includes('error_empty_file')) {
handleError(e.detail?.message);
verbAnalytics('error:empty_file', VERB);
}

// Code may be wrong. should be 'file_too_large'
if (e.detail?.code === 'file_too_largempty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-large', LIMITS[VERB].maxFileSizeFriendly);
if (e.detail?.code.includes('error_file_too_large')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

if (e.detail?.code === 'max_page_count') {
handleError(errorState, errorStateText, 'verb-widget-error-max', LIMITS[VERB].maxNumFiles);
if (e.detail?.code.includes('error_max_page_count')) {
handleError(e.detail?.message);
verbAnalytics('error:max_page_count', VERB);
}

if (e.detail?.code.includes('error_generic')
|| e.detail?.code.includes('error_max_quota_exceeded')
|| e.detail?.code.includes('error_no_storage_provision')
|| e.detail?.code.includes('error_duplicate_asset')) {
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

// acrobat:verb-fillsign:error:page_count_missing_from_metadata_api
// acrobat:verb-fillsign:error:403
// acrobat:verb-fillsign:error
// LANA for 403
});
}
Expand Down
10 changes: 5 additions & 5 deletions acrobat/scripts/alloy/verb-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ if (params.dropzone2) {
appTags.push('dropzone2');
}

export default function init(eventName, verb) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName}`);
export default function init(eventName, verb, metaData) {
console.log(`📡 Event Name - acrobat:verb-${verb}:${eventName} - metaData: ${metaData?.type} / ${metaData?.size} `);
const event = {
documentUnloading: true,
data: {
Expand Down Expand Up @@ -66,10 +66,10 @@ export default function init(eventName, verb) {
dcweb2: {
event: { pagename: `acrobat:verb-${verb}:${eventName}` },
content: {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
size: '2-5MB',
type: metaData?.type,
size: metaData?.size,
count: 1,
extension: 'docx',
// extension: 'docx', may not be needed
},
source: {
user_agent: navigator.userAgent,
Expand Down
3 changes: 1 addition & 2 deletions acrobat/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const setLibs = (prodLibs, location) => {
if (branch === 'main' && hostname === 'www.stage.adobe.com') return 'https://www.stage.adobe.com/libs';
if (!(hostname.includes('.hlx.') || hostname.includes('local') || hostname.includes('stage'))) return prodLibs;
if (branch === 'local') return 'http://localhost:6456/libs';
const tld = hostname.includes('live') ? 'live' : 'page';
return branch.includes('--') ? `https://${branch}.hlx.${tld}/libs` : `https://${branch}--milo--adobecom.hlx.${tld}/libs`;
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
};

const getLocale = (locales, pathname = window.location.pathname) => {
Expand Down

0 comments on commit 482d705

Please sign in to comment.