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

Refactor/event details page #7375

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = defineConfig({
supportFile: 'test/cypress/support/index.js',
},
retries: {
runMode: 2, // number of retries when running `cypress run`
openMode: 2, // number of retries when running `cypress open`
runMode: 2,
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function renderSendReferralForm(req, res) {
companyId: id,
cancelUrl: urls.companies.detail(id),
sendingAdviserTeamName,
flashMessages: res.locals.getMessages(),

// TODO: This should not be necessary as flashMessages are included in global props
// flashMessages: res.locals.flashMessages,
},
}
)
Expand Down
36 changes: 6 additions & 30 deletions src/apps/events/__test__/repos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ const proxyquire = require('proxyquire')
const authorisedRequestStub = sinon.stub()
const searchStub = sinon.stub()

const { saveEvent, fetchEvent, getAllEvents, getActiveEvents } = proxyquire(
'../repos',
{
'../../lib/authorised-request': {
authorisedRequest: authorisedRequestStub,
},
'../../modules/search/services': { search: searchStub },
}
)
const { saveEvent, getActiveEvents } = proxyquire('../repos', {
'../../lib/authorised-request': {
authorisedRequest: authorisedRequestStub,
},
'../../modules/search/services': { search: searchStub },
})

const config = require('../../../config')

Expand Down Expand Up @@ -50,27 +47,6 @@ describe('Event Service', () => {
})
})

context('fetchEvent', () => {
it('should fetch single event by id', async () => {
const id = '123'
await fetchEvent(mockReq, id)
expect(authorisedRequestStub).to.have.been.calledWith(
mockReq,
`${config.apiRoot}/v3/event/${id}`
)
})
})

context('getAllEvents', () => {
it('should fetch all events with limit and offset', async () => {
await getAllEvents(mockReq)
expect(authorisedRequestStub).to.have.been.calledWith(
mockReq,
`${config.apiRoot}/v3/event?limit=100000&offset=0`
)
})
})

context('getActiveEvents', () => {
let clock

Expand Down
1 change: 1 addition & 0 deletions src/apps/events/attendees/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function renderAttendees(req, res, next) {
children: [{ value: sortby }],
})

// TODO: Can we remove this?
res.breadcrumb(name).render('events/attendees/views/list', {
incompleteEvent,
attendees: attendeesCollection,
Expand Down
3 changes: 2 additions & 1 deletion src/apps/events/attendees/router.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// TODO: Remove this whole module and the whole parent folder ../
const router = require('express').Router()

const { createAttendee, renderAttendees } = require('./controllers')

router.get('/', renderAttendees)
router.get('/*', renderAttendees)

router.get('/create/:contactId', createAttendee)

Expand Down
2 changes: 2 additions & 0 deletions src/apps/events/middleware/details.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO: Get rid of this whole module
const { assign } = require('lodash')

const { transformEventFormBodyToApiRequest } = require('../transformers')
Expand Down Expand Up @@ -27,6 +28,7 @@ async function postDetails(req, res, next) {
}
}

// TODO: Get rid of this
async function getEventDetails(req, res, next, eventId) {
try {
res.locals.event = await fetchEvent(req, eventId)
Expand Down
11 changes: 4 additions & 7 deletions src/apps/events/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { APP_PERMISSIONS, LOCAL_NAV } = require('./constants')
const { handleRoutePermissions, setLocalNav } = require('../middleware')
const { getEventDetails } = require('./middleware/details')
const { renderEventsView } = require('./controllers/events')
const attendeesRouter = require('./attendees/router')
const { createAttendee } = require('./attendees/controllers/create')

router.get('/create', renderEventsView)
router.use(handleRoutePermissions(APP_PERMISSIONS))
Expand All @@ -19,12 +19,9 @@ router.use(
setLocalNav(LOCAL_NAV)
)

router.use('/:eventId/attendees', attendeesRouter)
// TODO: Get rid of this and fetch the event on the client
router.param('eventId', getEventDetails)
// TODO: When everything in the events space is converted to react
// router.get('/*', renderEventsView)
router.get('/:eventId/edit', renderEventsView)
router.get('/:eventId', renderEventsView)
router.get('/:eventId/details', renderEventsView)
router.get('/:eventId/attendees/create/:contactId', createAttendee)
router.get('/:eventId*', renderEventsView)

module.exports = router
3 changes: 3 additions & 0 deletions src/client/components/Resource/InteractionsV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createCollectionResource } from './Resource'

export default createCollectionResource('InteractionsV3', 'v3/interaction')
5 changes: 5 additions & 0 deletions src/client/components/Resource/Paginated.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ const StyledCollectionSort = styled(CollectionSort)`
* Forwarded to {qsParamName} prop of {StyledCollectionSort}.
* @param {number} [props.defaultSortOptionIndex = 0] - The index of the sort option
* that should be selected when there's nothing set in the query string.
* @param {string} [props.addItemUrl =] - If set, an "Add <item-name>" button
* will be displayed on the top-right corner of the header behaving as a link
* to the value of this prop. This is just forwarded to CollectionHeader.
* @example
* <PaginatedResource name="My task name" id="foo">
* {currentPage =>
Expand Down Expand Up @@ -100,6 +103,7 @@ const PaginatedResource = multiInstance({
result,
shouldPluralize,
noResults = "You don't have any results",
addItemUrl,
}) => {
// We know better than ESLint that we are in deed in a React component
// eslint-disable-next-line react-hooks/rules-of-hooks
Expand Down Expand Up @@ -150,6 +154,7 @@ const PaginatedResource = multiInstance({
totalItems={result.count}
collectionName={heading || name}
shouldPluralize={shouldPluralize}
addItemUrl={addItemUrl}
/>
{totalPages > 0 && (
<StyledCollectionSort
Expand Down
2 changes: 2 additions & 0 deletions src/client/components/Resource/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Company from './Company'
import CompanyContacts from './CompanyContacts'
import Countries from './Countries'
import Interactions from './Interactions'
import InteractionsV3 from './InteractionsV3'
import Opportunity from './Opportunity'
import OpportunityStatuses from './OpportunityStatuses'
import UKRegions from './UKRegions'
Expand Down Expand Up @@ -109,6 +110,7 @@ export default {
...ContactAuditHistory.tasks,
...Countries.tasks,
...Interactions.tasks,
...InteractionsV3.tasks,
...Opportunity.tasks,
...OpportunityStatuses.tasks,
...CapitalInvestmentRequiredChecksConducted.tasks,
Expand Down
2 changes: 1 addition & 1 deletion src/client/modules/Events/CollectionList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const EventTemplate = (item) => {
<StyledCollectionItem
dataTest="data-hub-event"
headingText={item.headingText}
headingUrl={item.headingUrl}
headingUrl={`/events/${item.id}/details`}
metadata={item.metadata}
tags={item.tags}
titleRenderer={TitleRenderer}
Expand Down
Loading
Loading