-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
196 additions
and
6 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
app/client/src/features/reports/ReportDairyTrailerInspection.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,107 @@ | ||
import React, { useEffect } from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { useSelector, useDispatch } from "react-redux"; | ||
import { Row, Col, Form, Button } from "react-bootstrap"; | ||
|
||
import { startOfToday, add } from "date-fns"; | ||
|
||
import CustomDatePicker from "../../components/CustomDatePicker"; | ||
import DocGenDownloadBar from "../../components/DocGenDownloadBar"; | ||
|
||
import { | ||
startDairyTrailerInspectionJob, | ||
generateReport, | ||
fetchReportJob, | ||
selectReportsJob, | ||
completeReportJob, | ||
} from "./reportsSlice"; | ||
|
||
import { REPORTS } from "../../utilities/constants"; | ||
|
||
export default function ReportDairyTrailerInspection() { | ||
const dispatch = useDispatch(); | ||
|
||
const job = useSelector(selectReportsJob); | ||
const { pendingDocuments } = job; | ||
|
||
const form = useForm({ | ||
reValidateMode: "onBlur", | ||
}); | ||
const { setValue, watch } = form; | ||
|
||
const startDate = startOfToday(); | ||
const endDate = add(startOfToday(), { days: 15 }); | ||
const watchStartDate = watch("startDate", startDate); | ||
const watchEndDate = watch("endDate", endDate); | ||
|
||
useEffect(() => { | ||
setValue("startDate", startDate); | ||
setValue("endDate", endDate); | ||
}, [dispatch]); | ||
|
||
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 handleFieldChange = (field) => { | ||
return (value) => { | ||
setValue(field, value); | ||
}; | ||
}; | ||
|
||
const onGenerateReport = () => { | ||
dispatch( | ||
startDairyTrailerInspectionJob({ | ||
startDate: watchStartDate, | ||
endDate: watchEndDate, | ||
}) | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Row> | ||
<Col lg={3}> | ||
<CustomDatePicker | ||
id="startDate" | ||
label="Start Date" | ||
notifyOnChange={handleFieldChange("startDate")} | ||
defaultValue={startDate} | ||
/> | ||
</Col> | ||
<Col lg={3}> | ||
<CustomDatePicker | ||
id="endDate" | ||
label="End Date" | ||
notifyOnChange={handleFieldChange("endDate")} | ||
defaultValue={endDate} | ||
/> | ||
</Col> | ||
<Col sm={2}> | ||
<Form.Label> </Form.Label> | ||
<Button | ||
variant="primary" | ||
type="button" | ||
onClick={() => onGenerateReport()} | ||
block | ||
> | ||
Generate Report | ||
</Button> | ||
</Col> | ||
</Row> | ||
<div className="mt-3"> | ||
<DocGenDownloadBar job={job} /> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
ReportDairyTrailerInspection.propTypes = {}; |
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
Binary file not shown.
Binary file added
BIN
+60.6 KB
app/server/static/templates/notices/Renewal_DairyTankTruck_Template.docx
Binary file not shown.
Binary file added
BIN
+9.59 KB
app/server/static/templates/reports/Dairy_Trailer_Inspection_Template.xlsx
Binary file not shown.
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