feat: Fix axios interceptors.

This commit is contained in:
Ahmed Bouhuolia
2020-05-26 17:51:00 +02:00
parent dd49774f93
commit 72ba394c53
15 changed files with 369 additions and 223 deletions

View File

@@ -1,29 +1,21 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { IntlProvider } from 'react-intl'; import { IntlProvider } from 'react-intl';
import { connect } from 'react-redux'; import { Router, Switch, Route } from 'react-router';
import { Router, Switch, Redirect } from 'react-router';
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
import { ReactQueryConfigProvider } from 'react-query';
import { ReactQueryDevtools } from 'react-query-devtools';
import PrivateRoute from 'components/PrivateRoute'; import PrivateRoute from 'components/PrivateRoute';
import Authentication from 'components/Authentication'; import Authentication from 'components/Authentication';
import Dashboard from 'components/Dashboard/Dashboard'; import Dashboard from 'components/Dashboard/Dashboard';
import { isAuthenticated } from 'store/authentication/authentication.reducer' import GlobalErrors from 'containers/GlobalErrors/GlobalErrors';
import { ReactQueryConfigProvider } from 'react-query';
import { ReactQueryDevtools } from "react-query-devtools";
import messages from 'lang/en'; import messages from 'lang/en';
import 'style/App.scss'; import 'style/App.scss';
function App({ function App({ locale }) {
isAuthorized,
locale,
}) {
const history = createBrowserHistory(); const history = createBrowserHistory();
history.listen((location, action) => {
console.log(`new location via ${action}`, location);
});
const queryConfig = { const queryConfig = {
refetchAllOnWindowFocus: false, refetchAllOnWindowFocus: false,
cacheTime: 10000, cacheTime: 10000,
@@ -34,10 +26,18 @@ function App({
<div className="App"> <div className="App">
<ReactQueryConfigProvider config={queryConfig}> <ReactQueryConfigProvider config={queryConfig}>
<Router history={history}> <Router history={history}>
<Authentication isAuthenticated={isAuthorized} /> <Switch>
<PrivateRoute isAuthenticated={isAuthorized} component={Dashboard} /> <Route path={'/auth'}>
<Authentication />
</Route>
<Route path={'/'}>
<PrivateRoute component={Dashboard} />
</Route>
</Switch>
</Router> </Router>
<GlobalErrors />
<ReactQueryDevtools /> <ReactQueryDevtools />
</ReactQueryConfigProvider> </ReactQueryConfigProvider>
</div> </div>
@@ -49,10 +49,4 @@ App.defaultProps = {
locale: 'en', locale: 'en',
}; };
const mapStateToProps = (state) => { export default App;
return {
isAuthorized: isAuthenticated(state),
};
};
export default connect(mapStateToProps)(App);

View File

@@ -2,22 +2,22 @@ import React from 'react';
import { Redirect, Route, Switch, Link } from 'react-router-dom'; import { Redirect, Route, Switch, Link } from 'react-router-dom';
import BodyClassName from 'react-body-classname'; import BodyClassName from 'react-body-classname';
import authenticationRoutes from 'routes/authentication'; import authenticationRoutes from 'routes/authentication';
import { FormattedMessage as T, useIntl } from 'react-intl'; import { FormattedMessage as T } from 'react-intl';
import withAuthentication from 'containers/Authentication/withAuthentication';
import { compose } from 'utils';
export default function AuthenticationWrapper({
isAuthenticated = false, function AuthenticationWrapper({ isAuthorized = false, ...rest }) {
...rest
}) {
const to = { pathname: '/homepage' }; const to = { pathname: '/homepage' };
return ( return (
<Route path='/auth'> <>
{isAuthenticated ? ( {isAuthorized ? (
<Redirect to={to} /> <Redirect to={to} />
) : ( ) : (
<BodyClassName className={'authentication'}> <BodyClassName className={'authentication'}>
<Switch> <Switch>
<div class='authentication-page'> <div class="authentication-page">
<Link <Link
to={'bigcapital.io'} to={'bigcapital.io'}
className={'authentication-page__goto-bigcapital'} className={'authentication-page__goto-bigcapital'}
@@ -25,7 +25,7 @@ export default function AuthenticationWrapper({
<T id={'go_to_bigcapital_com'} /> <T id={'go_to_bigcapital_com'} />
</Link> </Link>
<div class='authentication-page__form-wrapper'> <div class="authentication-page__form-wrapper">
{authenticationRoutes.map((route, index) => ( {authenticationRoutes.map((route, index) => (
<Route <Route
key={index} key={index}
@@ -39,6 +39,8 @@ export default function AuthenticationWrapper({
</Switch> </Switch>
</BodyClassName> </BodyClassName>
)} )}
</Route> </>
); );
} }
export default compose(withAuthentication)(AuthenticationWrapper);

View File

@@ -9,14 +9,13 @@ import {
Popover Popover
} from '@blueprintjs/core'; } from '@blueprintjs/core';
import t from 'store/types'; import t from 'store/types';
import { FormattedMessage as T, useIntl } from 'react-intl'; import { FormattedMessage as T } from 'react-intl';
function DashboardTopbarUser({ logout }) { function DashboardTopbarUser({ logout }) {
const history = useHistory(); const history = useHistory();
const onClickLogout = useCallback(() => { const onClickLogout = useCallback(() => {
logout(); logout();
history.go('/auth/login');
}, [logout, history]); }, [logout, history]);
const userAvatarDropMenu = useMemo(() => ( const userAvatarDropMenu = useMemo(() => (

View File

@@ -1,37 +1,29 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import BodyClassName from 'react-body-classname'; import BodyClassName from 'react-body-classname';
import { Route, Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import withAuthentication from 'containers/Authentication/withAuthentication';
import { compose } from 'utils';
const propTypes = {
isAuthenticated: PropTypes.bool,
component: PropTypes.func.isRequired
};
function PrivateRoute({ function PrivateRoute({
component: Component, component: Component,
isAuthenticated = false, isAuthorized = false,
...rest ...rest
}) { }) {
return ( return (
<BodyClassName className={''}> <BodyClassName className={''}>
<Route {(isAuthorized) ? (
{...rest} <Component />
path="/" ) : (
render={_props => <Redirect
isAuthenticated ? (<Component {..._props} />) : to={{
( pathname: '/auth/login',
<Redirect }}
to={{ />
pathname: '/auth/login', )}
}}
/>
)}
/>
</BodyClassName> </BodyClassName>
); );
} }
PrivateRoute.propTypes = propTypes; export default compose(withAuthentication)(PrivateRoute);
export default PrivateRoute;

View File

@@ -66,7 +66,6 @@ function Login({
crediential: values.crediential, crediential: values.crediential,
password: values.password, password: values.password,
}).then(() => { }).then(() => {
history.go('/homepage');
setSubmitting(false); setSubmitting(false);
}).catch((errors) => { }).catch((errors) => {
const toastBuilders = []; const toastBuilders = [];

View File

@@ -0,0 +1,11 @@
import { isAuthenticated } from 'store/authentication/authentication.reducer'
import { connect } from 'react-redux';
const mapStateToProps = (state) => {
return {
isAuthorized: isAuthenticated(state),
};
};
export default connect(mapStateToProps);

View File

@@ -0,0 +1,47 @@
import { Intent } from '@blueprintjs/core';
import { useIntl } from 'react-intl';
import AppToaster from 'components/AppToaster';
import withGlobalErrors from './withGlobalErrors';
import withGlobalErrorsActions from './withGlobalErrorsActions';
import { compose } from 'utils';
let toastKeySessionExpired;
let toastKeySomethingWrong;
function GlobalErrors({
// #withGlobalErrors
globalErrors,
// #withGlobalErrorsActions
globalErrorsSet,
}) {
const { formatMessage } = useIntl();
if (globalErrors.something_wrong) {
toastKeySessionExpired = AppToaster.show({
message: formatMessage({ id: 'ops_something_went_wrong' }),
intent: Intent.DANGER,
onDismiss: () => {
globalErrorsSet({ something_wrong: false });
}
}, toastKeySessionExpired);
}
if (globalErrors.session_expired) {
toastKeySomethingWrong = AppToaster.show({
message: formatMessage({ id: 'session_expired' }),
intent: Intent.DANGER,
onDismiss: () => {
globalErrorsSet({ session_expired: false });
}
}, toastKeySomethingWrong);
}
return null;
}
export default compose(
withGlobalErrors,
withGlobalErrorsActions,
)(GlobalErrors);

View File

@@ -0,0 +1,10 @@
import { connect } from 'react-redux';
const mapStateToProps = (state) => {
return {
globalErrors: state.globalErrors.data,
};
};
export default connect(mapStateToProps);

View File

@@ -0,0 +1,9 @@
import {connect} from 'react-redux';
import { setGlobalErrors } from 'store/globalErrors/globalErrors.actions';
import t from 'store/types';
export const mapDispatchToProps = (dispatch) => ({
globalErrorsSet: (errors) => dispatch(setGlobalErrors(errors)),
});
export default connect(null, mapDispatchToProps);

View File

@@ -1,14 +1,15 @@
export default { export default {
hello_world: 'Hello World', hello_world: 'Hello World',
'email_or_phone_number': 'Email or phone number', email_or_phone_number: 'Email or phone number',
password: 'Password', password: 'Password',
login: 'Login', login: 'Login',
invalid_email_or_phone_number: 'Invalid email or phone number.', invalid_email_or_phone_number: 'Invalid email or phone number.',
'required': 'Required', required: 'Required',
reset_password: 'Reset Password', reset_password: 'Reset Password',
the_user_has_been_suspended_from_admin: 'The user has been suspended from the administrator.', the_user_has_been_suspended_from_admin:
'The user has been suspended from the administrator.',
email_and_password_entered_did_not_match: email_and_password_entered_did_not_match:
'The email and password you entered did not match our records.', 'The email and password you entered did not match our records.',
field_name_must_be_number: 'field_name_must_be_number', field_name_must_be_number: 'field_name_must_be_number',
name: 'Name', name: 'Name',
search: 'Search', search: 'Search',
@@ -34,9 +35,9 @@ export default {
phone_number: 'Phone Number', phone_number: 'Phone Number',
you_email_address_is: 'You email address is', you_email_address_is: 'You email address is',
you_will_use_this_address_to_sign_in_to_bigcapital: you_will_use_this_address_to_sign_in_to_bigcapital:
'You will use this address to sign in to Bigcapital.', 'You will use this address to sign in to Bigcapital.',
signing_in_or_creating: signing_in_or_creating:
'By signing in or creating an account, you agree with our', 'By signing in or creating an account, you agree with our',
terms_conditions: 'Terms & Conditions', terms_conditions: 'Terms & Conditions',
and: 'and', and: 'and',
privacy_statement: 'Privacy Statement', privacy_statement: 'Privacy Statement',
@@ -47,13 +48,15 @@ export default {
organization_name: 'Organization Name', organization_name: 'Organization Name',
email: 'Email', email: 'Email',
register: 'Register', register: 'Register',
password_successfully_updated: 'The Password for your account was successfully updated.', password_successfully_updated:
'The Password for your account was successfully updated.',
choose_a_new_password: 'Choose a new password', choose_a_new_password: 'Choose a new password',
you_remembered_your_password: 'You remembered your password ?', you_remembered_your_password: 'You remembered your password ?',
new_password: 'New Password', new_password: 'New Password',
submit_new_password: 'Submit new password', submit_new_password: 'Submit new password',
reset_your_password: 'Reset Your Password', reset_your_password: 'Reset Your Password',
we_ll_send_you_a_link_to_reset_your_password: 'Enter your email address and well send you a link to reset your password.', we_ll_send_you_a_link_to_reset_your_password:
'Enter your email address and well send you a link to reset your password.',
send_password_reset_link: 'Send password reset link', send_password_reset_link: 'Send password reset link',
return_to_log_in: 'Return to log in', return_to_log_in: 'Return to log in',
sub_account: 'Sub account?', sub_account: 'Sub account?',
@@ -84,7 +87,8 @@ export default {
new: 'New', new: 'New',
new_category: 'New Category', new_category: 'New Category',
invite_user: 'invite User', invite_user: 'invite User',
your_access_to_your_team: 'Your teammate will get an email that gives them access to your team.', your_access_to_your_team:
'Your teammate will get an email that gives them access to your team.',
invite: 'invite', invite: 'invite',
count: 'Count', count: 'Count',
item_type: 'Item Type', item_type: 'Item Type',
@@ -137,7 +141,7 @@ export default {
inactivate: 'Inactivate', inactivate: 'Inactivate',
activate: 'Activate', activate: 'Activate',
inactivate_account: 'Inactivate Account', inactivate_account: 'Inactivate Account',
activate_account:'Activate Account', activate_account: 'Activate Account',
delete_account: 'Delete Account', delete_account: 'Delete Account',
code: 'Code', code: 'Code',
type: 'Type', type: 'Type',
@@ -169,164 +173,198 @@ export default {
view_name: 'View Name', view_name: 'View Name',
new_conditional: 'New Conditional', new_conditional: 'New Conditional',
item: 'Item', item: 'Item',
service_has_been_successful_created: '{service} {name} has been successfully created.', service_has_been_successful_created:
service_has_been_successful_edited: '{service} {name} has been successfully edited.', '{service} {name} has been successfully created.',
service_has_been_successful_edited:
'{service} {name} has been successfully edited.',
you_are_about_permanently_delete_this_journal: `You're about to permanently delete this journal and all its transactions on accounts and attachments, and all of its data. <br /><br />If you're not sure, you can archive this journal instead.`, you_are_about_permanently_delete_this_journal: `You're about to permanently delete this journal and all its transactions on accounts and attachments, and all of its data. <br /><br />If you're not sure, you can archive this journal instead.`,
once_delete_these_accounts_you_will_not_able_restore_them: 'Once you delete these accounts, you won\'t be able to retrieve them later. Are you sure you want to delete them?', once_delete_these_accounts_you_will_not_able_restore_them:
once_delete_these_service_you_will_not_able_restore_it: 'Once you delete these {service}, you won\'t be able to retrieve them later. Are you sure you want to delete this {service}?', "Once you delete these accounts, you won't be able to retrieve them later. Are you sure you want to delete them?",
you_could_not_delete_predefined_accounts: 'You could\'t delete predefined accounts.', once_delete_these_service_you_will_not_able_restore_it:
cannot_delete_account_has_associated_transactions: 'you could\'t not delete account that has associated transactions.', "Once you delete these {service}, you won't be able to retrieve them later. Are you sure you want to delete this {service}?",
the_account_has_been_successfully_inactivated: 'The account has been successfully inactivated.', you_could_not_delete_predefined_accounts:
the_account_has_been_successfully_activated: 'The account has been successfully activated.', "You could't delete predefined accounts.",
the_account_has_been_successfully_deleted: 'The account has been successfully deleted.', cannot_delete_account_has_associated_transactions:
the_accounts_has_been_successfully_deleted: 'The accounts have been successfully deleted.', "you could't not delete account that has associated transactions.",
are_sure_to_inactive_this_account: 'Are you sure you want to inactive this account? You will be able to activate it later', the_account_has_been_successfully_inactivated:
are_sure_to_activate_this_account: 'Are you sure you want to activate this account? You will be able to inactivate it later', 'The account has been successfully inactivated.',
the_account_has_been_successfully_activated:
'The account has been successfully activated.',
the_account_has_been_successfully_deleted:
'The account has been successfully deleted.',
the_accounts_has_been_successfully_deleted:
'The accounts have been successfully deleted.',
are_sure_to_inactive_this_account:
'Are you sure you want to inactive this account? You will be able to activate it later',
are_sure_to_activate_this_account:
'Are you sure you want to activate this account? You will be able to inactivate it later',
once_delete_this_account_you_will_able_to_restore_it: `Once you delete this account, you won\'t be able to restore it later. Are you sure you want to delete this account?<br /><br />If you're not sure, you can inactivate this account instead.`, once_delete_this_account_you_will_able_to_restore_it: `Once you delete this account, you won\'t be able to restore it later. Are you sure you want to delete this account?<br /><br />If you're not sure, you can inactivate this account instead.`,
the_journal_has_been_successfully_created: 'The journal #{number} has been successfully created.', the_journal_has_been_successfully_created:
the_journal_has_been_successfully_edited: 'The journal #{number} has been successfully edited.', 'The journal #{number} has been successfully created.',
the_journal_has_been_successfully_edited:
'The journal #{number} has been successfully edited.',
credit: 'Credit', credit: 'Credit',
debit: 'Debit', debit: 'Debit',
once_delete_this_item_you_will_able_to_restore_it: `Once you delete this item, you won\'t be able to restore the item later. Are you sure you want to delete ?<br /><br />If you're not sure, you can inactivate it instead.`, once_delete_this_item_you_will_able_to_restore_it: `Once you delete this item, you won\'t be able to restore the item later. Are you sure you want to delete ?<br /><br />If you're not sure, you can inactivate it instead.`,
the_item_has_been_successfully_deleted: 'The item has been successfully deleted.', the_item_has_been_successfully_deleted:
the_item_category_has_been_successfully_created: 'The item category has been successfully created.', 'The item has been successfully deleted.',
the_item_category_has_been_successfully_edited: 'The item category has been successfully edited.', the_item_category_has_been_successfully_created:
once_delete_these_views_you_will_not_able_restore_them: 'Once you delete the custom view, you won\'t be able to restore it later. Are you sure you want to delete this view?', 'The item category has been successfully created.',
the_custom_view_has_been_successfully_deleted: 'The custom view has been successfully deleted.', the_item_category_has_been_successfully_edited:
teammate_invited_to_organization_account: 'Your teammate has been invited to the organization account.', 'The item category has been successfully edited.',
once_delete_these_views_you_will_not_able_restore_them:
"Once you delete the custom view, you won't be able to restore it later. Are you sure you want to delete this view?",
the_custom_view_has_been_successfully_deleted:
'The custom view has been successfully deleted.',
teammate_invited_to_organization_account:
'Your teammate has been invited to the organization account.',
select_account_type: 'Select account type', select_account_type: 'Select account type',
menu:'Menu', menu: 'Menu',
graph:'Graph', graph: 'Graph',
map:'Map', map: 'Map',
table:'Table', table: 'Table',
nucleus:'Nucleus', nucleus: 'Nucleus',
logout:'Logout', logout: 'Logout',
the_expense_has_been_successfully_created: 'The expense has been successfully created.', the_expense_has_been_successfully_created:
select_payment_account:'Select Payment Account', 'The expense has been successfully created.',
select_expense_account:'Select Expense Account', select_payment_account: 'Select Payment Account',
and:'And', select_expense_account: 'Select Expense Account',
or:'OR', and: 'And',
select_a_comparator:'Select a comparator', or: 'OR',
equals:'Equals', select_a_comparator: 'Select a comparator',
not_equal:'Not Equal', equals: 'Equals',
contain:'Contain', not_equal: 'Not Equal',
not_contain:'Not Contain', contain: 'Contain',
cash:'Cash', not_contain: 'Not Contain',
accrual:'Accrual', cash: 'Cash',
from:'From', accrual: 'Accrual',
to:'To', from: 'From',
accounting_basis:'Accounting Basis:', to: 'To',
general:'General', accounting_basis: 'Accounting Basis:',
users:'Users', general: 'General',
currencies:'Currencies', users: 'Users',
accountant:'Accountant', currencies: 'Currencies',
accounts:'Accounts', accountant: 'Accountant',
homepage:'Homepage', accounts: 'Accounts',
items_list:'Items List', homepage: 'Homepage',
new_item:'New Item', items_list: 'Items List',
items:'Items', new_item: 'New Item',
category_list:'Category List', items: 'Items',
financial:'Financial', category_list: 'Category List',
accounts_chart:'Accounts Chart', financial: 'Financial',
manual_journal:'Manual Journal', accounts_chart: 'Accounts Chart',
make_journal:'Make Journal', manual_journal: 'Manual Journal',
exchange_rate:'Exchange Rate', make_journal: 'Make Journal',
banking:'Banking', exchange_rate: 'Exchange Rate',
sales:'Sales', banking: 'Banking',
purchases:'Purchases', sales: 'Sales',
financial_reports:'Financial Reports', purchases: 'Purchases',
balance_sheet:'Balance Sheet', financial_reports: 'Financial Reports',
trial_balance_sheet:'Trial Balance Sheet', balance_sheet: 'Balance Sheet',
journal:'Journal', trial_balance_sheet: 'Trial Balance Sheet',
general_ledger:'General Ledger', journal: 'Journal',
profit_loss_sheet:'Profit Loss Sheet', general_ledger: 'General Ledger',
expenses:'Expenses', profit_loss_sheet: 'Profit Loss Sheet',
expenses_list:'Expenses List', expenses: 'Expenses',
new_expenses:'New Expenses', expenses_list: 'Expenses List',
preferences:'Preferences', new_expenses: 'New Expenses',
auditing_system:'Auditing System', preferences: 'Preferences',
all:'All', auditing_system: 'Auditing System',
organization:'Organization.', all: 'All',
check_your_email_for_a_link_to_reset: 'Check your email for a link to reset your password.If it doesnt appear within a few minutes, check your spam folder.', organization: 'Organization.',
we_couldn_t_find_your_account_with_that_email:'We couldn\'t find your account with that email.', check_your_email_for_a_link_to_reset:
select_parent_account:'Select Parent Account', 'Check your email for a link to reset your password.If it doesnt appear within a few minutes, check your spam folder.',
the_exchange_rate_has_been_successfully_edited:'The exchange rate has been successfully edited', we_couldn_t_find_your_account_with_that_email:
the_exchange_rate_has_been_successfully_created:'The exchange rate has been successfully created', "We couldn't find your account with that email.",
the_exchange_rate_has_been_successfully_deleted: 'The exchange rate has been successfully deleted.', select_parent_account: 'Select Parent Account',
the_user_details_has_been_updated:'The user details has been updated', the_exchange_rate_has_been_successfully_edited:
the_category_has_been_successfully_created: 'The category has been successfully created.', 'The exchange rate has been successfully edited',
filters_applied:'filters applied', the_exchange_rate_has_been_successfully_created:
the_expense_has_been_successfully_deleted: 'The expense has been successfully deleted.', 'The exchange rate has been successfully created',
select_item_type:'Select Item Type', the_exchange_rate_has_been_successfully_deleted:
service:'Service', 'The exchange rate has been successfully deleted.',
inventory:'Inventory', the_user_details_has_been_updated: 'The user details has been updated',
non_inventory:'Non-Inventory', the_category_has_been_successfully_created:
select_category:'Select category', 'The category has been successfully created.',
select_account:'Select Account', filters_applied: 'filters applied',
custom_fields:'Custom Fields', the_expense_has_been_successfully_deleted:
the_currency_has_been_successfully_deleted:'The currency has been successfully deleted', 'The expense has been successfully deleted.',
organization_industry:'Organization Industry', select_item_type: 'Select Item Type',
business_location:'Business Location', service: 'Service',
base_currency:'Base Currency', inventory: 'Inventory',
fiscal_year:'Fiscal Year', non_inventory: 'Non-Inventory',
language:'Language', select_category: 'Select category',
time_zone:'Time Zone', select_account: 'Select Account',
date_format:'Date Format', custom_fields: 'Custom Fields',
edit_user:'Edit User', the_currency_has_been_successfully_deleted:
edit_invite:'Edit Invite', 'The currency has been successfully deleted',
inactivate_user:'Inactivate User', organization_industry: 'Organization Industry',
delete_user:'Delete User', business_location: 'Business Location',
full_name:'Full Name', base_currency: 'Base Currency',
the_user_has_been_successfully_inactivated: 'The user has been successfully inactivated.', fiscal_year: 'Fiscal Year',
the_user_has_been_successfully_deleted: 'The user has been successfully deleted.', language: 'Language',
customize_report:'Customize Report', time_zone: 'Time Zone',
print:'Print', date_format: 'Date Format',
export:'Export', edit_user: 'Edit User',
accounts_with_zero_balance:'Accounts with Zero Balance', edit_invite: 'Edit Invite',
all_transactions:'All Transactions', inactivate_user: 'Inactivate User',
filter_accounts:'Filter Accounts', delete_user: 'Delete User',
calculate_report:'Calculate Report', full_name: 'Full Name',
total:'Total', the_user_has_been_successfully_inactivated:
specific_accounts:'Specific Accounts', 'The user has been successfully inactivated.',
trans_num:'Trans. NUM', the_user_has_been_successfully_deleted:
journal_sheet:'Journal Sheet', 'The user has been successfully deleted.',
run_report:'Run Report', customize_report: 'Customize Report',
num:'Num.', print: 'Print',
acc_code:'Acc. Code', export: 'Export',
display_report_columns:'Display report columns', accounts_with_zero_balance: 'Accounts with Zero Balance',
select_display_columns_by:'Select display columns by...', all_transactions: 'All Transactions',
credit_and_debit_not_equal:'credit and debit not equal', filter_accounts: 'Filter Accounts',
the_currency_has_been_successfully_edited:'The currency has been successfully edited', calculate_report: 'Calculate Report',
the_currency_has_been_successfully_created:'The currency has been successfully created', total: 'Total',
specific_accounts: 'Specific Accounts',
trans_num: 'Trans. NUM',
journal_sheet: 'Journal Sheet',
run_report: 'Run Report',
num: 'Num.',
acc_code: 'Acc. Code',
display_report_columns: 'Display report columns',
select_display_columns_by: 'Select display columns by...',
credit_and_debit_not_equal: 'credit and debit not equal',
the_currency_has_been_successfully_edited:
'The currency has been successfully edited',
the_currency_has_been_successfully_created:
'The currency has been successfully created',
// Name Labels // Name Labels
expense_account_id :'Expense account', expense_account_id: 'Expense account',
payment_account_id: 'Payment account', payment_account_id: 'Payment account',
currency_code_: 'Currency code', currency_code_: 'Currency code',
publish:'Publish', publish: 'Publish',
exchange_rate_:'Exchange rate', exchange_rate_: 'Exchange rate',
journal_number_:'Journal number', journal_number_: 'Journal number',
first_name_: 'First name', first_name_: 'First name',
last_name_:'Last name', last_name_: 'Last name',
phone_number_:'Phone number', phone_number_: 'Phone number',
organization_name_:'Organization name', organization_name_: 'Organization name',
confirm_password:'Confirm password', confirm_password: 'Confirm password',
crediential:'Email or Phone number', crediential: 'Email or Phone number',
account_type_id:'Account type', account_type_id: 'Account type',
account_name_:'Account name', account_name_: 'Account name',
currency_name_:'Currency name', currency_name_: 'Currency name',
cost_account_id:'Cost account', cost_account_id: 'Cost account',
sell_account_id:'Sell account', sell_account_id: 'Sell account',
item_type_:'Item type', item_type_: 'Item type',
item_name_:'Item name', item_name_: 'Item name',
organization_industry_:'Organization industry', organization_industry_: 'Organization industry',
base_currency_:'Base currency', base_currency_: 'Base currency',
date_format_:'Date format', date_format_: 'Date format',
category_name_:'Category name', category_name_: 'Category name',
view_name_:'View name', view_name_: 'View name',
the_items_has_been_successfully_deleted: 'The items have been successfully deleted.', the_items_has_been_successfully_deleted:
once_delete_these_items_you_will_not_able_restore_them: 'Once you delete these items, you won\'t be able to retrieve them later. Are you sure you want to delete them?', 'The items have been successfully deleted.',
once_delete_these_items_you_will_not_able_restore_them:
"Once you delete these items, you won't be able to retrieve them later. Are you sure you want to delete them?",
ops_something_went_wrong: 'Something went wrong! Please try again.',
session_expired: 'Session Expired!',
}; };

View File

@@ -1,8 +1,15 @@
import axios from 'axios'; import axios from 'axios';
import React from 'react';
import { Intent } from '@blueprintjs/core';
import store from 'store/createStore'; import store from 'store/createStore';
import { logout } from 'store/authentication/authentication.actions';
import AppToaster from 'components/AppToaster';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { setGlobalErrors } from 'store/globalErrors/globalErrors.actions';
const http = axios.create(); const http = axios.create();
http.interceptors.request.use((request) => { http.interceptors.request.use((request) => {
const state = store.getState(); const state = store.getState();
const { token, organization } = state.authentication; const { token, organization } = state.authentication;
@@ -26,10 +33,11 @@ http.interceptors.response.use((response) => response, (error) => {
const { status } = error.response; const { status } = error.response;
if (status >= 500) { if (status >= 500) {
store.dispatch(setGlobalErrors({ something_wrong: true }));
} }
if (status === 401) { if (status === 401) {
store.dispatch(setGlobalErrors({ session_expired: true }));
store.dispatch(logout());
} }
return Promise.reject(error); return Promise.reject(error);
}); });

View File

@@ -26,6 +26,12 @@ export function login({ form }) {
}); });
} }
export const logout = () => {
return dispatch => dispatch({
type: t.LOGOUT,
});
};
export const register = ({ form }) => { export const register = ({ form }) => {
return (dispatch) => { return (dispatch) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@@ -0,0 +1,12 @@
export const setGlobalErrors = (errors) => {
return dispatch => {
dispatch({
type: 'GLOBAL_ERRORS_SET',
payload: {
errors,
},
});
}
}

View File

@@ -0,0 +1,17 @@
import { createReducer } from '@reduxjs/toolkit';
import t from 'store/types';
const initialState = {
data: {},
};
export default createReducer(initialState, {
['GLOBAL_ERRORS_SET']: (state, action) => {
const { errors } = action.payload;
state.data = {
...state.data,
...errors,
};
},
});

View File

@@ -16,6 +16,8 @@ import settings from './settings/settings.reducer';
import manualJournals from './manualJournals/manualJournals.reducers'; import manualJournals from './manualJournals/manualJournals.reducers';
import globalSearch from './search/search.reducer'; import globalSearch from './search/search.reducer';
import exchangeRates from './ExchangeRate/exchange.reducer' import exchangeRates from './ExchangeRate/exchange.reducer'
import globalErrors from './globalErrors/globalErrors.reducer';
export default combineReducers({ export default combineReducers({
authentication, authentication,
@@ -33,6 +35,6 @@ export default combineReducers({
itemCategories, itemCategories,
settings, settings,
globalSearch, globalSearch,
exchangeRates exchangeRates,
globalErrors,
}); });