|
1
|
"use client" |
|
2
|
|
|
3
|
import clsx from "clsx" |
|
4
|
import { DocsTrackingEvents, useAnalytics, useModal } from "docs-ui" |
|
5
|
import Link from "next/link" |
|
6
|
import HomepageNewsletterForm from "../../NewsletterForm" |
|
7
|
import { WhatsNewItem } from "../data" |
|
8
|
|
|
9
|
const MONTHS = [ |
|
10
|
"Jan", |
|
11
|
"Feb", |
|
12
|
"Mar", |
|
13
|
"Apr", |
|
14
|
"May", |
|
15
|
"Jun", |
|
16
|
"Jul", |
|
17
|
"Aug", |
|
18
|
"Sep", |
|
19
|
"Oct", |
|
20
|
"Nov", |
|
21
|
"Dec", |
|
22
|
] |
|
23
|
|
|
24
|
const formatDate = (date: string) => { |
|
25
|
const [year, month, day] = date.split("-") |
|
26
|
|
|
27
|
return `${day} ${MONTHS[parseInt(month, 10) - 1]} ${year}` |
|
28
|
} |
|
29
|
|
|
30
|
type HomepageWhatsNewRowProps = { |
|
31
|
item: WhatsNewItem |
|
32
|
position: number |
|
33
|
isLast: boolean |
|
34
|
} |
|
35
|
|
|
36
|
const HomepageWhatsNewRow = ({ |
|
37
|
item, |
|
38
|
position, |
|
39
|
isLast, |
|
40
|
}: HomepageWhatsNewRowProps) => { |
|
41
|
const { setModalProps } = useModal() |
|
42
|
const { track } = useAnalytics() |
|
43
|
|
|
44
|
const trackClick = () => { |
|
45
|
track({ |
|
46
|
event: { |
|
47
|
event: DocsTrackingEvents.WHATS_NEW_ITEM_CLICK, |
|
48
|
options: { |
|
49
|
item_title: item.title, |
|
50
|
item_tag: item.tag, |
|
51
|
item_link: item.link ?? null, |
|
52
|
item_date: item.date ?? null, |
|
53
|
item_coming_soon: !!item.comingSoon, |
|
54
|
item_early_access: !!item.earlyAccess, |
|
55
|
item_position: position, |
|
56
|
}, |
|
57
|
}, |
|
58
|
}) |
|
59
|
} |
|
60
|
|
|
61
|
const isHighlighted = !!item.comingSoon || !!item.earlyAccess |
|
62
|
|
|
63
|
const className = clsx( |
|
64
|
"w-full text-left flex-1 flex flex-col gap-0.5 px-2 py-1.5", |
|
65
|
"sm:grid sm:grid-cols-[96px_minmax(0,1fr)_auto] sm:items-center sm:gap-1.5", |
|
66
|
"transition-colors", |
|
67
|
isHighlighted |
|
68
|
? "bg-medusa-bg-highlight hover:bg-medusa-bg-highlight-hover" |
|
69
|
: "hover:bg-medusa-bg-base-hover", |
|
70
|
!isLast && "border-b border-medusa-border-base" |
|
71
|
) |
|
72
|
|
|
73
|
const content = ( |
|
74
|
<> |
|
75
|
{item.date ? ( |
|
76
|
<span |
|
77
|
className={clsx( |
|
78
|
"text-code-paragraph-xsmall font-monospace", |
|
79
|
"text-medusa-fg-subtle" |
|
80
|
)} |
|
81
|
> |
|
82
|
{formatDate(item.date)} |
|
83
|
</span> |
|
84
|
) : ( |
|
85
|
<span |
|
86
|
className={clsx( |
|
87
|
"text-code-paragraph-2xsmall font-monospace uppercase", |
|
88
|
"text-medusa-tag-blue-text" |
|
89
|
)} |
|
90
|
> |
|
91
|
{item.earlyAccess ? "[Early Access]" : "[Soon]"} |
|
92
|
</span> |
|
93
|
)} |
|
94
|
<h3 className="text-medium-plus text-medusa-fg-base">{item.title}</h3> |
|
95
|
<span |
|
96
|
className={clsx( |
|
97
|
"w-fit whitespace-nowrap rounded-full px-0.5 py-0.25", |
|
98
|
"text-code-paragraph-2xsmall font-monospace", |
|
99
|
"border border-medusa-tag-neutral-border text-medusa-tag-neutral-text", |
|
100
|
isHighlighted ? "bg-medusa-bg-base" : "bg-medusa-tag-neutral-bg" |
|
101
|
)} |
|
102
|
> |
|
103
|
{item.tag} |
|
104
|
</span> |
|
105
|
</> |
|
106
|
) |
|
107
|
|
|
108
|
if (item.comingSoon) { |
|
109
|
return ( |
|
110
|
<button |
|
111
|
type="button" |
|
112
|
className={clsx(className, "appearance-none cursor-pointer")} |
|
113
|
onClick={() => { |
|
114
|
trackClick() |
|
115
|
setModalProps({ |
|
116
|
title: `${item.title} is coming soon`, |
|
117
|
children: ( |
|
118
|
<div className="flex flex-col gap-1"> |
|
119
|
<p className="text-medium text-medusa-fg-subtle"> |
|
120
|
Subscribe to our newsletter to be the first to know when it |
|
121
|
ships. |
|
122
|
</p> |
|
123
|
<HomepageNewsletterForm autoFocus /> |
|
124
|
</div> |
|
125
|
), |
|
126
|
}) |
|
127
|
}} |
|
128
|
> |
|
129
|
{content} |
|
130
|
</button> |
|
131
|
) |
|
132
|
} |
|
133
|
|
|
134
|
return ( |
|
135
|
<Link href={item.link} className={className} onClick={trackClick}> |
|
136
|
{content} |
|
137
|
</Link> |
|
138
|
) |
|
139
|
} |
|
140
|
|
|
141
|
export default HomepageWhatsNewRow |