WIP Fix & last tasks

This commit is contained in:
elforjani3
2020-05-31 21:33:45 +02:00
parent 2e8ffa2aa9
commit 41d106e1a7
30 changed files with 1483 additions and 948 deletions

View File

@@ -33,13 +33,34 @@ export const fetchExchangeRates = () => {
};
export const submitExchangeRate = ({ form }) => {
return (dispatch) => {
return ApiService.post('exchange_rates', form);
};
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post('exchange_rates', form).then((response) => {
resolve(response);
}).catch((error)=>{
const {response} = error
const {data} = response;
reject(data?.errors)
})
});
};
// export const deleteExchangeRate = (id) => {
// return (dispatch) => ApiService.delete(`exchange_rates/${id}`);
// }
export const deleteExchangeRate = (id) => {
return (dispatch) => ApiService.delete(`exchange_rates/${id}`);
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`exchange_rates/${id}`)
.then((response) => {
dispatch({ type: t.EXCHANGE_RATE_DELETE, id });
resolve(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const editExchangeRate = (id, form) => {
@@ -59,23 +80,24 @@ export const editExchangeRate = (id, form) => {
if (errors) {
dispatch({ type: t.CLEAR_EXCHANGE_RATE_FORM_ERRORS, errors });
}
reject(error);
reject(data?.errors);
});
});
};
export const deleteBulkExchangeRates = ({ ids }) => {
return dispatch => new Promise((resolve, reject) => {
ApiService.delete(`exchange_rates/bulk`, { params: { ids }}).then((response) => {
dispatch({
type: t.EXCHANGE_RATES_BULK_DELETE,
payload: { ids }
});
resolve(response);
}).catch((error) => {
reject(error);
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`exchange_rates/bulk`, { params: { ids } })
.then((response) => {
dispatch({
type: t.EXCHANGE_RATES_BULK_DELETE,
payload: { ids },
});
resolve(response);
})
.catch((error) => {
reject(error);
});
});
});
};
};

View File

@@ -21,17 +21,17 @@ export default createReducer(initialState, {
state.loading = action.loading;
},
[t.EXCHANGE_RATES_BULK_DELETE]:(state,action)=>{
const {ids} =action.payload;
const {exchange_rate} = {...state.exchangeRates};
ids.forEach((id)=>{
if(typeof exchange_rate[id] !=='undefined'){
delete exchange_rate[id]
[t.EXCHANGE_RATES_BULK_DELETE]: (state, action) => {
const { ids } = action.payload;
ids.forEach((id) => {
if (typeof state.exchangeRates[id] !== 'undefined') {
delete state.exchangeRates[id];
}
});
state.exchangeRates =exchange_rate
}
},
[t.EXCHANGE_RATE_DELETE]: (state, action) => {
if (typeof state.exchangeRates[action.id] !== 'undefined') {
delete state.exchangeRates[action.id];
}
},
});

View File

@@ -8,7 +8,17 @@ export const submitCurrencies = ({ form }) => {
};
export const deleteCurrency = ({ currency_code }) => {
return (dispatch) => ApiService.delete(`currencies/${currency_code}`);
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`currencies/${currency_code}`)
.then((response) => {
dispatch({ type: t.CURRENCY_CODE_DELETE, currency_code });
resolve(response);
})
.catch((error) => {
reject(error.response.data.errors || []);
});
});
};
export const editCurrency = ({ id, form }) => {
@@ -36,12 +46,20 @@ export const editCurrency = ({ id, form }) => {
export const fetchCurrencies = () => {
return (dispatch) =>
new Promise((resolve, reject) => {
dispatch({
type: t.CURRENCIES_TABLE_LOADING,
loading: true,
});
ApiService.get('currencies')
.then((response) => {
dispatch({
type: t.CURRENCIES_REGISTERED_SET,
currencies: response.data.currencies,
});
dispatch({
type: t.CURRENCIES_TABLE_LOADING,
loading: false,
});
resolve(response);
})
.catch((error) => {

View File

@@ -17,4 +17,12 @@ export default createReducer(initialState, {
..._currencies,
};
},
[t.CURRENCIES_TABLE_LOADING]: (state, action) => {
state.loading = action.loading;
},
[t.CURRENCY_CODE_DELETE]: (state, action) => {
if (typeof state.data[action.currency_code] !== 'undefined') {
delete state.data[action.currency_code];
}
},
});

View File

@@ -1,4 +1,6 @@
export default {
CURRENCIES_REGISTERED_SET: 'CURRENCIES_REGISTERED_SET',
CLEAR_CURRENCY_FORM_ERRORS: 'CLEAR_CURRENCY_FORM_ERRORS',
CURRENCIES_TABLE_LOADING: 'CURRENCIES_TABLE_LOADING',
CURRENCY_CODE_DELETE: 'CURRENCY_CODE_DELETE',
};

View File

@@ -10,18 +10,16 @@ export default createReducer(initialState, {
[t.ITEMS_CATEGORY_LIST_SET]: (state, action) => {
const _categories = {};
action.categories.forEach(category => {
action.categories.forEach((category) => {
_categories[category.id] = category;
});
state.categories = {
...state.categories,
..._categories
..._categories,
};
},
[t.ITEM_CATEGORIES_TABLE_SET]: (state, action) => {
},
[t.ITEM_CATEGORIES_TABLE_SET]: (state, action) => {},
[t.CATEGORY_DELETE]: (state, action) => {
const { id } = action.payload;
@@ -31,21 +29,19 @@ export default createReducer(initialState, {
}
},
[t.ITEM_CATEGORIES_TABLE_LOADING]: (state, action ) => {
[t.ITEM_CATEGORIES_TABLE_LOADING]: (state, action) => {
const { loading } = action.payload;
state.loading = !!loading;
},
[t.ITEM_CATEGORIES_BULK_DELETE]:(state,action)=>{
const {ids} =action.payload;
const {categories} = {...state.categories};
ids.forEach((id)=>{
[t.ITEM_CATEGORIES_BULK_DELETE]: (state, action) => {
const { ids } = action.payload;
if(typeof categories[id] !=='undefined'){
delete categories[id]
ids.forEach((id) => {
if (typeof state.categories[id] !== 'undefined') {
delete state.categories[id];
}
});
state.categories =categories
}
},
});
export const getCategoryId = (state, id) => {