Skip to content

Commit

Permalink
feat: generate a universal link that includes the enterprise slug
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Oct 1, 2024
1 parent 06819d8 commit 8f8b447
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/components/settings/SettingsAccessTab/ActionsTableCell.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React, { useState } from 'react';
import { ActionRow, Button } from '@openedx/paragon';
import PropTypes from 'prop-types';
import { getConfig } from '@edx/frontend-platform/config';
import { logError } from '@edx/frontend-platform/logging';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';

import { FormattedMessage } from '@edx/frontend-platform/i18n';
import LinkDeactivationAlertModal from './LinkDeactivationAlertModal';
import LinkCopiedToast from './LinkCopiedToast';
import { SETTINGS_ACCESS_EVENTS } from '../../../eventTracking';
import getInviteURL from './utils';

const ActionsTableCell = ({ row, onDeactivateLink, enterpriseUUID }) => {
const ActionsTableCell = ({
row,
onDeactivateLink,
enterpriseUUID,
enterpriseSlug,
}) => {
const [isLinkDeactivationModalOpen, setIsLinkDeactivationModalOpen] = useState(false);
const [isCopyLinkToastOpen, setIsCopyLinkToastOpen] = useState(false);
const { isValid, uuid: inviteKeyUUID } = row.original;
Expand All @@ -25,7 +30,7 @@ const ActionsTableCell = ({ row, onDeactivateLink, enterpriseUUID }) => {
return;
}
const addToClipboard = async () => {
const inviteURL = `${getConfig().ENTERPRISE_LEARNER_PORTAL_URL}/invite/${inviteKeyUUID}`;
const inviteURL = getInviteURL(enterpriseSlug, inviteKeyUUID);
try {
await navigator.clipboard.writeText(inviteURL);
setIsCopyLinkToastOpen(true);
Expand Down Expand Up @@ -107,6 +112,7 @@ ActionsTableCell.propTypes = {
}).isRequired,
onDeactivateLink: PropTypes.func,
enterpriseUUID: PropTypes.string.isRequired,
enterpriseSlug: PropTypes.string.isRequired,
};

ActionsTableCell.defaultProps = {
Expand Down
8 changes: 5 additions & 3 deletions src/components/settings/SettingsAccessTab/LinkTableCell.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import PropTypes from 'prop-types';
import { getConfig } from '@edx/frontend-platform/config';

const LinkTableCell = ({ row }) => {
import getInviteURL from './utils';

const LinkTableCell = ({ row, enterpriseSlug }) => {
const { uuid } = row.original;
return `${getConfig().ENTERPRISE_LEARNER_PORTAL_URL}/invite/${uuid}`;
return getInviteURL(enterpriseSlug, uuid);
};

LinkTableCell.propTypes = {
Expand All @@ -12,6 +13,7 @@ LinkTableCell.propTypes = {
uuid: PropTypes.string,
}),
}).isRequired,
enterpriseSlug: PropTypes.string.isRequired,
};

export default LinkTableCell;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { MAX_UNIVERSAL_LINKS } from '../data/constants';

const SettingsAccessLinkManagement = ({
enterpriseUUID,
enterpriseSlug,
isUniversalLinkEnabled,
updatePortalConfiguration,
}) => {
Expand Down Expand Up @@ -157,7 +158,13 @@ const SettingsAccessLinkManagement = ({
description: 'Column header for the link management data table in the settings page.',
}),
accessor: 'link',
Cell: LinkTableCell,
// eslint-disable-next-line react/no-unstable-nested-components
Cell: (props) => (
<LinkTableCell
{...props}
enterpriseSlug={enterpriseSlug}
/>
),
},
{
Header: intl.formatMessage({
Expand Down Expand Up @@ -196,6 +203,7 @@ const SettingsAccessLinkManagement = ({
<ActionsTableCell
{...props}
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseSlug}
onDeactivateLink={handleDeactivatedLink}
/>
),
Expand Down Expand Up @@ -229,6 +237,7 @@ const SettingsAccessLinkManagement = ({

const mapStateToProps = (state) => ({
enterpriseUUID: state.portalConfiguration.enterpriseId,
enterpriseSlug: state.portalConfiguration.enterpriseSlug,
isUniversalLinkEnabled: state.portalConfiguration.enableUniversalLink,
});

Expand All @@ -238,6 +247,7 @@ const mapDispatchToProps = dispatch => ({

SettingsAccessLinkManagement.propTypes = {
enterpriseUUID: PropTypes.string.isRequired,
enterpriseSlug: PropTypes.string.isRequired,
isUniversalLinkEnabled: PropTypes.bool.isRequired,
updatePortalConfiguration: PropTypes.func.isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TEST_INVITE_KEY_UUID = 'test-uuid-1';

const ActionsTableCellWrapper = (props) => (
<IntlProvider locale="en">
<ActionsTableCell enterpriseUUID="test-enterprise-id" {...props} />
<ActionsTableCell enterpriseUUID="test-enterprise-id" enterpriseSlug="test-enterprise" {...props} />
</IntlProvider>
);

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('ActionsTableCell', () => {
);
const copyBtn = screen.getByText('Copy');
userEvent.click(copyBtn);
const expectedURL = `http://localhost:8734/invite/${TEST_INVITE_KEY_UUID}`;
const expectedURL = `http://localhost:8734/test-enterprise/invite/${TEST_INVITE_KEY_UUID}`;
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(expectedURL);
await waitFor(() => expect(screen.getByText('Link copied to clipboard')));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('LinkTableCell', () => {
uuid: 'test-invite-key-uuid',
},
},
enterpriseSlug: 'test-enterprise',
};
const tree = renderer
.create(<LinkTableCell {...props} />)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LinkTableCell renders correctly 1`] = `"http://localhost:8734/invite/test-invite-key-uuid"`;
exports[`LinkTableCell renders correctly 1`] = `"http://localhost:8734/test-enterprise/invite/test-invite-key-uuid"`;
5 changes: 5 additions & 0 deletions src/components/settings/SettingsAccessTab/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getConfig } from '@edx/frontend-platform/config';

export default function getInviteURL(enterpriseSlug, inviteUUID) {
return `${getConfig().ENTERPRISE_LEARNER_PORTAL_URL}/${enterpriseSlug}/invite/${inviteUUID}`;
}

0 comments on commit 8f8b447

Please sign in to comment.