Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ia tickets 26 71 user dashboard #94

Merged
merged 48 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d6287cb
created dashboard control panel
ialej001 Sep 3, 2022
47c33ca
created summary tile
ialej001 Sep 3, 2022
bc07c7f
updated styling
ialej001 Sep 3, 2022
eb71ebd
created dash
ialej001 Sep 3, 2022
6aba9d4
incorporated dashboard and control panel
ialej001 Sep 3, 2022
e708cc8
created dashboard route
ialej001 Sep 3, 2022
ba86978
renamed power to electricity for consistency
ialej001 Sep 3, 2022
96c517b
added circular progress indicator for relative %s
ialej001 Sep 3, 2022
dfaf7e9
added summary output schema
ialej001 Sep 3, 2022
0bfc8ef
added loading spinner
ialej001 Sep 3, 2022
70382b9
removed unused types
ialej001 Sep 3, 2022
5cb10a3
added and refactored layouts
ialej001 Sep 3, 2022
64731c1
moved greeting into dashboard
ialej001 Sep 3, 2022
2a3ae3d
renamed a folder
ialej001 Sep 3, 2022
ef091b3
init individual summary pages
ialej001 Sep 3, 2022
322f168
added handler to route to each page
ialej001 Sep 3, 2022
5a790be
fixed routing issue
ialej001 Sep 3, 2022
45fc402
added layouts
ialej001 Sep 3, 2022
7389c9f
Merge branch 'development' into feature/ia-tickets-26-71-user-dashboard
ialej001 Sep 3, 2022
4873896
init preferences router and schema
ialej001 Sep 3, 2022
f380d16
removed some files
ialej001 Sep 7, 2022
c48ceb5
created dashboard detailed data endpoints
ialej001 Sep 7, 2022
2e2aa80
Merge branch 'development' into feature/ia-tickets-26-71-user-dashboard
ialej001 Sep 7, 2022
945f775
elec table with mapped rows
ialej001 Sep 7, 2022
d1b7d01
styling: table is responsive
ialej001 Sep 7, 2022
627f2a0
added empty table message w/ redirect
ialej001 Sep 7, 2022
1aa3f05
Flight table complete and responsive
ialej001 Sep 7, 2022
e1a3228
Merge branch 'development' into feature/ia-tickets-26-71-user-dashboard
ialej001 Sep 7, 2022
d0f2d73
fixed residual mess from merge
ialej001 Sep 7, 2022
a4e973a
cleaned up empty table message
ialej001 Sep 7, 2022
5bac8f0
fuel table created with responsiveness
ialej001 Sep 7, 2022
1e48e84
added vehicle tables within tabs on larger screens
ialej001 Sep 8, 2022
308c7a9
styling: use an accordion on smaller screens
ialej001 Sep 8, 2022
e59eff3
renamed page routes for clarity
ialej001 Sep 8, 2022
4e1db77
fixed nested p tags
ialej001 Sep 8, 2022
aba60f8
updated router links after rename
ialej001 Sep 8, 2022
696bba3
fixed missing key prop
ialej001 Sep 8, 2022
f953c18
styling: switched to grid for summary tiles
ialej001 Sep 8, 2022
4610fea
refactor: moved all queries to the page level
ialej001 Sep 8, 2022
78d7180
refactor: lifted queries to page level
ialej001 Sep 8, 2022
3011d8d
emissions values change to user preference
ialej001 Sep 8, 2022
a1dab94
emissions values change to user preference
ialej001 Sep 8, 2022
95336cb
Added titles to each summary page
ialej001 Sep 8, 2022
babadaa
Merge branch 'feature/ia-tickets-26-71-user-dashboard' of https://git…
ialej001 Sep 8, 2022
a3aa9e1
added headers to all pages
ialej001 Sep 8, 2022
d186e98
refactored loading spinner
ialej001 Sep 8, 2022
8a5152c
added no vehicle message
ialej001 Sep 8, 2022
783437f
styling: fixed mobile summary tiles overlap
ialej001 Sep 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"next": "12.2.3",
"next-auth": "^4.10.3",
"nodemailer": "^6.7.8",
"rc-progress": "^3.4.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.4.0",
Expand Down
74 changes: 74 additions & 0 deletions src/components/Account/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { useRouter } from 'next/router';
import React from 'react';
import { EmissionsSummaryData } from '../../schema/dashboard.schema';
import { formatWeightToUserUnitPreference } from '../../utils/unitConverter';
import SummaryTile from './SummaryTile';

interface DashboardProps {
greeting: string;
emissionsSummaryData: EmissionsSummaryData[] | undefined;
unitPreference: string;
}

