41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
import { useMutation } from "@apollo/react-hooks";
|
|
import { Form, notification } from "antd";
|
|
import React, { useEffect } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { connect } from "react-redux";
|
|
import { createStructuredSelector } from "reselect";
|
|
import { INSERT_NEW_COURTESY_CAR } from "../../graphql/courtesy-car.queries";
|
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
|
import CourtesyCarCreateComponent from "./courtesy-car-create.page.component";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
bodyshop: selectBodyshop
|
|
});
|
|
|
|
export function CourtesyCarCreateContainer({ bodyshop }) {
|
|
const [form] = Form.useForm();
|
|
const [insertCourtesyCar] = useMutation(INSERT_NEW_COURTESY_CAR);
|
|
const { t } = useTranslation();
|
|
|
|
const handleFinish = values => {
|
|
insertCourtesyCar({
|
|
variables: { courtesycar: { ...values, bodyshopid: bodyshop.id } }
|
|
})
|
|
.then(response => {
|
|
notification["success"]({ message: t("courtesycars.successes.saved") });
|
|
})
|
|
.catch(error => console.log("error", error));
|
|
};
|
|
|
|
useEffect(() => {
|
|
document.title = t("titles.courtesycars-create");
|
|
}, [t]);
|
|
|
|
return (
|
|
<Form form={form} autoComplete="no" onFinish={handleFinish}>
|
|
<CourtesyCarCreateComponent />
|
|
</Form>
|
|
);
|
|
}
|
|
export default connect(mapStateToProps, null)(CourtesyCarCreateContainer);
|