Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

simplify program invite card + formatDateSmart

Steven Tey2ac717163117
diff --git a/apps/web/ui/partners/program-invite-card.tsx b/apps/web/ui/partners/program-invite-card.tsx
index 054c4142af..d4aabbd9ca 100644
--- a/apps/web/ui/partners/program-invite-card.tsx
+++ b/apps/web/ui/partners/program-invite-card.tsx
@@ -6,10 +6,10 @@ import {
BlurImage,
Button,
buttonVariants,
- Calendar6,
- Link4,
+ Envelope,
+ StatusBadge,
} from "@dub/ui";
-import { OG_AVATAR_URL } from "@dub/utils";
+import { formatDateSmart, OG_AVATAR_URL } from "@dub/utils";
import { cn } from "@dub/utils/src";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
@@ -41,7 +41,7 @@ export function ProgramInviteCard({
: null;
return (
- <div className="relative flex flex-col rounded-xl bg-neutral-100 p-5">
+ <div className="hover:drop-shadow-card-hover relative flex flex-col rounded-xl border border-neutral-200 bg-neutral-50 p-5 transition-[filter]">
<div className="flex justify-between gap-2">
<BlurImage
width={64}
@@ -50,20 +50,20 @@ export function ProgramInviteCard({
alt={program.name}
className="size-8 rounded-full"
/>
+ <StatusBadge variant="new" icon={Envelope} className="py-0.5">
+ Invited {formatDateSmart(programEnrollment.createdAt)}
+ </StatusBadge>
</div>
<p className="mt-3 font-medium text-neutral-900">{program.name}</p>
- <p className="flex items-left gap-1 text-neutral-500 pt-1 pb-4 flex-col">
- {program.domain && program.url && (
- <span className="text-sm font-medium flex items-center gap-1">
- <Link4 className="size-3.5" />
- <a href={program.url} target="_blank" rel="noopener noreferrer" className="hover:underline">{program.domain}</a>
- </span>
- )}
- <span className="text-sm font-medium flex items-center gap-1">
- <Calendar6 className="size-3.5" />
- Invited {new Date(programEnrollment.createdAt).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })}
- </span>
+
+ <p className="mt-2 text-balance text-xs text-neutral-600">
+ <ProgramRewardDescription
+ reward={reward}
+ discount={discount}
+ amountClassName="font-light"
+ periodClassName="font-light"
+ />
</p>
<div className="mt-2 flex grow flex-col justify-end">
diff --git a/packages/utils/src/functions/datetime/format-date-smart.ts b/packages/utils/src/functions/datetime/format-date-smart.ts
new file mode 100644
index 0000000000..7fa8ff8bf2
--- /dev/null
+++ b/packages/utils/src/functions/datetime/format-date-smart.ts
@@ -0,0 +1,18 @@
+export const formatDateSmart = (
+ datetime: Date | string,
+ options?: Intl.DateTimeFormatOptions,
+) => {
+ const date = new Date(datetime);
+ const now = new Date();
+
+ return date.toLocaleDateString("en-US", {
+ day: "numeric",
+ month: "long",
+ // if date is in previous year, show year
+ // else, hide year
+ ...(date.getUTCFullYear() !== now.getUTCFullYear()
+ ? { year: "numeric" }
+ : {}),
+ ...options,
+ });
+};
diff --git a/packages/utils/src/functions/datetime/format-datetime-smart.ts b/packages/utils/src/functions/datetime/format-datetime-smart.ts
index 543818841a..885187bcaa 100644
--- a/packages/utils/src/functions/datetime/format-datetime-smart.ts
+++ b/packages/utils/src/functions/datetime/format-datetime-smart.ts
@@ -5,7 +5,7 @@ export const formatDateTimeSmart = (
const date = new Date(datetime);
const now = new Date();
- return new Date(datetime).toLocaleDateString("en-US", {
+ return date.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
// if date is in previous year, show year
diff --git a/packages/utils/src/functions/datetime/index.ts b/packages/utils/src/functions/datetime/index.ts
index b24e5308ed..86342d6a13 100644
--- a/packages/utils/src/functions/datetime/index.ts
+++ b/packages/utils/src/functions/datetime/index.ts
@@ -1,5 +1,6 @@
export * from "./billing-utils";
export * from "./format-date";
+export * from "./format-date-smart";
export * from "./format-datetime";
export * from "./format-datetime-smart";
export * from "./format-period";