Skip to content

Commit

Permalink
initing theme and services
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Banci <guibanci@gmail.com>
  • Loading branch information
gdeusdara committed Aug 30, 2021
1 parent 3fcbac3 commit 1833c83
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/masks/phoneMask.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions src/services/api.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions src/services/api2.js
Original file line number Diff line number Diff line change
@@ -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;
21 changes: 21 additions & 0 deletions src/theme/theme.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
38 changes: 38 additions & 0 deletions src/validators/phone.js
Original file line number Diff line number Diff line change
@@ -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;
27 changes: 27 additions & 0 deletions src/validators/required.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 1833c83

Please sign in to comment.