Added group verify to the reporting page RPS-74

This commit is contained in:
Patrick Fic
2021-02-17 17:40:31 -08:00
parent 969485ac03
commit 321ec92d91
7 changed files with 75 additions and 32 deletions

View File

@@ -0,0 +1,50 @@
import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
import { useMutation } from "@apollo/client";
import { message, Switch } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { UPDATE_JOB } from "../../../graphql/jobs.queries";
import { toggleGroupVerified } from "../../../redux/reporting/reporting.actions";
const mapStateToProps = createStructuredSelector({});
const mapDispatchToProps = (dispatch) => ({
toggleGroupVerified: (jobId) => dispatch(toggleGroupVerified(jobId)),
});
export default connect(mapStateToProps, mapDispatchToProps)(GroupVerifySwitch);
export function GroupVerifySwitch({
job,
loading,
loadingCallback,
toggleGroupVerified,
}) {
const [updateJob] = useMutation(UPDATE_JOB);
const handleVerifyGroup = async (val) => {
if (loadingCallback) loadingCallback(true);
const result = await updateJob({
variables: { jobId: job.id, job: { group_verified: val } },
});
if (!result.errors) {
message.success("Vehicle group updated.");
toggleGroupVerified(job.id);
} else {
message.error("Error updating job.");
}
if (loadingCallback) loadingCallback(false);
};
return (
<Switch
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
disabled={loading}
checked={job.group_verified}
onChange={handleVerifyGroup}
/>
);
}

View File

@@ -1,18 +1,13 @@
import {
AlertFilled,
DownOutlined,
LoadingOutlined,
CloseOutlined,
CheckOutlined,
} from "@ant-design/icons";
import { AlertFilled, DownOutlined, LoadingOutlined } from "@ant-design/icons";
import { useMutation } from "@apollo/client";
import { Dropdown, Menu, message, Space, Switch } from "antd";
import { Dropdown, Menu, message, Space } from "antd";
import React, { useState } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { UPDATE_JOB } from "../../../graphql/jobs.queries";
import ipcTypes from "../../../ipc.types";
import { selectBodyshop } from "../../../redux/user/user.selectors";
import GroupVerifySwitch from "../group-verify-switch/group-verify-switch.component";
import JobsGroupModalMolecule from "../jobs-group-modal/jobs-group-modal.molecule";
const { ipcRenderer } = window;
@@ -49,20 +44,6 @@ export function JobGroupMolecule({ bodyshop, jobId, group, job }) {
setLoading(false);
};
const handleVerifyGroup = async (val) => {
setLoading(true);
const result = await updateJob({
variables: { jobId: jobId, job: { group_verified: val } },
});
if (!result.errors) {
message.success("Vehicle group updated.");
} else {
message.error("Error updating job.");
}
setLoading(false);
};
const menu = (
<Menu onClick={handleMenuClick}>
{bodyshop.groups.map((g, idx) => (
@@ -87,12 +68,10 @@ export function JobGroupMolecule({ bodyshop, jobId, group, job }) {
)}
{group && (
<div style={{ marginLeft: ".2rem" }}>
<Switch
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
disabled={loading}
defaultChecked={job.group_verified}
onChange={handleVerifyGroup}
<GroupVerifySwitch
job={job}
loading={loading}
loadingCallback={setLoading}
/>
</div>
)}

View File

@@ -13,6 +13,7 @@ import {
} from "../../../redux/reporting/reporting.selectors";
import { alphaSort } from "../../../util/sorters";
import VehicleGroupAlertAtom from "../../atoms/vehicle-group-alert/vehicle-group-alert.atom";
import GroupVerifySwitch from "../group-verify-switch/group-verify-switch.component";
const { ipcRenderer } = window;
@@ -99,9 +100,7 @@ export function ReportingJobsListMolecule({
dataIndex: "group_verified",
key: "group_verified",
sorter: (a, b) => a.group_verified - b.group_verified,
render: (text, record) => (
<Checkbox disabled={true} checked={record.group_verified} />
),
render: (text, record) => <GroupVerifySwitch job={record} />,
},
{
title: "$ (Act./Target)",

View File

@@ -20,7 +20,6 @@ const mapStateToProps = createStructuredSelector({
error: selectReportingError,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
setSelectedJobId: (id) => dispatch(setSelectedJobId(id)),
});