Skip to content

Commit

Permalink
Merge pull request #22 from michacurri/workorderDisplay
Browse files Browse the repository at this point in the history
ternary to show either 'view workorders' or 'create new workorder'
  • Loading branch information
michacurri authored Jan 2, 2021
2 parents b435a3b + c5c680c commit 6c74587
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/components/root/Workorder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, Fragment } from "react";
import React, { useContext, Fragment, useState } from "react";
import { UserContext } from "../../backend/authorization/UserContext";
import { ImpersonatorContext } from "../../backend/authorization/ImpersonatorContext";
import WorkorderDisplay from "./WorkorderDisplay";
Expand All @@ -7,13 +7,31 @@ import WorkorderCreate from "../admin/WorkorderCreate";
const Workorder = () => {
const [currentProfile] = useContext(UserContext);
const [admin] = useContext(ImpersonatorContext);
const [workView, setWorkView] = useState("display");

function workorderClick() {
if (workView === "display") {
setWorkView("create");
} else {
setWorkView("display");
}
}

let content;
if (!admin) {
content = (
<Fragment>
<WorkorderDisplay currentProfile={currentProfile} />
<WorkorderCreate currentProfile={currentProfile} />
{workView === "display" ? (
<Fragment>
<button onClick={workorderClick}>Create new Workorder</button>
<WorkorderDisplay currentProfile={currentProfile} />
</Fragment>
) : (
<Fragment>
<button onClick={workorderClick}>View Workorders</button>
<WorkorderCreate currentProfile={currentProfile} />
</Fragment>
)}
</Fragment>
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/root/WorkorderDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Paper from "@material-ui/core/Paper";

const useStyles = makeStyles({
table: {
minWidth: 650,
minWidth: 350,
},
});

Expand Down

0 comments on commit 6c74587

Please sign in to comment.