Skip to content

Commit

Permalink
only post to parent once
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandria.gomez authored and alexandria.gomez committed Oct 16, 2023
1 parent f87915a commit 285e7d3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ export default function LaserficheRepositoryAccessWebPart(
loginWindow.close();
} else if (event.data) {
const parsedError: AbortedLoginError = event.data;
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
if (parsedError.ErrorMessage && parsedError.ErrorType) {
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const fileNameValidation = 'Please provide a valid filename';
const fileNameWithBacklash =
'Please provide a valid filename without backslash';
const folderValidation = 'Please provide a folder name';
const folderNameValidation = 'Entry names cannot contain backslash';
const folderBackslashNameValidation = 'Entry names cannot contain backslash';
const folderExists = 'Object already exists';

export default function RepositoryViewComponent(props: {
Expand Down Expand Up @@ -720,8 +720,8 @@ function CreateFolderModal(props: {

const createNewFolderAsync: () => Promise<void> = async () => {
if (folderName) {
if (/^[^\\\\]*$/.test(folderName)) {
setCreateFolderNameValidationMessage(folderNameValidation);
if (/^[\\\\]*$/.test(folderName)) {
setCreateFolderNameValidationMessage(folderBackslashNameValidation);
} else {
setCreateFolderNameValidationMessage(undefined);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ export default function LaserficheAdminConfiguration(
loginWindow.close();
} else if (event.data) {
const parsedError: AbortedLoginError = event.data;
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
if (parsedError.ErrorMessage && parsedError.ErrorType) {
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function SendToLaserficheLoginComponent(
> = React.useRef();

const [loggedIn, setLoggedIn] = React.useState<boolean>(false);
let sentPostMessage = false;

const region = getRegion();

Expand All @@ -61,7 +62,10 @@ export default function SendToLaserficheLoginComponent(
const loginText: JSX.Element | undefined = getLoginText();

const autoLoginCompleted: () => Promise<void> = async () => {
window.opener.postMessage('loginWindowSuccess', window.origin);
if (!sentPostMessage) {
window.opener.postMessage('loginWindowSuccess', window.origin);
sentPostMessage = true;
}
};

const loginCompleted: () => Promise<void> = async () => {
Expand Down Expand Up @@ -91,9 +95,15 @@ export default function SendToLaserficheLoginComponent(
) => {
const logOutError = ev.detail;
if (autoLogout && !logOutError) {
window.opener.postMessage('loginWindowSuccess', window.origin);
if (!sentPostMessage) {
window.opener.postMessage('loginWindowSuccess', window.origin);
sentPostMessage = true;
}
} else if (logOutError) {
window.opener.postMessage(logOutError, window.origin);
if (!sentPostMessage) {
window.opener.postMessage(logOutError, window.origin);
sentPostMessage = true;
}
} else {
setLoggedIn(false);
}
Expand Down Expand Up @@ -154,7 +164,10 @@ export default function SendToLaserficheLoginComponent(
autoLoginCompleted
);
} else if (loginComponent.current.state === LoginState.LoggedOut) {
window.opener.postMessage('loginWindowSuccess', window.origin);
if (!sentPostMessage) {
window.opener.postMessage('loginWindowSuccess', window.origin);
sentPostMessage = true;
}
} else {
loginComponent.current.addEventListener(
'loginCompleted',
Expand Down Expand Up @@ -200,6 +213,7 @@ export default function SendToLaserficheLoginComponent(
}
};

cleanUpFunction();
void setUpLoginComponentAsync();

return cleanUpFunction;
Expand Down Expand Up @@ -284,10 +298,12 @@ export default function SendToLaserficheLoginComponent(
loginWindow.close();
} else if (event.data) {
const parsedError: AbortedLoginError = event.data;
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
if (parsedError.ErrorMessage && parsedError.ErrorType) {
loginWindow.close();
window.alert(
`Error retrieving login credentials: ${parsedError.ErrorMessage}. Please try again.`
);
}
}
}
});
Expand Down

0 comments on commit 285e7d3

Please sign in to comment.