diff --git a/components/finance/FinanceCategories/index.tsx b/components/finance/FinanceCategories/index.tsx index 8503a73..5bb2111 100644 --- a/components/finance/FinanceCategories/index.tsx +++ b/components/finance/FinanceCategories/index.tsx @@ -1,5 +1,6 @@ /* eslint-disable jsx-a11y/mouse-events-have-key-events */ import { gql, useQuery } from '@apollo/client' +import { useRouter } from 'next/router' import React, { useState } from 'react' import { useToggle } from 'react-use' @@ -17,7 +18,7 @@ type financeCategoriesProps = { const FinanceCategories = ({ columns, activeCell, setActiveCell }: financeCategoriesProps) => { const getCategories = () => gql` - query Finance { + { finance { incomeExpenseCategories { name @@ -25,9 +26,32 @@ const FinanceCategories = ({ columns, activeCell, setActiveCell }: financeCatego order id } + workItemsPlan { + months { + currentMonth + incomeExpenseCategories { + name + incomeOrExpense + currency + plannedTotal + percentageOfTotalExpense + } + } + } + } + + charts { + currentMonth { + budget + spent + } } } ` + + const router = useRouter() + const actualSwitch = router.pathname.split('/')[2] + const leftMargin = 384 const topMargin = 138 const [panelPosition, setPanelPosition] = useState({ @@ -65,7 +89,8 @@ const FinanceCategories = ({ columns, activeCell, setActiveCell }: financeCatego ) const [activeRow, activeColumn] = activeCell - const workItems = data.finance.incomeExpenseCategories + const { workItems, workItemsPlan } = data.finance + const panelSize = 880 const togglePanel = (row: any, col: any) => { @@ -79,29 +104,58 @@ const FinanceCategories = ({ columns, activeCell, setActiveCell }: financeCatego return (
Income/Expense
- + ) : ( +
- - - ))} - + + ))} + + )} {isOn ? (
-
summaryOnClick(item)} - // onKeyDown={() => summaryOnClick(item)} - aria-hidden="true" - role="button" - tabIndex={0} - className={`p-2.5 flex-1 cursor-pointer ${rowIndex === activeRow ? 'bg-workItemActive' : 'bg-workItem'}`} - > - {item.name} -
-
+ {actualsOrPlan === 'actuals' ? ( + <> +
summaryOnClick(item)} + aria-hidden="true" + role="button" + tabIndex={0} + className={`p-2.5 flex-1 cursor-pointer ${rowIndex === activeRow ? 'bg-workItemActive' : 'bg-workItem'}`} + > + {item.name} +
+
+ + ) : ( + <> +
summaryOnClick(item)} + aria-hidden="true" + role="button" + tabIndex={0} + className={`p-2.5 flex-1 cursor-pointer ${rowIndex === activeRow ? 'bg-workItemActive' : 'bg-workItem'}`} + > + {item.name} +
+
+ {percentage === null ? ( +
+ + % + +
+ ) : ( +
+ + {percentage}% + +
+ )} +
+ + )} ) } diff --git a/components/finance/FinanceSwitch/index.tsx b/components/finance/FinanceSwitch/index.tsx index 94ee29f..47bfe20 100644 --- a/components/finance/FinanceSwitch/index.tsx +++ b/components/finance/FinanceSwitch/index.tsx @@ -6,10 +6,10 @@ const FinanceSwitch = ({ actualOrPlan }: any) => ( diff --git a/pages/finance/actuals.tsx b/pages/finance/actuals.tsx index cdccc5d..ac5604c 100644 --- a/pages/finance/actuals.tsx +++ b/pages/finance/actuals.tsx @@ -32,7 +32,7 @@ export default withPageAuthRequired(() => {
- +
diff --git a/pages/finance/plan.tsx b/pages/finance/plan.tsx index a9ce582..d273c46 100644 --- a/pages/finance/plan.tsx +++ b/pages/finance/plan.tsx @@ -1,10 +1,125 @@ import { withPageAuthRequired } from '@auth0/nextjs-auth0' -import React from 'react' +import { Button, makeStyles } from '@material-ui/core' +import React, { useState } from 'react' +import FinanceCategories from '../../components/finance/FinanceCategories' +import FinanceDateHeader from '../../components/finance/FinanceDateHeader' import FinanceSwitch from '../../components/finance/FinanceSwitch' +import { dateAfterDays, dateBeforeDays, startDateAfterMonths, startDateBeforeMonths } from '../../lib/date-helper' -export default withPageAuthRequired(() => ( -
- -
-)) +const useStyles = makeStyles({ + button: { + marginLeft: '0.5rem', + fontSize: '1rem', + textTransform: 'none', + }, +}) + +export default withPageAuthRequired(() => { + const classes = useStyles() + const marginLeft = 384 + const spreadSheetWidth = window.innerWidth - marginLeft + const cellWidth = 160 + const dateColumns = Math.ceil(spreadSheetWidth / cellWidth) + + const [values, setValues] = useState({ + startDate: dateBeforeDays(Math.floor(dateColumns / 2)), + endDate: dateAfterDays(Math.ceil(dateColumns / 2 - 1)), + }) + const [activeCell, setActiveCell] = useState([0, 0]) + + return ( +
+
+
+ + +
+
+ setActiveCell(cell)} + /> +
+
+ + + + + +
+
+
+ ) +})