57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import React from "react";
|
|
import { useMutation } from "react-apollo";
|
|
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { Dropdown, Menu, notification } from "antd";
|
|
import { DownOutlined } from "@ant-design/icons";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
bodyshop: selectBodyshop,
|
|
});
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
//setUserLanguage: language => dispatch(setUserLanguage(language))
|
|
});
|
|
|
|
export function ScheduleAtChange({ bodyshop, event }) {
|
|
const [updateJob] = useMutation(UPDATE_JOB);
|
|
const { t } = useTranslation();
|
|
|
|
const onClick = async ({ key }) => {
|
|
const result = await updateJob({
|
|
variables: { jobId: event.job.id, job: { alt_transport: key } },
|
|
});
|
|
|
|
if (!!!result.errors) {
|
|
notification["success"]({ message: t("appointments.successes.saved") });
|
|
} else {
|
|
notification["error"]({
|
|
message: t("appointments.errors.saving", {
|
|
error: JSON.stringify(result.errors),
|
|
}),
|
|
});
|
|
}
|
|
};
|
|
const menu = (
|
|
<Menu
|
|
selectedKeys={[event.job && event.job.alt_transport]}
|
|
onClick={onClick}
|
|
>
|
|
{bodyshop.appt_alt_transport &&
|
|
bodyshop.appt_alt_transport.map((alt) => (
|
|
<Menu.Item key={alt}>{alt}</Menu.Item>
|
|
))}
|
|
</Menu>
|
|
);
|
|
return (
|
|
<Dropdown overlay={menu}>
|
|
<a href=" #" onClick={(e) => e.preventDefault()}>
|
|
<DownOutlined />
|
|
</a>
|
|
</Dropdown>
|
|
);
|
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ScheduleAtChange);
|