-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into knguyen2/ent-9159
- Loading branch information
Showing
13 changed files
with
272 additions
and
98 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
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
124 changes: 87 additions & 37 deletions
124
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 |
---|---|---|
@@ -1,45 +1,95 @@ | ||
import { ActionRow, Button, Card, Hyperlink } from '@openedx/paragon'; | ||
import { Launch } from '@openedx/paragon/icons'; | ||
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 } from '../data/utils'; | ||
import { formatDate, useCopyToClipboard } from '../data/utils'; | ||
|
||
const CustomerCard = ({ enterpriseCustomer }) => { | ||
const { ADMIN_PORTAL_BASE_URL } = getConfig(); | ||
const { ADMIN_PORTAL_BASE_URL, LMS_BASE_URL } = getConfig(); | ||
const { showToast, copyToClipboard, setShowToast } = useCopyToClipboard(); | ||
|
||
return ( | ||
<Card variant="dark mb-0"> | ||
<Card.Section | ||
actions={ | ||
<ActionRow> | ||
<Button>View Details</Button> | ||
<Button variant="inverse-primary" iconAfter={Launch}>Open in Django</Button> | ||
</ActionRow> | ||
} | ||
> | ||
<p className="small font-weight-bold mb-0 mt-4"> | ||
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" | ||
<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> | ||
)} | ||
> | ||
/{enterpriseCustomer.slug}/ | ||
</Hyperlink> | ||
<p className="small mb-1"> | ||
{enterpriseCustomer.uuid} | ||
</p> | ||
<p className="small mb-1"> | ||
Created {enterpriseCustomer.created} • Last modified {formatDate(enterpriseCustomer.modified)} | ||
</p> | ||
</Card.Section> | ||
</Card> | ||
) | ||
<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; | ||
export default CustomerCard; |
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
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')); | ||
}); | ||
}); |
Oops, something went wrong.