1
0
Fork 0

feat: overdue badge

feat/audit-log
Paul Makles 2023-11-01 16:23:41 +00:00
parent 221ce0e75d
commit cdb05a5af7
No known key found for this signature in database
GPG Key ID: 5059F398521BB0F6
2 changed files with 29 additions and 6 deletions

View File

@ -7,7 +7,17 @@ import { decodeTime } from "ulid";
import relativeTime from "dayjs/plugin/relativeTime";
dayjs.extend(relativeTime);
const lastWeek = new Date();
lastWeek.setDate(lastWeek.getDate() - 7);
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
export function ReportCard({ report }: { report: Report }) {
const dueDate = +(report.content.report_reason.includes("Illegal")
? yesterday
: lastWeek);
return (
<Card>
<CardHeader>
@ -37,6 +47,17 @@ export function ReportCard({ report }: { report: Report }) {
{dayjs(decodeTime(report._id)).fromNow()}{" "}
{report.status !== "Created" && report.closed_at && (
<>&middot; Closed {dayjs(report.closed_at).fromNow()}</>
)}{" "}
{report.status === "Created" && decodeTime(report._id) < dueDate && (
<>
&middot;{" "}
<Badge className="align-middle" variant="relatively-destructive">
Due{" "}
{dayjs()
.add(dayjs(decodeTime(report._id)).diff(dueDate))
.fromNow()}
</Badge>
</>
)}
</CardDescription>
</CardHeader>

View File

@ -1,7 +1,7 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";
const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
@ -14,6 +14,8 @@ const badgeVariants = cva(
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
"relatively-destructive":
"border-transparent bg-destructive/60 text-destructive-foreground hover:bg-destructive/40",
outline: "text-foreground",
},
},
@ -21,7 +23,7 @@ const badgeVariants = cva(
variant: "default",
},
}
)
);
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
@ -30,7 +32,7 @@ export interface BadgeProps
function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
);
}
export { Badge, badgeVariants }
export { Badge, badgeVariants };