Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
JiashuHarryHuang committed Apr 27, 2024
1 parent d9d2106 commit bfbcc31
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 228 deletions.
41 changes: 19 additions & 22 deletions components/Logs/LogsDashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { DashboardContainer } from '@/styles/volunteerDashboard.styles';
import { useEffect, useState } from 'react';
import { VolunteerLogData, VolunteerEventData } from 'bookem-shared/src/types/database';
import {
VolunteerLogData,
VolunteerEventData,
} from 'bookem-shared/src/types/database';
import LogsTable from './LogsTable';
import LogsStats from './LogsStats';
import {
Greeting,
Header,
} from '@/styles/dashboard.styles';
import { Greeting, Header } from '@/styles/dashboard.styles';
import { Card } from 'antd';

type VolunteerLogWithEvent = VolunteerLogData & {
event: VolunteerEventData;
}
};

export type LogTableData = (VolunteerLogWithEvent & {
export type LogTableData = VolunteerLogWithEvent & {
eventName: string;
});
};

// unpack the eventName from the event object so that it can be used as a column in the table
const processLogDataForTable = (logData: VolunteerLogWithEvent[]): LogTableData[] => {
return logData.map((log) => {
const processLogDataForTable = (
logData: VolunteerLogWithEvent[]
): LogTableData[] => {
return logData.map(log => {
return {
...log,
eventName: log.event.name,
} ;
};
});
}

};

export default function LogsDashboard() {
const [logData, setLogData] = useState<LogTableData[]>([]);
Expand All @@ -36,15 +37,12 @@ export default function LogsDashboard() {
const response = await fetch('/api/volunteer-logs');
const data: VolunteerLogWithEvent[] = await response.json();
// console.log("Logs data: ", data);
setLogData(
processLogDataForTable(data)
);
}
setLogData(processLogDataForTable(data));
};
fetchLogs();
}
, []);
}, []);

console.log("Log data: ", logData);
console.log('Log data: ', logData);

return (
<DashboardContainer>
Expand All @@ -54,8 +52,7 @@ export default function LogsDashboard() {
<Header>Log Details:</Header>
<Card
// gray background
style={{ backgroundColor: "#f0f2f5" }}
>
style={{ backgroundColor: '#f0f2f5' }}>
<LogsTable logData={logData} />
</Card>
</DashboardContainer>
Expand Down
33 changes: 14 additions & 19 deletions components/Logs/LogsStats.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { LogTableData } from "./LogsDashboard"
import {VolunteerStatsContainer} from '@/styles/volunteerDashboard.styles';
import { LogTableData } from './LogsDashboard';
import { VolunteerStatsContainer } from '@/styles/volunteerDashboard.styles';
import {
Greeting,
StatsFlex,
Expand All @@ -9,45 +8,41 @@ import {
StatsDescription,
Header,
} from '@/styles/dashboard.styles';
import { VolunteerLogStatus } from "bookem-shared/src/types/database";
import { VolunteerLogStatus } from 'bookem-shared/src/types/database';

// only count the approved logs
const calcTotalHours = (logData: LogTableData[]) => {
let totalHours = 0;
logData.forEach((log) => {
logData.forEach(log => {
if (log.status === VolunteerLogStatus.Approved) {
totalHours += log.hours;
}
});
return totalHours;
}
};

const calcTotalBooks = (logData: LogTableData[]) => {
let totalBooks = 0;
logData.forEach(
(log) => {
if (log.status === VolunteerLogStatus.Approved) {
totalBooks += (log.numBooks || 0);
}
logData.forEach(log => {
if (log.status === VolunteerLogStatus.Approved) {
totalBooks += log.numBooks || 0;
}
});
return totalBooks;
}
};

// only count approved logs of events and only count unique events
const calcNumEvents = (logData: LogTableData[]) => {
const eventSet = new Set<string>();
logData.forEach((log) => {
logData.forEach(log => {
if (log.status === VolunteerLogStatus.Approved) {
eventSet.add(log.eventName);
}
});
return eventSet.size;
};

}

export default function LogsStats({
logData,
}) {
export default function LogsStats({ logData }) {
return (
<VolunteerStatsContainer>
<Header>Your accomplishments at a glance:</Header>
Expand All @@ -67,4 +62,4 @@ export default function LogsStats({
</StatsFlex>
</VolunteerStatsContainer>
);
}
}
22 changes: 8 additions & 14 deletions components/Logs/LogsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {Table, Tag } from 'antd';
import { Table, Tag } from 'antd';
import { LogTableData } from './LogsDashboard';
import { VolunteerLogStatus} from 'bookem-shared/src/types/database';
import Link from "next/link";
import { VolunteerLogStatus } from 'bookem-shared/src/types/database';
import Link from 'next/link';
// use antd link icon
import { LinkOutlined } from '@ant-design/icons';

export default function LogsTable({ logData }
: { logData: LogTableData[]}
) {
export default function LogsTable({ logData }: { logData: LogTableData[] }) {
const columns = [
{
title: 'Event',
Expand All @@ -23,14 +21,14 @@ export default function LogsTable({ logData }
return (
<Link href={`/event/${event._id}`}>
{/* light blue color text */}
<div style={{ color: "#1890ff" }}>
<div style={{ color: '#1890ff' }}>
<LinkOutlined /> See event
</div>
</Link>
);
},
},

{
title: 'Atended on',
dataIndex: 'date',
Expand Down Expand Up @@ -71,15 +69,11 @@ export default function LogsTable({ logData }
}
return <Tag color={color}>{status}</Tag>;
},
}
},
];

return (
// allow the table to scroll horizontally
<Table
dataSource={logData}
columns={columns}
scroll={{ x: true }}
/>
<Table dataSource={logData} columns={columns} scroll={{ x: true }} />
);
}
Loading

0 comments on commit bfbcc31

Please sign in to comment.