Skip to content

Commit f659a19

Browse files
committed
feat(webpage): add mask to phone input number on pressure phone
1 parent 2783846 commit f659a19

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

clients/packages/webpage-client/src/bonde-webpage/components/forms/InputField.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import styled from '@emotion/styled';
33
import { useField } from 'react-final-form';
4+
import InputMask from 'react-input-mask';
5+
46
import Box from './Box';
57
import Label from './Label';
68
import Raise from './Raise';
@@ -24,6 +26,7 @@ export interface InputFieldProperties {
2426
label?: string;
2527
validate?: any;
2628
disabled?: boolean;
29+
mask?: string;
2730
}
2831

2932
const InputField: React.FC<InputFieldProperties> = ({
@@ -32,7 +35,8 @@ const InputField: React.FC<InputFieldProperties> = ({
3235
type,
3336
label,
3437
disabled,
35-
validate
38+
validate,
39+
mask
3640
}) => {
3741
const { input, meta } = useField(name, { validate });
3842

@@ -42,12 +46,18 @@ const InputField: React.FC<InputFieldProperties> = ({
4246
{label && <Label>{label}</Label>}
4347
{meta.touched && meta.error && <Raise>{meta.error}</Raise>}
4448
</Box>
45-
<InputStyled
46-
{...input}
47-
disabled={disabled}
48-
placeholder={placeholder}
49-
type={type || input.type}
50-
/>
49+
{mask ? (
50+
<InputMask mask={mask} value={input.value} onChange={input.onChange}>
51+
{(inputProps) => <InputStyled {...inputProps} type="tel" disableUnderline />}
52+
</InputMask>
53+
) : (
54+
<InputStyled
55+
{...input}
56+
disabled={disabled}
57+
placeholder={placeholder}
58+
type={type || input.type}
59+
/>
60+
)}
5161
</>
5262
);
5363
}

clients/packages/webpage-client/src/bonde-webpage/components/forms/Validators.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const regexPhoneE164 = /^\+\d{12,13}$/;
2929

3030
const isValidPhoneE164 = ({ code, invalid }: { code: string; invalid: string }) =>
3131
(value: string) => {
32+
value = value.replace("(", "").replace(")", "").replace("-", "").split(" ").join("")
33+
3234
const phoneE164 = /^\+/.test(value) ? value : `+${value}`;
3335
const message = [11, 12].includes(phoneE164.length) ? code : invalid;
3436
return regexPhoneE164.test(phoneE164) ? undefined : message;

clients/packages/webpage-client/src/bonde-webpage/plugins/Phone/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ const PhoneWidget = (props: any) => {
4747
fetchData()
4848
}, [])
4949

50-
const submit = async (values) => {
50+
const submit = async ({ person, ...values }) => {
51+
const phone_number = person.phone_number.replace("(", "").replace(")", "").replace("-", "").split(" ").join("")
5152
const payload = {
5253
...values,
54+
person: {
55+
...person,
56+
phone_number: phone_number
57+
},
5358
targets: [target]
5459
// targets: campaign?.details.targets.map((target) => target.id)
5560
}
@@ -131,6 +136,7 @@ const PhoneWidget = (props: any) => {
131136
name='person.phone_number'
132137
label="Telefone"
133138
placeholder="Insira seu telefone. Ex: +5511987654321"
139+
mask="+55 (99) 9 9999-9999"
134140
validate={Validators.composeValidators(
135141
Validators.required("Preenchimento obrigatório"),
136142
Validators.isValidPhoneE164({

0 commit comments

Comments
 (0)