diff --git a/.eslintrc b/.eslintrc index 41b81f943..38c1ed5c5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,7 @@ "jest": true, "commonjs": true }, - "parser": "@babel/eslint-parser", + "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2020, "sourceType": "module", diff --git a/package.json b/package.json index 2b689b95d..26d545587 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "test:unit-windows": "node ./node_modules/jest/bin/jest.js", "test:unit-win-upd": "node ./node_modules/jest/bin/jest.js --updateSnapshot", "lint": "eslint . && echo 'Lint complete.'", - "lintfix": "eslint . --max-warnings 0 --fix", + "lintfix": "eslint . --fix", "test:e2e": "NODE_ENV=test start-test http://localhost:5001 cy:run", "e2e:audit": "NODE_ENV=test start-test http://localhost:5001 cy:run:audit", "cy:run": "cypress run --browser chrome --headless", diff --git a/src/components/Errors/ErrorMessage/index.js b/src/components/Errors/ErrorMessage/index.tsx similarity index 62% rename from src/components/Errors/ErrorMessage/index.js rename to src/components/Errors/ErrorMessage/index.tsx index 37e9fe2f9..b619ee512 100644 --- a/src/components/Errors/ErrorMessage/index.js +++ b/src/components/Errors/ErrorMessage/index.tsx @@ -1,7 +1,13 @@ -import PropTypes from 'prop-types' import cx from 'classnames' -const ErrorMessage = ({ label, className, id }) => ( +interface Props { + // label: JSX.Element + label: string + className?: string + id?: number +} + +const ErrorMessage = ({ label, className, id }: Props) => ( = 0 ? `error-${id}` : null)} className={cx('govuk-error-message lbh-error-message', className)} @@ -11,9 +17,4 @@ const ErrorMessage = ({ label, className, id }) => ( ) -ErrorMessage.propTypes = { - label: PropTypes.node.isRequired, - className: PropTypes.string, -} - export default ErrorMessage diff --git a/src/components/Spinner/index.js b/src/components/Spinner/index.tsx similarity index 89% rename from src/components/Spinner/index.js rename to src/components/Spinner/index.tsx index 85f9ebf5e..c3ee85f51 100644 --- a/src/components/Spinner/index.js +++ b/src/components/Spinner/index.tsx @@ -1,4 +1,8 @@ -const Spinner = ({ resource }) => ( +interface Props { + resource?: string +} + +const Spinner = ({ resource }: Props) => ( { +const WarningText = ({ text, name }: Props) => { return (
@@ -259,17 +277,4 @@ const PrintJobTicketDetails = ({ ) } -PrintJobTicketDetails.propTypes = { - workOrder: PropTypes.instanceOf(WorkOrder).isRequired, - property: PropTypes.object.isRequired, - tasksAndSors: PropTypes.arrayOf( - PropTypes.shape({ - code: PropTypes.string, - description: PropTypes.string, - quantity: PropTypes.number, - standardMinuteValue: PropTypes.number, - }) - ).isRequired, -} - export default PrintJobTicketDetails diff --git a/src/components/WorkOrder/WorkOrderView.js b/src/components/WorkOrder/WorkOrderView.tsx similarity index 63% rename from src/components/WorkOrder/WorkOrderView.js rename to src/components/WorkOrder/WorkOrderView.tsx index 5e7dcc170..34210d74c 100644 --- a/src/components/WorkOrder/WorkOrderView.js +++ b/src/components/WorkOrder/WorkOrderView.tsx @@ -10,16 +10,31 @@ import { sortObjectsByDateKey } from '@/utils/date' import PrintJobTicketDetails from './PrintJobTicketDetails' import { getOrCreateSchedulerSessionId } from '../../utils/frontEndApiClient/users/schedulerSession' -const WorkOrderView = ({ workOrderReference }) => { - const [property, setProperty] = useState({}) - const [workOrder, setWorkOrder] = useState({}) +interface Props { + workOrderReference: string +} + +interface IProperty { + address: { + addressLine: string + streetSuffix: string + postalCode: string + } + tmoName: string + hierarchyType: string + propertyReference: string +} + +const WorkOrderView = ({ workOrderReference }: Props) => { + const [property, setProperty] = useState() + const [workOrder, setWorkOrder] = useState() const [tasksAndSors, setTasksAndSors] = useState([]) const [locationAlerts, setLocationAlerts] = useState([]) const [personAlerts, setPersonAlerts] = useState([]) const [tenure, setTenure] = useState({}) - const [schedulerSessionId, setSchedulerSessionId] = useState() - const [loading, setLoading] = useState(false) - const [error, setError] = useState() + const [schedulerSessionId, setSchedulerSessionId] = useState() + const [loading, setLoading] = useState(false) + const [error, setError] = useState() const tabsList = [ 'Tasks and SORs', 'Notes', @@ -53,7 +68,7 @@ const WorkOrderView = ({ workOrderReference }) => { } } - const getWorkOrderView = async (workOrderReference) => { + const getWorkOrderView = async (workOrderReference: string) => { setError(null) try { @@ -108,49 +123,44 @@ const WorkOrderView = ({ workOrderReference }) => { getWorkOrderView(workOrderReference) }, []) + if (loading) return + return ( <> - {loading ? ( - - ) : ( - <> - {property && - property.address && - property.hierarchyType && - tenure && - workOrder && ( - <> - - - {/* Only displayed for print media */} - - - )} - {error && } - - )} + {property && + property.address && + property.hierarchyType && + tenure && + workOrder && ( + <> + + + {/* Only displayed for print media */} + + + )} + {error && } ) } diff --git a/src/components/WorkOrder/__snapshots__/PrintJobTicketDetails.test.js.snap b/src/components/WorkOrder/__snapshots__/PrintJobTicketDetails.test.js.snap index 9416c8bc4..a9b1aab86 100644 --- a/src/components/WorkOrder/__snapshots__/PrintJobTicketDetails.test.js.snap +++ b/src/components/WorkOrder/__snapshots__/PrintJobTicketDetails.test.js.snap @@ -57,12 +57,11 @@ exports[`PrintJobTicketDetails component Renders the PrintJobTicketDetails compo d="M200.955311,28.5221077 C200.298901,30.3958684 199.56337,32.7989483 198.29304,34.3912803 C196.164103,37.0407925 192.887912,37 189.733333,37 L186.048352,37 L186.048352,30.5577263 L187.92967,30.5577263 C188.750183,30.5577263 189.813919,30.6408425 190.389744,30.3550393 C190.880586,30.1115234 191.1663,29.7032331 191.1663,28.7670818 C191.1663,27.7463561 188.054212,19.964052 187.604396,18.7406393 L184,9 L192.681319,9 L196.082051,21.1451774 L196.164103,21.1451774 L199.604396,9 L208,9 L200.955311,28.5221077" /> - @@ -392,12 +391,11 @@ exports[`PrintJobTicketDetails component Renders the PrintJobTicketDetails compo d="M200.955311,28.5221077 C200.298901,30.3958684 199.56337,32.7989483 198.29304,34.3912803 C196.164103,37.0407925 192.887912,37 189.733333,37 L186.048352,37 L186.048352,30.5577263 L187.92967,30.5577263 C188.750183,30.5577263 189.813919,30.6408425 190.389744,30.3550393 C190.880586,30.1115234 191.1663,29.7032331 191.1663,28.7670818 C191.1663,27.7463561 188.054212,19.964052 187.604396,18.7406393 L184,9 L192.681319,9 L196.082051,21.1451774 L196.164103,21.1451774 L199.604396,9 L208,9 L200.955311,28.5221077" /> - diff --git a/src/models/workOrder.js b/src/models/workOrder.ts similarity index 79% rename from src/models/workOrder.js rename to src/models/workOrder.ts index 4d8c3385c..47b5eb781 100644 --- a/src/models/workOrder.js +++ b/src/models/workOrder.ts @@ -10,6 +10,33 @@ import { } from '@/utils/statusCodes' export class WorkOrder { + reference: string + status: string + callerName: string + callerNumber: string + + appointment: null | { + description: string + date: Date + start: Date + } + target: Date + raisedBy: string + operatives: { + name: string + }[] + priorityCode: number + tradeCode: string + contractorReference: string + priority: string + description: string + plannerComments: string + budgetCode?: { + externalCostCode?: string + corporateSubjectiveCode?: string + descriptionOfWorks?: string + } + constructor(workOrderData) { Object.assign(this, workOrderData) } diff --git a/src/pages/work-orders/[id]/index.js b/src/pages/work-orders/[id]/index.tsx similarity index 100% rename from src/pages/work-orders/[id]/index.js rename to src/pages/work-orders/[id]/index.tsx diff --git a/src/utils/frontEndApiClient/requests.js b/src/utils/frontEndApiClient/requests.ts similarity index 93% rename from src/utils/frontEndApiClient/requests.js rename to src/utils/frontEndApiClient/requests.ts index ea166da91..ea0406038 100644 --- a/src/utils/frontEndApiClient/requests.js +++ b/src/utils/frontEndApiClient/requests.ts @@ -1,4 +1,4 @@ -import axios from 'axios' +import axios, { Method } from 'axios' import { paramsSerializer } from '@/utils/urls' export const frontEndApiRequest = async ({ @@ -7,6 +7,12 @@ export const frontEndApiRequest = async ({ params, requestData, paramsSerializer, +}: { + method: Method + path: string + params?: object + requestData?: any + paramsSerializer?: (params: any) => string }) => { const { data } = await axios({ method: method,