re-structure to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 01:02:31 +02:00
parent 8242ec64ba
commit 7a0a13f9d5
10400 changed files with 46966 additions and 17223 deletions

View File

@@ -0,0 +1,70 @@
// @ts-nocheck
import ApiService from '@/services/ApiService';
import t from '@/store/types';
export const submitCurrencies = ({ form }) => {
return (dispatch) => {
return ApiService.post('currencies', form);
};
};
export const deleteCurrency = ({ 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 }) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post(`currencies/${id}`, form)
.then((response) => {
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
resolve(response);
})
.catch((error) => {
const { response } = error;
const { data } = response;
const { errors } = data;
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS });
if (errors) {
dispatch({ type: t.CLEAR_CURRENCY_FORM_ERRORS, errors });
}
reject(error);
});
});
};
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) => {
reject(error);
});
});
};

View File

@@ -0,0 +1,30 @@
// @ts-nocheck
import { createReducer } from '@reduxjs/toolkit';
import t from '@/store/types';
const initialState = {
data: {},
loading: false,
};
export default createReducer(initialState, {
[t.CURRENCIES_REGISTERED_SET]: (state, action) => {
const _currencies = {};
action.currencies.forEach((currency) => {
_currencies[currency.currency_code] = currency;
});
state.data = {
...state.data,
..._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

@@ -0,0 +1,23 @@
// @ts-nocheck
// @flow
import { createSelector } from 'reselect';
import { getItemById } from '@/store/selectors';
const currenciesItemsSelector = (state) => state.currencies.data;
const currenciesCodePropSelector = (state, props) => props.currencyId;
export const getCurrenciesList = createSelector(
currenciesItemsSelector,
(currencies) => {
return Object.values(currencies);
},
);
export const getCurrencyByCode = createSelector(
currenciesItemsSelector,
currenciesCodePropSelector,
(currencies, currencyCode) => {
return getItemById(currencies, currencyCode);
},
);

View File

@@ -0,0 +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',
};