Skip to content

Commit

Permalink
Merge pull request #466 from bcgov/MALS2-26
Browse files Browse the repository at this point in the history
MALS2-26 - Dairy Farm Trailers & Trailer Inspections
  • Loading branch information
mgtennant authored Oct 3, 2024
2 parents c015ea9 + a92968a commit d43b9ab
Show file tree
Hide file tree
Showing 50 changed files with 3,249 additions and 249 deletions.
18 changes: 18 additions & 0 deletions app/client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ import AdminConfig from "./features/admin/AdminConfig";
import AdminDairyTestResults from "./features/admin/AdminDairyTestResults";
import AdminPremisesId from "./features/admin/AdminPremisesId";

import ViewTrailerPage from "./features/trailers/ViewTrailerPage";

import ViewTrailerInspectionPage from "./features/trailerinspections/ViewTrailerInspectionPage";
import CreateTrailerInspectionPage from "./features/trailerinspections/CreateTrailerInspectionPage";

import ModalComponent from "./components/ModalComponent";
import keycloak from "./app/keycloak";
import { fetchCurrentUser } from "./app/appSlice";
Expand Down Expand Up @@ -97,6 +102,9 @@ function App() {
<ProtectedRoute path={`${Constant.SITES_PATHNAME}/:id`}>
<ViewSitePage />
</ProtectedRoute>
<ProtectedRoute path={`${Constant.TRAILERS_PATHNAME}/:id`}>
<ViewTrailerPage />
</ProtectedRoute>
<ProtectedRoute path={`${Constant.CREATE_CONTACTS_PATHNAME}`}>
<ContactsCreate />
</ProtectedRoute>
Expand All @@ -111,6 +119,16 @@ function App() {
<ProtectedRoute path={`${Constant.INSPECTIONS_PATHNAME}/:id`}>
<ViewInspectionPage />
</ProtectedRoute>
<ProtectedRoute
path={`${Constant.CREATE_TRAILER_INSPECTIONS_PATHNAME}/:id`}
>
<CreateTrailerInspectionPage />
</ProtectedRoute>
<ProtectedRoute
path={`${Constant.TRAILER_INSPECTIONS_PATHNAME}/:id`}
>
<ViewTrailerInspectionPage />
</ProtectedRoute>
<ProtectedRoute path={`${Constant.REPORTS_PATHNAME}`}>
<Reports />
</ProtectedRoute>
Expand Down
17 changes: 11 additions & 6 deletions app/client/src/app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import dairyTankNoticesReducer from "../features/documents/dairyTankNoticesSlice
import adminReducer from "../features/admin/adminSlice";
import reportsReducer from "../features/reports/reportsSlice";
import inspectionsReducer from "../features/inspections/inspectionsSlice";
import trailersReducer from "../features/trailers/trailersSlice";
import trailerInspectionsReducer from "../features/trailerinspections/trailerInspectionsSlice";

const reducer = {
admin: adminReducer,
Expand All @@ -24,21 +26,24 @@ const reducer = {
dairyTankNotices: dairyTankNoticesReducer,
comments: commentsReducer,
inspections: inspectionsReducer,
trailerinspections: trailerInspectionsReducer,
licences: licencesReducer,
lookups: lookupsReducer,
reports: reportsReducer,
search: searchReducer,
sites: sitesReducer,
trailers: trailersReducer,
config: configReducer,
};

export default configureStore({
reducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
serializableCheck: {
// Ignore these action types
ignoredActions: ["app/SHOW_MODAL"],
},
}),
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
// Ignore these action types
ignoredActions: ["app/SHOW_MODAL"],
},
}),
devTools: process.env.NODE_ENV !== "production",
});
27 changes: 17 additions & 10 deletions app/client/src/features/documents/SelectApiaryRenewalsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export default function SelectApiaryRenewalsPage() {
useEffect(() => {
licences = queuedRenewals.data
? queuedRenewals.data.map((licence) => ({
...licence,
licenceId: licence.licenceId,
issuedOnDate: formatDateString(licence.issuedOnDate),
expiryDate: formatDateString(licence.expiryDate),
selected: "true",
}))
...licence,
licenceId: licence.licenceId,
issuedOnDate: formatDateString(licence.issuedOnDate),
expiryDate: formatDateString(licence.expiryDate),
selected: "true",
}))
: [];
setValue("licences", licences);
}, [queuedRenewals.data]);
Expand All @@ -95,7 +95,9 @@ export default function SelectApiaryRenewalsPage() {
}, [watchStartDate, watchEndDate]);

