forked from openedx/frontend-app-support-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openedx#396 from openedx/knguyen2/ent-9159
feat: add customer record card
- Loading branch information
Showing
10 changed files
with
322 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/Configuration/Customers/CustomerDetailView/CustomerCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
ActionRow, | ||
Button, | ||
Card, | ||
Icon, | ||
Hyperlink, | ||
Toast, | ||
} from '@openedx/paragon'; | ||
import { Launch, ContentCopy } from '@openedx/paragon/icons'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { formatDate, useCopyToClipboard } from '../data/utils'; | ||
|
||
const CustomerCard = ({ enterpriseCustomer }) => { | ||
const { ADMIN_PORTAL_BASE_URL, LMS_BASE_URL } = getConfig(); | ||
const { showToast, copyToClipboard, setShowToast } = useCopyToClipboard(); | ||
|
||
return ( | ||
<div> | ||
<Card variant="dark" className="mb-0"> | ||
<Card.Section | ||
actions={( | ||
<ActionRow> | ||
<Button>View Details</Button> | ||
<Button | ||
className="text-dark-500" | ||
as="a" | ||
href={`${LMS_BASE_URL}/admin/enterprise/enterprisecustomer/${enterpriseCustomer.uuid}/change`} | ||
variant="inverse-primary" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
iconAfter={Launch} | ||
> | ||
Open in Django | ||
</Button> | ||
</ActionRow> | ||
)} | ||
> | ||
<p className="small font-weight-bold mb-0 mt-2"> | ||
CUSTOMER RECORD | ||
</p> | ||
<p className="lead font-weight-bold mb-0"> | ||
{enterpriseCustomer.name} | ||
</p> | ||
<Hyperlink | ||
destination={`${ADMIN_PORTAL_BASE_URL}/${enterpriseCustomer.slug}/admin/learners`} | ||
variant="muted" | ||
target="_blank" | ||
showLaunchIcon | ||
className="small mb-1" | ||
> | ||
/{enterpriseCustomer.slug}/ | ||
</Hyperlink> | ||
<div | ||
role="presentation" | ||
className="pgn-doc__icons-table__preview-footer" | ||
> | ||
<p className="small mb-1"> | ||
{enterpriseCustomer.uuid} | ||
</p> | ||
<Icon | ||
key="ContentCopy" | ||
src={ContentCopy} | ||
data-testid="copy" | ||
onClick={() => copyToClipboard(enterpriseCustomer.uuid)} | ||
/> | ||
</div> | ||
<p className="small mb-1"> | ||
Created {formatDate(enterpriseCustomer.created)} • Last modified {formatDate(enterpriseCustomer.modified)} | ||
</p> | ||
</Card.Section> | ||
</Card> | ||
<Toast | ||
onClose={() => setShowToast(false)} | ||
show={showToast} | ||
delay={2000} | ||
> | ||
Copied to clipboard | ||
</Toast> | ||
</div> | ||
|
||
); | ||
}; | ||
|
||
CustomerCard.propTypes = { | ||
enterpriseCustomer: PropTypes.shape({ | ||
created: PropTypes.string, | ||
modified: PropTypes.string, | ||
slug: PropTypes.string, | ||
name: PropTypes.string, | ||
uuid: PropTypes.string, | ||
}).isRequired, | ||
}; | ||
|
||
export default CustomerCard; |
67 changes: 67 additions & 0 deletions
67
src/Configuration/Customers/CustomerDetailView/CustomerViewContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useState, useEffect, useCallback } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
import { | ||
Breadcrumb, | ||
Container, | ||
Skeleton, | ||
Stack, | ||
} from '@openedx/paragon'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import CustomerCard from './CustomerCard'; | ||
import { getEnterpriseCustomer } from '../data/utils'; | ||
|
||
const CustomerViewContainer = () => { | ||
const { id } = useParams(); | ||
const [enterpriseCustomer, setEnterpriseCustomer] = useState({}); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const intl = useIntl(); | ||
|
||
const fetchData = useCallback( | ||
async () => { | ||
try { | ||
const response = await getEnterpriseCustomer({ uuid: id }); | ||
setEnterpriseCustomer(response[0]); | ||
} catch (error) { | ||
logError(error); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, | ||
[], | ||
); | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
{!isLoading ? ( | ||
<Container className="mt-5"> | ||
<Breadcrumb | ||
arial-label="customer detail" | ||
links={[ | ||
{ | ||
label: intl.formatMessage({ | ||
id: 'supportTool.customers.page.breadcrumb.customer', | ||
defaultMessage: 'Customers', | ||
description: 'Breadcrumb label for the customers page', | ||
}), | ||
href: '/enterprise-configuration/customers/', | ||
}, | ||
{ label: enterpriseCustomer.name }, | ||
]} | ||
/> | ||
</Container> | ||
) : <Skeleton />} | ||
<Container className="mt-4"> | ||
<Stack gap={2}> | ||
{!isLoading ? <CustomerCard enterpriseCustomer={enterpriseCustomer} /> : <Skeleton height={230} />} | ||
</Stack> | ||
</Container> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CustomerViewContainer; |
40 changes: 40 additions & 0 deletions
40
src/Configuration/Customers/CustomerDetailView/tests/CustomerCard.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-disable react/prop-types */ | ||
import { screen, render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { formatDate } from '../../data/utils'; | ||
import CustomerCard from '../CustomerCard'; | ||
|
||
jest.mock('../../data/utils', () => ({ | ||
getEnterpriseCustomer: jest.fn(), | ||
formatDate: jest.fn(), | ||
useCopyToClipboard: jest.fn(() => ({ | ||
showToast: true, | ||
copyToClipboard: jest.fn(), | ||
setShowToast: jest.fn(), | ||
})), | ||
})); | ||
|
||
const mockData = { | ||
uuid: 'test-id', | ||
name: 'Test Customer Name', | ||
slug: 'customer-6', | ||
created: '2024-07-23T20:02:57.651943Z', | ||
modified: '2024-07-23T20:02:57.651943Z', | ||
}; | ||
|
||
describe('CustomerCard', () => { | ||
it('renders customer card data', () => { | ||
formatDate.mockReturnValue('July 23, 2024'); | ||
render( | ||
<IntlProvider locale="en"> | ||
<CustomerCard enterpriseCustomer={mockData} /> | ||
</IntlProvider>, | ||
); | ||
expect(screen.getByText('test-id')).toBeInTheDocument(); | ||
expect(screen.getByText('/customer-6/')).toBeInTheDocument(); | ||
expect(screen.getByText('Created July 23, 2024 • Last modified July 23, 2024')).toBeInTheDocument(); | ||
expect(screen.getByText('Test Customer Name')); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
src/Configuration/Customers/CustomerDetailView/tests/CustomerViewContainer.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* eslint-disable react/prop-types */ | ||
import { screen, render, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { getEnterpriseCustomer, formatDate } from '../../data/utils'; | ||
import CustomerViewContainer from '../CustomerViewContainer'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ id: 'test-id' }), | ||
})); | ||
|
||
jest.mock('../../data/utils', () => ({ | ||
getEnterpriseCustomer: jest.fn(), | ||
formatDate: jest.fn(), | ||
useCopyToClipboard: jest.fn(() => ({ | ||
showToast: true, | ||
copyToClipboard: jest.fn(), | ||
setShowToast: jest.fn(), | ||
})), | ||
})); | ||
|
||
describe('CustomerViewContainer', () => { | ||
it('renders data', async () => { | ||
getEnterpriseCustomer.mockReturnValue([{ | ||
uuid: 'test-id', | ||
name: 'Test Customer Name', | ||
slug: 'customer-6', | ||
created: '2024-07-23T20:02:57.651943Z', | ||
modified: '2024-07-23T20:02:57.651943Z', | ||
}]); | ||
formatDate.mockReturnValue('July 23, 2024'); | ||
render( | ||
<IntlProvider locale="en"> | ||
<CustomerViewContainer /> | ||
</IntlProvider>, | ||
); | ||
await waitFor(() => { | ||
expect(screen.getByText('test-id')).toBeInTheDocument(); | ||
expect(screen.getByText('/customer-6/')).toBeInTheDocument(); | ||
expect(screen.getByText('Created July 23, 2024 • Last modified July 23, 2024')).toBeInTheDocument(); | ||
const customerNameText = screen.getAllByText('Test Customer Name'); | ||
customerNameText.forEach(customerName => { | ||
expect(customerName).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.