Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding toast after deleting a group #1383

Merged
merged 9 commits into from
Jan 16, 2025
4 changes: 2 additions & 2 deletions src/components/PeopleManagement/GroupCardGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const GroupCardGrid = ({ groups }) => {
lg: 6,
xl: 4,
}}
hasEqualColumnHeights="true"
hasEqualColumnHeights
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was giving a warning, I fixed it but it's unrelated to this ticket

>
{overflowGroups.map((group) => (
<GroupDetailCard group={group} />
Expand All @@ -61,7 +61,7 @@ const GroupCardGrid = ({ groups }) => {
};

GroupCardGrid.propTypes = {
groups: PropTypes.shape.isRequired,
groups: PropTypes.arrayOf(PropTypes.shape({})),
};

export default GroupCardGrid;
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ const DeleteGroupModal = ({
try {
await LmsApiService.removeEnterpriseGroup(group?.uuid);
close();
const param = {
toast: true,
};
const urlParams = new URLSearchParams(param);
// redirect back to the people management page
window.location.href = `/${enterpriseSlug}/admin/${ROUTE_NAMES.peopleManagement}`;
window.location.href = `/${enterpriseSlug}/admin/${ROUTE_NAMES.peopleManagement}/?${urlParams.toString()}`;
} catch (error) {
logError(error);
openError();
Expand Down
25 changes: 21 additions & 4 deletions src/components/PeopleManagement/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import PropTypes from 'prop-types';
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
import {
ActionRow,
Button,
Skeleton,
useToggle,
ActionRow, Button, Skeleton, Toast, useToggle,
} from '@openedx/paragon';
import { Add } from '@openedx/paragon/icons';

Expand All @@ -28,6 +25,13 @@
description: 'Title for the people management page.',
});

const [isToastOpen, openToast, closeToast] = useToggle(false);
const toastText = intl.formatMessage({
id: 'admin.portal.people.management.group.deleted.toast',
defaultMessage: 'Group deleted',
description: 'Toast text after a user has deleted a group.',
});

const { enterpriseSubsidyTypes } = useContext(EnterpriseSubsidiesContext);
const { data, isLoading: isGroupsLoading } = useAllEnterpriseGroups(enterpriseId);

Expand All @@ -45,6 +49,14 @@
}
}, [data]);

useEffect(() => {
// parameter is for confirmation toast after deleting a group
const searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('toast')) {
openToast();

Check warning on line 56 in src/components/PeopleManagement/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/PeopleManagement/index.jsx#L56

Added line #L56 was not covered by tests
kiram15 marked this conversation as resolved.
Show resolved Hide resolved
}
}, [openToast]);

let groupsCardSection = (<Skeleton height="20vh" />);
if (!isGroupsLoading) {
if (groups && groups.length > 0) {
Expand All @@ -58,6 +70,11 @@
<>
<Helmet title={PAGE_TITLE} />
<Hero title={PAGE_TITLE} />
{isToastOpen && (
<Toast onClose={closeToast} show={isToastOpen}>

Check warning on line 74 in src/components/PeopleManagement/index.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/PeopleManagement/index.jsx#L74

Added line #L74 was not covered by tests
kiram15 marked this conversation as resolved.
Show resolved Hide resolved
{toastText}
</Toast>
)}
<div className="mx-3 mt-4">
<ActionRow className="mb-4">
<span className="flex-column">
Expand Down
Loading