earnings update

This commit is contained in:
2024-03-08 01:44:40 -05:00
parent ac6e89720f
commit 31348ba105
5 changed files with 154 additions and 114 deletions
+57 -37
View File
@@ -1,45 +1,65 @@
import React from "react";
import { ResponsiveTimeRange } from "@nivo/calendar";
import { earningsCalendar } from "@/app/MockData/MockData";
import {
compareAsc,
format,
lightFormat,
parse,
startOfWeek,
subDays,
} from "date-fns";
import { cn } from "@/lib/utils";
const CalendarSquares = ({ data }: any) => {
const fromDate = new Date();
const toDate = fromDate.getDate() + 30;
interface earningsData {
value: number;
day: string;
}
interface calendarSquaresProps {
data: earningsData[];
}
const CalendarSquares = ({ data }: calendarSquaresProps) => {
const today = new Date();
const thisWeek = startOfWeek(today);
const lastWeek = lightFormat(subDays(thisWeek, 6), "yyyy-MM-dd");
const calendar = data.filter(
(item: any) => compareAsc(item.day, lastWeek) >= 0
);
const values = calendar.map((obj) => obj.value);
const minValue = Math.min(...values);
const maxValue = Math.max(...values);
const valueRange = maxValue - minValue;
const lowBreakpoint = minValue + valueRange / 3;
const mediumBreakpoint = minValue + (2 * valueRange) / 3;
return (
<ResponsiveTimeRange
data={data}
// from={fromDate.toLocaleString("en-us")}
// to={toDate.toLocaleDateString("en-us")}
from="2024-03-07"
to="2024-04-11"
emptyColor="#171717"
colors={["#61cdbb", "#97e3d5", "#e8c1a0", "#f47560"]}
margin={{ top: -70 }}
direction="vertical"
square={false}
firstWeekday="thursday"
weekdayTicks={[]}
tooltip={undefined}
// monthLegendOffset={0}
weekdayLegendOffset={0}
dayBorderWidth={1}
dayBorderColor="#ffffff"
// legends={[
// {
// anchor: "bottom-right",
// direction: "row",
// justify: false,
// itemCount: 4,
// itemWidth: 42,
// itemHeight: 36,
// itemsSpacing: 14,
// itemDirection: "right-to-left",
// translateX: -60,
// translateY: -60,
// symbolSize: 20,
// },
// ]}
/>
<div className="h-full grid grid-rows-4 grid-cols-7 xl:grid-rows-5 2xl:grid-rows-6 overflow-hidden text-neutral-900">
{calendar.map((item: any) => (
<div
className={cn(
compareAsc(item.day, today) < 0
? "bg-neutral-500 text-neutral-700"
: item.value < lowBreakpoint
? "bg-[#fef7dc]/75"
: item.value < mediumBreakpoint
? "bg-[#fdedaa]/75"
: "bg-primary/75",
"flex flex-col items-center justify-center font-bold hover:cursor-pointer"
)}
key={item.day}
>
<div className={"text-xs"}>{format(item.day, "MMM")}</div>
<div className="">{lightFormat(item.day, "d")}</div>
</div>
))}
</div>
);
};