Skip to content

Commit

Permalink
MWPW-158944
Browse files Browse the repository at this point in the history
  • Loading branch information
Blainegunn committed Sep 23, 2024
1 parent 290a911 commit 1b231bf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 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
34 changes: 17 additions & 17 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 @@ -147,32 +136,43 @@ 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) => {
console.log(`⛔️ Error Code - ${e.detail?.code}`);

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

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

if (e.detail?.code === 'empty_file') {
handleError(errorState, errorStateText, 'verb-widget-error-empty');
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);
handleError(e.detail?.message);
verbAnalytics('error', VERB);
}

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

Expand All @@ -183,5 +183,5 @@ export default async function init(element) {
});
}

// const ce = (new CustomEvent('unity:show-error-toast', { detail: { code: 'only_accept_one_file', message: 'Error message' } }));
// const ce = (new CustomEvent('unity:show-error-toast', { detail: { event: 'choose-file-clicked', data: {size: 33, type: 'df'}, code: 'only_accept_one_file', message: 'Error message' } }));
// dispatchEvent(ce)
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 1b231bf

Please sign in to comment.