From cca9a2d24eb3c5fedc75e0cad4cfbf2a46120978 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Fri, 15 Jan 2021 15:00:20 -0500 Subject: [PATCH] Removed monthlyExpensesComplete from initial state, moved into API call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Removed: - monthlyExpensesComplete from initial state, moved into API call - set up expenses to read from redux for Progress panel/injection --- app/javascript/gabsocial/actions/expenses.js | 35 +++++++++++++++++++ .../components/panel/progress_panel.js | 32 +++++++++++++---- .../timeline_injections/progress_injection.js | 35 +++++++++++++++---- app/javascript/gabsocial/initial_state.js | 1 - app/javascript/gabsocial/reducers/expenses.js | 23 ++++++++++++ app/javascript/gabsocial/reducers/index.js | 2 ++ 6 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 app/javascript/gabsocial/actions/expenses.js create mode 100644 app/javascript/gabsocial/reducers/expenses.js diff --git a/app/javascript/gabsocial/actions/expenses.js b/app/javascript/gabsocial/actions/expenses.js new file mode 100644 index 00000000..b7ff97c0 --- /dev/null +++ b/app/javascript/gabsocial/actions/expenses.js @@ -0,0 +1,35 @@ +import api from '../api' +import { me } from '../initial_state' + +export const EXPENSES_FETCH_REQUEST = 'EXPENSES_FETCH_REQUEST' +export const EXPENSES_FETCH_SUCCESS = 'EXPENSES_FETCH_SUCCESS' +export const EXPENSES_FETCH_FAIL = 'EXPENSES_FETCH_FAIL' + +/** + * Fetch monthly expenses completion + */ +export const fetchExpenses = () => (dispatch, getState) => { + if (!me) return + + dispatch(fetchExpensesRequest()) + + api(getState).get('/api/v1/expenses').then((response) => { + dispatch(fetchExpensesSuccess(response.data.expenses)) + }).catch((error) => { + dispatch(fetchExpensesFail(error)) + }) +} + +const fetchExpensesRequest = () => ({ + type: EXPENSES_FETCH_REQUEST, +}) + +const fetchExpensesSuccess = (value) => ({ + type: EXPENSES_FETCH_SUCCESS, + value, +}) + +const fetchExpensesFail = (error, listType) => ({ + type: EXPENSES_FETCH_FAIL, + error, +}) \ No newline at end of file diff --git a/app/javascript/gabsocial/components/panel/progress_panel.js b/app/javascript/gabsocial/components/panel/progress_panel.js index 96a59f8b..3e9062d8 100644 --- a/app/javascript/gabsocial/components/panel/progress_panel.js +++ b/app/javascript/gabsocial/components/panel/progress_panel.js @@ -1,11 +1,12 @@ import React from 'react' import PropTypes from 'prop-types' +import { connect } from 'react-redux' import { injectIntl, defineMessages } from 'react-intl' -import { monthlyExpensesComplete } from '../../initial_state' import { URL_DISSENTER_SHOP, URL_DISSENTER_SHOP_DONATIONS, } from '../../constants' +import { fetchExpenses } from '../../actions/expenses' import PanelLayout from './panel_layout'; import ProgressBar from '../progress_bar' import Button from '../button' @@ -14,12 +15,17 @@ import Icon from '../icon' class ProgressPanel extends React.PureComponent { + componentDidMount() { + if (!this.props.isFetched) { + this.props.onFetchExpenses() + } + } + render() { - const { intl } = this.props + const { intl, value, isFetched } = this.props - if (!monthlyExpensesComplete) return null + if (value === 0 && !isFetched) return null - const value = Math.min(parseFloat(monthlyExpensesComplete), 100) const subtitle = (