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,36 @@
1
+ // @flow
2
+
3
+ import agent from "superagent";
4
+ import * as Immutable from "immutable";
5
+
6
+ import { noError, normalizeArrayByField, withPromiseCallback, normalizeArray } from "../utility";
7
+
8
+ const normalizeInitialInformation = (info : any) => {
9
+
10
+ const
11
+ { Account, IsConnected, Counties, Companies } = info;
12
+
13
+ return {
14
+ Account : Immutable.Map(Account || {}),
15
+ IsConnected,
16
+ Error : IsConnected ? noError : "Not connected",
17
+ Counties : (typeof Counties === "undefined") ? [] : (
18
+ normalizeArrayByField(Counties,
19
+ "Short").entities
20
+ ),
21
+ Companies: (typeof Companies === "undefined") ? [] : (
22
+ normalizeArray(Companies).entities
23
+ ),
24
+ };
25
+ };
26
+
27
+ export const fetchInitialInformation = (app : string) => (
28
+ new Promise((resolve, reject) => (
29
+ agent.
30
+ get("/api/extern/get-initial-information").
31
+ type("form").
32
+ query({ app }).
33
+ end(withPromiseCallback((reponse) => resolve(normalizeInitialInformation(reponse)),
34
+ reject))
35
+ )) : Promise<any>
36
+ );
@@ -0,0 +1,114 @@
1
+ // @flow
2
+
3
+ import type { RouteType, PaginatorType } from "./types";
4
+
5
+ import type { Dispatch, State } from "src\\types";
6
+
7
+ type Props = {
8
+ +ready: bool;
9
+ +props: any;
10
+ +route: RouteType;
11
+ +initModule: () => void;
12
+ };
13
+
14
+ type OwnProps = {
15
+ route: RouteType,
16
+ props: any;
17
+ }
18
+
19
+ import * as React from "react";
20
+
21
+ import { LoadingMessage } from "../Messages/Loading";
22
+ import { injectModals } from "../Modal/util";
23
+ import { injectReducer } from "redux-injector";
24
+ import { delay } from "../utility";
25
+
26
+ const injectPaginator = ({ key, itemsReducer, pagesReducer } : PaginatorType) => {
27
+ injectReducer(`entities.${key}`, itemsReducer);
28
+ injectReducer(`paginations.${key}`, pagesReducer);
29
+ };
30
+
31
+ import { connect } from "react-redux";
32
+
33
+ import { getIsModuleReady, moduleIsReadyAction } from "../reducer/module";
34
+
35
+ const
36
+ mapStateToProps = (state : State, { route : { default : { module } } } : OwnProps) => ({
37
+ ready: getIsModuleReady(state, module),
38
+ }),
39
+ mapDispatchToProps = (dispatch : Dispatch, { route } : OwnProps) => ({
40
+ initModule () {
41
+ const { reducers, modals, paginators, module } = route.default;
42
+
43
+ delay().
44
+ then(() => {
45
+ if (reducers) {
46
+ if (Array.isArray(reducers)) {
47
+ for (const { key, func } of reducers) {
48
+ injectReducer(key, func);
49
+ }
50
+ } else {
51
+ const { key, func } = reducers;
52
+
53
+ injectReducer(key, func);
54
+ }
55
+ }
56
+ }).
57
+ then(() => {
58
+ if (modals) {
59
+ injectModals(modals);
60
+ }
61
+ }).
62
+ then(() => {
63
+ if (paginators) {
64
+ if (Array.isArray(paginators)) {
65
+ for (const paginator of paginators) {
66
+ injectPaginator(paginator);
67
+ }
68
+ } else {
69
+ injectPaginator(paginators);
70
+ }
71
+ }
72
+ }).
73
+ then(() => {
74
+ dispatch(moduleIsReadyAction(module));
75
+ });
76
+ },
77
+ });
78
+
79
+ class InitModule extends React.Component<Props> {
80
+ componentDidMount () {
81
+ if (!this.props.ready) {
82
+ this.props.initModule();
83
+ }
84
+ }
85
+
86
+ shouldComponentUpdate () {
87
+ return (
88
+ true
89
+ );
90
+ }
91
+
92
+ render () {
93
+ const { route, ready, props } = this.props;
94
+ const { Component } = route.default;
95
+
96
+ if (ready) {
97
+ return <Component {...props} />;
98
+ }
99
+
100
+ return (
101
+ <div className="mt-3">
102
+ <LoadingMessage message="Așteaptă un pic..." />
103
+ </div>
104
+ );
105
+ }
106
+ }
107
+
108
+ const WrapInitModule = connect(mapStateToProps, mapDispatchToProps)(InitModule);
109
+
110
+ const createWrap = (route : RouteType, props: any) => (
111
+ <WrapInitModule props={props} route={route} />
112
+ );
113
+
114
+ export default createWrap;
@@ -0,0 +1,52 @@
1
+ // @flow
2
+
3
+ type LoadingPropTypes = {
4
+ +error?: any;
5
+ +timedOut: bool;
6
+ +pastDelay: bool;
7
+ +retry: () => void;
8
+ }
9
+
10
+ type FireErrorPropTypes = {
11
+ error: any;
12
+ }
13
+
14
+ import React from "react";
15
+
16
+ import { LoadingMessage } from "../Messages/Loading";
17
+ import SimulatedException from "./SimulatedException";
18
+
19
+ import { ErrorBoundary } from "./index";
20
+
21
+ const IgnoreThisNode = ({ error : { message, stack } } : FireErrorPropTypes) => {
22
+ throw new SimulatedException(message, stack);
23
+ };
24
+
25
+ const RouteLoading = ({ error, retry, timedOut } : LoadingPropTypes) => {
26
+ if (error) {
27
+ return (
28
+ <ErrorBoundary>
29
+ <IgnoreThisNode error={error} />
30
+ </ErrorBoundary>
31
+ );
32
+ }
33
+
34
+ if (timedOut) {
35
+ return (
36
+ <div>{"Se pare că se încarcă mai greu ca de obicei "}
37
+ <button
38
+ className="btn btn-primary btn-block"
39
+ onClick={retry} type="button">{"Încearcă din nou"}
40
+ </button>
41
+ </div>
42
+ );
43
+ }
44
+
45
+ return (
46
+ <div className="mt-3">
47
+ <LoadingMessage message="Așteaptă un pic..." />
48
+ </div>
49
+ );
50
+ };
51
+
52
+ export default RouteLoading;
@@ -0,0 +1,19 @@
1
+ // @flow
2
+ /* eslint-disable max-classes-per-file */
3
+
4
+ class CustomError<Message: string, Stack: string> extends Error {
5
+
6
+ constructor (message: Message, stack: Stack) {
7
+ super(message);
8
+ this.message = message;
9
+ this.name = message;
10
+ this.stack = stack;
11
+ }
12
+ }
13
+
14
+ type Message = string;
15
+ type Stack = string;
16
+
17
+ class SimulatedException extends CustomError<Message, Stack> {}
18
+
19
+ export default SimulatedException;
@@ -0,0 +1,75 @@
1
+ // @flow
2
+ /* eslint-disable new-cap, react/prefer-stateless-function, react/require-optimization */
3
+
4
+
5
+ type LoaderType = (path : string) => void;
6
+
7
+ import Loadable from "react-loadable";
8
+ import * as React from "react";
9
+
10
+ import RouteLoading from "./RouteLoading";
11
+ import InitModule from "./InitModule";
12
+
13
+ // type injectPaginatorTypes = {
14
+ // key: string,
15
+ // itemsReducer: any;
16
+ // pagesReducer: any;
17
+ // };
18
+ // import { injectReducer } from "redux-injector";
19
+ // import { injectModals } from "../Modal/util";
20
+
21
+ const
22
+ timeout = 15000;
23
+
24
+ export let
25
+ ErrorBoundary = () => (
26
+ <div>{"No ErrorBoundary passed to x25"}</div>
27
+ );
28
+
29
+ // const injectPaginator = ({ key, itemsReducer, pagesReducer } : injectPaginatorTypes) => {
30
+ // injectReducer(`entities.${key}`, itemsReducer);
31
+ // injectReducer(`paginations.${key}`, pagesReducer);
32
+ // };
33
+
34
+ // const renderWithReducer = (route, props) => {
35
+ // const { Component, reducers, modals, paginators } = route.default;
36
+ //
37
+ // if (reducers) {
38
+ // if (Array.isArray(reducers)) {
39
+ // for (const { key, func } of reducers) {
40
+ // injectReducer(key, func);
41
+ // }
42
+ // } else {
43
+ // const { key, func } = reducers;
44
+ //
45
+ // injectReducer(key, func);
46
+ // }
47
+ // }
48
+ //
49
+ // if (modals) {
50
+ // injectModals(modals);
51
+ // }
52
+ //
53
+ // if (paginators) {
54
+ // if (Array.isArray(paginators)) {
55
+ // for (const paginator of paginators) {
56
+ // injectPaginator(paginator);
57
+ // }
58
+ // } else {
59
+ // injectPaginator(paginators);
60
+ // }
61
+ // }
62
+ //
63
+ // return <Component {...props} />;
64
+ // };
65
+
66
+ export const setErrorBoundary = (theError : React.Node) => {
67
+ ErrorBoundary = theError;
68
+ };
69
+
70
+ export const createAsyncRoute = (loader : LoaderType) => Loadable({
71
+ loader,
72
+ loading : RouteLoading,
73
+ render : InitModule,
74
+ timeout,
75
+ });
@@ -0,0 +1,39 @@
1
+ // @flow
2
+
3
+ // import * as React from "react";
4
+
5
+ import type { State } from "src\\types";
6
+ import type { ModalsTypes } from "../Modal/types";
7
+
8
+ type Reducer = (state : State, action : any) => void;
9
+
10
+ type ReducerOptionsType = {
11
+ key: string,
12
+ func: Reducer,
13
+ };
14
+
15
+ type PaginatorType = {
16
+ key: string,
17
+ itemsReducer: Reducer;
18
+ pagesReducer: Reducer;
19
+ };
20
+
21
+ type ReducersTypes = Array<ReducerOptionsType> | ReducerOptionsType;
22
+ type PaginatorsTypes = Array<PaginatorType> | PaginatorType;
23
+
24
+ type RouteType = {
25
+ default: {
26
+ module: string,
27
+ Component: any,
28
+ reducers: ReducersTypes,
29
+ modals: ModalsTypes,
30
+ paginators: PaginatorsTypes,
31
+ },
32
+ }
33
+
34
+ export type {
35
+ ReducersTypes,
36
+ PaginatorsTypes,
37
+ PaginatorType,
38
+ RouteType,
39
+ };
@@ -0,0 +1,84 @@
1
+ // @flow
2
+ /* eslint-disable react/require-optimization */
3
+
4
+ import type { Dispatch, State } from "src\\types";
5
+
6
+ type PropTypes = {
7
+ +isAdministrator: bool;
8
+ +isFetching: bool;
9
+ +hasError: bool;
10
+
11
+ +data: any;
12
+ +shouldFetch: any;
13
+ +children: any;
14
+
15
+ +fetchCurrentCompany: () => void;
16
+ }
17
+
18
+ import React from "react";
19
+
20
+ import { withRouter } from "react-router-dom";
21
+ // import moment from "moment";
22
+ import { connect } from "react-redux";
23
+
24
+ import { selectors } from "./reducer";
25
+ import { accountSelectors } from "../Account";
26
+
27
+ import { fetchCurrentCompany as fetchCurrentCompanyAction } from "./actions";
28
+
29
+ import { LargeErrorMessage, LoadingMessage } from "../Messages";
30
+
31
+ // import EstimatePrice from "../Payment/EstimatePrice";
32
+
33
+ const
34
+ mapStateToProps = (state : State) => ({
35
+ isAdministrator : accountSelectors.getIsCurrentAccountAdministrator(state),
36
+ data : selectors.getCurrentCompany(state),
37
+ hasError : selectors.getCurrentCompanyHasError(state),
38
+ fetched : selectors.getCurrentCompanyIsFetched(state),
39
+ isFetching : selectors.getCurrentCompanyIsFetching(state),
40
+ shouldFetch : selectors.getCurrentCompanyShouldFetch(state),
41
+ }),
42
+ mapDispatchToProps = (dispatch : Dispatch, { match : { params : { company } } }) => ({
43
+ fetchCurrentCompany () {
44
+ dispatch(fetchCurrentCompanyAction(company));
45
+ },
46
+ });
47
+
48
+
49
+ const LoadCompany = (props : PropTypes) => {
50
+ const { children, data, isFetching, shouldFetch, hasError, fetchCurrentCompany } = props;
51
+
52
+ React.useEffect(() => {
53
+ if (shouldFetch) {
54
+ fetchCurrentCompany();
55
+ }
56
+ }, [
57
+ shouldFetch,
58
+ isFetching,
59
+ hasError,
60
+ ]);
61
+
62
+ if (isFetching) {
63
+ return (
64
+ <LoadingMessage message="Așteaptă..." />
65
+ );
66
+ }
67
+
68
+ if (hasError) {
69
+ return (
70
+ <LargeErrorMessage
71
+ message="Nu am putut stabili conexiunea cu server-ul"
72
+ onRetry={fetchCurrentCompany}
73
+ />
74
+ );
75
+ }
76
+
77
+ if (data.size === 0) {
78
+ return null;
79
+ }
80
+
81
+ return children;
82
+ };
83
+
84
+ export default withRouter(connect(mapStateToProps, mapDispatchToProps)(LoadCompany));
@@ -0,0 +1,10 @@
1
+ // @flow
2
+
3
+ import type { Action } from "src\\types";
4
+
5
+ import { fetchCurrentCompany as fetchCurrentCompanyRequest } from "./request";
6
+
7
+ export const fetchCurrentCompany = (rawID : string) : Action => ({
8
+ type : "FETCH_CURRENT_COMPANY_INFO",
9
+ payload : fetchCurrentCompanyRequest(rawID),
10
+ });
@@ -0,0 +1,11 @@
1
+ // @flow
2
+
3
+ import companyReducer, { selectors as companySelectors } from "./reducer";
4
+
5
+ import LoadCompany from "./Load";
6
+
7
+ export {
8
+ companySelectors,
9
+ companyReducer,
10
+ LoadCompany,
11
+ };
@@ -0,0 +1,201 @@
1
+ // @flow
2
+ /* eslint-disable global-require */
3
+
4
+ import * as Immutable from "immutable";
5
+
6
+ import type { Action, State } from "src\\types";
7
+
8
+ import { createSelector } from "reselect";
9
+
10
+ import { noError } from "../utility";
11
+
12
+ import { getIDFromURL } from "./util";
13
+
14
+ const reducerKey = "companyInfo";
15
+
16
+ type CurrentState = any;
17
+
18
+ const initialState : CurrentState = Immutable.Map({
19
+ error : noError,
20
+ fetched : false,
21
+ fetching : false,
22
+
23
+ company: Immutable.Map(),
24
+ });
25
+
26
+ const
27
+ fetchCompanyPending = () => (
28
+ initialState.set("fetching",
29
+ true)
30
+ ),
31
+ fetchCompanyRejected = (state : any, { payload : { error } }) => (
32
+ state.merge({
33
+ error,
34
+ fetching: false,
35
+ })
36
+ ),
37
+ fetchCompanyFulfilled = (state : any, { payload }) => (
38
+ state.mergeDeep({
39
+ fetched : true,
40
+ fetching : false,
41
+ company : payload,
42
+ })
43
+ ),
44
+ modifyCompany = (state : any, { payload }) => (
45
+ state.set("company",
46
+ payload)
47
+ ),
48
+ clearInfoIfCurrentCompany = (state : any, { payload }) => {
49
+ const
50
+ companyID = String(state.getIn([
51
+ "company",
52
+ "ID",
53
+ ])),
54
+ fetched = state.get("fetched"),
55
+ dataID = String(payload.get("ID")),
56
+ theCurrentCompanyHasChanged = fetched && (dataID === companyID);
57
+
58
+ if (theCurrentCompanyHasChanged) {
59
+ return state.clear();
60
+ }
61
+
62
+ return state;
63
+ };
64
+
65
+ const reducer = (state : any = initialState, action : Action) => {
66
+ switch (action.type) {
67
+ case "FETCH_CURRENT_COMPANY_INFO_PENDING":
68
+ return fetchCompanyPending();
69
+
70
+ case "FETCH_CURRENT_COMPANY_INFO_REJECTED":
71
+ return fetchCompanyRejected(state,
72
+ action);
73
+
74
+ case "FETCH_CURRENT_COMPANY_INFO_FULFILLED":
75
+ return fetchCompanyFulfilled(state,
76
+ action);
77
+
78
+ case "MODIFY_CURRENT_COMPANY_INFO":
79
+ return modifyCompany(state,
80
+ action);
81
+
82
+ case "TOGGLE_COMPANY_STATE":
83
+ case "DELETE_COMPANY":
84
+ return clearInfoIfCurrentCompany(state,
85
+ action);
86
+
87
+ default:
88
+ return state;
89
+ }
90
+ };
91
+
92
+ const
93
+ getFetching = (state : State) => state.getIn([
94
+ reducerKey,
95
+ "fetching",
96
+ ]) || false,
97
+ getFetched = (state : State) => state.getIn([
98
+ reducerKey,
99
+ "fetched",
100
+ ]) || false,
101
+ getError = (state : State) => state.getIn([
102
+ reducerKey,
103
+ "error",
104
+ ]) || noError,
105
+ getCurrentAccountFetched = (state : State) => state.getIn([
106
+ "account",
107
+ "fetched",
108
+ ]) || false;
109
+
110
+ const checkForNoErrors = (error) => error !== noError;
111
+
112
+ const
113
+ getCurrentCompany = (state : State) : any => (
114
+ state.getIn([
115
+ reducerKey,
116
+ "company",
117
+ ]) || Immutable.Map()
118
+ ),
119
+ getCurrentCompanyIsFetched = createSelector(
120
+ getFetching,
121
+ getFetched,
122
+ getError,
123
+ (isFetching, isFetched, error) => (
124
+ !isFetching && isFetched && error === noError
125
+ ),
126
+ ),
127
+ getCurrentCompanyIsFetching = createSelector(
128
+ getFetching,
129
+ getError,
130
+ (isFetching, error) => (
131
+ isFetching && error === noError
132
+ ),
133
+ ),
134
+ getCurrentCompanyHasError = createSelector(
135
+ getError,
136
+ checkForNoErrors,
137
+ ),
138
+ getCurrentCompanyShouldFetch = createSelector(
139
+ getCurrentAccountFetched,
140
+ getCurrentCompanyIsFetched,
141
+ getCurrentCompanyHasError,
142
+ getFetching,
143
+ getCurrentCompany,
144
+ (accountFetched, isFetched, hasError, isFetching, company) => (rawID : string) => {
145
+ const
146
+ hasIDChanged = () => {
147
+ const
148
+ id = company.get("ID"),
149
+ newID = Number(rawID);
150
+
151
+ return (
152
+ id === 0 ||
153
+ id !== newID ||
154
+ (id === newID && !isFetched)
155
+ );
156
+ };
157
+
158
+ return (
159
+ accountFetched && !hasError && !isFetching && hasIDChanged()
160
+ );
161
+ },
162
+ ),
163
+ getCompanyModules = createSelector(
164
+ getCurrentCompany,
165
+ (company) => company.get("Modules") || "",
166
+ ),
167
+
168
+ /*
169
+ This function is special, because it is called also in the
170
+ requests
171
+ In case the state is not ready, we take the id of the current company
172
+ from the URL
173
+
174
+ The url must have this pathname:
175
+
176
+ something/:companyID/something...
177
+ */
178
+ getCurrentCompanyID = (state : any) => {
179
+ if (typeof state === "undefined" || state === null) {
180
+ return getIDFromURL();
181
+ }
182
+
183
+ return state.getIn([
184
+ reducerKey,
185
+ "company",
186
+ "ID",
187
+ ]);
188
+ };
189
+
190
+
191
+ export const selectors = {
192
+ getCurrentCompany,
193
+ getCurrentCompanyIsFetched,
194
+ getCurrentCompanyIsFetching,
195
+ getCurrentCompanyHasError,
196
+ getCurrentCompanyShouldFetch,
197
+ getCompanyModules,
198
+ getCurrentCompanyID,
199
+ };
200
+
201
+ export default reducer;
@@ -0,0 +1,30 @@
1
+ // @flow
2
+
3
+ import agent from "superagent";
4
+ import * as Immutable from "immutable";
5
+
6
+ import { withPromiseCallback } from "../utility";
7
+ import { selectors } from "./reducer";
8
+
9
+ export const fetchCurrentCompany = (id : string) => (
10
+ new Promise((resolve, reject) => (
11
+ agent.
12
+ get(`/api/company/${id}/get-information`).
13
+ set("Accept",
14
+ "application/json").
15
+ end(withPromiseCallback((data) => resolve(Immutable.Map(data)),
16
+ reject))
17
+ )) : Promise<any>
18
+ );
19
+
20
+ export const modifyCurrentCompany = (data : any) => (
21
+ new Promise((resolve, reject) => (
22
+ agent.
23
+ post(`/api/company/${selectors.getCurrentCompanyID()}/modify-info`).
24
+ set("Accept",
25
+ "application/json").
26
+ send(data).
27
+ end(withPromiseCallback(resolve,
28
+ reject))
29
+ )) : Promise<any>
30
+ );
@@ -0,0 +1,7 @@
1
+ // @flow
2
+
3
+ export const getIDFromURL = () => {
4
+ const parts = String(window.location.pathname).split("/");
5
+
6
+ return parts[2];
7
+ };