x25 2.9.2 → 3.0.0
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/.eslintignore +2 -0
- package/.eslintrc.json +275 -0
- package/.flowconfig +23 -0
- package/conf/dev.js +19 -0
- package/conf/dist.js +19 -0
- package/conf/polyfills/tempPolyfills.js +7 -0
- package/package.json +16 -16
- package/src/Account/Load.jsx +79 -0
- package/src/Account/actions.js +10 -0
- package/src/Account/index.js +11 -0
- package/src/Account/reducer.js +139 -0
- package/src/Account/request.js +36 -0
- package/src/Async/InitModule.jsx +114 -0
- package/src/Async/RouteLoading.jsx +52 -0
- package/src/Async/SimulatedException.jsx +19 -0
- package/src/Async/index.jsx +75 -0
- package/src/Async/types.js +39 -0
- package/src/Company/Load.jsx +84 -0
- package/src/Company/actions.js +10 -0
- package/src/Company/index.js +11 -0
- package/src/Company/reducer.js +201 -0
- package/src/Company/request.js +30 -0
- package/src/Company/util.js +7 -0
- package/src/Header/AccountOptionsContainer.jsx +124 -0
- package/src/Header/AdminSelectCompany.jsx +101 -0
- package/src/Header/ClientSelectCompany.jsx +90 -0
- package/src/Header/Header.jsx +120 -0
- package/src/Header/HeaderContainer.jsx +30 -0
- package/src/Header/Logo.jsx +16 -0
- package/src/Header/LogoutButton.jsx +34 -0
- package/src/Header/index.jsx +9 -0
- package/src/Header/request.js +28 -0
- package/src/Header/types.js +6 -0
- package/src/Header/util.jsx +61 -0
- package/src/Inputs/Business/BankAccount.jsx +39 -0
- package/src/Inputs/Business/BankName.jsx +40 -0
- package/src/Inputs/Business/CifField.jsx +93 -0
- package/src/Inputs/Business/CifFieldContainer.jsx +142 -0
- package/src/Inputs/Business/Email.jsx +23 -0
- package/src/Inputs/Business/NidField.jsx +77 -0
- package/src/Inputs/Business/Phone.jsx +23 -0
- package/src/Inputs/Business/index.js +16 -0
- package/src/Inputs/Business/request.js +39 -0
- package/src/Inputs/CaptchaBox.jsx +131 -0
- package/src/Inputs/DateInput.jsx +188 -0
- package/src/Inputs/DateTemplate.jsx +213 -0
- package/src/Inputs/DelayInputChange.jsx +130 -0
- package/src/Inputs/FocusTemplate.jsx +41 -0
- package/src/Inputs/InputTemplate.jsx +79 -0
- package/src/Inputs/LabelTemplate.jsx +47 -0
- package/src/Inputs/NumericInput.jsx +142 -0
- package/src/Inputs/NumericTemplate.jsx +155 -0
- package/src/Inputs/Selects/County.jsx +19 -0
- package/src/Inputs/Selects/Custom.jsx +55 -0
- package/src/Inputs/Selects/Simple.jsx +73 -0
- package/src/Inputs/Selects/index.jsx +37 -0
- package/src/Inputs/SimpleInput.jsx +40 -0
- package/src/Inputs/SimpleTextarea.jsx +55 -0
- package/src/Inputs/TextareaTemplate.jsx +57 -0
- package/src/Inputs/Tooltip.jsx +61 -0
- package/src/Inputs/index.js +22 -0
- package/src/Messages/Error.jsx +83 -0
- package/src/Messages/Loading.jsx +43 -0
- package/src/Messages/index.jsx +4 -0
- package/src/Modal/Delete.jsx +237 -0
- package/src/Modal/Root.jsx +57 -0
- package/src/Modal/SimpleModal.jsx +47 -0
- package/src/Modal/actions.js +7 -0
- package/src/Modal/getComponent.jsx +32 -0
- package/src/Modal/index.jsx +12 -0
- package/src/Modal/reducer.js +40 -0
- package/src/Modal/types.js +6 -0
- package/src/Modal/util.js +15 -0
- package/src/Payment/EstimatePrice/Description.jsx +101 -0
- package/src/Payment/EstimatePrice/PayBox.jsx +173 -0
- package/src/Payment/EstimatePrice/index.jsx +63 -0
- package/src/Payment/EstimatePrice/util.js +15 -0
- package/src/Payment/MobilpayForm.jsx +77 -0
- package/src/Payment/Modal/BankTransfer.jsx +129 -0
- package/src/Payment/Modal/CompanyValability.jsx +14 -0
- package/src/Payment/Modal/DoneForm.jsx +209 -0
- package/src/Payment/Modal/PaymentDone.jsx +27 -0
- package/src/Payment/Modal/index.js +13 -0
- package/src/Payment/actions.jsx +22 -0
- package/{Payment → src/Payment}/codes.js +16 -19
- package/src/Payment/index.jsx +124 -0
- package/src/Payment/request.js +50 -0
- package/src/Payment/types.js +14 -0
- package/src/Payment/util.jsx +52 -0
- package/src/Payment/validate.js +25 -0
- package/src/Sidebar.jsx +158 -0
- package/src/Things.jsx +35 -0
- package/src/actions.js +36 -0
- package/src/config.js +7 -0
- package/src/dev/ErrorBoundary.jsx +98 -0
- package/src/dev/TheError.jsx +87 -0
- package/src/dev/index.js +127 -0
- package/src/dev/types.js +10 -0
- package/src/prod/SentryErrorBoundary.jsx +98 -0
- package/src/reducer/captchas.js +44 -0
- package/src/reducer/counties.js +46 -0
- package/src/reducer/index.js +25 -0
- package/src/reducer/module.jsx +43 -0
- package/src/style/.sass-lint.yml +84 -0
- package/src/style/.stylelintrc.json +161 -0
- package/src/style/_fancy-text.scss +37 -0
- package/src/style/_fix_bootstrap_placeholder_color.scss +14 -0
- package/src/style/_header-company.scss +69 -0
- package/src/style/_inputs.scss +12 -0
- package/src/style/_minimal.scss +31 -0
- package/src/style/_navigation.scss +24 -0
- package/src/style/_others.scss +79 -0
- package/src/style/index.scss +7 -0
- package/src/style/sidebar/_animations.scss +21 -0
- package/src/style/sidebar/_dark-theme.scss +77 -0
- package/src/style/sidebar/_scroll.scss +37 -0
- package/src/style/sidebar/_structure.scss +299 -0
- package/src/style/sidebar.scss +4 -0
- package/src/types.js +31 -0
- package/src/utility/calendar.js +39 -0
- package/src/utility/date.js +100 -0
- package/src/utility/index.js +12 -0
- package/src/utility/language.js +17 -0
- package/src/utility/mql.js +3 -0
- package/src/utility/normalize-test.js +58 -0
- package/src/utility/normalize.js +119 -0
- package/src/utility/numbers.js +87 -0
- package/src/utility/numeric.js +114 -0
- package/src/utility/others.jsx +160 -0
- package/src/utility/strings-test.js +136 -0
- package/src/utility/strings.js +80 -0
- package/src/utility/validation/common.js +360 -0
- package/src/utility/validation/index.js +70 -0
- package/src/utility/validation/specific.js +9 -0
- package/src/utility/validation/validate/bank-test.js +129 -0
- package/src/utility/validation/validate/bank.js +176 -0
- package/src/utility/validation/validate/cif-test.js +105 -0
- package/src/utility/validation/validate/cif.js +44 -0
- package/src/utility/validation/validate/cnp-test.js +216 -0
- package/src/utility/validation/validate/cnp.js +261 -0
- package/{utility → src/utility}/validation/validate/date.js +73 -61
- package/src/utility/validation/validate/email-test.js +36 -0
- package/src/utility/validation/validate/email.js +6 -0
- package/src/utility/validation/validate/index.js +7 -0
- package/webpack.config.js +90 -0
- package/x25.wiki/Account.md +41 -0
- package/x25.wiki/Company.md +39 -0
- package/x25.wiki/Header.md +21 -0
- package/x25.wiki/Home.md +1 -0
- package/x25.wiki/Inputs.md +33 -0
- package/x25.wiki/Messages.md +27 -0
- package/x25.wiki/Payment.md +42 -0
- package/Account/Load.js +0 -75
- package/Account/actions.js +0 -15
- package/Account/index.js +0 -20
- package/Account/reducer.js +0 -122
- package/Account/request.js +0 -44
- package/Async/InitModule.js +0 -190
- package/Async/RouteLoading.js +0 -64
- package/Async/SimulatedException.js +0 -44
- package/Async/index.js +0 -95
- package/Async/types.js +0 -1
- package/Company/Load.js +0 -82
- package/Company/actions.js +0 -15
- package/Company/index.js +0 -20
- package/Company/reducer.js +0 -165
- package/Company/request.js +0 -36
- package/Company/util.js +0 -10
- package/Header/AccountOptionsContainer.js +0 -144
- package/Header/AdminSelectCompany.js +0 -109
- package/Header/ClientSelectCompany.js +0 -104
- package/Header/Header.js +0 -127
- package/Header/HeaderContainer.js +0 -39
- package/Header/Logo.js +0 -30
- package/Header/LogoutButton.js +0 -39
- package/Header/index.js +0 -19
- package/Header/request.js +0 -26
- package/Header/types.js +0 -1
- package/Header/util.js +0 -58
- package/Inputs/Business/BankAccount.js +0 -48
- package/Inputs/Business/BankName.js +0 -49
- package/Inputs/Business/CifField.js +0 -112
- package/Inputs/Business/CifFieldContainer.js +0 -157
- package/Inputs/Business/Email.js +0 -37
- package/Inputs/Business/NidField.js +0 -91
- package/Inputs/Business/Phone.js +0 -37
- package/Inputs/Business/index.js +0 -34
- package/Inputs/Business/request.js +0 -39
- package/Inputs/CaptchaBox.js +0 -151
- package/Inputs/DateInput.js +0 -172
- package/Inputs/DateTemplate.js +0 -200
- package/Inputs/DelayInputChange.js +0 -135
- package/Inputs/FocusTemplate.js +0 -47
- package/Inputs/InputTemplate.js +0 -78
- package/Inputs/LabelTemplate.js +0 -59
- package/Inputs/NumericInput.js +0 -139
- package/Inputs/NumericTemplate.js +0 -148
- package/Inputs/Selects/County.js +0 -29
- package/Inputs/Selects/Custom.js +0 -56
- package/Inputs/Selects/Simple.js +0 -75
- package/Inputs/Selects/index.js +0 -52
- package/Inputs/SimpleInput.js +0 -42
- package/Inputs/SimpleTextarea.js +0 -47
- package/Inputs/TextareaTemplate.js +0 -55
- package/Inputs/Tooltip.js +0 -82
- package/Inputs/index.js +0 -185
- package/Messages/Error.js +0 -106
- package/Messages/Loading.js +0 -68
- package/Messages/index.js +0 -29
- package/Modal/Delete.js +0 -240
- package/Modal/Root.js +0 -81
- package/Modal/SimpleModal.js +0 -57
- package/Modal/actions.js +0 -10
- package/Modal/getComponent.js +0 -42
- package/Modal/index.js +0 -22
- package/Modal/reducer.js +0 -53
- package/Modal/types.js +0 -7
- package/Modal/util.js +0 -17
- package/Payment/EstimatePrice/Description.js +0 -92
- package/Payment/EstimatePrice/PayBox.js +0 -220
- package/Payment/EstimatePrice/index.js +0 -92
- package/Payment/EstimatePrice/util.js +0 -21
- package/Payment/MobilpayForm.js +0 -86
- package/Payment/Modal/BankTransfer.js +0 -233
- package/Payment/Modal/CompanyValability.js +0 -28
- package/Payment/Modal/DoneForm.js +0 -222
- package/Payment/Modal/PaymentDone.js +0 -53
- package/Payment/Modal/index.js +0 -27
- package/Payment/actions.js +0 -23
- package/Payment/index.js +0 -141
- package/Payment/request.js +0 -49
- package/Payment/types.js +0 -1
- package/Payment/util.js +0 -50
- package/Payment/validate.js +0 -23
- package/Sidebar.js +0 -156
- package/Things.js +0 -53
- package/actions.js +0 -73
- package/config.js +0 -10
- package/dev/ErrorBoundary.js +0 -109
- package/dev/TheError.js +0 -113
- package/dev/index.js +0 -132
- package/dev/types.js +0 -1
- package/prod/SentryErrorBoundary.js +0 -150
- package/reducer/captchas.js +0 -51
- package/reducer/counties.js +0 -57
- package/reducer/index.js +0 -38
- package/reducer/module.js +0 -48
- package/style/index.css +0 -1
- package/style/sidebar.css +0 -1
- package/types.js +0 -1
- package/utility/calendar.js +0 -45
- package/utility/date.js +0 -111
- package/utility/index.js +0 -125
- package/utility/language.js +0 -20
- package/utility/mql.js +0 -6
- package/utility/normalize-test.js +0 -54
- package/utility/normalize.js +0 -108
- package/utility/numbers.js +0 -93
- package/utility/numeric.js +0 -103
- package/utility/others.js +0 -142
- package/utility/strings-test.js +0 -216
- package/utility/strings.js +0 -85
- package/utility/validation/common.js +0 -278
- package/utility/validation/index.js +0 -110
- package/utility/validation/specific.js +0 -14
- package/utility/validation/validate/bank-test.js +0 -41
- package/utility/validation/validate/bank.js +0 -176
- package/utility/validation/validate/cif-test.js +0 -37
- package/utility/validation/validate/cif.js +0 -44
- package/utility/validation/validate/cnp-test.js +0 -68
- package/utility/validation/validate/cnp.js +0 -193
- package/utility/validation/validate/email-test.js +0 -30
- package/utility/validation/validate/email.js +0 -11
- package/utility/validation/validate/index.js +0 -65
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* eslint-disable max-len, no-duplicate-imports */
|
|
2
|
+
// @flow
|
|
3
|
+
|
|
4
|
+
import type { NormalizedResult } from "src\\types";
|
|
5
|
+
|
|
6
|
+
type Normalizr = (item : any) => any;
|
|
7
|
+
|
|
8
|
+
type NormalizeBoolean = (input : "" | bool) => bool;
|
|
9
|
+
type NormalizeArray = (raw : Array<any>) => NormalizedResult;
|
|
10
|
+
type Normalize = (raw : Array<any>, field : string, normalizr : Normalizr) => NormalizedResult;
|
|
11
|
+
type DefaultNormalize = (raw : Array<any>, field : string) => NormalizedResult;
|
|
12
|
+
|
|
13
|
+
type Resolve = (data : any) => void;
|
|
14
|
+
type Reject = (arg : any) => void;
|
|
15
|
+
|
|
16
|
+
type Response = {
|
|
17
|
+
body: any;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type Error = {
|
|
21
|
+
status: any;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
import * as Immutable from "immutable";
|
|
25
|
+
|
|
26
|
+
const timeout = 500;
|
|
27
|
+
|
|
28
|
+
const defaultNormalizr : Normalizr = (item) => Immutable.Map(item);
|
|
29
|
+
|
|
30
|
+
const defaultValue = () => ({
|
|
31
|
+
entities : Immutable.Map(),
|
|
32
|
+
result : Immutable.List(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const customNormalizeArrayByField : Normalize = (raw : Array<any>, field : string, normalizr : Normalizr) => (
|
|
36
|
+
raw === null ? defaultValue() : (
|
|
37
|
+
raw.reduce((previous, current) => {
|
|
38
|
+
const stringID = String(current[field]);
|
|
39
|
+
|
|
40
|
+
previous.entities = previous.entities.set(stringID,
|
|
41
|
+
normalizr(current));
|
|
42
|
+
|
|
43
|
+
previous.result = previous.result.push(stringID);
|
|
44
|
+
|
|
45
|
+
return previous;
|
|
46
|
+
}, defaultValue())
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export const normalizeArrayByField : DefaultNormalize = (raw : Array<any>, field : string) => (
|
|
51
|
+
customNormalizeArrayByField(raw,
|
|
52
|
+
field,
|
|
53
|
+
defaultNormalizr)
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export const withPromiseCallback = (resolve : Resolve, reject : Reject) => (error : Error, response : Response) => {
|
|
57
|
+
if (error) {
|
|
58
|
+
const StatusUnauthorized = 401;
|
|
59
|
+
|
|
60
|
+
if (error.status === StatusUnauthorized) {
|
|
61
|
+
document.location.href = "/";
|
|
62
|
+
} else {
|
|
63
|
+
// error.message
|
|
64
|
+
reject({ error: "Ceva nu a funcționat cum trebuia" });
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
resolve(response.body);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const withHandlePDFCallback = (
|
|
72
|
+
{ resolve, reject, title } : { resolve : Resolve, reject : Reject, title : string },
|
|
73
|
+
) => (error : Error, response : Response) => {
|
|
74
|
+
// It is necessary to create a new blob object with mime-type explicitly set
|
|
75
|
+
// otherwise only Chrome works like it should
|
|
76
|
+
const newBlob = new Blob([response.body],
|
|
77
|
+
{ type: "application/pdf" });
|
|
78
|
+
|
|
79
|
+
// IE doesn't allow using a blob object directly as link href
|
|
80
|
+
// instead it is necessary to use msSaveOrOpenBlob
|
|
81
|
+
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
|
82
|
+
window.navigator.msSaveOrOpenBlob(newBlob);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// For other browsers:
|
|
87
|
+
// Create a link pointing to the ObjectURL containing the blob.
|
|
88
|
+
const data = window.URL.createObjectURL(newBlob);
|
|
89
|
+
const link = document.createElement("a");
|
|
90
|
+
|
|
91
|
+
link.href = data;
|
|
92
|
+
link.download = `${title}.pdf`;
|
|
93
|
+
link.click();
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
// For Firefox it is necessary to delay revoking the ObjectURL
|
|
96
|
+
window.URL.revokeObjectURL(data);
|
|
97
|
+
withPromiseCallback(resolve,
|
|
98
|
+
reject)(error,
|
|
99
|
+
response);
|
|
100
|
+
}, timeout);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* entities ---> Object { "1": Immutable.Map(), ... ]) }
|
|
105
|
+
* result ---> List([ "1", "2", "3" ])
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
export const normalizeArray : NormalizeArray = (raw : Array<any>, normalizr?: Normalizr) => (
|
|
109
|
+
customNormalizeArrayByField(raw,
|
|
110
|
+
"ID",
|
|
111
|
+
typeof normalizr === "undefined" ? defaultNormalizr : normalizr)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
export const normalizeBoolean : NormalizeBoolean = (value : boolean | "") => value || false;
|
|
115
|
+
|
|
116
|
+
export const normalizeSelectNumeric = (raw : string) => (
|
|
117
|
+
(typeof raw === "string" && raw !== "") ? parseInt(raw,
|
|
118
|
+
10) : raw
|
|
119
|
+
);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
/* eslint-disable no-magic-numbers */
|
|
3
|
+
|
|
4
|
+
declare var Intl:any
|
|
5
|
+
|
|
6
|
+
const numberFormat : any = new Intl.NumberFormat("ro",
|
|
7
|
+
{
|
|
8
|
+
minimumFractionDigits: 2,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const plainNumberFormat : any = new Intl.NumberFormat("ro");
|
|
12
|
+
|
|
13
|
+
const replaceCharInString = ({ word, oldChar, newChar } : {
|
|
14
|
+
word: string,
|
|
15
|
+
oldChar: string,
|
|
16
|
+
newChar: string
|
|
17
|
+
}) : string => {
|
|
18
|
+
|
|
19
|
+
const regex = new RegExp(oldChar,
|
|
20
|
+
"gu");
|
|
21
|
+
|
|
22
|
+
return word.replace(regex,
|
|
23
|
+
newChar);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// 127.99 ----> 127,99
|
|
27
|
+
// 0 ----> ""
|
|
28
|
+
export const formatZeroValue = (word : any, optional?: bool) : string => (
|
|
29
|
+
optional && word === ""
|
|
30
|
+
) ? "" : replaceCharInString({
|
|
31
|
+
word : String(word),
|
|
32
|
+
oldChar : "\\.",
|
|
33
|
+
newChar : ",",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const formatNumber = (word : any) : string => replaceCharInString({
|
|
37
|
+
word : String(word),
|
|
38
|
+
oldChar : "\\.",
|
|
39
|
+
newChar : ",",
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 78,45 ---> 78.45
|
|
43
|
+
export const normalizeNumber = (word : any) : string => replaceCharInString({
|
|
44
|
+
word : String(word),
|
|
45
|
+
oldChar : ",",
|
|
46
|
+
newChar : ".",
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const numberToLocale = (value : number) : string => numberFormat.format(value);
|
|
50
|
+
|
|
51
|
+
export const plainNumberToLocale = (value : number) : string => (
|
|
52
|
+
plainNumberFormat.format(value)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const numberToLocaleForm = (value : number) : string => {
|
|
56
|
+
const upperLimit = 20,
|
|
57
|
+
formatted = plainNumberFormat.format(value);
|
|
58
|
+
|
|
59
|
+
if (value < upperLimit) {
|
|
60
|
+
return formatted;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return `${formatted} de`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const numericBehavior = {
|
|
67
|
+
normalize : normalizeNumber,
|
|
68
|
+
format : formatNumber,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const tryToParseNumber = (raw : string) => {
|
|
72
|
+
const result = Number(raw);
|
|
73
|
+
|
|
74
|
+
if (!isNaN(result) && raw !== "") {
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return raw;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const numberToLocaleHideBlank = (raw : any) => (
|
|
82
|
+
(typeof raw === "number" && raw !== 0) ? numberToLocale(raw) : ""
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
export const plainNumberToLocaleHideZero = (raw : any) => (
|
|
86
|
+
(typeof raw === "number" && raw !== 0) ? plainNumberToLocale(raw) : ""
|
|
87
|
+
);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
type This = any;
|
|
4
|
+
|
|
5
|
+
import { normalizeNumber } from "./numbers";
|
|
6
|
+
|
|
7
|
+
export const handleBlur = (that : This) => {
|
|
8
|
+
const { state, props } = that;
|
|
9
|
+
|
|
10
|
+
const
|
|
11
|
+
{ input, normalizeValue, optional } = props,
|
|
12
|
+
{ onBlur } = input,
|
|
13
|
+
{ value: currentValue } = state;
|
|
14
|
+
|
|
15
|
+
const performBlur = (value : number | null, shouldRenderAgain : bool) => {
|
|
16
|
+
|
|
17
|
+
input.onChange(value);
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Swallow the event to prevent Redux Form from
|
|
21
|
+
* extracting the form value
|
|
22
|
+
*/
|
|
23
|
+
onBlur();
|
|
24
|
+
|
|
25
|
+
if (shouldRenderAgain) {
|
|
26
|
+
const setState = that.setState.bind(that);
|
|
27
|
+
|
|
28
|
+
return setState({
|
|
29
|
+
value,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const shouldNotChange = currentValue === "" && optional;
|
|
37
|
+
|
|
38
|
+
if (shouldNotChange) {
|
|
39
|
+
if (input.value === "") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return performBlur(null,
|
|
44
|
+
true);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const
|
|
48
|
+
normalizedValue = normalizeValue(currentValue),
|
|
49
|
+
shouldRenderAgain = (
|
|
50
|
+
(!isNaN(normalizedValue)) &&
|
|
51
|
+
(currentValue !== normalizedValue)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
return performBlur(normalizedValue,
|
|
55
|
+
shouldRenderAgain);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const normalizeFloat = (raw : string) : number => {
|
|
59
|
+
|
|
60
|
+
/* eslint-disable no-magic-numbers */
|
|
61
|
+
|
|
62
|
+
const value = normalizeNumber(raw),
|
|
63
|
+
shouldNotNormalize = (
|
|
64
|
+
(value.trim() === "") ||
|
|
65
|
+
isNaN(Number(value))
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (shouldNotNormalize) {
|
|
69
|
+
return NaN;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const result = Number(value),
|
|
73
|
+
truncateTo = (unRouned : number, nrOfDecimals? : number = 2) : number => {
|
|
74
|
+
const parts = String(unRouned).split(".");
|
|
75
|
+
|
|
76
|
+
if (parts.length !== 2) {
|
|
77
|
+
// ex. 12
|
|
78
|
+
return unRouned;
|
|
79
|
+
}
|
|
80
|
+
const newDecimals = parts[1].slice(0,
|
|
81
|
+
nrOfDecimals),
|
|
82
|
+
newString = `${parts[0]}.${newDecimals}`;
|
|
83
|
+
|
|
84
|
+
return Number(newString);
|
|
85
|
+
},
|
|
86
|
+
normalized = truncateTo(result);
|
|
87
|
+
|
|
88
|
+
return normalized;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const cwrp = (that : This, nextany : any) => {
|
|
92
|
+
const { state } = that;
|
|
93
|
+
|
|
94
|
+
const {
|
|
95
|
+
input: {
|
|
96
|
+
value: newValue,
|
|
97
|
+
},
|
|
98
|
+
} = nextany;
|
|
99
|
+
|
|
100
|
+
const { value: currentValue } = state;
|
|
101
|
+
|
|
102
|
+
const shouldRenderAgain = (
|
|
103
|
+
!isNaN(newValue) &&
|
|
104
|
+
(currentValue !== newValue)
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const setState = that.setState.bind(that);
|
|
108
|
+
|
|
109
|
+
if (shouldRenderAgain) {
|
|
110
|
+
setState({
|
|
111
|
+
value: newValue,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type { List as ImmutableList, Map as ImmutableMap } from "immutable";
|
|
4
|
+
|
|
5
|
+
type ReduxError = {
|
|
6
|
+
error: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { SubmissionError } from "redux-form/immutable";
|
|
11
|
+
|
|
12
|
+
export const getDateSortNumber = (item : string) => (
|
|
13
|
+
Number(new Date(item).getTime())
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
export const isAdministratorAccount = (current : number) => (
|
|
17
|
+
current === 0
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const createModal = (modalType : string, modalProps? : any) => ({
|
|
21
|
+
type : "SHOW_MODAL",
|
|
22
|
+
payload : {
|
|
23
|
+
modalType,
|
|
24
|
+
modalProps,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const
|
|
29
|
+
noError = "",
|
|
30
|
+
rowsPerLoad = 50,
|
|
31
|
+
nothingFetched = -1;
|
|
32
|
+
|
|
33
|
+
export const removeID = (payload : ImmutableMap<string, any>) => (list : ImmutableList<string>) => (
|
|
34
|
+
// $FlowFixMe
|
|
35
|
+
list.delete(list.findIndex((current : string) => current === String(payload.get("ID"))))
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const addID = (payload : ImmutableMap<string, any>) => (list : ImmutableList<string>) => (
|
|
39
|
+
list.push(String(payload.get("ID")))
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const ReduxFormSubmissionError = (error? : ReduxError) => {
|
|
43
|
+
if (error) {
|
|
44
|
+
if (error instanceof SubmissionError) {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const _error = typeof error.error === "string" ? error.error : "Am pierdut conexiunea cu server-ul";
|
|
49
|
+
|
|
50
|
+
throw new SubmissionError({
|
|
51
|
+
_error,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const delay = () => (
|
|
57
|
+
new Promise((resolve) => {
|
|
58
|
+
setTimeout(resolve);
|
|
59
|
+
}) : Promise<any>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const showCheck = (value : boolean) => (
|
|
63
|
+
value ? (
|
|
64
|
+
<i className="fa fa-check text-success" />
|
|
65
|
+
) : null
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const userHasPressedCKeyAlone = (currentEvent : KeyboardEvent) : boolean => {
|
|
69
|
+
const {
|
|
70
|
+
ctrlKey,
|
|
71
|
+
keyCode,
|
|
72
|
+
srcElement: {
|
|
73
|
+
localName,
|
|
74
|
+
},
|
|
75
|
+
} = currentEvent;
|
|
76
|
+
|
|
77
|
+
const
|
|
78
|
+
createInvoiceKey = 67,
|
|
79
|
+
tag = localName.toLowerCase(),
|
|
80
|
+
isNotInputOrTextarea = (
|
|
81
|
+
tag !== "input" &&
|
|
82
|
+
tag !== "textarea"
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
!ctrlKey &&
|
|
87
|
+
keyCode === createInvoiceKey &&
|
|
88
|
+
isNotInputOrTextarea
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export const years = [
|
|
93
|
+
{
|
|
94
|
+
value : 2018,
|
|
95
|
+
name : "2018",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
value : 2019,
|
|
99
|
+
name : "2019",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value : 2020,
|
|
103
|
+
name : "2020",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
value : 2021,
|
|
107
|
+
name : "2021",
|
|
108
|
+
},
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
export const months = [
|
|
112
|
+
{
|
|
113
|
+
value : 0,
|
|
114
|
+
name : "Ianuarie",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
value : 1,
|
|
118
|
+
name : "Februarie",
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
value : 2,
|
|
122
|
+
name : "Martie",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
value : 3,
|
|
126
|
+
name : "Aprilie",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
value : 4,
|
|
130
|
+
name : "Mai",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
value : 5,
|
|
134
|
+
name : "Iunie",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value : 6,
|
|
138
|
+
name : "Iulie",
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
value : 7,
|
|
142
|
+
name : "August",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
value : 8,
|
|
146
|
+
name : "Septembrie",
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
value : 9,
|
|
150
|
+
name : "Octombrie",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
value : 10,
|
|
154
|
+
name : "Noiembrie",
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
value : 11,
|
|
158
|
+
name : "Decembrie",
|
|
159
|
+
},
|
|
160
|
+
];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
firstToUppercase,
|
|
3
|
+
toLower,
|
|
4
|
+
toTitle,
|
|
5
|
+
toUpper,
|
|
6
|
+
} from "./strings";
|
|
7
|
+
|
|
8
|
+
// toTitle
|
|
9
|
+
(() => {
|
|
10
|
+
describe("Test toTitle",
|
|
11
|
+
() => {
|
|
12
|
+
const tests = [
|
|
13
|
+
{
|
|
14
|
+
input : "",
|
|
15
|
+
output : "",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
input : "cosovei",
|
|
19
|
+
output : "Cosovei",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
input : "simona cosovei",
|
|
23
|
+
output : "Simona Cosovei",
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
input : "ștefănică țepeș",
|
|
27
|
+
output : "Ștefănică Țepeș",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
input : "this is 4 long name 5",
|
|
31
|
+
output : "This Is 4 Long Name 5",
|
|
32
|
+
},
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
for (const { input, output } of tests) {
|
|
36
|
+
describe(`Given the raw string "${input}"`,
|
|
37
|
+
() => {
|
|
38
|
+
it(`should be transformed to "${output}"`,
|
|
39
|
+
() => {
|
|
40
|
+
expect(toTitle(input)).toEqual(output);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
// firstToUppercase
|
|
48
|
+
(() => {
|
|
49
|
+
describe("Test firstToUppercase",
|
|
50
|
+
() => {
|
|
51
|
+
const tests = [
|
|
52
|
+
{
|
|
53
|
+
input : "",
|
|
54
|
+
output : "",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
input : "sima",
|
|
58
|
+
output : "Sima",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
input : "Simona Cosovei",
|
|
62
|
+
output : "Simona Cosovei",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
input : "this is 4 long name 5",
|
|
66
|
+
output : "This is 4 long name 5",
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
for (const { input, output } of tests) {
|
|
71
|
+
describe(`given "${input}"`,
|
|
72
|
+
() => {
|
|
73
|
+
it(`should be transformed to "${output}"`,
|
|
74
|
+
() => {
|
|
75
|
+
expect(firstToUppercase(input)).toEqual(output);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
})();
|
|
81
|
+
|
|
82
|
+
// toUpper
|
|
83
|
+
(() => {
|
|
84
|
+
const tests = [
|
|
85
|
+
{
|
|
86
|
+
input : "",
|
|
87
|
+
output : "",
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
input : "sima",
|
|
91
|
+
output : "SIMA",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
input : "this is 4 long name 5",
|
|
95
|
+
output : "THIS IS 4 LONG NAME 5",
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
for (const { input, output } of tests) {
|
|
100
|
+
describe(`given "${input}"`,
|
|
101
|
+
() => {
|
|
102
|
+
it(`should be transformed to "${output}"`,
|
|
103
|
+
() => {
|
|
104
|
+
expect(toUpper(input)).toEqual(output);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
})();
|
|
109
|
+
|
|
110
|
+
// toLower
|
|
111
|
+
(() => {
|
|
112
|
+
const tests = [
|
|
113
|
+
{
|
|
114
|
+
input : "",
|
|
115
|
+
output : "",
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
input : "siMa",
|
|
119
|
+
output : "sima",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
input : "This is 4 long Name 5",
|
|
123
|
+
output : "this is 4 long name 5",
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
for (const { input, output } of tests) {
|
|
128
|
+
describe(`given "${input}"`,
|
|
129
|
+
() => {
|
|
130
|
+
it(`should be transformed to "${output}"`,
|
|
131
|
+
() => {
|
|
132
|
+
expect(toLower(input)).toEqual(output);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
})();
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @flow
|
|
3
|
+
* Simona Cosovei ---> Simona Cosovei
|
|
4
|
+
*/
|
|
5
|
+
export const toTitle = (str : string) : string => {
|
|
6
|
+
const transform = (txt : string) : string => {
|
|
7
|
+
const firstPart = txt.charAt(0).toUpperCase(),
|
|
8
|
+
secondPart = txt.substr(1).toLowerCase();
|
|
9
|
+
|
|
10
|
+
return `${firstPart}${secondPart}`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
return str.replace(/\S+/gu,
|
|
14
|
+
transform);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// this is an example ---> This is an example
|
|
18
|
+
export const firstToUppercase = (str : string) : string => {
|
|
19
|
+
const firstPart = str.charAt(0).toUpperCase(),
|
|
20
|
+
secondPart = str.slice(1);
|
|
21
|
+
|
|
22
|
+
return `${firstPart}${secondPart}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const normalizeDiacritics = (str: string) : string => {
|
|
26
|
+
const chars = {
|
|
27
|
+
"ă" : "a",
|
|
28
|
+
"â" : "a",
|
|
29
|
+
"î" : "i",
|
|
30
|
+
"ț" : "t",
|
|
31
|
+
"ș" : "s",
|
|
32
|
+
|
|
33
|
+
"Ă" : "A",
|
|
34
|
+
"Â" : "A",
|
|
35
|
+
"Î" : "I",
|
|
36
|
+
"Ț" : "T",
|
|
37
|
+
"Ș" : "S",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return str.replace(/ă|â|î|ț|ș|Ă|Â|Î|Ț|Ș/gui,
|
|
41
|
+
(matched) => chars[matched]);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// This is ---> THIS IS
|
|
45
|
+
export const toUpper = (str : string) : string => str.toUpperCase();
|
|
46
|
+
|
|
47
|
+
// This is ---> this is
|
|
48
|
+
export const toLower = (str : string) : string => str.toLowerCase();
|
|
49
|
+
|
|
50
|
+
export const formatBankAccount = (raw: string) : string => {
|
|
51
|
+
|
|
52
|
+
if (typeof raw === "undefined" || raw === "") {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let output = "";
|
|
57
|
+
|
|
58
|
+
const nrOfCharsPerGroup = 4,
|
|
59
|
+
withoutSpaces = raw.replace(/ /gu,
|
|
60
|
+
"");
|
|
61
|
+
|
|
62
|
+
for (let index = 0; index < withoutSpaces.length; index += 1) {
|
|
63
|
+
const currentChar = withoutSpaces.charAt(index);
|
|
64
|
+
|
|
65
|
+
if (output !== "" && index % nrOfCharsPerGroup === 0) {
|
|
66
|
+
output += " ";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
output += currentChar;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return output;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const normalizeCompanyName = (raw : string) : string => (
|
|
76
|
+
toTitle(raw).replace(/\ssrl/gui,
|
|
77
|
+
" S.R.L.").
|
|
78
|
+
replace(/\ss\.r\.l/gui,
|
|
79
|
+
" S.R.L")
|
|
80
|
+
);
|