const onSubmit = (data) => {
const checked = isCheckAll ? watchLicences.map((x) => x.licenceId) : isChecked;
const checked = isCheckAll
? watchLicences.map((x) => x.licenceId)
: isChecked;
dispatch(startRenewalJob(checked));
history.push(DOWNLOAD_RENEWALS_PATHNAME);
};
Expand Down Expand Up @@ -139,7 +141,8 @@ export default function SelectApiaryRenewalsPage() {
variant="primary"
type="submit"
disabled={
!isCheckAll && (isChecked.length === 0 || renewalJob.status !== REQUEST_STATUS.IDLE)
!isCheckAll &&
(isChecked.length === 0 || renewalJob.status !== REQUEST_STATUS.IDLE)
}
>
Generate
Expand Down Expand Up @@ -184,8 +187,12 @@ export default function SelectApiaryRenewalsPage() {
<Form onSubmit={handleSubmit(onSubmit)}>
<Row className="mt-3 d-flex justify-content-end">
<Col md="auto">
{isCheckAll ? licences.length : isChecked.length} {pluralize(isCheckAll ? licences.length : isChecked.length, "renewal")} selected
for generation.
{isCheckAll ? licences.length : isChecked.length}{" "}
{pluralize(
isCheckAll ? licences.length : isChecked.length,
"renewal"
)}{" "}
selected for generation.
</Col>
</Row>
<Table striped size="sm" responsive className="mt-3" hover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function ApiaryInspectionDetailsEdit({
initialValues,
site,
}) {
console.log("ApiaryInspectionDetailsEdit");
const {
setValue,
register,
Expand Down
2 changes: 2 additions & 0 deletions app/client/src/features/inspections/CreateInspectionPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export default function CreateInspectionPage() {

const submissionLabel = submitting ? "Submitting..." : "Create";

console.log(inspection.status);

if (inspection.status === REQUEST_STATUS.FULFILLED) {
return <Redirect to={`${SITES_PATHNAME}/${id}`} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function InspectionDetailsViewEdit({
site,
licence,
}) {
console.log("InspectionDetailsViewEdit");
const { status, error, mode } = inspection;

const dispatch = useDispatch();
Expand Down Expand Up @@ -71,7 +72,7 @@ export default function InspectionDetailsViewEdit({
inspectionComment: null,
};

useEffect(() => { }, [dispatch]);
useEffect(() => {}, [dispatch]);

useEffect(() => {
setValue("inspectionDate", new Date(inspection.data.inspectionDate));
Expand Down Expand Up @@ -184,7 +185,9 @@ export default function InspectionDetailsViewEdit({
supersInspected: parseAsInt(data.supersInspected),
supersDestroyed: parseAsInt(data.supersDestroyed),
inspectionComment:
data.inspectionComment?.length === 0 ? null : data.inspectionComment,
data.inspectionComment?.length === 0
? null
: data.inspectionComment,
};

dispatch(
Expand Down
1 change: 0 additions & 1 deletion app/client/src/features/licences/AssociatedLicences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ export default function AssociatedLicences({ licence }) {
</>
);
} else if (results.status === REQUEST_STATUS.FULFILLED && results.count > 0) {
console.log(licence.data);
control = (
<>
<Table striped size="sm" responsive className="mt-3 mb-0" hover>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { Row, Col, Form, Button } from "react-bootstrap";

import DocGenDownloadBar from "../../components/DocGenDownloadBar";

import {
startDairyTrailerInspectionJob,
generateReport,
fetchReportJob,
selectReportsJob,
completeReportJob,
} from "../reports/reportsSlice";

import { REPORTS } from "../../utilities/constants";

export default function GenerateDairyTrailerInspection({ licenceNumber }) {
const dispatch = useDispatch();

const job = useSelector(selectReportsJob);
const { pendingDocuments } = job;

useEffect(() => {
if (job.id && job.type === REPORTS.DAIRY_TRAILER_INSPECTION) {
dispatch(fetchReportJob());

if (pendingDocuments?.length > 0) {
dispatch(generateReport(pendingDocuments[0].documentId));
} else {
dispatch(completeReportJob(job.id));
}
}
}, [pendingDocuments]); // eslint-disable-line react-hooks/exhaustive-deps

const onGenerateReport = () => {
dispatch(
startDairyTrailerInspectionJob({
licenceNumber: licenceNumber,
})
);
};

return (
<>
<Row>
<Col sm={3}>
<Form.Label>&nbsp;</Form.Label>
<Button
variant="primary"
type="button"
onClick={() => onGenerateReport()}
block
disabled={!licenceNumber}
>
Generate Inspections Report
</Button>
</Col>
</Row>
<div className="mt-3">
<DocGenDownloadBar job={job} />
</div>
</>
);
}

GenerateDairyTrailerInspection.propTypes = {};
13 changes: 6 additions & 7 deletions app/client/src/features/licences/LicenceSites.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
selectSiteResults,
setSiteSearchPage,
setSiteFilterText,
clearSiteFilterText
clearSiteFilterText,
} from "../search/searchSlice";

import { selectLicenceStatuses } from "../lookups/licenceStatusesSlice";
Expand Down Expand Up @@ -96,7 +96,6 @@ export default function LicenceSites({ licence }) {
dispatch(setSiteSearchPage(1));
dispatch(setSiteFilterText(newFilterText));
dispatch(fetchSiteResults());

}, 700);

setDebouncedActionTimeout(newTimeout);
Expand All @@ -113,7 +112,7 @@ export default function LicenceSites({ licence }) {
province: PROVINCES.BC,
region: null,
regionalDistrict: null,
registrationDate: startOfToday()
registrationDate: startOfToday(),
};
dispatch(createSite(payload));
}
Expand Down Expand Up @@ -173,7 +172,7 @@ export default function LicenceSites({ licence }) {
errorMessage={"There are no sites associated with this licence."}
/>
{currentUser.data.roleId !== SYSTEM_ROLES.READ_ONLY &&
currentUser.data.roleId !== SYSTEM_ROLES.INSPECTOR ? (
currentUser.data.roleId !== SYSTEM_ROLES.INSPECTOR ? (
<Row>
<Col lg={2}>{addSiteButton}</Col>
</Row>
Expand All @@ -199,7 +198,7 @@ export default function LicenceSites({ licence }) {
</Table>
<Row className="mt-3">
{currentUser.data.roleId !== SYSTEM_ROLES.READ_ONLY &&
currentUser.data.roleId !== SYSTEM_ROLES.INSPECTOR ? (
currentUser.data.roleId !== SYSTEM_ROLES.INSPECTOR ? (
<Col md="3">{addSiteButton}</Col>
) : null}
<Col className="d-flex justify-content-center">
Expand Down Expand Up @@ -235,15 +234,15 @@ export default function LicenceSites({ licence }) {
<>
<SectionHeading>Sites</SectionHeading>
<Container className="mt-3 mb-4">
<div className="mb-3">
<div className="mb-3">
<input
type="text"
placeholder="Filter sites"
onChange={handleFilterTextChange}
/>
</div>
{control}
</Container>
</Container>
</>
);
}
Expand Down
Loading

0 comments on commit d43b9ab

Please sign in to comment.