diff --git a/src/masks/phoneMask.js b/src/masks/phoneMask.js new file mode 100644 index 0000000..55f2186 --- /dev/null +++ b/src/masks/phoneMask.js @@ -0,0 +1,9 @@ +/* eslint-disable no-param-reassign */ +const phoneMask = (text) => { + text = text.replace(/\D/g, ''); + text = text.replace(/^(\d{2})(\d)/g, '($1) $2'); + text = text.replace(/(\d)(\d{4})$/, '$1-$2'); + return text; +}; + +export default phoneMask; diff --git a/src/services/api.js b/src/services/api.js new file mode 100644 index 0000000..f034e4c --- /dev/null +++ b/src/services/api.js @@ -0,0 +1,17 @@ +import axios from 'axios'; +import AsyncStorage from '@react-native-community/async-storage'; +import Config from 'react-native-config'; + +const instance = axios.create({ + baseURL: Config.API, +}); + +instance.interceptors.request.use(async (config) => ({ + ...config, + headers: { + ...config.headers, + Authorization: await AsyncStorage.getItem('access_token'), + }, +})); + +export default instance; diff --git a/src/services/api2.js b/src/services/api2.js new file mode 100644 index 0000000..45fdf1a --- /dev/null +++ b/src/services/api2.js @@ -0,0 +1,17 @@ +import axios from 'axios'; +import AsyncStorage from '@react-native-community/async-storage'; +import Config from 'react-native-config'; + +const instance = axios.create({ + baseURL: Config.API2, +}); + +instance.interceptors.request.use(async (config) => ({ + ...config, + headers: { + ...config.headers, + Authorization: await AsyncStorage.getItem('access_token'), + }, +})); + +export default instance; diff --git a/src/theme/theme.js b/src/theme/theme.js new file mode 100644 index 0000000..f653e58 --- /dev/null +++ b/src/theme/theme.js @@ -0,0 +1,21 @@ +export default { + font: { + family: '', + sizes: { + S: 12, + SM: 14, + M: 17, + ML: 20, + L: 22, + LX: 25, + X: 28, + }, + }, + colors: { + primary: '#448AFF', + red: '#ff0000', + grey: '#9E9E9E', + white: '#ffffff', + black: '#000000', + }, +}; diff --git a/src/validators/phone.js b/src/validators/phone.js new file mode 100644 index 0000000..dce51ac --- /dev/null +++ b/src/validators/phone.js @@ -0,0 +1,38 @@ +import lodashIsEmpty from 'lodash/isEmpty'; + +/** + * Validate if value is a valid date + * @param {String} value Param to do valid + * @return {Object} + * @property {Boolean} isValid `true` if value is a valid value + * @property {String} errorText message of an invalid rule + * */ +const phone = (value) => { + const errorObject = { + isValid: false, + errorText: 'Telefone em formato inválido', + }; + + const successObject = { + isValid: true, + }; + + if (lodashIsEmpty(value)) { + return successObject; + } + + const regex = /\d+/g; + + let phoneNumber = value.match(regex); + + phoneNumber = phoneNumber ? phoneNumber.join('') : ''; + + // Length including region identifier + if (phoneNumber.length !== 11 && phoneNumber.length !== 13) { + return errorObject; + } + + return successObject; +}; + +export default phone; diff --git a/src/validators/required.js b/src/validators/required.js new file mode 100644 index 0000000..a736e1b --- /dev/null +++ b/src/validators/required.js @@ -0,0 +1,27 @@ +import lodashIsEmpty from 'lodash/isEmpty'; + +/** + * Validate if value is true + * @param {String} value Param to do valid + * + * @return {Object} + * @property {Boolean} isValid `true` if value is a valid value + * @property {String} errorText message of an invalid rule + * */ +const required = (value, errorMessage) => { + const errorText = errorMessage || 'Este campo é obrigatório'; + const errorObject = { + isValid: false, + errorText, + }; + + if (lodashIsEmpty(value)) { + return errorObject; + } + + return { + isValid: true, + }; +}; + +export default required;