Added employee email validation IO-421
This commit is contained in:
@@ -5955,6 +5955,32 @@
|
|||||||
</concept_node>
|
</concept_node>
|
||||||
</children>
|
</children>
|
||||||
</folder_node>
|
</folder_node>
|
||||||
|
<folder_node>
|
||||||
|
<name>validation</name>
|
||||||
|
<children>
|
||||||
|
<concept_node>
|
||||||
|
<name>useremailmustexist</name>
|
||||||
|
<definition_loaded>false</definition_loaded>
|
||||||
|
<description></description>
|
||||||
|
<comment></comment>
|
||||||
|
<default_text></default_text>
|
||||||
|
<translations>
|
||||||
|
<translation>
|
||||||
|
<language>en-US</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>es-MX</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
<translation>
|
||||||
|
<language>fr-CA</language>
|
||||||
|
<approved>false</approved>
|
||||||
|
</translation>
|
||||||
|
</translations>
|
||||||
|
</concept_node>
|
||||||
|
</children>
|
||||||
|
</folder_node>
|
||||||
</children>
|
</children>
|
||||||
</folder_node>
|
</folder_node>
|
||||||
<folder_node>
|
<folder_node>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
|||||||
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
|
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
|
||||||
import BillFormLines from "./bill-form.lines.component";
|
import BillFormLines from "./bill-form.lines.component";
|
||||||
import { CalculateBillTotal } from "./bill-form.totals.utility";
|
import { CalculateBillTotal } from "./bill-form.totals.utility";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { Button, Form, Input, InputNumber, Select, Switch } from "antd";
|
import { Button, Form, Input, InputNumber, Select, Switch } from "antd";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect } from "react";
|
||||||
|
import { useApolloClient } from "react-apollo";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { QUERY_USERS_BY_EMAIL } from "../../graphql/employees.queries";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
||||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
});
|
});
|
||||||
@@ -21,6 +24,7 @@ export function ShopEmployeesFormComponent({
|
|||||||
handleFinish,
|
handleFinish,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const client = useApolloClient();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEmployee) form.resetFields();
|
if (selectedEmployee) form.resetFields();
|
||||||
}, [selectedEmployee, form]);
|
}, [selectedEmployee, form]);
|
||||||
@@ -159,7 +163,36 @@ export function ShopEmployeesFormComponent({
|
|||||||
>
|
>
|
||||||
<CurrencyInput />
|
<CurrencyInput />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("employees.fields.user_email")} name="user_email">
|
<Form.Item
|
||||||
|
label={t("employees.fields.user_email")}
|
||||||
|
name="user_email"
|
||||||
|
validateTrigger="onBlur"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) => ({
|
||||||
|
async validator(rule, value) {
|
||||||
|
const user_email = getFieldValue("user_email");
|
||||||
|
|
||||||
|
if (user_email && value) {
|
||||||
|
const response = await client.query({
|
||||||
|
query: QUERY_USERS_BY_EMAIL,
|
||||||
|
variables: {
|
||||||
|
email: user_email,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.users.length === 1) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return Promise.reject(
|
||||||
|
t("bodyshop.validation.useremailmustexist")
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]}
|
||||||
|
>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@@ -59,3 +59,11 @@ export const DELETE_EMPLOYEE = gql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const QUERY_USERS_BY_EMAIL = gql`
|
||||||
|
query QUERY_USERS_BY_EMAIL($email: String!) {
|
||||||
|
users(where: { email: { _ilike: $email } }) {
|
||||||
|
email
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -383,6 +383,9 @@
|
|||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"save": "Bodyshop saved successfully. "
|
"save": "Bodyshop saved successfully. "
|
||||||
|
},
|
||||||
|
"validation": {
|
||||||
|
"useremailmustexist": "This email is not a valid user."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"checklist": {
|
"checklist": {
|
||||||
|
|||||||
@@ -383,6 +383,9 @@
|
|||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"save": ""
|
"save": ""
|
||||||
|
},
|
||||||
|
"validation": {
|
||||||
|
"useremailmustexist": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"checklist": {
|
"checklist": {
|
||||||
|
|||||||
@@ -383,6 +383,9 @@
|
|||||||
},
|
},
|
||||||
"successes": {
|
"successes": {
|
||||||
"save": ""
|
"save": ""
|
||||||
|
},
|
||||||
|
"validation": {
|
||||||
|
"useremailmustexist": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"checklist": {
|
"checklist": {
|
||||||
|
|||||||
Reference in New Issue
Block a user