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.
Files changed (274) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.json +275 -0
  3. package/.flowconfig +23 -0
  4. package/conf/dev.js +19 -0
  5. package/conf/dist.js +19 -0
  6. package/conf/polyfills/tempPolyfills.js +7 -0
  7. package/package.json +16 -16
  8. package/src/Account/Load.jsx +79 -0
  9. package/src/Account/actions.js +10 -0
  10. package/src/Account/index.js +11 -0
  11. package/src/Account/reducer.js +139 -0
  12. package/src/Account/request.js +36 -0
  13. package/src/Async/InitModule.jsx +114 -0
  14. package/src/Async/RouteLoading.jsx +52 -0
  15. package/src/Async/SimulatedException.jsx +19 -0
  16. package/src/Async/index.jsx +75 -0
  17. package/src/Async/types.js +39 -0
  18. package/src/Company/Load.jsx +84 -0
  19. package/src/Company/actions.js +10 -0
  20. package/src/Company/index.js +11 -0
  21. package/src/Company/reducer.js +201 -0
  22. package/src/Company/request.js +30 -0
  23. package/src/Company/util.js +7 -0
  24. package/src/Header/AccountOptionsContainer.jsx +124 -0
  25. package/src/Header/AdminSelectCompany.jsx +101 -0
  26. package/src/Header/ClientSelectCompany.jsx +90 -0
  27. package/src/Header/Header.jsx +120 -0
  28. package/src/Header/HeaderContainer.jsx +30 -0
  29. package/src/Header/Logo.jsx +16 -0
  30. package/src/Header/LogoutButton.jsx +34 -0
  31. package/src/Header/index.jsx +9 -0
  32. package/src/Header/request.js +28 -0
  33. package/src/Header/types.js +6 -0
  34. package/src/Header/util.jsx +61 -0
  35. package/src/Inputs/Business/BankAccount.jsx +39 -0
  36. package/src/Inputs/Business/BankName.jsx +40 -0
  37. package/src/Inputs/Business/CifField.jsx +93 -0
  38. package/src/Inputs/Business/CifFieldContainer.jsx +142 -0
  39. package/src/Inputs/Business/Email.jsx +23 -0
  40. package/src/Inputs/Business/NidField.jsx +77 -0
  41. package/src/Inputs/Business/Phone.jsx +23 -0
  42. package/src/Inputs/Business/index.js +16 -0
  43. package/src/Inputs/Business/request.js +39 -0
  44. package/src/Inputs/CaptchaBox.jsx +131 -0
  45. package/src/Inputs/DateInput.jsx +188 -0
  46. package/src/Inputs/DateTemplate.jsx +213 -0
  47. package/src/Inputs/DelayInputChange.jsx +130 -0
  48. package/src/Inputs/FocusTemplate.jsx +41 -0
  49. package/src/Inputs/InputTemplate.jsx +79 -0
  50. package/src/Inputs/LabelTemplate.jsx +47 -0
  51. package/src/Inputs/NumericInput.jsx +142 -0
  52. package/src/Inputs/NumericTemplate.jsx +155 -0
  53. package/src/Inputs/Selects/County.jsx +19 -0
  54. package/src/Inputs/Selects/Custom.jsx +55 -0
  55. package/src/Inputs/Selects/Simple.jsx +73 -0
  56. package/src/Inputs/Selects/index.jsx +37 -0
  57. package/src/Inputs/SimpleInput.jsx +40 -0
  58. package/src/Inputs/SimpleTextarea.jsx +55 -0
  59. package/src/Inputs/TextareaTemplate.jsx +57 -0
  60. package/src/Inputs/Tooltip.jsx +61 -0
  61. package/src/Inputs/index.js +22 -0
  62. package/src/Messages/Error.jsx +83 -0
  63. package/src/Messages/Loading.jsx +43 -0
  64. package/src/Messages/index.jsx +4 -0
  65. package/src/Modal/Delete.jsx +237 -0
  66. package/src/Modal/Root.jsx +57 -0
  67. package/src/Modal/SimpleModal.jsx +47 -0
  68. package/src/Modal/actions.js +7 -0
  69. package/src/Modal/getComponent.jsx +32 -0
  70. package/src/Modal/index.jsx +12 -0
  71. package/src/Modal/reducer.js +40 -0
  72. package/src/Modal/types.js +6 -0
  73. package/src/Modal/util.js +15 -0
  74. package/src/Payment/EstimatePrice/Description.jsx +101 -0
  75. package/src/Payment/EstimatePrice/PayBox.jsx +173 -0
  76. package/src/Payment/EstimatePrice/index.jsx +63 -0
  77. package/src/Payment/EstimatePrice/util.js +15 -0
  78. package/src/Payment/MobilpayForm.jsx +77 -0
  79. package/src/Payment/Modal/BankTransfer.jsx +129 -0
  80. package/src/Payment/Modal/CompanyValability.jsx +14 -0
  81. package/src/Payment/Modal/DoneForm.jsx +209 -0
  82. package/src/Payment/Modal/PaymentDone.jsx +27 -0
  83. package/src/Payment/Modal/index.js +13 -0
  84. package/src/Payment/actions.jsx +22 -0
  85. package/{Payment → src/Payment}/codes.js +16 -19
  86. package/src/Payment/index.jsx +124 -0
  87. package/src/Payment/request.js +50 -0
  88. package/src/Payment/types.js +14 -0
  89. package/src/Payment/util.jsx +52 -0
  90. package/src/Payment/validate.js +25 -0
  91. package/src/Sidebar.jsx +158 -0
  92. package/src/Things.jsx +35 -0
  93. package/src/actions.js +36 -0
  94. package/src/config.js +7 -0
  95. package/src/dev/ErrorBoundary.jsx +98 -0
  96. package/src/dev/TheError.jsx +87 -0
  97. package/src/dev/index.js +127 -0
  98. package/src/dev/types.js +10 -0
  99. package/src/prod/SentryErrorBoundary.jsx +98 -0
  100. package/src/reducer/captchas.js +44 -0
  101. package/src/reducer/counties.js +46 -0
  102. package/src/reducer/index.js +25 -0
  103. package/src/reducer/module.jsx +43 -0
  104. package/src/style/.sass-lint.yml +84 -0
  105. package/src/style/.stylelintrc.json +161 -0
  106. package/src/style/_fancy-text.scss +37 -0
  107. package/src/style/_fix_bootstrap_placeholder_color.scss +14 -0
  108. package/src/style/_header-company.scss +69 -0
  109. package/src/style/_inputs.scss +12 -0
  110. package/src/style/_minimal.scss +31 -0
  111. package/src/style/_navigation.scss +24 -0
  112. package/src/style/_others.scss +79 -0
  113. package/src/style/index.scss +7 -0
  114. package/src/style/sidebar/_animations.scss +21 -0
  115. package/src/style/sidebar/_dark-theme.scss +77 -0
  116. package/src/style/sidebar/_scroll.scss +37 -0
  117. package/src/style/sidebar/_structure.scss +299 -0
  118. package/src/style/sidebar.scss +4 -0
  119. package/src/types.js +31 -0
  120. package/src/utility/calendar.js +39 -0
  121. package/src/utility/date.js +100 -0
  122. package/src/utility/index.js +12 -0
  123. package/src/utility/language.js +17 -0
  124. package/src/utility/mql.js +3 -0
  125. package/src/utility/normalize-test.js +58 -0
  126. package/src/utility/normalize.js +119 -0
  127. package/src/utility/numbers.js +87 -0
  128. package/src/utility/numeric.js +114 -0
  129. package/src/utility/others.jsx +160 -0
  130. package/src/utility/strings-test.js +136 -0
  131. package/src/utility/strings.js +80 -0
  132. package/src/utility/validation/common.js +360 -0
  133. package/src/utility/validation/index.js +70 -0
  134. package/src/utility/validation/specific.js +9 -0
  135. package/src/utility/validation/validate/bank-test.js +129 -0
  136. package/src/utility/validation/validate/bank.js +176 -0
  137. package/src/utility/validation/validate/cif-test.js +105 -0
  138. package/src/utility/validation/validate/cif.js +44 -0
  139. package/src/utility/validation/validate/cnp-test.js +216 -0
  140. package/src/utility/validation/validate/cnp.js +261 -0
  141. package/{utility → src/utility}/validation/validate/date.js +73 -61
  142. package/src/utility/validation/validate/email-test.js +36 -0
  143. package/src/utility/validation/validate/email.js +6 -0
  144. package/src/utility/validation/validate/index.js +7 -0
  145. package/webpack.config.js +90 -0
  146. package/x25.wiki/Account.md +41 -0
  147. package/x25.wiki/Company.md +39 -0
  148. package/x25.wiki/Header.md +21 -0
  149. package/x25.wiki/Home.md +1 -0
  150. package/x25.wiki/Inputs.md +33 -0
  151. package/x25.wiki/Messages.md +27 -0
  152. package/x25.wiki/Payment.md +42 -0
  153. package/Account/Load.js +0 -75
  154. package/Account/actions.js +0 -15
  155. package/Account/index.js +0 -20
  156. package/Account/reducer.js +0 -122
  157. package/Account/request.js +0 -44
  158. package/Async/InitModule.js +0 -190
  159. package/Async/RouteLoading.js +0 -64
  160. package/Async/SimulatedException.js +0 -44
  161. package/Async/index.js +0 -95
  162. package/Async/types.js +0 -1
  163. package/Company/Load.js +0 -82
  164. package/Company/actions.js +0 -15
  165. package/Company/index.js +0 -20
  166. package/Company/reducer.js +0 -165
  167. package/Company/request.js +0 -36
  168. package/Company/util.js +0 -10
  169. package/Header/AccountOptionsContainer.js +0 -144
  170. package/Header/AdminSelectCompany.js +0 -109
  171. package/Header/ClientSelectCompany.js +0 -104
  172. package/Header/Header.js +0 -127
  173. package/Header/HeaderContainer.js +0 -39
  174. package/Header/Logo.js +0 -30
  175. package/Header/LogoutButton.js +0 -39
  176. package/Header/index.js +0 -19
  177. package/Header/request.js +0 -26
  178. package/Header/types.js +0 -1
  179. package/Header/util.js +0 -58
  180. package/Inputs/Business/BankAccount.js +0 -48
  181. package/Inputs/Business/BankName.js +0 -49
  182. package/Inputs/Business/CifField.js +0 -112
  183. package/Inputs/Business/CifFieldContainer.js +0 -157
  184. package/Inputs/Business/Email.js +0 -37
  185. package/Inputs/Business/NidField.js +0 -91
  186. package/Inputs/Business/Phone.js +0 -37
  187. package/Inputs/Business/index.js +0 -34
  188. package/Inputs/Business/request.js +0 -39
  189. package/Inputs/CaptchaBox.js +0 -151
  190. package/Inputs/DateInput.js +0 -172
  191. package/Inputs/DateTemplate.js +0 -200
  192. package/Inputs/DelayInputChange.js +0 -135
  193. package/Inputs/FocusTemplate.js +0 -47
  194. package/Inputs/InputTemplate.js +0 -78
  195. package/Inputs/LabelTemplate.js +0 -59
  196. package/Inputs/NumericInput.js +0 -139
  197. package/Inputs/NumericTemplate.js +0 -148
  198. package/Inputs/Selects/County.js +0 -29
  199. package/Inputs/Selects/Custom.js +0 -56
  200. package/Inputs/Selects/Simple.js +0 -75
  201. package/Inputs/Selects/index.js +0 -52
  202. package/Inputs/SimpleInput.js +0 -42
  203. package/Inputs/SimpleTextarea.js +0 -47
  204. package/Inputs/TextareaTemplate.js +0 -55
  205. package/Inputs/Tooltip.js +0 -82
  206. package/Inputs/index.js +0 -185
  207. package/Messages/Error.js +0 -106
  208. package/Messages/Loading.js +0 -68
  209. package/Messages/index.js +0 -29
  210. package/Modal/Delete.js +0 -240
  211. package/Modal/Root.js +0 -81
  212. package/Modal/SimpleModal.js +0 -57
  213. package/Modal/actions.js +0 -10
  214. package/Modal/getComponent.js +0 -42
  215. package/Modal/index.js +0 -22
  216. package/Modal/reducer.js +0 -53
  217. package/Modal/types.js +0 -7
  218. package/Modal/util.js +0 -17
  219. package/Payment/EstimatePrice/Description.js +0 -92
  220. package/Payment/EstimatePrice/PayBox.js +0 -220
  221. package/Payment/EstimatePrice/index.js +0 -92
  222. package/Payment/EstimatePrice/util.js +0 -21
  223. package/Payment/MobilpayForm.js +0 -86
  224. package/Payment/Modal/BankTransfer.js +0 -233
  225. package/Payment/Modal/CompanyValability.js +0 -28
  226. package/Payment/Modal/DoneForm.js +0 -222
  227. package/Payment/Modal/PaymentDone.js +0 -53
  228. package/Payment/Modal/index.js +0 -27
  229. package/Payment/actions.js +0 -23
  230. package/Payment/index.js +0 -141
  231. package/Payment/request.js +0 -49
  232. package/Payment/types.js +0 -1
  233. package/Payment/util.js +0 -50
  234. package/Payment/validate.js +0 -23
  235. package/Sidebar.js +0 -156
  236. package/Things.js +0 -53
  237. package/actions.js +0 -73
  238. package/config.js +0 -10
  239. package/dev/ErrorBoundary.js +0 -109
  240. package/dev/TheError.js +0 -113
  241. package/dev/index.js +0 -132
  242. package/dev/types.js +0 -1
  243. package/prod/SentryErrorBoundary.js +0 -150
  244. package/reducer/captchas.js +0 -51
  245. package/reducer/counties.js +0 -57
  246. package/reducer/index.js +0 -38
  247. package/reducer/module.js +0 -48
  248. package/style/index.css +0 -1
  249. package/style/sidebar.css +0 -1
  250. package/types.js +0 -1
  251. package/utility/calendar.js +0 -45
  252. package/utility/date.js +0 -111
  253. package/utility/index.js +0 -125
  254. package/utility/language.js +0 -20
  255. package/utility/mql.js +0 -6
  256. package/utility/normalize-test.js +0 -54
  257. package/utility/normalize.js +0 -108
  258. package/utility/numbers.js +0 -93
  259. package/utility/numeric.js +0 -103
  260. package/utility/others.js +0 -142
  261. package/utility/strings-test.js +0 -216
  262. package/utility/strings.js +0 -85
  263. package/utility/validation/common.js +0 -278
  264. package/utility/validation/index.js +0 -110
  265. package/utility/validation/specific.js +0 -14
  266. package/utility/validation/validate/bank-test.js +0 -41
  267. package/utility/validation/validate/bank.js +0 -176
  268. package/utility/validation/validate/cif-test.js +0 -37
  269. package/utility/validation/validate/cif.js +0 -44
  270. package/utility/validation/validate/cnp-test.js +0 -68
  271. package/utility/validation/validate/cnp.js +0 -193
  272. package/utility/validation/validate/email-test.js +0 -30
  273. package/utility/validation/validate/email.js +0 -11
  274. 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
+ );