2018-10-22 22:08:39 +00:00
|
|
|
import api from '../api';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
2021-04-19 12:45:15 +00:00
|
|
|
import { fetchRelationships } from './accounts';
|
2023-05-23 15:15:17 +00:00
|
|
|
import { importFetchedAccounts } from './importer';
|
2018-10-22 22:08:39 +00:00
|
|
|
|
|
|
|
export const SUGGESTIONS_FETCH_REQUEST = 'SUGGESTIONS_FETCH_REQUEST';
|
|
|
|
export const SUGGESTIONS_FETCH_SUCCESS = 'SUGGESTIONS_FETCH_SUCCESS';
|
|
|
|
export const SUGGESTIONS_FETCH_FAIL = 'SUGGESTIONS_FETCH_FAIL';
|
|
|
|
|
|
|
|
export const SUGGESTIONS_DISMISS = 'SUGGESTIONS_DISMISS';
|
|
|
|
|
2021-04-19 12:45:15 +00:00
|
|
|
export function fetchSuggestions(withRelationships = false) {
|
2024-05-22 14:45:18 +00:00
|
|
|
return (dispatch) => {
|
2018-10-22 22:08:39 +00:00
|
|
|
dispatch(fetchSuggestionsRequest());
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().get('/api/v2/suggestions', { params: { limit: 20 } }).then(response => {
|
2021-04-12 10:37:14 +00:00
|
|
|
dispatch(importFetchedAccounts(response.data.map(x => x.account)));
|
2018-10-22 22:08:39 +00:00
|
|
|
dispatch(fetchSuggestionsSuccess(response.data));
|
2021-04-19 12:45:15 +00:00
|
|
|
|
|
|
|
if (withRelationships) {
|
|
|
|
dispatch(fetchRelationships(response.data.map(item => item.account.id)));
|
|
|
|
}
|
2018-10-22 22:08:39 +00:00
|
|
|
}).catch(error => dispatch(fetchSuggestionsFail(error)));
|
|
|
|
};
|
2022-12-18 15:51:37 +00:00
|
|
|
}
|
2018-10-22 22:08:39 +00:00
|
|
|
|
|
|
|
export function fetchSuggestionsRequest() {
|
|
|
|
return {
|
|
|
|
type: SUGGESTIONS_FETCH_REQUEST,
|
|
|
|
skipLoading: true,
|
|
|
|
};
|
2022-12-18 15:51:37 +00:00
|
|
|
}
|
2018-10-22 22:08:39 +00:00
|
|
|
|
2021-04-12 10:37:14 +00:00
|
|
|
export function fetchSuggestionsSuccess(suggestions) {
|
2018-10-22 22:08:39 +00:00
|
|
|
return {
|
|
|
|
type: SUGGESTIONS_FETCH_SUCCESS,
|
2021-04-12 10:37:14 +00:00
|
|
|
suggestions,
|
2018-10-22 22:08:39 +00:00
|
|
|
skipLoading: true,
|
|
|
|
};
|
2022-12-18 15:51:37 +00:00
|
|
|
}
|
2018-10-22 22:08:39 +00:00
|
|
|
|
|
|
|
export function fetchSuggestionsFail(error) {
|
|
|
|
return {
|
|
|
|
type: SUGGESTIONS_FETCH_FAIL,
|
|
|
|
error,
|
|
|
|
skipLoading: true,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
2022-12-18 15:51:37 +00:00
|
|
|
}
|
2018-10-22 22:08:39 +00:00
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
export const dismissSuggestion = accountId => (dispatch) => {
|
2018-10-22 22:08:39 +00:00
|
|
|
dispatch({
|
|
|
|
type: SUGGESTIONS_DISMISS,
|
|
|
|
id: accountId,
|
|
|
|
});
|
|
|
|
|
2024-05-22 14:45:18 +00:00
|
|
|
api().delete(`/api/v1/suggestions/${accountId}`).catch(() => {});
|
2018-10-22 22:08:39 +00:00
|
|
|
};
|