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

ternary to show either 'view workorders' or 'create new workorder' #22

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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