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,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,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
|
+
);
|