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

Web API Implementation for Submitting Projects #1753

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 32 additions & 0 deletions client/src/components/Button/SubmitButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import PropTypes from "prop-types";
import Button from "../Button/Button";

const SubmitButton = ({ id, onClick, isDisabled, isDisplayed, color }) => {
return (
<>
<Button
type="input"
color={color}
onClick={onClick}
id={id}
data-testid={id}
disabled={isDisabled}
isDisplayed={isDisplayed}
>
SUBMIT
</Button>
</>
);
};

SubmitButton.propTypes = {
children: PropTypes.object,
onClick: PropTypes.func.isRequired,
id: PropTypes.string.isRequired,
color: PropTypes.string,
isDisabled: PropTypes.bool,
isDisplayed: PropTypes.bool.isRequired
};

export default SubmitButton;
8 changes: 8 additions & 0 deletions client/src/components/ProjectWizard/TdmCalculationWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ const TdmCalculationWizard = props => {
return false;
};

const setDisplaySubmitButton = () => {
if (page === 5) {
return true;
}
return false;
};

const handleValidate = () => {
const { page } = params;
const validations = {
Expand Down Expand Up @@ -329,6 +336,7 @@ const TdmCalculationWizard = props => {
setDisabledSaveButton={setDisabledSaveButton}
setDisplaySaveButton={setDisplaySaveButton}
setDisplayPrintButton={setDisplayPrintButton}
setDisplaySubmitButton={setDisplaySubmitButton}
onSave={onSave}
project={project}
// dateModified={dateModified}
Expand Down
8 changes: 8 additions & 0 deletions client/src/components/ProjectWizard/WizardFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useRef, useContext } from "react";
import PropTypes from "prop-types";
import NavButton from "../Button/NavButton";
import SaveButton from "../Button/SaveButton";
import SubmitButton from "../Button/SubmitButton";
import { createUseStyles } from "react-jss";
import PrintButton from "../Button/PrintButton";
import ReactToPrint from "react-to-print";
Expand Down Expand Up @@ -48,6 +49,7 @@ const WizardFooter = ({
setDisabledSaveButton,
setDisplaySaveButton,
setDisplayPrintButton,
setDisplaySubmitButton,
onSave,
project
}) => {
Expand Down Expand Up @@ -115,6 +117,11 @@ const WizardFooter = ({
isDisplayed={setDisplaySaveButton()}
onClick={onSave}
/>
<SubmitButton
id="submitButton"
color="colorPrimary"
isDisplayed={setDisplaySubmitButton()}
/>
</>
) : null}
</div>
Expand Down Expand Up @@ -163,6 +170,7 @@ WizardFooter.propTypes = {
setDisabledSaveButton: PropTypes.any,
setDisplaySaveButton: PropTypes.any,
setDisplayPrintButton: PropTypes.any,
setDisplaySubmitButton: PropTypes.any,
onSave: PropTypes.any,
onDownload: PropTypes.any,
project: PropTypes.shape
Expand Down
8 changes: 8 additions & 0 deletions client/src/components/Projects/ProjectTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ const ProjectTableRow = ({
return <span>{formatDate(project.dateModified)}</span>;
};

const dateSubmittedDisplay = () => {
if (project.dateSubmitted) {
return <span>{moment(project.dateSubmitted).format("YYYY-MM-DD")}</span>;
}
return <span>{moment(project.dateSubmitted).format("YYYY-MM-DD")}</span>;
};

return (
<tr key={project.id}>
<td className={classes.tdCenterAlign}>
Expand Down Expand Up @@ -141,6 +148,7 @@ const ProjectTableRow = ({
</td>

<td className={classes.td}>{dateModifiedDisplay()}</td>
<td className={classes.td}>{dateSubmittedDisplay()}</td>

<td className={classes.actionIcons}>
{projectRules && (
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Projects/ProjectsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ const ProjectsPage = ({ contentContainerRef }) => {
{ id: "firstName", label: "Created By" },
{ id: "dateCreated", label: "Created On" },
{ id: "dateModified", label: "Last Modified" },
{ id: "dateSubmitted", label: "Submitted" },
{
id: "contextMenu",
label: ""
Expand Down
4 changes: 4 additions & 0 deletions client/src/services/project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function del(id) {
return axios.delete(baseUrl + "/" + id);
}

export function submit(id) {
return axios.put(baseUrl + "/submit", id);
}

export function snapshot(id) {
return axios.put(baseUrl + "/snapshot", id);
}
Expand Down
16 changes: 16 additions & 0 deletions server/app/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ const trash = async (req, res) => {
}
};

const submit = async (req, res) => {
try {
const { id, name } = req.body;

const result = await projectService.submit(id, req.user.id, name);
if (result === 1) {
res.sendStatus(403);
} else {
res.sendStatus(204);
}
} catch (err) {
res.status(500).send(err);
}
};

const snapshot = async (req, res) => {
try {
const { id, name } = req.body;
Expand Down Expand Up @@ -160,6 +175,7 @@ module.exports = {
del,
hide,
trash,
submit,
snapshot,
renameSnapshot,
getAllArchivedProjects
Expand Down
1 change: 1 addition & 0 deletions server/app/routes/project.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ router.post("/", jwtSession.validateUser, projectController.post);
router.put("/hide", jwtSession.validateUser, projectController.hide);
router.put("/trash", jwtSession.validateUser, projectController.trash);
router.put("/snapshot", jwtSession.validateUser, projectController.snapshot);
router.put("/submit", jwtSession.validateUser, projectController.submit);
router.put(
"/renameSnapshot",
jwtSession.validateUser,
Expand Down
18 changes: 18 additions & 0 deletions server/app/services/project.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ const snapshot = async (id, loginId, name) => {
}
};

const submit = async (id, loginId, name) => {
try {
await poolConnect;
const request = pool.request();

request.input("id", id);
request.input("loginId", loginId);
request.input("name", name);

const response = await request.execute("Project_Submit");
return response.returnValue;
} catch (err) {
console.log("err:", err);
return Promise.reject(err);
}
};

const renameSnapshot = async (id, loginId, name) => {
try {
await poolConnect;
Expand Down Expand Up @@ -175,6 +192,7 @@ module.exports = {
del,
hide,
trash,
submit,
snapshot,
renameSnapshot,
getAllArchivedProjects
Expand Down
Loading