Added parts location to job line list view. BOD-208

This commit is contained in:
Patrick Fic
2020-07-31 10:25:58 -07:00
parent 23f8243002
commit 4d60ffd597
25 changed files with 933 additions and 1 deletions

View File

@@ -0,0 +1,83 @@
import React, { useState, useEffect } from "react";
import { Input, notification, Select } from "antd";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import { useMutation } from "react-apollo";
import { UPDATE_JOB_LINE } from "../../graphql/jobs-lines.queries";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
//currentUser: selectCurrentUser
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function JobLineLocationPopup({ bodyshop, jobline }) {
const [editing, setEditing] = useState(false);
const [loading, setLoading] = useState(false);
const [location, setLocation] = useState(jobline.location);
const [updateJob] = useMutation(UPDATE_JOB_LINE);
const { t } = useTranslation();
useEffect(() => {
if (editing) setLocation(jobline.location);
}, [editing, jobline.location]);
const handleChange = (e) => {
setLocation(e);
};
const handleSave = async (e) => {
setLoading(true);
const result = await updateJob({
variables: { lineId: jobline.id, line: { location: location || "" } },
});
if (!!!result.errors) {
notification["success"]({ message: t("joblines.successes.saved") });
} else {
notification["error"]({
message: t("joblines.errors.saving", {
error: JSON.stringify(result.errors),
}),
});
}
setLoading(false);
setEditing(false);
};
if (editing)
return (
<div>
<Select
autoFocus
dropdownMatchSelectWidth={100}
value={location}
onSelect={handleChange}
onBlur={handleSave}
>
{bodyshop.md_parts_locations.map((loc, idx) => (
<Select.Option key={idx} value={loc}>
{loc}
</Select.Option>
))}
</Select>
</div>
);
return (
<div
style={{ width: "100%", minHeight: "2rem", cursor: "pointer" }}
onClick={() => setEditing(true)}
>
{jobline.location}
</div>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(JobLineLocationPopup);