Skip to content

Commit

Permalink
fix: more PR stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
kiram15 committed Oct 10, 2024
1 parent 68b99ac commit 61d9d90
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 97 deletions.
44 changes: 25 additions & 19 deletions src/components/PeopleManagement/EditGroupNameModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import LmsApiService from '../../data/services/LmsApiService';
import GeneralErrorModal from './GeneralErrorModal';

const EditGroupNameModal = ({
group, isOpen, close, setShowToast, setToastMessage,
group, isOpen, close, setShowToast, setToastMessage, forceUpdate,
}) => {
const intl = useIntl();
const [isErrorOpen, openError, closeError] = useToggle(false);
const [name, setName] = useState(group?.name);
const [nameLength, setNameLength] = useState(group?.name.length || 0);
const [name, setName] = useState(group.name);
const [nameLength, setNameLength] = useState(group.name.length || 0);
const [buttonState, setButtonState] = useState('default');

const handleGroupNameChange = (e) => {
Expand All @@ -32,25 +32,25 @@ const EditGroupNameModal = ({

const editEnterpriseGroup = async () => {
setButtonState('pending');
const formData = { name };
const response = await LmsApiService.updateEnterpriseGroup(group?.uuid, formData);
if (response.status === 200) {
setButtonState('complete');
close();
setShowToast(true);
setToastMessage('Group name updated');
} else {
try {
const formData = { name };
const response = await LmsApiService.updateEnterpriseGroup(group.uuid, formData);
if (response.status === 200) {
setButtonState('complete');
close();
setShowToast(true);
setToastMessage('Group name updated');
forceUpdate();
}
} catch (error) {
openError();
}
setButtonState('default');
};

return (
<>
<GeneralErrorModal
isOpen={isErrorOpen}
close={closeError}
/>
<GeneralErrorModal isOpen={isErrorOpen} close={closeError} />
<ModalDialog
title="Edit group"
isOpen={isOpen}
Expand Down Expand Up @@ -85,21 +85,26 @@ const EditGroupNameModal = ({
default: intl.formatMessage({
id: 'adminPortal.peopleManagement.editGroupNameModal.button.save',
defaultMessage: 'Save',
description: 'Label for the download button in the module activity report page.',
description:
'Label for the download button in the module activity report page.',
}),
pending: intl.formatMessage({
id: 'adminPortal.peopleManagement.editGroupNameModal.button.pending',
defaultMessage: 'Saving',
description: 'Label for the download button in the module activity report page when the download is in progress.',
description:
'Label for the download button in the module activity report page when the download is in progress.',
}),
complete: intl.formatMessage({
id: 'adminPortal.peopleManagement.editGroupNameModal.button.complete',
defaultMessage: 'Saved',
description: 'Label for the download button in the module activity report page when the download is complete.',
description:
'Label for the download button in the module activity report page when the download is complete.',
}),
}}
icons={{
pending: <Spinner animation="border" variant="light" size="sm" />,
pending: (
<Spinner animation="border" variant="light" size="sm" />
),
}}
disabledStates={['pending']}
onClick={editEnterpriseGroup}
Expand All @@ -120,6 +125,7 @@ EditGroupNameModal.propTypes = {
close: PropTypes.func.isRequired,
setShowToast: PropTypes.func.isRequired,
setToastMessage: PropTypes.func.isRequired,
forceUpdate: PropTypes.func.isRequired,
};

export default EditGroupNameModal;
166 changes: 90 additions & 76 deletions src/components/PeopleManagement/GroupDetailPage.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useState } from 'react';
import React, { useReducer, useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
import {
Breadcrumb, Card, Hyperlink, Icon, IconButton, IconButtonWithTooltip, Toast, useToggle,
Breadcrumb, Card, Hyperlink, Icon, IconButton, IconButtonWithTooltip, Skeleton, Toast, useToggle,
} from '@openedx/paragon';
import { Delete, Edit } from '@openedx/paragon/icons';

Expand All @@ -19,6 +19,14 @@ const GroupDetailPage = () => {
const [isEditModalOpen, openEditModal, closeEditModal] = useToggle(false);
const [showToast, setShowToast] = useState(false);
const [toastMessage, setToastMessage] = useState('');
const [isLoading, setIsLoading] = useState(true);
const [, forceUpdate] = useReducer(x => x + 1, 0);

useEffect(() => {
if (enterpriseGroup !== undefined) {
setIsLoading(false);
}
}, [enterpriseGroup]);

const tooltipContent = (
<FormattedMessage
Expand All @@ -28,84 +36,90 @@ const GroupDetailPage = () => {
/>
);

const budgetNameAndEdit = (
<>
<span className="pr-1">{enterpriseGroup?.name}</span>
<IconButton
key="editGroupTooltip"
src={Edit}
iconAs={Icon}
alt="Edit group"
className="mr-2"
onClick={openEditModal}
size="sm"
data-testid="edit-modal-icon"
/>
</>
);
return (
<div className="pt-4 pl-4">
<Toast
onClose={() => setShowToast(false)}
show={showToast}
>
{toastMessage}
</Toast>
<DeleteGroupModal
group={enterpriseGroup}
isOpen={isDeleteModalOpen}
close={closeDeleteModal}
/>
<EditGroupNameModal
group={enterpriseGroup}
isOpen={isEditModalOpen}
close={closeEditModal}
setShowToast={setShowToast}
setToastMessage={setToastMessage}
/>
<Breadcrumb
aria-label="people management breadcrumb navigation"
links={[
{
label: intl.formatMessage({
id: 'adminPortal.peopleManagement.breadcrumb',
defaultMessage: 'People Management',
description: 'Breadcrumb label for the people management page',
}),
href: `/${enterpriseSlug}/admin/${ROUTE_NAMES.peopleManagement}`,
},
]}
activeLabel={enterpriseGroup?.name}
/>

<Card orientation="horizontal">
<Card.Body>
<Card.Header
title={budgetNameAndEdit}
subtitle={`${enterpriseGroup?.acceptedMembersCount} accepted members`}
{isLoading && <Skeleton className="mt-3" height={200} count={1} />}
{!isLoading && (
<>
<Toast onClose={() => setShowToast(false)} show={showToast}>
{toastMessage}
</Toast>
<DeleteGroupModal
group={enterpriseGroup}
isOpen={isDeleteModalOpen}
close={closeDeleteModal}
/>
<EditGroupNameModal
group={enterpriseGroup}
isOpen={isEditModalOpen}
close={closeEditModal}
setShowToast={setShowToast}
setToastMessage={setToastMessage}
forceUpdate={forceUpdate}
/>
<Card.Section className="pt-1 x-small">Created on</Card.Section>
</Card.Body>
<Card.Footer className="justify-content-end" orientation="horizontal">
<IconButtonWithTooltip
key="trashGroupTooltip"
tooltipPlacement="top"
tooltipContent={tooltipContent}
src={Delete}
iconAs={Icon}
data-testid="delete-group-icon"
className="mr-2"
onClick={openDeleteModal}
<Breadcrumb
aria-label="people management breadcrumb navigation"
links={[
{
label: intl.formatMessage({
id: 'adminPortal.peopleManagement.breadcrumb',
defaultMessage: 'People Management',
description:
'Breadcrumb label for the people management page',
}),
href: `/${enterpriseSlug}/admin/${ROUTE_NAMES.peopleManagement}`,
},
]}
activeLabel={enterpriseGroup.name}
/>
<Hyperlink
className="btn btn-primary"
target="_blank"
destination={`/${enterpriseSlug}/admin/${ROUTE_NAMES.learners}`}
>
View group progress
</Hyperlink>
</Card.Footer>
</Card>
<Card orientation="horizontal">
<Card.Body>
<Card.Header
title={(
<>
<span className="pr-1">{enterpriseGroup.name}</span>
<IconButton
key="editGroupTooltip"
src={Edit}
iconAs={Icon}
alt="Edit group"
className="mr-2"
onClick={openEditModal}
size="sm"
data-testid="edit-modal-icon"
/>
</>
)}
subtitle={`${enterpriseGroup.acceptedMembersCount} accepted members`}
/>
<Card.Section className="pt-1 x-small">Created on</Card.Section>
</Card.Body>
<Card.Footer
className="justify-content-end"
orientation="horizontal"
>
<IconButtonWithTooltip
alt="icon to trash group"
key="trashGroupTooltip"
tooltipPlacement="top"
tooltipContent={tooltipContent}
src={Delete}
iconAs={Icon}
data-testid="delete-group-icon"
className="mr-2"
onClick={openDeleteModal}
/>
<Hyperlink
className="btn btn-primary"
target="_blank"
destination={`/${enterpriseSlug}/admin/${ROUTE_NAMES.learners}`}
>
View group progress
</Hyperlink>
</Card.Footer>
</Card>
</>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { learnerCreditManagementQueryKeys } from '../constants';
import LmsApiService from '../../../../data/services/LmsApiService';

/**
* Retrieves a enterprise group by the group UUID from the API.
* Retrieves an enterprise group by group UUID from the API.
*
* @param {*} queryKey The queryKey from the associated `useQuery` call.
* @returns The enterprise group object
Expand Down
2 changes: 1 addition & 1 deletion src/data/services/LmsApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class LmsApiService {
};

static removeEnterpriseGroup = async (groupUuid) => {
const removeGroupEndpoint = `${LmsApiService.enterpriseGroupListUrl}///////${groupUuid}/`;
const removeGroupEndpoint = `${LmsApiService.enterpriseGroupListUrl}${groupUuid}/`;
return LmsApiService.apiClient().delete(removeGroupEndpoint);
};

Expand Down

0 comments on commit 61d9d90

Please sign in to comment.