feature/IO-2681-Share-To-Teams-Button - Final revisions.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo } from "react";
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { Button } from "antd";
|
||||
import { useLocation } from "react-router-dom";
|
||||
@@ -31,7 +31,7 @@ const mapStateToProps = createStructuredSelector({
|
||||
* @param {Object} [props.additionalProps] - Additional props to pass to the rendered component.
|
||||
* @returns {React.ReactElement} A button or text link for sharing to Microsoft Teams.
|
||||
*/
|
||||
const ShareToTeamsButton = ({
|
||||
const ShareToTeamsComponent = ({
|
||||
bodyshop,
|
||||
messageTextOverride,
|
||||
urlOverride,
|
||||
@@ -54,24 +54,13 @@ const ShareToTeamsButton = ({
|
||||
splitKey: bodyshop && bodyshop.imexshopid
|
||||
});
|
||||
|
||||
const currentUrl = useMemo(
|
||||
() =>
|
||||
urlOverride ||
|
||||
encodeURIComponent(`${window.location.origin}${location.pathname}${location.search}${location.hash}`),
|
||||
[urlOverride, location]
|
||||
);
|
||||
|
||||
const pageTitle = useMemo(
|
||||
() =>
|
||||
pageTitleOverride ||
|
||||
encodeURIComponent(typeof document !== "undefined" ? document.title : t("general.actions.sharetoteams")),
|
||||
[pageTitleOverride, t]
|
||||
);
|
||||
|
||||
const messageText = useMemo(
|
||||
() => messageTextOverride || encodeURIComponent(t("general.actions.sharetoteams")),
|
||||
[messageTextOverride, t]
|
||||
);
|
||||
const currentUrl =
|
||||
urlOverride ||
|
||||
encodeURIComponent(`${window.location.origin}${location.pathname}${location.search}${location.hash}`);
|
||||
const pageTitle =
|
||||
pageTitleOverride ||
|
||||
encodeURIComponent(typeof document !== "undefined" ? document.title : t("general.actions.sharetoteams"));
|
||||
const messageText = messageTextOverride || encodeURIComponent(t("general.actions.sharetoteams"));
|
||||
|
||||
// Construct the Teams share URL with parameters
|
||||
const teamsShareUrl = `https://teams.microsoft.com/share?href=${currentUrl}&preText=${messageText}&title=${pageTitle}`;
|
||||
@@ -92,9 +81,9 @@ const ShareToTeamsButton = ({
|
||||
window.open(teamsShareUrl, "_blank", windowFeatures);
|
||||
};
|
||||
|
||||
// if (Share_To_Teams?.treatment !== "on") {
|
||||
// return null;
|
||||
// }
|
||||
if (Share_To_Teams?.treatment !== "on") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (noIcon) {
|
||||
return (
|
||||
@@ -120,7 +109,7 @@ const ShareToTeamsButton = ({
|
||||
);
|
||||
};
|
||||
|
||||
ShareToTeamsButton.propTypes = {
|
||||
ShareToTeamsComponent.propTypes = {
|
||||
messageTextOverride: PropTypes.string,
|
||||
urlOverride: PropTypes.string,
|
||||
pageTitleOverride: PropTypes.string,
|
||||
@@ -129,7 +118,7 @@ ShareToTeamsButton.propTypes = {
|
||||
buttonStyle: PropTypes.object,
|
||||
buttonIconStyle: PropTypes.object,
|
||||
linkText: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
||||
additionalProps: PropTypes.object
|
||||
additionalProps: PropTypes.oneOfType([PropTypes.object, PropTypes.node])
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(ShareToTeamsButton);
|
||||
export default connect(mapStateToProps)(ShareToTeamsComponent);
|
||||
Reference in New Issue
Block a user