Skip to content

Commit

Permalink
admin view retrieving data. no put request yet
Browse files Browse the repository at this point in the history
  • Loading branch information
cdalton713 committed Nov 28, 2020
1 parent 8057b85 commit ba87554
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 43 deletions.
17 changes: 8 additions & 9 deletions client/src/api/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ export const dataFetchReducer = (state, action) => {
...state,
isLoading: true,
isError: false,
allTickets: {},
data: fields,
};
case "FETCH_SUCCESS":
case "FETCH_TICKET_SUCCESS":
return {
...state,
isLoading: false,
isError: false,
data: action.payload,
};
case "FETCH_ALL_TICKETS_SUCCESS":
return {
...state,
isTicketsLoading: false,
isError: false,
};
case "FETCH_TECHNICIANS_SUCCESS":
return {
...state,
Expand All @@ -55,6 +47,13 @@ export const dataFetchReducer = (state, action) => {
return {
...state,
workLogData: action.payload,
workLogLoading: false,
};
case "FETCH_ASSIGN_LOG_SUCCESS":
return {
...state,
assignLog: action.payload,
assignLogLoading: false,
};
default:
throw new Error();
Expand Down
14 changes: 9 additions & 5 deletions client/src/components/form/ManageTicketForm/adminView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import { TimeLogTable } from "../../table/TimeLogTable";

var _ = require("lodash");

export const AdminView = ({ data, dispatch, workLogData }, ...props) => {
export const AdminView = (
{ data, dispatch, workLogData, assignLogData },
...props
) => {
return (
<>
<EuiSpacer />
Expand Down Expand Up @@ -93,9 +96,10 @@ export const AdminView = ({ data, dispatch, workLogData }, ...props) => {
<EuiFlexItem style={{ maxWidth: 500 }}>
<EuiFormRow hasEmptyLabelSpace={true}>
<>
<TicketAssignmentTable />
<EuiSpacer size={"s"} />
<AddTechnicianPopover />
{/* TODO: WAITING ON BACKEND*/}
{/*<TicketAssignmentTable />*/}
{/*<EuiSpacer size={"s"} />*/}
{/*<AddTechnicianPopover />*/}
</>
</EuiFormRow>
</EuiFlexItem>
Expand All @@ -109,7 +113,7 @@ export const AdminView = ({ data, dispatch, workLogData }, ...props) => {
<TimeLogTable />
</EuiFlexItem>
</EuiFlexGroup>

{/* TODO: WAITING ON BACKEND*/}
{/*<EuiFlexGroup style={{ maxWidth: 1000 }}>*/}
{/* <EuiFlexItem style={{ maxWidth: 200 }}>*/}
{/* <EuiFormRow>*/}
Expand Down
16 changes: 14 additions & 2 deletions client/src/components/form/ManageTicketForm/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ const postData = async (endpoint, data) => {
return response;
};

export const handleFormSubmit = async (e, data, endpoint) => {
const putData = async (endpoint, data) => {
console.log(data);
const response = await axios.put(endpoint, data);
return response;
};

export const handleFormSubmit = async (e, data, endpoint, put) => {
const errors = _.find(data, ["error", true]);
if (errors === undefined) {
let d = data.map((o) => ({ [o.name]: o.value }));
const dd = Object.assign({}, ...d);

const response = await postData(endpoint, dd);
let response;
if (put === true) {
response = await putData(endpoint, dd);
} else {
response = await postData(endpoint, dd);
}

addToast({
title: "Ticket Submitted!",
color: "success",
Expand Down
1 change: 1 addition & 0 deletions client/src/components/form/MyTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const MyTextField = (
name={item.name}
onChange={(e) => handleChange(e)}
onBlur={(e) => handleBlur(e)}
value={item.value}
/>
</EuiFormRow>
);
Expand Down
19 changes: 18 additions & 1 deletion client/src/components/form/selectOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ export const selectOptions = [
name: "problem_category",
options: [
{ value: "", text: "" },

{ value: "general_help", text: "General Help" },
{ value: "problem_2", text: "Problem 2" },
{ value: "login_help", text: "Login Help" },
{ value: "missing_documents", text: "Missing Documents" },
{ value: "class_access", text: "Can't access your class?" },
{ value: "view_grades_help", text: "Can't see your grades?" },
{ value: "upload_help", text: "Upload Help" },
{ value: "download_help", text: "Download Help" },
{ value: "tigerware_support", text: "Tigerware support" },
{ value: "hardware_support", text: "Hardware support" },
],
},
{
Expand Down Expand Up @@ -258,6 +266,11 @@ export const selectOptions = [
{ value: "broken_screen", text: "Broken Screen" },
{ value: "expanded_battery", text: "Expanded Battery" },
{ value: "faulty_ram", text: "Faulty RAM" },
{ value: "network_problem", text: "Network Problem" },
{ value: "post_error", text: "Post Error" },
{ value: "virus_infection", text: "Malware or Spyware Infection" },
{ value: "system_overheat", text: "System overheating" },
{ value: "system_crash", text: "System Crash" },
],
},
{
Expand All @@ -269,6 +282,10 @@ export const selectOptions = [
{ value: "storage_device", text: "Storage Device" },
{ value: "power_supply", text: "Power Supply" },
{ value: "gpu", text: "GPU" },
{ value: "motherboard", text: "Motherboard" },
{ value: "heatsink", text: "Heatsink" },
{ value: "case_fans", text: "Case Fans" },
{ value: "usb_port", text: "USB Port" },
],
},
{
Expand Down
112 changes: 93 additions & 19 deletions client/src/routes/admin/ManageTicket.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,58 +31,129 @@ import axios from "../../api/api";
import { fields } from "../../components/form/ManageTicketForm/fields";
import { dataFetchReducer } from "../../api/reducers";
import { MyStat } from "./Stats";
import { personFields } from "../../components/form/person/fields";

var _ = require("lodash");

const TicketForm = ({ selected }, ...props) => {
const [workLogData, setWorkLogData] = useState(null);
const [workLogLoading, setWorkLogLoading] = useState(true);
const [data, setData] = useState(fields);
const TicketForm = ({ setSelectedTicket, selectedTicket }, ...props) => {
const [state, dispatch] = useReducer(dataFetchReducer, {
isLoading: false,
isError: false,
data: fields,
workLogData: null,
workLogLoading: true,
assignLog: null,
assignLogLoading: true,
});

useEffect(() => {
const fetchWorkLog = async () => {
const fetchWorkLog = async (selectedTicket) => {
try {
const result = await axios.get("/ticket/work/" + selected.id);
setWorkLogData(result.data);
setWorkLogLoading(false);
const result = await axios.get(
"/ticket/work/" + selectedTicket.ticket_id
);
dispatch({ type: "FETCH_WORK_LOG_SUCCESS", payload: result.data });
} catch (error) {
console.log(error);
}
};

const fetchData = () => {
const fetchAssignLog = async (selectedTicket) => {
try {
const ticketFields = axios.get("/ticket/" + selected.id);
const userFields = axios.get("/user/" + selected.lsu_id);
const result = await axios.get(
"/ticket/assign/" + selectedTicket.ticket_id
);
dispatch({ type: "FETCH_ASSIGN_LOG_SUCCESS", payload: result.data });
} catch (error) {
console.log(error);
}
};
fetchData();
fetchWorkLog();
}, [selected]);

const fetchData = async (selectedTicket) => {
String.prototype.toProperCase = function () {
return this.replace(/\w\S*/g, function (txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
};

try {
const result = await axios.get("/ticket/" + selectedTicket.ticket_id);
const userResult = await axios.get("/user/" + selectedTicket.lsu_id);
let final = [];
for (const [key, value] of Object.entries(result.data)) {
console.log(`${key}: ${value}`);
final.push({
name: key,
value: value,
error: false,
error_type: "none",
label: key.replace("_", " ").toProperCase(),
});
}

for (const [key, value] of Object.entries(userResult.data)) {
console.log(`${key}: ${value}`);
final.push({
name: key,
value: value,
error: false,
error_type: "none",
label: key.replace("_", " ").toProperCase(),
});
}
const union = _.unionBy(final, fields, "name");
dispatch({
type: "FETCH_TICKET_SUCCESS",
payload: union,
});
} catch (error) {
console.log(error);
}
};
if (selectedTicket != null) {
fetchData(selectedTicket);
fetchWorkLog(selectedTicket);
fetchAssignLog(selectedTicket);
}
}, [selectedTicket]);

const internalFormSubmit = async (e, data) => {
const response = await handleFormSubmit(e, data, "/ticket");
if (response.status === 201) {
dispatch({ type: "CLEAR_FORM" });
}
};
return (
<>
<EuiForm>
<EuiTitle size={"s"}>
<h3>Customer Information</h3>
</EuiTitle>
<UserView data={data} setData={setData} />
<AdminView data={data} setData={setData} workLogData={workLogData} />
{state.isLoading ? null : (
<>
<UserView data={state.data} dispatch={dispatch} />
<AdminView
data={state.data}
dispatch={dispatch}
workLogData={state.workLogData}
assignLogData={state.assignLogData}
/>
</>
)}

<EuiSpacer />
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButton
type={"submit"}
onClick={(e) => handleFormSubmit(e, data)}
onClick={(e) => internalFormSubmit(e, state.data)}
>
Submit
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiForm>
<Debug data={data} />
<Debug data={state.data} />
</>
);
};
Expand Down Expand Up @@ -171,7 +242,10 @@ export const ManageTicket = (props) => {
{selectedTicket == null ? (
"Please select ticket."
) : (
<TicketForm selected={selectedTicket} setData={setSelectedTicket} />
<TicketForm
selectedTicket={selectedTicket}
setSelectedTicket={setSelectedTicket}
/>
)}
</EuiPanel>
</>
Expand Down
1 change: 0 additions & 1 deletion client/src/routes/admin/SelectTechnician.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const SelectTechnician = ({ technician, setTechnician }, ...props) => {

useEffect(() => {
const fetchData = async () => {
dispatch({ type: "FETCH_INIT" });
try {
const result = await axios.get("/user/admin");
const final = {
Expand Down
6 changes: 0 additions & 6 deletions client/src/routes/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import {
EuiCode,
} from "@elastic/eui";
import { NavBar } from "../../components/navbar/navbar";
import { TicketsTable } from "../../components/table/TicketsTable";
import { AdminTicketFlyout } from "../../components/flyout/flyout";
import { UserView } from "../../components/form/ManageTicketForm/userView";
import { fields } from "../../components/form/ManageTicketForm/fields";
import { handleFormSubmit } from "../../components/form/ManageTicketForm/handlers";
import { AdminView } from "../../components/form/ManageTicketForm/adminView";
import { SelectTechnician } from "./SelectTechnician";
import { ManageTicket } from "./ManageTicket";

Expand Down

0 comments on commit ba87554

Please sign in to comment.