argous 1.2.234 → 1.2.236
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ContactValidationInput/ContactValidationInput.d.ts +62 -0
- package/dist/components/ContactValidationInput/ContactValidationInput.js +384 -0
- package/dist/components/ContactValidationInput/SealModal.d.ts +6 -0
- package/dist/components/ContactValidationInput/SealModal.js +40 -0
- package/dist/components/ContactValidationInput/index.d.ts +2 -0
- package/dist/components/ContactValidationInput/index.js +8 -0
- package/dist/components/ContactValidationInput/style.css +10 -0
- package/dist/components/index.d.ts +4 -1
- package/dist/components/index.js +4 -1
- package/lib/components/ContactValidationInput/ContactValidationInput.d.ts +62 -0
- package/lib/components/ContactValidationInput/ContactValidationInput.js +403 -0
- package/lib/components/ContactValidationInput/SealModal.js +49 -0
- package/lib/components/ContactValidationInput/index.d.ts +2 -0
- package/lib/components/ContactValidationInput/index.js +1 -0
- package/lib/components/ContactValidationInput/style.css +10 -0
- package/lib/components/index.d.ts +4 -1
- package/lib/components/index.js +4 -1
- package/package.json +4 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TextFieldProps } from '@material-ui/core';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface ContactValidationInputProps {
|
|
6
|
+
/**
|
|
7
|
+
* Component id
|
|
8
|
+
*/
|
|
9
|
+
id?: string,
|
|
10
|
+
/**
|
|
11
|
+
* Component type
|
|
12
|
+
*/
|
|
13
|
+
type: ('cellphone' | 'email'),
|
|
14
|
+
/**
|
|
15
|
+
* MUI TextField props object
|
|
16
|
+
*/
|
|
17
|
+
textFieldProps?: TextFieldProps,
|
|
18
|
+
/**
|
|
19
|
+
* Component style
|
|
20
|
+
*/
|
|
21
|
+
style?: CSSProperties,
|
|
22
|
+
/**
|
|
23
|
+
* Component css className
|
|
24
|
+
*/
|
|
25
|
+
className?: string,
|
|
26
|
+
/**
|
|
27
|
+
* Disabled prop
|
|
28
|
+
* If true disable the component
|
|
29
|
+
*/
|
|
30
|
+
disabled?: boolean,
|
|
31
|
+
/**
|
|
32
|
+
* User CPF document number
|
|
33
|
+
* Required to use the component
|
|
34
|
+
*/
|
|
35
|
+
cpf: string,
|
|
36
|
+
/**
|
|
37
|
+
* User name
|
|
38
|
+
* Required to use the component
|
|
39
|
+
*/
|
|
40
|
+
userName: string,
|
|
41
|
+
/**
|
|
42
|
+
* Input value
|
|
43
|
+
*/
|
|
44
|
+
value: string,
|
|
45
|
+
/**
|
|
46
|
+
* Function called on change
|
|
47
|
+
* @param event
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
onChange: (event: Event) => void,
|
|
51
|
+
/**
|
|
52
|
+
* Function called when component state change
|
|
53
|
+
* @param state
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getComponentData?: (state: object) => void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
declare function ContactValidationInput(props: ContactValidationInputProps) : JSX.Element
|
|
61
|
+
|
|
62
|
+
export default ContactValidationInput;
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
69
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
70
|
+
};
|
|
71
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
|
+
exports.GREEN_COLOR = exports.SealIcon = void 0;
|
|
73
|
+
require("./style.css");
|
|
74
|
+
var SealModal_1 = __importDefault(require("./SealModal"));
|
|
75
|
+
var __1 = require("../");
|
|
76
|
+
var api_1 = require("../../api");
|
|
77
|
+
var utils_1 = require("../../utils");
|
|
78
|
+
var api_2 = require("../../utils/api");
|
|
79
|
+
var core_1 = require("@material-ui/core");
|
|
80
|
+
var react_1 = __importStar(require("react"));
|
|
81
|
+
var io_1 = require("react-icons/io");
|
|
82
|
+
var lia_1 = require("react-icons/lia");
|
|
83
|
+
var pi_1 = require("react-icons/pi");
|
|
84
|
+
var react_maskedinput_1 = __importDefault(require("react-maskedinput"));
|
|
85
|
+
var EMAIL_VALIDATION_REGEX = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/;
|
|
86
|
+
var cellphoneMaskedInput = function (props) { return react_1.default.createElement(react_maskedinput_1.default, __assign({ mask: '(11) 11111-1111' }, props)); };
|
|
87
|
+
exports.SealIcon = pi_1.PiSealCheck;
|
|
88
|
+
exports.GREEN_COLOR = '#00995D';
|
|
89
|
+
var ORANGE_COLOR = '#f5781e';
|
|
90
|
+
var RED_COLOR = '#f44336';
|
|
91
|
+
var INPUT_ADORNMENT_ICON_SIZE = 18;
|
|
92
|
+
var loadingInitialState = {
|
|
93
|
+
input: false,
|
|
94
|
+
validation: false,
|
|
95
|
+
sendValidationLink: false
|
|
96
|
+
};
|
|
97
|
+
var messageInitialState = { color: '', text: '' };
|
|
98
|
+
var initialState = {
|
|
99
|
+
loading: loadingInitialState,
|
|
100
|
+
validated: false,
|
|
101
|
+
validating: false,
|
|
102
|
+
searched: false,
|
|
103
|
+
idContato: '',
|
|
104
|
+
cdContato: '',
|
|
105
|
+
code: '',
|
|
106
|
+
message: messageInitialState
|
|
107
|
+
};
|
|
108
|
+
var ContactValidationInput = function (_a) {
|
|
109
|
+
var id = _a.id, _b = _a.type, type = _b === void 0 ? ('cellphone' || 'email') : _b, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, _d = _a.style, style = _d === void 0 ? {} : _d, _e = _a.className, className = _e === void 0 ? '' : _e, disabled = _a.disabled, _f = _a.cpf, cpf = _f === void 0 ? '' : _f, _g = _a.userName, userName = _g === void 0 ? '' : _g, _h = _a.value, value = _h === void 0 ? '' : _h, _j = _a.onChange, onChange = _j === void 0 ? function () { return ''; } : _j, _k = _a.getComponentData, getComponentData = _k === void 0 ? function () { return ''; } : _k;
|
|
110
|
+
var theme = core_1.useTheme();
|
|
111
|
+
var _l = react_1.useState(__assign(__assign({}, initialState), { inputValue: value })), state = _l[0], setState = _l[1];
|
|
112
|
+
var inputValue = state.inputValue, loading = state.loading, searched = state.searched, validated = state.validated, idContato = state.idContato, cdContato = state.cdContato, code = state.code, message = state.message, validating = state.validating;
|
|
113
|
+
var createModal = utils_1.useModal().createModal;
|
|
114
|
+
var sealModal = createModal(SealModal_1.default);
|
|
115
|
+
var onChangeRef = react_1.useRef(onChange);
|
|
116
|
+
var logicSetState = function (_a) {
|
|
117
|
+
var type = _a.type, field = _a.field, value = _a.value;
|
|
118
|
+
return setState(function (states) {
|
|
119
|
+
var _a, _b;
|
|
120
|
+
return (__assign(__assign({}, states), (_a = {}, _a[type] = (type && field) ? __assign(__assign({}, states[type]), (_b = {}, _b[field] = value, _b)) : value, _a)));
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var cellphoneType = (type === 'cellphone');
|
|
124
|
+
var emailType = (type === 'email');
|
|
125
|
+
var formattedInputValue = (cellphoneType) ? utils_1.numbersOnly(inputValue) : inputValue;
|
|
126
|
+
var invalidType = (!cellphoneType && !emailType);
|
|
127
|
+
var disabledRule = (disabled || !cpf || !userName || invalidType || loading.input);
|
|
128
|
+
var validatedRule = (searched && validated && !validating);
|
|
129
|
+
var noValidatedRule = ((searched && !validated) || validating);
|
|
130
|
+
var validCellphone = (cellphoneType && (formattedInputValue.length === 11));
|
|
131
|
+
var validEmail = (emailType && (EMAIL_VALIDATION_REGEX.test(inputValue)));
|
|
132
|
+
var sendValidationCodeButtonDisabled = (validCellphone || validEmail) ? false : true;
|
|
133
|
+
var codeWasSent = !!idContato;
|
|
134
|
+
var containerStyle = { gap: 10 };
|
|
135
|
+
var endInputAdornmentStyle = { gap: 7 };
|
|
136
|
+
var messageStyle = {
|
|
137
|
+
color: (message.color || theme.palette.text.primary),
|
|
138
|
+
fontStyle: 'italic'
|
|
139
|
+
};
|
|
140
|
+
var validateCodeButtonsContainerStyle = { gap: 10 };
|
|
141
|
+
var validateCodeButtonStyle = {
|
|
142
|
+
width: 'calc(100% - 36px - 10px)'
|
|
143
|
+
};
|
|
144
|
+
var sealButtonStyle = {
|
|
145
|
+
height: '100%',
|
|
146
|
+
color: exports.GREEN_COLOR,
|
|
147
|
+
border: "2px solid " + exports.GREEN_COLOR,
|
|
148
|
+
borderRadius: 4,
|
|
149
|
+
padding: 5,
|
|
150
|
+
fontSize: 22
|
|
151
|
+
};
|
|
152
|
+
var handleOnChange = react_1.useCallback(function (event) {
|
|
153
|
+
event.target.value = event.target.value.toString().toLowerCase();
|
|
154
|
+
logicSetState({ type: 'inputValue', value: event.target.value });
|
|
155
|
+
(typeof onChangeRef.current === 'function') && onChangeRef.current(event);
|
|
156
|
+
}, []);
|
|
157
|
+
var search = react_1.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
|
+
var parameters, fetchOptions, _a, status, cdContato, isVerificado, newInputValue_1, newEvent;
|
|
159
|
+
return __generator(this, function (_b) {
|
|
160
|
+
switch (_b.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
if (invalidType)
|
|
163
|
+
return [2 /*return*/];
|
|
164
|
+
logicSetState({ type: 'loading', field: 'input', value: true });
|
|
165
|
+
parameters = {
|
|
166
|
+
method: 'S',
|
|
167
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
168
|
+
cdCpf: utils_1.numbersOnly(cpf)
|
|
169
|
+
};
|
|
170
|
+
fetchOptions = {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
body: JSON.stringify(parameters),
|
|
173
|
+
headers: api_1.headers()
|
|
174
|
+
};
|
|
175
|
+
return [4 /*yield*/, fetch(api_1.api() + "agscontactconfirmation.rslvr", fetchOptions).then(function (response) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
178
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
179
|
+
}
|
|
180
|
+
}); }); })];
|
|
181
|
+
case 1:
|
|
182
|
+
_a = _b.sent(), status = _a.status, cdContato = _a.cdContato, isVerificado = _a.isVerificado;
|
|
183
|
+
if (status) {
|
|
184
|
+
newInputValue_1 = (cdContato || '');
|
|
185
|
+
setState(function (states) { return (__assign(__assign({}, states), { cdContato: cdContato, inputValue: newInputValue_1, searched: true, validated: isVerificado })); });
|
|
186
|
+
newEvent = new Event('search');
|
|
187
|
+
Object.defineProperty(newEvent, 'target', { writable: false, value: { value: newInputValue_1 } });
|
|
188
|
+
handleOnChange(newEvent);
|
|
189
|
+
}
|
|
190
|
+
logicSetState({ type: 'loading', field: 'input', value: false });
|
|
191
|
+
return [2 /*return*/];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}); }, [cellphoneType, emailType, invalidType, cpf, handleOnChange]);
|
|
195
|
+
react_1.useEffect(function () {
|
|
196
|
+
search();
|
|
197
|
+
}, [search]);
|
|
198
|
+
var sendValidationCode = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
199
|
+
var parameters, fetchOptions, _a, status, idContato, cdContato, dsErro;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0:
|
|
203
|
+
if (invalidType)
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
logicSetState({ type: 'loading', field: 'input', value: true });
|
|
206
|
+
parameters = {
|
|
207
|
+
method: 'C',
|
|
208
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
209
|
+
tpMetodo: (emailType) ? '3' : '',
|
|
210
|
+
cdCpf: utils_1.numbersOnly(cpf),
|
|
211
|
+
dsNome: userName,
|
|
212
|
+
cdContato: formattedInputValue
|
|
213
|
+
};
|
|
214
|
+
fetchOptions = {
|
|
215
|
+
method: 'POST',
|
|
216
|
+
body: JSON.stringify(parameters),
|
|
217
|
+
headers: api_1.headers()
|
|
218
|
+
};
|
|
219
|
+
return [4 /*yield*/, fetch(api_1.api() + "agscontactconfirmation.rslvr", fetchOptions).then(function (response) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
220
|
+
switch (_a.label) {
|
|
221
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
222
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
223
|
+
}
|
|
224
|
+
}); }); })];
|
|
225
|
+
case 1:
|
|
226
|
+
_a = _b.sent(), status = _a.status, idContato = _a.idContato, cdContato = _a.cdContato, dsErro = _a.dsErro;
|
|
227
|
+
if (status) {
|
|
228
|
+
setState(function (states) { return (__assign(__assign({}, states), { idContato: idContato,
|
|
229
|
+
cdContato: cdContato, validated: false, validating: true, message: {
|
|
230
|
+
color: ORANGE_COLOR,
|
|
231
|
+
text: (cellphoneType) ? 'Utilize o código recebido via sms' : (emailType) ? 'Utilize o código recebido via e-mail' : ''
|
|
232
|
+
} })); });
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
(dsErro) && api_2.setError(dsErro);
|
|
236
|
+
}
|
|
237
|
+
logicSetState({ type: 'loading', field: 'input', value: false });
|
|
238
|
+
return [2 /*return*/];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}); };
|
|
242
|
+
var sendValidationLink = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
243
|
+
var parameters, fetchOptions, _a, status, cdContato, dsErro;
|
|
244
|
+
return __generator(this, function (_b) {
|
|
245
|
+
switch (_b.label) {
|
|
246
|
+
case 0:
|
|
247
|
+
if (invalidType)
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
logicSetState({ type: 'loading', field: 'sendValidationLink', value: true });
|
|
250
|
+
parameters = {
|
|
251
|
+
method: 'C',
|
|
252
|
+
type: '2',
|
|
253
|
+
tpMetodo: '4',
|
|
254
|
+
cdCpf: utils_1.numbersOnly(cpf),
|
|
255
|
+
dsNome: userName,
|
|
256
|
+
cdContato: formattedInputValue
|
|
257
|
+
};
|
|
258
|
+
fetchOptions = {
|
|
259
|
+
method: 'POST',
|
|
260
|
+
body: JSON.stringify(parameters),
|
|
261
|
+
headers: api_1.headers()
|
|
262
|
+
};
|
|
263
|
+
return [4 /*yield*/, fetch(api_1.api() + "agscontactconfirmation.rslvr", fetchOptions).then(function (response) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
266
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
267
|
+
}
|
|
268
|
+
}); }); })];
|
|
269
|
+
case 1:
|
|
270
|
+
_a = _b.sent(), status = _a.status, cdContato = _a.cdContato, dsErro = _a.dsErro;
|
|
271
|
+
if (status) {
|
|
272
|
+
setState(function (states) { return (__assign(__assign({}, states), { idContato: '', cdContato: cdContato, code: '', message: {
|
|
273
|
+
color: '',
|
|
274
|
+
text: "O link de valida\u00E7\u00E3o foi enviado para o e-mail \"" + cdContato + "\""
|
|
275
|
+
} })); });
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
(dsErro) && api_2.setError(dsErro);
|
|
279
|
+
}
|
|
280
|
+
logicSetState({ type: 'loading', field: 'sendValidationLink', value: false });
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}); };
|
|
285
|
+
var validateCode = function (_a) {
|
|
286
|
+
var _b = _a.snChancela, snChancela = _b === void 0 ? false : _b;
|
|
287
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
288
|
+
var parameters, fetchOptions, _c, status, isVerificado, messageText_1;
|
|
289
|
+
return __generator(this, function (_d) {
|
|
290
|
+
switch (_d.label) {
|
|
291
|
+
case 0:
|
|
292
|
+
if (invalidType)
|
|
293
|
+
return [2 /*return*/];
|
|
294
|
+
logicSetState({ type: 'loading', field: (snChancela) ? 'input' : 'validation', value: true });
|
|
295
|
+
parameters = {
|
|
296
|
+
method: 'V',
|
|
297
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
298
|
+
cdCpf: utils_1.numbersOnly(cpf),
|
|
299
|
+
dsNome: userName,
|
|
300
|
+
cdCode: code,
|
|
301
|
+
cdContato: formattedInputValue,
|
|
302
|
+
idContato: idContato,
|
|
303
|
+
snChancela: snChancela
|
|
304
|
+
};
|
|
305
|
+
fetchOptions = {
|
|
306
|
+
method: 'POST',
|
|
307
|
+
body: JSON.stringify(parameters),
|
|
308
|
+
headers: api_1.headers()
|
|
309
|
+
};
|
|
310
|
+
return [4 /*yield*/, fetch(api_1.api() + "agscontactconfirmation.rslvr", fetchOptions).then(function (response) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
311
|
+
switch (_a.label) {
|
|
312
|
+
case 0: return [4 /*yield*/, response.json()];
|
|
313
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
314
|
+
}
|
|
315
|
+
}); }); })];
|
|
316
|
+
case 1:
|
|
317
|
+
_c = _d.sent(), status = _c.status, isVerificado = _c.isVerificado;
|
|
318
|
+
if (status) {
|
|
319
|
+
messageText_1 = '';
|
|
320
|
+
if (isVerificado) {
|
|
321
|
+
if (cellphoneType)
|
|
322
|
+
messageText_1 = 'Celular validado com sucesso';
|
|
323
|
+
else if (emailType)
|
|
324
|
+
messageText_1 = 'E-mail validado com sucesso';
|
|
325
|
+
setTimeout(function () { return logicSetState({ type: 'message', value: messageInitialState }); }, 6000);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
messageText_1 = 'Código inválido. Por favor tente novamente.';
|
|
329
|
+
}
|
|
330
|
+
setState(function (states) { return (__assign(__assign({}, states), { validated: isVerificado, validating: false, idContato: '', code: '', message: {
|
|
331
|
+
color: (isVerificado) ? '' : RED_COLOR,
|
|
332
|
+
text: messageText_1
|
|
333
|
+
} })); });
|
|
334
|
+
}
|
|
335
|
+
logicSetState({ type: 'loading', field: (snChancela) ? 'input' : 'validation', value: false });
|
|
336
|
+
return [2 /*return*/];
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
var toSeal = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
342
|
+
var status;
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
switch (_a.label) {
|
|
345
|
+
case 0: return [4 /*yield*/, sealModal()];
|
|
346
|
+
case 1:
|
|
347
|
+
status = (_a.sent()).status;
|
|
348
|
+
if (status)
|
|
349
|
+
validateCode({ snChancela: true });
|
|
350
|
+
return [2 /*return*/];
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}); };
|
|
354
|
+
var checkConsistency = react_1.useCallback(function () {
|
|
355
|
+
if ((formattedInputValue === cdContato) && validated)
|
|
356
|
+
logicSetState({ type: 'validating', value: false });
|
|
357
|
+
else if (!(formattedInputValue === cdContato) && validated)
|
|
358
|
+
logicSetState({ type: 'validating', value: true });
|
|
359
|
+
else if (!(formattedInputValue === cdContato) && validating) {
|
|
360
|
+
setState(function (states) { return (__assign(__assign({}, states), { idContato: '', validated: false, validating: false, code: '', message: messageInitialState })); });
|
|
361
|
+
}
|
|
362
|
+
}, [formattedInputValue, cdContato, validated, validating]);
|
|
363
|
+
react_1.useEffect(function () { return checkConsistency(); }, [formattedInputValue, checkConsistency]);
|
|
364
|
+
react_1.useEffect(function () {
|
|
365
|
+
(typeof getComponentData === 'function') && getComponentData(state);
|
|
366
|
+
}, [state, getComponentData]);
|
|
367
|
+
return react_1.default.createElement(core_1.Grid, __assign({ container: true, direction: 'column' }, { id: id, className: className }, { style: __assign(__assign({}, style), containerStyle) }),
|
|
368
|
+
react_1.default.createElement(core_1.TextField, __assign({}, textFieldProps, { disabled: disabledRule, value: inputValue, onChange: handleOnChange, InputProps: __assign(__assign({}, textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.InputProps), { inputComponent: (cellphoneType) ? cellphoneMaskedInput : undefined, endAdornment: (react_1.default.createElement(core_1.InputAdornment, { position: 'end', style: endInputAdornmentStyle },
|
|
369
|
+
(validatedRule) && react_1.default.createElement(io_1.IoMdCheckmark, { color: exports.GREEN_COLOR, size: INPUT_ADORNMENT_ICON_SIZE }),
|
|
370
|
+
(noValidatedRule) && react_1.default.createElement(lia_1.LiaExclamationTriangleSolid, { color: ORANGE_COLOR, size: INPUT_ADORNMENT_ICON_SIZE }),
|
|
371
|
+
(loading.input) && react_1.default.createElement(core_1.CircularProgress, { color: 'secondary', size: INPUT_ADORNMENT_ICON_SIZE }),
|
|
372
|
+
(noValidatedRule) && (react_1.default.createElement(core_1.Button, { size: 'small', variant: 'contained', disableElevation: true, disabled: disabledRule || loading.validation || sendValidationCodeButtonDisabled, onClick: sendValidationCode }, "Validar")))) }) })),
|
|
373
|
+
(message.text) && (react_1.default.createElement("div", null,
|
|
374
|
+
react_1.default.createElement(core_1.Typography, { style: messageStyle }, message.text))),
|
|
375
|
+
(codeWasSent) && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
376
|
+
react_1.default.createElement("div", { className: 'otp-input-container' },
|
|
377
|
+
react_1.default.createElement(__1.OtpInput, { autoFocus: true, numInputs: 5, disabled: disabledRule || loading.validation, value: code, onChange: function (newCode) { return logicSetState({ type: 'code', value: newCode }); } })),
|
|
378
|
+
react_1.default.createElement(core_1.Grid, { container: true, alignItems: 'center', style: validateCodeButtonsContainerStyle },
|
|
379
|
+
react_1.default.createElement(core_1.IconButton, { title: 'Chancelar', tabIndex: '1', size: 'small', disabled: disabledRule || loading.validation || loading.sendValidationLink, onClick: toSeal, style: sealButtonStyle },
|
|
380
|
+
react_1.default.createElement(exports.SealIcon, null)),
|
|
381
|
+
react_1.default.createElement(core_1.Button, { color: 'primary', variant: 'contained', disableElevation: true, disabled: disabledRule || loading.validation || loading.sendValidationLink || (code.length < 5), startIcon: (loading.validation) ? react_1.default.createElement(core_1.CircularProgress, { color: 'secondary', size: 20 }) : null, onClick: validateCode, style: validateCodeButtonStyle }, "Validar c\u00F3digo")),
|
|
382
|
+
(emailType) && (react_1.default.createElement(core_1.Button, { variant: 'contained', disableElevation: true, disabled: disabledRule || loading.validation || loading.sendValidationLink, startIcon: (loading.sendValidationLink) ? react_1.default.createElement(core_1.CircularProgress, { color: 'secondary', size: 20 }) : null, onClick: sendValidationLink }, "Enviar link para valida\u00E7\u00E3o no e-mail")))));
|
|
383
|
+
};
|
|
384
|
+
exports.default = ContactValidationInput;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
var ContactValidationInput_1 = require("./ContactValidationInput");
|
|
18
|
+
var core_1 = require("@material-ui/core");
|
|
19
|
+
var react_1 = __importDefault(require("react"));
|
|
20
|
+
var SealModal = function (_a) {
|
|
21
|
+
var open = _a.open, proceed = _a.proceed;
|
|
22
|
+
var containerStyle = {
|
|
23
|
+
padding: 20,
|
|
24
|
+
gap: 20
|
|
25
|
+
};
|
|
26
|
+
var buttonsContainerStyle = { gap: 20 };
|
|
27
|
+
var headerContainerStyle = { gap: 10 };
|
|
28
|
+
var onClose = function () { return proceed({ status: false }); };
|
|
29
|
+
return react_1.default.createElement(core_1.Dialog, __assign({}, { open: open, onClose: onClose }),
|
|
30
|
+
react_1.default.createElement(core_1.Grid, { container: true, direction: 'column', style: containerStyle },
|
|
31
|
+
react_1.default.createElement(core_1.Grid, { container: true, alignItems: 'center', style: headerContainerStyle },
|
|
32
|
+
react_1.default.createElement(core_1.Typography, { variant: 'h6' }, "Chancela"),
|
|
33
|
+
react_1.default.createElement(ContactValidationInput_1.SealIcon, { color: ContactValidationInput_1.GREEN_COLOR, size: 20 })),
|
|
34
|
+
react_1.default.createElement("div", null,
|
|
35
|
+
react_1.default.createElement(core_1.Typography, null, "Ao confirmar voc\u00EA estar\u00E1 validando o contato com um selo especial")),
|
|
36
|
+
react_1.default.createElement(core_1.Grid, { container: true, justifyContent: 'flex-end', style: buttonsContainerStyle },
|
|
37
|
+
react_1.default.createElement(core_1.Button, { onClick: onClose }, "Voltar"),
|
|
38
|
+
react_1.default.createElement(core_1.Button, { color: 'primary', variant: 'contained', onClick: function (event) { return proceed({ status: true }); } }, "Confirmar"))));
|
|
39
|
+
};
|
|
40
|
+
exports.default = SealModal;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var ContactValidationInput_1 = require("./ContactValidationInput");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(ContactValidationInput_1).default; } });
|
|
@@ -174,4 +174,7 @@ export * from './Cam';
|
|
|
174
174
|
export * from './Document';
|
|
175
175
|
|
|
176
176
|
export { default as UtilTextField } from './UtilTextField';
|
|
177
|
-
export * from './UtilTextField';
|
|
177
|
+
export * from './UtilTextField';
|
|
178
|
+
|
|
179
|
+
export { default as ContactValidationInput } from './ContactValidationInput';
|
|
180
|
+
export * from './ContactValidationInput';
|
package/dist/components/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.AutoCompleteFavorites = exports.UtilAutoComplete = exports.ThreadLog = exports.TextArea = exports.Tabs = exports.TablePicker = exports.Stepper = exports.SimpleTable = exports.Select = exports.ProgressBar = exports.Programa = exports.Pagination = exports.OutputText = exports.OtpInput = exports.MultipleSelect = exports.MonthPicker = exports.ModalProvider = exports.MenuBar = exports.MaterialButton = exports.ListSelect = exports.InputTags = exports.Input = exports.ImageResizeButton = exports.ImageResize = exports.Highlight = exports.FormVisualizer = exports.FileUploader = exports.FilePreparer = exports.DropArea = exports.Compartilhar = exports.Collapse = exports.CartaoUsuario = exports.Calendar = exports.Cabecalho = exports.Button = exports.BarraFerramentas = exports.BarChart = exports.AutoComplete = exports.ArgousSimpleTable = exports.ArgousProgressBar = exports.ArgousPagination = exports.ArgousInput = exports.ArgousComplexTableToolbar = exports.ArgousComplexTableHead = exports.ArgousComplexTableBody = exports.ArgousComplexTable = exports.ArgousComplexPagination = exports.ArgousAvatar = exports.ArgousAction = exports.Alert = void 0;
|
|
17
|
-
exports.UtilTextField = exports.Cam = exports.Carousel = exports.Zoom = exports.TextToHtml = exports.UserCard = exports.HalfGauge = exports.PercentageDisplay = void 0;
|
|
17
|
+
exports.ContactValidationInput = exports.UtilTextField = exports.Cam = exports.Carousel = exports.Zoom = exports.TextToHtml = exports.UserCard = exports.HalfGauge = exports.PercentageDisplay = void 0;
|
|
18
18
|
var Alert_1 = require("./Alert");
|
|
19
19
|
Object.defineProperty(exports, "Alert", { enumerable: true, get: function () { return __importDefault(Alert_1).default; } });
|
|
20
20
|
__exportStar(require("./Alert"), exports);
|
|
@@ -189,3 +189,6 @@ __exportStar(require("./Document"), exports);
|
|
|
189
189
|
var UtilTextField_1 = require("./UtilTextField");
|
|
190
190
|
Object.defineProperty(exports, "UtilTextField", { enumerable: true, get: function () { return __importDefault(UtilTextField_1).default; } });
|
|
191
191
|
__exportStar(require("./UtilTextField"), exports);
|
|
192
|
+
var ContactValidationInput_1 = require("./ContactValidationInput");
|
|
193
|
+
Object.defineProperty(exports, "ContactValidationInput", { enumerable: true, get: function () { return __importDefault(ContactValidationInput_1).default; } });
|
|
194
|
+
__exportStar(require("./ContactValidationInput"), exports);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TextFieldProps } from '@material-ui/core';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface ContactValidationInputProps {
|
|
6
|
+
/**
|
|
7
|
+
* Component id
|
|
8
|
+
*/
|
|
9
|
+
id?: string,
|
|
10
|
+
/**
|
|
11
|
+
* Component type
|
|
12
|
+
*/
|
|
13
|
+
type: ('cellphone' | 'email'),
|
|
14
|
+
/**
|
|
15
|
+
* MUI TextField props object
|
|
16
|
+
*/
|
|
17
|
+
textFieldProps?: TextFieldProps,
|
|
18
|
+
/**
|
|
19
|
+
* Component style
|
|
20
|
+
*/
|
|
21
|
+
style?: CSSProperties,
|
|
22
|
+
/**
|
|
23
|
+
* Component css className
|
|
24
|
+
*/
|
|
25
|
+
className?: string,
|
|
26
|
+
/**
|
|
27
|
+
* Disabled prop
|
|
28
|
+
* If true disable the component
|
|
29
|
+
*/
|
|
30
|
+
disabled?: boolean,
|
|
31
|
+
/**
|
|
32
|
+
* User CPF document number
|
|
33
|
+
* Required to use the component
|
|
34
|
+
*/
|
|
35
|
+
cpf: string,
|
|
36
|
+
/**
|
|
37
|
+
* User name
|
|
38
|
+
* Required to use the component
|
|
39
|
+
*/
|
|
40
|
+
userName: string,
|
|
41
|
+
/**
|
|
42
|
+
* Input value
|
|
43
|
+
*/
|
|
44
|
+
value: string,
|
|
45
|
+
/**
|
|
46
|
+
* Function called on change
|
|
47
|
+
* @param event
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
onChange: (event: Event) => void,
|
|
51
|
+
/**
|
|
52
|
+
* Function called when component state change
|
|
53
|
+
* @param state
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getComponentData?: (state: object) => void
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
declare function ContactValidationInput(props: ContactValidationInputProps) : JSX.Element
|
|
61
|
+
|
|
62
|
+
export default ContactValidationInput;
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import './style.css';
|
|
2
|
+
import SealModal from './SealModal';
|
|
3
|
+
import { OtpInput } from '../';
|
|
4
|
+
import { api, headers } from '../../api';
|
|
5
|
+
import { numbersOnly, useModal } from '../../utils';
|
|
6
|
+
import { setError } from '../../utils/api';
|
|
7
|
+
import { Button, CircularProgress, Grid, IconButton, InputAdornment, TextField, Typography, useTheme } from '@material-ui/core';
|
|
8
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { IoMdCheckmark } from 'react-icons/io';
|
|
10
|
+
import { LiaExclamationTriangleSolid } from 'react-icons/lia';
|
|
11
|
+
import { PiSealCheck } from 'react-icons/pi';
|
|
12
|
+
import MaskedInput from 'react-maskedinput';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const EMAIL_VALIDATION_REGEX = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/;
|
|
16
|
+
|
|
17
|
+
const cellphoneMaskedInput = (props) => <MaskedInput mask='(11) 11111-1111' {...props} />;
|
|
18
|
+
export const SealIcon = PiSealCheck;
|
|
19
|
+
|
|
20
|
+
export const GREEN_COLOR = '#00995D';
|
|
21
|
+
const ORANGE_COLOR = '#f5781e';
|
|
22
|
+
const RED_COLOR = '#f44336';
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const INPUT_ADORNMENT_ICON_SIZE = 18;
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const loadingInitialState = {
|
|
29
|
+
input: false,
|
|
30
|
+
validation: false,
|
|
31
|
+
sendValidationLink: false
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const messageInitialState = { color: '', text: '' };
|
|
35
|
+
|
|
36
|
+
const initialState = {
|
|
37
|
+
loading: loadingInitialState,
|
|
38
|
+
validated: false,
|
|
39
|
+
validating: false,
|
|
40
|
+
searched: false,
|
|
41
|
+
idContato: '',
|
|
42
|
+
cdContato: '',
|
|
43
|
+
code: '',
|
|
44
|
+
message: messageInitialState
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
const ContactValidationInput = ({
|
|
49
|
+
id,
|
|
50
|
+
type = ('cellphone' || 'email'),
|
|
51
|
+
textFieldProps = {},
|
|
52
|
+
style = {},
|
|
53
|
+
className = '',
|
|
54
|
+
disabled,
|
|
55
|
+
cpf = '',
|
|
56
|
+
userName = '',
|
|
57
|
+
value = '',
|
|
58
|
+
onChange = () => '',
|
|
59
|
+
getComponentData = () => ''
|
|
60
|
+
}) => {
|
|
61
|
+
|
|
62
|
+
const theme = useTheme();
|
|
63
|
+
const [state, setState] = useState({ ...initialState, inputValue: value });
|
|
64
|
+
const { inputValue, loading, searched, validated, idContato, cdContato, code, message, validating } = state;
|
|
65
|
+
const { createModal } = useModal();
|
|
66
|
+
const sealModal = createModal(SealModal);
|
|
67
|
+
const onChangeRef = useRef(onChange);
|
|
68
|
+
|
|
69
|
+
const logicSetState = ({ type, field, value }) => setState((states) => ({
|
|
70
|
+
...states,
|
|
71
|
+
[type]: (type && field) ? { ...states[type], [field]: value } : value
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
const cellphoneType = (type === 'cellphone');
|
|
75
|
+
const emailType = (type === 'email');
|
|
76
|
+
|
|
77
|
+
const formattedInputValue = (cellphoneType) ? numbersOnly(inputValue) : inputValue;
|
|
78
|
+
const invalidType = (!cellphoneType && !emailType);
|
|
79
|
+
const disabledRule = (disabled || !cpf || !userName || invalidType || loading.input);
|
|
80
|
+
const validatedRule = (searched && validated && !validating);
|
|
81
|
+
const noValidatedRule = ((searched && !validated) || validating);
|
|
82
|
+
const validCellphone = (cellphoneType && (formattedInputValue.length === 11));
|
|
83
|
+
const validEmail = (emailType && (EMAIL_VALIDATION_REGEX.test(inputValue)));
|
|
84
|
+
const sendValidationCodeButtonDisabled = (validCellphone || validEmail) ? false : true;
|
|
85
|
+
const codeWasSent = !!idContato;
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const containerStyle = { gap: 10 };
|
|
89
|
+
const endInputAdornmentStyle = { gap: 7 };
|
|
90
|
+
|
|
91
|
+
const messageStyle = {
|
|
92
|
+
color: (message.color || theme.palette.text.primary),
|
|
93
|
+
fontStyle: 'italic'
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const validateCodeButtonsContainerStyle = { gap: 10 };
|
|
97
|
+
|
|
98
|
+
const validateCodeButtonStyle = {
|
|
99
|
+
width: 'calc(100% - 36px - 10px)'
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const sealButtonStyle = {
|
|
103
|
+
height: '100%',
|
|
104
|
+
color: GREEN_COLOR,
|
|
105
|
+
border: `2px solid ${GREEN_COLOR}`,
|
|
106
|
+
borderRadius: 4,
|
|
107
|
+
padding: 5,
|
|
108
|
+
fontSize: 22
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const handleOnChange = useCallback((event) => {
|
|
113
|
+
event.target.value = event.target.value.toString().toLowerCase();
|
|
114
|
+
logicSetState({ type: 'inputValue', value: event.target.value });
|
|
115
|
+
(typeof onChangeRef.current === 'function') && onChangeRef.current(event);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
const search = useCallback(async () => {
|
|
119
|
+
if (invalidType) return;
|
|
120
|
+
|
|
121
|
+
logicSetState({ type: 'loading', field: 'input', value: true });
|
|
122
|
+
|
|
123
|
+
const parameters = {
|
|
124
|
+
method: 'S',
|
|
125
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
126
|
+
cdCpf: numbersOnly(cpf)
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const fetchOptions = {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
body: JSON.stringify(parameters),
|
|
132
|
+
headers: headers()
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const { status, cdContato, isVerificado } = await fetch(`${api()}agscontactconfirmation.rslvr`, fetchOptions).then(async (response) => await response.json());
|
|
136
|
+
if (status) {
|
|
137
|
+
const newInputValue = (cdContato || '');
|
|
138
|
+
|
|
139
|
+
setState((states) => ({
|
|
140
|
+
...states,
|
|
141
|
+
cdContato,
|
|
142
|
+
inputValue: newInputValue,
|
|
143
|
+
searched: true,
|
|
144
|
+
validated: isVerificado
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
let newEvent = new Event('search');
|
|
148
|
+
Object.defineProperty(newEvent, 'target', { writable: false, value: { value: newInputValue } });
|
|
149
|
+
handleOnChange(newEvent);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
logicSetState({ type: 'loading', field: 'input', value: false });
|
|
153
|
+
}, [cellphoneType, emailType, invalidType, cpf, handleOnChange]);
|
|
154
|
+
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
search();
|
|
157
|
+
}, [search]);
|
|
158
|
+
|
|
159
|
+
const sendValidationCode = async () => {
|
|
160
|
+
if (invalidType) return;
|
|
161
|
+
|
|
162
|
+
logicSetState({ type: 'loading', field: 'input', value: true });
|
|
163
|
+
|
|
164
|
+
const parameters = {
|
|
165
|
+
method: 'C',
|
|
166
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
167
|
+
tpMetodo: (emailType) ? '3' : '',
|
|
168
|
+
cdCpf: numbersOnly(cpf),
|
|
169
|
+
dsNome: userName,
|
|
170
|
+
cdContato: formattedInputValue
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const fetchOptions = {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
body: JSON.stringify(parameters),
|
|
176
|
+
headers: headers()
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const { status, idContato, cdContato, dsErro } = await fetch(`${api()}agscontactconfirmation.rslvr`, fetchOptions).then(async (response) => await response.json());
|
|
180
|
+
if (status) {
|
|
181
|
+
setState((states) => ({
|
|
182
|
+
...states,
|
|
183
|
+
idContato,
|
|
184
|
+
cdContato,
|
|
185
|
+
validated: false,
|
|
186
|
+
validating: true,
|
|
187
|
+
message: {
|
|
188
|
+
color: ORANGE_COLOR,
|
|
189
|
+
text: (cellphoneType) ? 'Utilize o código recebido via sms' : (emailType) ? 'Utilize o código recebido via e-mail' : ''
|
|
190
|
+
}
|
|
191
|
+
}));
|
|
192
|
+
} else {
|
|
193
|
+
(dsErro) && setError(dsErro);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
logicSetState({ type: 'loading', field: 'input', value: false });
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const sendValidationLink = async () => {
|
|
200
|
+
if (invalidType) return;
|
|
201
|
+
|
|
202
|
+
logicSetState({ type: 'loading', field: 'sendValidationLink', value: true });
|
|
203
|
+
|
|
204
|
+
const parameters = {
|
|
205
|
+
method: 'C',
|
|
206
|
+
type: '2',
|
|
207
|
+
tpMetodo: '4',
|
|
208
|
+
cdCpf: numbersOnly(cpf),
|
|
209
|
+
dsNome: userName,
|
|
210
|
+
cdContato: formattedInputValue
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const fetchOptions = {
|
|
214
|
+
method: 'POST',
|
|
215
|
+
body: JSON.stringify(parameters),
|
|
216
|
+
headers: headers()
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const { status, cdContato, dsErro } = await fetch(`${api()}agscontactconfirmation.rslvr`, fetchOptions).then(async (response) => await response.json());
|
|
220
|
+
if (status) {
|
|
221
|
+
setState((states) => ({
|
|
222
|
+
...states,
|
|
223
|
+
idContato: '',
|
|
224
|
+
cdContato,
|
|
225
|
+
code: '',
|
|
226
|
+
message: {
|
|
227
|
+
color: '',
|
|
228
|
+
text: `O link de validação foi enviado para o e-mail "${cdContato}"`
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
231
|
+
} else {
|
|
232
|
+
(dsErro) && setError(dsErro);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
logicSetState({ type: 'loading', field: 'sendValidationLink', value: false });
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const validateCode = async ({ snChancela = false }) => {
|
|
239
|
+
if (invalidType) return;
|
|
240
|
+
|
|
241
|
+
logicSetState({ type: 'loading', field: (snChancela) ? 'input' : 'validation', value: true });
|
|
242
|
+
|
|
243
|
+
const parameters = {
|
|
244
|
+
method: 'V',
|
|
245
|
+
type: (cellphoneType) ? '1' : (emailType) ? '2' : '',
|
|
246
|
+
cdCpf: numbersOnly(cpf),
|
|
247
|
+
dsNome: userName,
|
|
248
|
+
cdCode: code,
|
|
249
|
+
cdContato: formattedInputValue,
|
|
250
|
+
idContato,
|
|
251
|
+
snChancela
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const fetchOptions = {
|
|
255
|
+
method: 'POST',
|
|
256
|
+
body: JSON.stringify(parameters),
|
|
257
|
+
headers: headers()
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const { status, isVerificado } = await fetch(`${api()}agscontactconfirmation.rslvr`, fetchOptions).then(async (response) => await response.json());
|
|
261
|
+
if (status) {
|
|
262
|
+
|
|
263
|
+
let messageText = '';
|
|
264
|
+
|
|
265
|
+
if (isVerificado) {
|
|
266
|
+
if (cellphoneType) messageText = 'Celular validado com sucesso';
|
|
267
|
+
else if (emailType) messageText = 'E-mail validado com sucesso';
|
|
268
|
+
|
|
269
|
+
setTimeout(() => logicSetState({ type: 'message', value: messageInitialState }), 6000);
|
|
270
|
+
} else {
|
|
271
|
+
messageText = 'Código inválido. Por favor tente novamente.';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
setState((states) => ({
|
|
275
|
+
...states,
|
|
276
|
+
validated: isVerificado,
|
|
277
|
+
validating: false,
|
|
278
|
+
idContato: '',
|
|
279
|
+
code: '',
|
|
280
|
+
message: {
|
|
281
|
+
color: (isVerificado) ? '' : RED_COLOR,
|
|
282
|
+
text: messageText
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
logicSetState({ type: 'loading', field: (snChancela) ? 'input' : 'validation', value: false });
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const toSeal = async () => {
|
|
291
|
+
const { status } = await sealModal();
|
|
292
|
+
if (status) validateCode({ snChancela: true });
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const checkConsistency = useCallback(() => {
|
|
296
|
+
if ((formattedInputValue === cdContato) && validated) logicSetState({ type: 'validating', value: false });
|
|
297
|
+
else if (!(formattedInputValue === cdContato) && validated) logicSetState({ type: 'validating', value: true });
|
|
298
|
+
else if (!(formattedInputValue === cdContato) && validating) {
|
|
299
|
+
setState((states) => ({
|
|
300
|
+
...states,
|
|
301
|
+
idContato: '',
|
|
302
|
+
validated: false,
|
|
303
|
+
validating: false,
|
|
304
|
+
code: '',
|
|
305
|
+
message: messageInitialState
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
}, [formattedInputValue, cdContato, validated, validating]);
|
|
309
|
+
useEffect(() => checkConsistency(), [formattedInputValue, checkConsistency]);
|
|
310
|
+
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
(typeof getComponentData === 'function') && getComponentData(state);
|
|
313
|
+
}, [state, getComponentData]);
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
return <Grid container direction='column' {...{ id, className }} style={{ ...style, ...containerStyle }}>
|
|
317
|
+
<TextField
|
|
318
|
+
{...textFieldProps}
|
|
319
|
+
disabled={disabledRule}
|
|
320
|
+
value={inputValue}
|
|
321
|
+
onChange={handleOnChange}
|
|
322
|
+
InputProps={{
|
|
323
|
+
...textFieldProps?.InputProps,
|
|
324
|
+
inputComponent: (cellphoneType) ? cellphoneMaskedInput : undefined,
|
|
325
|
+
endAdornment: (
|
|
326
|
+
<InputAdornment position='end' style={endInputAdornmentStyle}>
|
|
327
|
+
{(validatedRule) && <IoMdCheckmark color={GREEN_COLOR} size={INPUT_ADORNMENT_ICON_SIZE} />}
|
|
328
|
+
{(noValidatedRule) && <LiaExclamationTriangleSolid color={ORANGE_COLOR} size={INPUT_ADORNMENT_ICON_SIZE} />}
|
|
329
|
+
{(loading.input) && <CircularProgress color='secondary' size={INPUT_ADORNMENT_ICON_SIZE} />}
|
|
330
|
+
{(noValidatedRule) && (
|
|
331
|
+
<Button
|
|
332
|
+
size='small'
|
|
333
|
+
variant='contained'
|
|
334
|
+
disableElevation
|
|
335
|
+
disabled={disabledRule || loading.validation || sendValidationCodeButtonDisabled}
|
|
336
|
+
onClick={sendValidationCode}
|
|
337
|
+
>
|
|
338
|
+
Validar
|
|
339
|
+
</Button>
|
|
340
|
+
)}
|
|
341
|
+
</InputAdornment>
|
|
342
|
+
)
|
|
343
|
+
}}
|
|
344
|
+
/>
|
|
345
|
+
{(message.text) && (
|
|
346
|
+
<div>
|
|
347
|
+
<Typography style={messageStyle}>
|
|
348
|
+
{message.text}
|
|
349
|
+
</Typography>
|
|
350
|
+
</div>
|
|
351
|
+
)}
|
|
352
|
+
{(codeWasSent) && (
|
|
353
|
+
<>
|
|
354
|
+
<div className='otp-input-container'>
|
|
355
|
+
<OtpInput
|
|
356
|
+
autoFocus
|
|
357
|
+
numInputs={5}
|
|
358
|
+
disabled={disabledRule || loading.validation}
|
|
359
|
+
value={code}
|
|
360
|
+
onChange={(newCode) => logicSetState({ type: 'code', value: newCode })}
|
|
361
|
+
/>
|
|
362
|
+
</div>
|
|
363
|
+
<Grid container alignItems='center' style={validateCodeButtonsContainerStyle}>
|
|
364
|
+
<IconButton
|
|
365
|
+
title='Chancelar'
|
|
366
|
+
tabIndex='1'
|
|
367
|
+
size='small'
|
|
368
|
+
disabled={disabledRule || loading.validation || loading.sendValidationLink}
|
|
369
|
+
onClick={toSeal}
|
|
370
|
+
style={sealButtonStyle}
|
|
371
|
+
>
|
|
372
|
+
<SealIcon />
|
|
373
|
+
</IconButton>
|
|
374
|
+
<Button
|
|
375
|
+
color='primary'
|
|
376
|
+
variant='contained'
|
|
377
|
+
disableElevation
|
|
378
|
+
disabled={disabledRule || loading.validation || loading.sendValidationLink || (code.length < 5)}
|
|
379
|
+
startIcon={(loading.validation) ? <CircularProgress color='secondary' size={20} /> : null}
|
|
380
|
+
onClick={validateCode}
|
|
381
|
+
style={validateCodeButtonStyle}
|
|
382
|
+
>
|
|
383
|
+
Validar código
|
|
384
|
+
</Button>
|
|
385
|
+
</Grid>
|
|
386
|
+
{(emailType) && (
|
|
387
|
+
<Button
|
|
388
|
+
variant='contained'
|
|
389
|
+
disableElevation
|
|
390
|
+
disabled={disabledRule || loading.validation || loading.sendValidationLink}
|
|
391
|
+
startIcon={(loading.sendValidationLink) ? <CircularProgress color='secondary' size={20} /> : null}
|
|
392
|
+
onClick={sendValidationLink}
|
|
393
|
+
>
|
|
394
|
+
Enviar link para validação no e-mail
|
|
395
|
+
</Button>
|
|
396
|
+
)}
|
|
397
|
+
</>
|
|
398
|
+
)}
|
|
399
|
+
</Grid>;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
export default ContactValidationInput;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { GREEN_COLOR, SealIcon } from './ContactValidationInput';
|
|
2
|
+
import { Button, Dialog, Grid, Typography } from '@material-ui/core';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const SealModal = ({ open, proceed }) => {
|
|
7
|
+
|
|
8
|
+
const containerStyle = {
|
|
9
|
+
padding: 20,
|
|
10
|
+
gap: 20
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const buttonsContainerStyle = { gap: 20 };
|
|
14
|
+
const headerContainerStyle = { gap: 10 };
|
|
15
|
+
|
|
16
|
+
const onClose = () => proceed({ status: false });
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
return <Dialog {...{ open, onClose }}>
|
|
20
|
+
<Grid container direction='column' style={containerStyle}>
|
|
21
|
+
<Grid container alignItems='center' style={headerContainerStyle}>
|
|
22
|
+
<Typography variant='h6'>
|
|
23
|
+
Chancela
|
|
24
|
+
</Typography>
|
|
25
|
+
<SealIcon color={GREEN_COLOR} size={20} />
|
|
26
|
+
</Grid>
|
|
27
|
+
<div>
|
|
28
|
+
<Typography>
|
|
29
|
+
Ao confirmar você estará validando o contato com um selo especial
|
|
30
|
+
</Typography>
|
|
31
|
+
</div>
|
|
32
|
+
<Grid container justifyContent='flex-end' style={buttonsContainerStyle}>
|
|
33
|
+
<Button onClick={onClose}>
|
|
34
|
+
Voltar
|
|
35
|
+
</Button>
|
|
36
|
+
<Button
|
|
37
|
+
color='primary'
|
|
38
|
+
variant='contained'
|
|
39
|
+
onClick={(event) => proceed({ status: true })}
|
|
40
|
+
>
|
|
41
|
+
Confirmar
|
|
42
|
+
</Button>
|
|
43
|
+
</Grid>
|
|
44
|
+
</Grid>
|
|
45
|
+
</Dialog>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
export default SealModal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ContactValidationInput';
|
|
@@ -174,4 +174,7 @@ export * from './Cam';
|
|
|
174
174
|
export * from './Document';
|
|
175
175
|
|
|
176
176
|
export { default as UtilTextField } from './UtilTextField';
|
|
177
|
-
export * from './UtilTextField';
|
|
177
|
+
export * from './UtilTextField';
|
|
178
|
+
|
|
179
|
+
export { default as ContactValidationInput } from './ContactValidationInput';
|
|
180
|
+
export * from './ContactValidationInput';
|
package/lib/components/index.js
CHANGED
|
@@ -172,4 +172,7 @@ export * from './Cam';
|
|
|
172
172
|
export * from './Document';
|
|
173
173
|
|
|
174
174
|
export { default as UtilTextField } from './UtilTextField';
|
|
175
|
-
export * from './UtilTextField';
|
|
175
|
+
export * from './UtilTextField';
|
|
176
|
+
|
|
177
|
+
export { default as ContactValidationInput } from './ContactValidationInput';
|
|
178
|
+
export * from './ContactValidationInput';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "argous",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.236",
|
|
4
4
|
"description": "Argous.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Carlos Schneider",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/chart.js": "^2.9.31",
|
|
20
20
|
"@types/glob": "^7",
|
|
21
21
|
"@types/jquery": "^3.5.5",
|
|
22
|
-
"@types/lodash": "
|
|
22
|
+
"@types/lodash": "4.17.5",
|
|
23
23
|
"@types/node": "^14.14.35",
|
|
24
24
|
"@types/react": "^17.0.3",
|
|
25
25
|
"@types/react-custom-scrollbars": "^4",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"fs-extra": "^9.1.0",
|
|
49
49
|
"glob": "^7.1.6",
|
|
50
50
|
"immer": "^8.0.2",
|
|
51
|
-
"lodash": "
|
|
51
|
+
"lodash": "4.17.5",
|
|
52
52
|
"moment": "^2.29.1",
|
|
53
53
|
"path": "^0.12.7",
|
|
54
54
|
"prop-types": "^15.7.2",
|
|
@@ -107,4 +107,4 @@
|
|
|
107
107
|
"smooth-dnd": "^0.12.1",
|
|
108
108
|
"typescript": "4.2.3"
|
|
109
109
|
}
|
|
110
|
-
}
|
|
110
|
+
}
|