const Dashboard = ({
greeting,
emissionsSummaryData,
unitPreference,
}: DashboardProps) => {
const router = useRouter();

const totalEmissions =
emissionsSummaryData?.reduce((previousValue, current) => {
return previousValue + current.emissions;
}, 0) ?? 0;

const handleOnClickTile = (type: string) => {
switch (type) {
case 'Electricity':
return router.push('/account/electricity-summary');
case 'Driving':
return router.push('/account/driving-summary');
case 'Fuel':
return router.push('/account/fuel-summary');
case 'Flight':
return router.push('/account/flight-summary');
default:
return;
}
};

if (!emissionsSummaryData) return <p>Something went wrong</p>;

return (
<div className="flex flex-col justify-between px-5 mb-10 gap-5">
<h2 className="text-4xl mb-14">{greeting}</h2>
<div className="flex flex-col justify-center text-center">
<h2 className="text-2xl mb-5">Your total emissions to date</h2>
<h2 className="text-xl mb-5 font-bold">
{formatWeightToUserUnitPreference(unitPreference, totalEmissions)}
</h2>
</div>
<div className="flex justify-center text-center">
<h4 className="text-2xl mb-5">
To this date, your total emissions break down as follows
</h4>
</div>
<div className="grid grid-cols-1 md:grid-cols-4 xl:grid-cols-8 gap-5 md:px-10">
{emissionsSummaryData.map((classification) => {
return (
<SummaryTile
type={classification.type}
unitPreference={unitPreference}
emissionsValue={classification.emissions}
totalEmissions={totalEmissions}
key={classification.type}
handleOnClick={() => handleOnClickTile(classification.type)}
/>
);
})}
</div>
</div>
);
};

export default Dashboard;
95 changes: 95 additions & 0 deletions src/components/Account/ElectricityTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Button, Spinner, Table } from 'flowbite-react';
import Link from 'next/link';
import React from 'react';
import { ElectricityData } from '../../schema/dashboard.schema';

interface ElectricityTableProps {
electricityData: ElectricityData[] | undefined;
}

const ElectricityTable = ({ electricityData }: ElectricityTableProps) => {
const electricityDataDatesDesc = () => {
const dataToBeSorted = [...electricityData!];
if (electricityData)
return dataToBeSorted.sort(
(a, b) => b.estimated_at.valueOf() - a.estimated_at.valueOf()
);
};

if (!electricityData) {
return (
<div className="flex justify-center items-center">
<Spinner />
</div>
);
}

return (
<div className="px-10">
<Table hoverable={true}>
<Table.Head>
<Table.HeadCell>Date</Table.HeadCell>
<Table.HeadCell className="hidden sm:table-cell">
Electricity Used
</Table.HeadCell>
<Table.HeadCell className="hidden sm:table-cell">
Emissions
</Table.HeadCell>
<Table.HeadCell className="sm:hidden">
<div className="text-end">
<p>Electricity Used</p>
<strong>Emissions</strong>
</div>
</Table.HeadCell>
</Table.Head>
<Table.Body className="divide-y">
{electricityData.length !== 0 ? (
electricityDataDatesDesc()!.map((entry) => {
return (
<Table.Row
className="bg-white dark:border-gray-700 dark:bg-gray-800"
key={entry.id}
>
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 dark:text-white">
<p>{entry.estimated_at.toLocaleDateString()}</p>
<p>{entry.estimated_at.toLocaleTimeString()}</p>
</Table.Cell>
{/** Todo: update this to use the users unit preference */}
<Table.Cell className="font-medium text-gray-900 dark:text-white hidden sm:table-cell">
<>
{entry.electricity_value} {entry.electricity_unit}
</>
</Table.Cell>
<Table.Cell className="font-medium text-gray-900 dark:text-white hidden sm:table-cell">
<>{entry.carbon_g / 1000.0}kg</>
</Table.Cell>
<Table.Cell className="whitespace-nowrap font-medium text-gray-900 flex flex-col dark:text-white text-end sm:hidden">
<>
{entry.electricity_value} {entry.electricity_unit}
<strong>{entry.carbon_g / 1000.0}kg</strong>
</>
</Table.Cell>
</Table.Row>
);
})
) : (
<div></div>
)}
</Table.Body>
</Table>
{electricityData.length === 0 ? (
<div className="flex flex-col items-center pt-10 gap-4">
<strong>You haven't recorded any electricity data.</strong>
<p>You can make your emissions calculation here:</p>
<Button size="sm">
<Link href="/electricity">Make a new calculation</Link>
</Button>
</div>
) : (
''
)}
</div>
);
};

export default ElectricityTable;
Loading