Added phone validation + new phone input box IO-414
This commit is contained in:
@@ -5,7 +5,9 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import { openChatByPhone } from "../../redux/messaging/messaging.actions";
|
import { openChatByPhone } from "../../redux/messaging/messaging.actions";
|
||||||
import PhoneFormItem from "../form-items-formatted/phone-form-item.component";
|
import PhoneFormItem, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
//currentUser: selectCurrentUser
|
//currentUser: selectCurrentUser
|
||||||
@@ -26,7 +28,14 @@ export function ChatNewConversation({ openChatByPhone }) {
|
|||||||
const popContent = (
|
const popContent = (
|
||||||
<div>
|
<div>
|
||||||
<Form form={form} onFinish={handleFinish}>
|
<Form form={form} onFinish={handleFinish}>
|
||||||
<Form.Item label={t("messaging.labels.phonenumber")} name="phoneNumber">
|
<Form.Item
|
||||||
|
label={t("messaging.labels.phonenumber")}
|
||||||
|
name="phoneNumber"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "phoneNumber"),
|
||||||
|
]}
|
||||||
|
>
|
||||||
<PhoneFormItem />
|
<PhoneFormItem />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { useTranslation } from "react-i18next";
|
|||||||
import ContractStatusSelector from "../contract-status-select/contract-status-select.component";
|
import ContractStatusSelector from "../contract-status-select/contract-status-select.component";
|
||||||
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
import FormDatePicker from "../form-date-picker/form-date-picker.component";
|
||||||
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
|
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
|
||||||
import InputPhone from "../form-items-formatted/phone-form-item.component";
|
import InputPhone, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
||||||
|
|
||||||
@@ -207,6 +209,8 @@ export default function ContractFormComponent({ form, create = false }) {
|
|||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required"),
|
message: t("general.validation.required"),
|
||||||
},
|
},
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "driver_ph1"),
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<InputPhone />
|
<InputPhone />
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
import i18n from "i18next";
|
import i18n from "i18next";
|
||||||
import React, { forwardRef } from "react";
|
|
||||||
import NumberFormat from "react-number-format";
|
|
||||||
import phone from "phone";
|
import phone from "phone";
|
||||||
|
import React, { forwardRef } from "react";
|
||||||
import PhoneInput from "react-phone-input-2";
|
import PhoneInput from "react-phone-input-2";
|
||||||
//import "react-phone-input-2/lib/style.css";
|
import "./phone-form-item.styles.scss";
|
||||||
|
import "react-phone-input-2/lib/high-res.css";
|
||||||
import "react-phone-input-2/lib/plain.css";
|
|
||||||
|
|
||||||
function FormItemPhone(props, ref) {
|
function FormItemPhone(props, ref) {
|
||||||
return (
|
return (
|
||||||
<PhoneInput country={"ca"} {...props} ref={ref} className="ant-input" />
|
<PhoneInput
|
||||||
|
country={"ca"}
|
||||||
|
onlyCountries={["ca", "us"]}
|
||||||
|
ref={ref}
|
||||||
|
className="ant-input"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
// return (
|
// return (
|
||||||
@@ -27,18 +30,27 @@ export default forwardRef(FormItemPhone);
|
|||||||
|
|
||||||
export const PhoneItemFormatterValidation = (getFieldValue, name) => ({
|
export const PhoneItemFormatterValidation = (getFieldValue, name) => ({
|
||||||
async validator(rule, value) {
|
async validator(rule, value) {
|
||||||
PhoneInput({
|
console.log("getFieldValue(name)", getFieldValue(name));
|
||||||
value: getFieldValue(name),
|
|
||||||
isValid: async (value, country) => {
|
const p = phone(getFieldValue(name), "ca");
|
||||||
console.log("value", value);
|
if (p.length > 0) {
|
||||||
if (value.match(/12345/)) {
|
return Promise.resolve();
|
||||||
return Promise.reject(i18n.t("general.validation.invalidphone"));
|
} else {
|
||||||
} else if (value.match(/1234/)) {
|
return Promise.reject(i18n.t("general.validation.invalidphone"));
|
||||||
return false;
|
}
|
||||||
} else {
|
|
||||||
return Promise.resolve();
|
// PhoneInput({
|
||||||
}
|
// value: getFieldValue(name),
|
||||||
},
|
// isValid: async (value, country) => {
|
||||||
});
|
// console.log("value", value);
|
||||||
|
// if (value.match(/12345/)) {
|
||||||
|
|
||||||
|
// } else if (value.match(/1234/)) {
|
||||||
|
// return false;
|
||||||
|
// } else {
|
||||||
|
// return Promise.resolve();
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
.react-tel-input .form-control {
|
||||||
|
width: 100% !important;
|
||||||
|
height: unset !important;
|
||||||
|
border-radius: unset !important;
|
||||||
|
line-height: unset !important;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ 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 InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
||||||
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
||||||
import FormItemPhone from "../form-items-formatted/phone-form-item.component";
|
import FormItemPhone, {PhoneItemFormatterValidation} from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
@@ -62,7 +62,11 @@ export function JobsCreateJobsInfo({ bodyshop, form, selected }) {
|
|||||||
<Form.Item label={t("jobs.fields.ins_ct_fn")} name="ins_ct_fn">
|
<Form.Item label={t("jobs.fields.ins_ct_fn")} name="ins_ct_fn">
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("jobs.fields.ins_ph1")} name="ins_ph1">
|
<Form.Item label={t("jobs.fields.ins_ph1")} name="ins_ph1"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "ins_ph1"),
|
||||||
|
]}>
|
||||||
<FormItemPhone customInput={Input} />
|
<FormItemPhone customInput={Input} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import React, { useContext } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import JobCreateContext from "../../pages/jobs-create/jobs-create.context";
|
import JobCreateContext from "../../pages/jobs-create/jobs-create.context";
|
||||||
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
||||||
import FormItemPhone from "../form-items-formatted/phone-form-item.component";
|
import FormItemPhone, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
export default function JobsCreateOwnerInfoNewComponent() {
|
export default function JobsCreateOwnerInfoNewComponent() {
|
||||||
@@ -134,6 +136,13 @@ export default function JobsCreateOwnerInfoNewComponent() {
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
label={t("owners.fields.ownr_ph1")}
|
label={t("owners.fields.ownr_ph1")}
|
||||||
name={["owner", "data", "ownr_ph1"]}
|
name={["owner", "data", "ownr_ph1"]}
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(
|
||||||
|
getFieldValue,
|
||||||
|
"owner.data.ownr_ph1"
|
||||||
|
),
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
<FormItemPhone customInput={Input} disabled={!state.owner.new} />
|
<FormItemPhone customInput={Input} disabled={!state.owner.new} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import { createStructuredSelector } from "reselect";
|
|||||||
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
import { selectJobReadOnly } from "../../redux/application/application.selectors";
|
||||||
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 InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
|
||||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||||
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
||||||
import FormItemPhone from "../form-items-formatted/phone-form-item.component";
|
import FormItemPhone, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import Car from "../job-damage-visual/job-damage-visual.component";
|
import Car from "../job-damage-visual/job-damage-visual.component";
|
||||||
import FormRow from "../layout-form-row/layout-form-row.component";
|
import FormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
@@ -73,7 +74,14 @@ export function JobsDetailGeneral({ bodyshop, jobRO, job, form }) {
|
|||||||
<Form.Item label={t("jobs.fields.ins_ct_fn")} name="ins_ct_fn">
|
<Form.Item label={t("jobs.fields.ins_ct_fn")} name="ins_ct_fn">
|
||||||
<Input disabled={jobRO} />
|
<Input disabled={jobRO} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("jobs.fields.ins_ph1")} name="ins_ph1">
|
<Form.Item
|
||||||
|
label={t("jobs.fields.ins_ph1")}
|
||||||
|
name="ins_ph1"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "ins_ph1"),
|
||||||
|
]}
|
||||||
|
>
|
||||||
<FormItemPhone customInput={Input} disabled={jobRO} />
|
<FormItemPhone customInput={Input} disabled={jobRO} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import React from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
|
import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component";
|
||||||
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
||||||
import FormItemPhone from "../form-items-formatted/phone-form-item.component";
|
import FormItemPhone, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
export default function OwnerDetailFormComponent({ form, loading }) {
|
export default function OwnerDetailFormComponent({ form, loading }) {
|
||||||
@@ -118,7 +120,14 @@ export default function OwnerDetailFormComponent({ form, loading }) {
|
|||||||
>
|
>
|
||||||
<FormItemEmail email={getFieldValue("ownr_ea")} />
|
<FormItemEmail email={getFieldValue("ownr_ea")} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("owners.fields.ownr_ph1")} name="ownr_ph1">
|
<Form.Item
|
||||||
|
label={t("owners.fields.ownr_ph1")}
|
||||||
|
name="ownr_ph1"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "ownr_ph1"),
|
||||||
|
]}
|
||||||
|
>
|
||||||
<FormItemPhone customInput={Input} />
|
<FormItemPhone customInput={Input} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import {
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
||||||
import PhoneFormItem from "../form-items-formatted/phone-form-item.component";
|
import PhoneFormItem, {
|
||||||
|
PhoneItemFormatterValidation,
|
||||||
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import FormListMoveArrows from "../form-list-move-arrows/form-list-move-arrows.component";
|
import FormListMoveArrows from "../form-list-move-arrows/form-list-move-arrows.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
import ShopInfoIntakeChecklistComponent from "./shop-info.intake.component";
|
import ShopInfoIntakeChecklistComponent from "./shop-info.intake.component";
|
||||||
@@ -100,7 +102,14 @@ export default function ShopInfoComponent({ form, saveLoading }) {
|
|||||||
<Form.Item label={t("bodyshop.fields.email")} name="email">
|
<Form.Item label={t("bodyshop.fields.email")} name="email">
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("bodyshop.fields.phone")} name="phone">
|
<Form.Item
|
||||||
|
label={t("bodyshop.fields.phone")}
|
||||||
|
name="phone"
|
||||||
|
rules={[
|
||||||
|
({ getFieldValue }) =>
|
||||||
|
PhoneItemFormatterValidation(getFieldValue, "phone"),
|
||||||
|
]}
|
||||||
|
>
|
||||||
<PhoneFormItem />
|
<PhoneFormItem />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import {
|
|||||||
InputNumber,
|
InputNumber,
|
||||||
Select,
|
Select,
|
||||||
Space,
|
Space,
|
||||||
Typography,
|
Typography
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
||||||
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
import FormItemEmail from "../form-items-formatted/email-form-item.component";
|
||||||
import PhoneFormItem, {
|
import PhoneFormItem, {
|
||||||
PhoneItemFormatterValidation,
|
PhoneItemFormatterValidation
|
||||||
} from "../form-items-formatted/phone-form-item.component";
|
} from "../form-items-formatted/phone-form-item.component";
|
||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user