diff --git a/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx b/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx index d8e22c9c9..1f3c05f3b 100644 --- a/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx +++ b/packages/web-app/src/modules/earn-views/EarningLineChartContainer.tsx @@ -1,6 +1,6 @@ import { connect } from '../../connect' import type { RootStore } from '../../Store' -import { EarningLineChart } from './components' +import { EarningLineChart } from './components/EarningLineChart' const mockedEarningsPerMachine = (daysShowing: number) => { const shouldShowAmPm = daysShowing === 1 diff --git a/packages/web-app/src/modules/earn-views/EarningSummaryContainer.tsx b/packages/web-app/src/modules/earn-views/EarningSummaryContainer.tsx index f20474f7e..89251278c 100644 --- a/packages/web-app/src/modules/earn-views/EarningSummaryContainer.tsx +++ b/packages/web-app/src/modules/earn-views/EarningSummaryContainer.tsx @@ -26,6 +26,9 @@ const mapStoreToProps = (store: RootStore): any => { trackEarnPageFAQLinkClicked: store.analytics.trackEarnPageFAQLinkClicked, trackEarnPageViewed: store.analytics.trackEarnPageViewed, trackAndNavigateToRewardVaultPage, + viewLast24Hours: store.balance.viewLast24Hours, + viewLast7Days: store.balance.viewLast7Days, + viewLast30Days: store.balance.viewLast30Days, } } diff --git a/packages/web-app/src/modules/earn-views/components/EarningChart.tsx b/packages/web-app/src/modules/earn-views/components/EarningChart.tsx index 9cb3cf809..bea2e1173 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningChart.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningChart.tsx @@ -1,4 +1,4 @@ -import { DefaultTheme as GardenTheme, Switch } from '@saladtechnologies/garden-components' +import { DefaultTheme as GardenTheme } from '@saladtechnologies/garden-components' import classnames from 'classnames' import { uniq } from 'lodash' import moment from 'moment' @@ -10,36 +10,14 @@ import { Bar, BarChart, CartesianGrid, Cell, ResponsiveContainer, Tooltip, XAxis import type { CategoricalChartState } from 'recharts/types/chart/types' import type { SaladTheme } from '../../../SaladTheme' import { P } from '../../../components' -import { Segments } from '../../../components/elements/Segments' import { formatBalance } from '../../../utils' import type { ChartDaysShowing, EarningWindow } from '../../balance/models' import { MidnightHour, NoonHour } from '../pages/constants' const styles = (theme: SaladTheme) => ({ - container: { - display: 'flex', - height: 250, - width: '100%', - position: 'relative', - flexDirection: 'column', - }, removeContainerPadding: { paddingTop: 0, }, - chartHeader: { - display: 'flex', - justifyContent: 'flex-start', - alignItems: 'flex-end', - flexDirection: 'row', - }, - segmentsContainer: { - '&>label:first-child': { - borderRadius: '2px 0px 0px 2px', - }, - '&>label:last-child': { - borderRadius: '0px 2px 2px 0px', - }, - }, placeholderText: { fontFamily: 'Mallory', fontSize: 12, @@ -99,9 +77,6 @@ const styles = (theme: SaladTheme) => ({ tickMobile: { display: 'block', }, - earningPerMachineSwitchWrapper: { - marginLeft: 32, - }, '@media screen and (min-width: 1025px)': { tickDesktop: { display: 'block', @@ -296,7 +271,6 @@ interface State { selectedLeftToRight?: boolean selectedRangeIndexes: number[] showEarningsRange?: boolean - isEarningsPerMachineEnabled: boolean } class _EarningChart extends Component { @@ -304,14 +278,9 @@ class _EarningChart extends Component { super(props) this.state = { selectedRangeIndexes: [], - isEarningsPerMachineEnabled: false, } } - public override componentDidMount() { - this.props.viewLast24Hours() - } - public override shouldComponentUpdate(nextProps: Props, nextState: State): boolean { if (this.props.earningHistory !== nextProps.earningHistory) { return true @@ -335,10 +304,6 @@ class _EarningChart extends Component { return true } - if (this.state.isEarningsPerMachineEnabled !== nextState.isEarningsPerMachineEnabled) { - return true - } - return false } @@ -442,26 +407,14 @@ class _EarningChart extends Component { getTimeValue = (earningWindow: EarningWindow) => moment(earningWindow.timestamp).valueOf() - handleEarningsPerMachineClick = () => { - this.setState((prevState) => ({ - isEarningsPerMachineEnabled: !prevState.isEarningsPerMachineEnabled, - })) - } - public override render(): ReactNode { - const { daysShowing, classes, earningHistory, viewLast24Hours, viewLast7Days, viewLast30Days } = this.props + const { daysShowing, classes, earningHistory } = this.props const { hoverIndex, showEarningsRange, earningsRangeSum, rangeCenterCoordinate, selectedRangeIndexes } = this.state const isZero: boolean = !earningHistory || earningHistory.length === 0 || !earningHistory.some((x) => x.earnings > 0) - const segmentOptions = [ - { name: '24 Hours', action: viewLast24Hours }, - { name: '7 Days', action: viewLast7Days }, - { name: '30 Days', action: viewLast30Days }, - ] - return ( -
+ <>
{ >

No data to display

-
-
- -
-
- -
-
{earningHistory && ( <> @@ -573,7 +513,7 @@ class _EarningChart extends Component { )} -
+ ) } } diff --git a/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx b/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx index 7835a1456..6e263a91a 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningHistory.tsx @@ -1,8 +1,11 @@ -import type { FC } from 'react' +import { Switch } from '@saladtechnologies/garden-components' +import { useState } from 'react' import type { WithStyles } from 'react-jss' import withStyles from 'react-jss' import type { SaladTheme } from '../../../SaladTheme' +import { Segments } from '../../../components/elements/Segments' import { EarningChartContainer } from '../EarningChartContainer' +import { EarningLineChartContainer } from '../EarningLineChartContainer' import { EarnSectionHeader } from './EarnSectionHeader' const styles = (theme: SaladTheme) => ({ @@ -12,6 +15,13 @@ const styles = (theme: SaladTheme) => ({ maxWidth: 860, position: 'relative', }, + chartContainer: { + display: 'flex', + height: 250, + width: '100%', + position: 'relative', + flexDirection: 'column', + }, subtitle: { fontFamily: 'Mallory', fontSize: 16, @@ -21,16 +31,61 @@ const styles = (theme: SaladTheme) => ({ marginTop: 32, marginBottom: 10, }, + chartHeader: { + display: 'flex', + justifyContent: 'flex-start', + alignItems: 'flex-end', + flexDirection: 'row', + }, + segmentsContainer: { + '&>label:first-child': { + borderRadius: '2px 0px 0px 2px', + }, + '&>label:last-child': { + borderRadius: '0px 2px 2px 0px', + }, + }, + earningPerMachineSwitchWrapper: { + marginLeft: 32, + }, }) -interface Props extends WithStyles {} +interface Props extends WithStyles { + viewLast24Hours: () => void + viewLast7Days: () => void + viewLast30Days: () => void +} + +const EarningHistoryRaw = ({ classes, viewLast24Hours, viewLast7Days, viewLast30Days }: Props) => { + const [isEarningsPerMachineEnabled, setIsEarningsPerMachineEnabled] = useState(false) + const segmentOptions = [ + { name: '24 Hours', action: viewLast24Hours }, + { name: '7 Days', action: viewLast7Days }, + { name: '30 Days', action: viewLast30Days }, + ] -const EarningHistoryRaw: FC = ({ classes }) => ( -
- Earning History -

See earnings from the last...

- -
-) + return ( +
+ Earning History +

See earnings from the last...

+
+
+ +
+
+ +
+
+
+ {isEarningsPerMachineEnabled ? : } +
+
+ ) +} export const EarningHistory = withStyles(styles)(EarningHistoryRaw) diff --git a/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx b/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx index 60b3b608c..0bf2080a2 100644 --- a/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx +++ b/packages/web-app/src/modules/earn-views/components/EarningLineChart/EarningLineChart.tsx @@ -39,8 +39,8 @@ const _EarningLineChart = ({ classes, earningsPerMachine, daysShowing }: Props) })) return ( - - + + { trackAndNavigateToRewardVaultPage: () => void trackEarnPageFAQLinkClicked: (faqLink: string) => void trackEarnPageViewed: () => void + viewLast24Hours: () => void + viewLast7Days: () => void + viewLast30Days: () => void } const _EarningSummaryPage: FC = ({ @@ -51,6 +54,9 @@ const _EarningSummaryPage: FC = ({ trackAndNavigateToRewardVaultPage, trackEarnPageFAQLinkClicked, trackEarnPageViewed, + viewLast24Hours, + viewLast7Days, + viewLast30Days, }) => { useEffect(() => { startRedemptionsRefresh() @@ -77,7 +83,11 @@ const _EarningSummaryPage: FC = ({ redeemedRewardsCount={redeemedRewardsCount} totalChoppingHours={totalChoppingHours} /> - +