@octarq/plugin-links 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/api.ts +223 -0
- package/components/BotToggle.tsx +18 -0
- package/filters.test.ts +68 -0
- package/filters.ts +29 -0
- package/i18n.ts +730 -0
- package/index.ts +20 -0
- package/instanceScope.test.ts +45 -0
- package/package.json +26 -3
- package/pages/LinkEditorForm.test.tsx +592 -0
- package/pages/LinkEditorForm.tsx +458 -0
- package/pages/LinkModals.tsx +138 -0
- package/pages/LinkTableRow.tsx +183 -0
- package/pages/StatsView.tsx +119 -0
- package/pages/emptyState.test.tsx +86 -0
- package/pages/failureState.test.tsx +75 -0
- package/pages/index.tsx +462 -0
- package/pages/linkPassword.test.tsx +102 -0
- package/pages/linksTitlePriority.test.tsx +188 -0
- package/pages/tabs.test.tsx +92 -0
- package/store.ts +21 -0
- package/tsconfig.json +15 -0
- package/widgets/ClicksChartWidget.tsx +36 -0
- package/widgets/DevicesPanelWidget.tsx +18 -0
- package/widgets/LinksSetupStepWidget.tsx +27 -0
- package/widgets/LinksStatCardWidget.tsx +42 -0
- package/widgets/TopCitiesPanelWidget.tsx +31 -0
- package/widgets/TopLinksPanelWidget.test.tsx +77 -0
- package/widgets/TopLinksPanelWidget.tsx +67 -0
- package/README.md +0 -3
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { Field, Switch, Button, Select, FormError, Input, Textarea, Alert, Badge, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { useNavigate, useInRouterContext } from "react-router-dom";
|
|
4
|
+
import { api, linksApi, Link, LinksCapabilities } from "../api";
|
|
5
|
+
import { Sparkles, Trash2, Plus } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
function DomainConfigNavButton({ onClick, label }: { onClick: () => void; label: string }) {
|
|
8
|
+
const inRouter = useInRouterContext();
|
|
9
|
+
if (inRouter) {
|
|
10
|
+
return <RouterDomainConfigNavButton onClick={onClick} label={label} />;
|
|
11
|
+
}
|
|
12
|
+
return (
|
|
13
|
+
<Button
|
|
14
|
+
variant="subtle"
|
|
15
|
+
size="sm"
|
|
16
|
+
type="button"
|
|
17
|
+
onClick={() => {
|
|
18
|
+
onClick();
|
|
19
|
+
if (typeof window !== "undefined") window.location.href = "/admin/domains";
|
|
20
|
+
}}
|
|
21
|
+
className="shrink-0 text-xs"
|
|
22
|
+
>
|
|
23
|
+
{label}
|
|
24
|
+
</Button>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function RouterDomainConfigNavButton({ onClick, label }: { onClick: () => void; label: string }) {
|
|
29
|
+
const navigate = useNavigate();
|
|
30
|
+
return (
|
|
31
|
+
<Button
|
|
32
|
+
variant="subtle"
|
|
33
|
+
size="sm"
|
|
34
|
+
type="button"
|
|
35
|
+
onClick={() => {
|
|
36
|
+
onClick();
|
|
37
|
+
navigate("/domains");
|
|
38
|
+
}}
|
|
39
|
+
className="shrink-0 text-xs"
|
|
40
|
+
>
|
|
41
|
+
{label}
|
|
42
|
+
</Button>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function LinkEditorForm({
|
|
47
|
+
link,
|
|
48
|
+
hosts: rawHosts = [],
|
|
49
|
+
onCancel,
|
|
50
|
+
onSaved,
|
|
51
|
+
}: {
|
|
52
|
+
link: Link | null;
|
|
53
|
+
hosts?: string[];
|
|
54
|
+
onCancel: () => void;
|
|
55
|
+
onSaved: (l?: any) => void;
|
|
56
|
+
}) {
|
|
57
|
+
const hosts = rawHosts ?? [];
|
|
58
|
+
const { t } = useTranslation();
|
|
59
|
+
const [slug, setSlug] = useState(link?.slug ?? "");
|
|
60
|
+
// New links default to the first real link host when one exists; editing an
|
|
61
|
+
// existing link always keeps its own host. A bare "" default would drop every
|
|
62
|
+
// new Cloud link into the cross-tenant host='' shared pool.
|
|
63
|
+
const [host, setHost] = useState(() => (link ? (link.host ?? "") : hosts.length > 0 ? hosts[0] : ""));
|
|
64
|
+
const [target, setTarget] = useState(link?.target ?? "");
|
|
65
|
+
const [title, setTitle] = useState(link?.title ?? "");
|
|
66
|
+
const [note, setNote] = useState(link?.note ?? "");
|
|
67
|
+
const [tags, setTags] = useState(link?.tags ?? "");
|
|
68
|
+
const [password, setPassword] = useState(link?.password ?? "");
|
|
69
|
+
const [expiresAt, setExpiresAt] = useState(link?.expiresAt?.slice(0, 16) ?? "");
|
|
70
|
+
const [expiredUrl, setExpiredUrl] = useState(link?.expiredUrl ?? "");
|
|
71
|
+
const [clickLimit, setClickLimit] = useState(link?.clickLimit ?? 0);
|
|
72
|
+
const [enabled, setEnabled] = useState(link?.enabled ?? true);
|
|
73
|
+
const [routingRules, setRoutingRules] = useState<any[]>(link?.routingRules ?? []);
|
|
74
|
+
const [err, setErr] = useState<string | { message?: string; status?: number; requestId?: string }>("");
|
|
75
|
+
const [fetching, setFetching] = useState(false);
|
|
76
|
+
const [showUtm, setShowUtm] = useState(false);
|
|
77
|
+
const [aiEnabled, setAiEnabled] = useState(false);
|
|
78
|
+
const [aiBusy, setAiBusy] = useState(false);
|
|
79
|
+
const [aiSlugs, setAiSlugs] = useState<string[]>([]);
|
|
80
|
+
const [geoCapabilities, setGeoCapabilities] = useState<LinksCapabilities | null>(null);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
api.aiAssistStatus().then((s) => setAiEnabled(s.configured)).catch(() => {});
|
|
84
|
+
linksApi.capabilities().then(setGeoCapabilities).catch(() => setGeoCapabilities({ geoReady: false, mode: "unavailable" }));
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
async function suggestSlugs() {
|
|
88
|
+
if (!target) return;
|
|
89
|
+
setAiBusy(true);
|
|
90
|
+
setAiSlugs([]);
|
|
91
|
+
try {
|
|
92
|
+
const r = await api.aiSuggestSlug(target, title || undefined);
|
|
93
|
+
setAiSlugs(r.slugs);
|
|
94
|
+
} catch {
|
|
95
|
+
setErr(t("links.aiSuggestFailed"));
|
|
96
|
+
} finally {
|
|
97
|
+
setAiBusy(false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function fetchTitle() {
|
|
102
|
+
if (!target) return;
|
|
103
|
+
setFetching(true);
|
|
104
|
+
try {
|
|
105
|
+
const m = await linksApi.linkMetadata(target);
|
|
106
|
+
if (m.title) setTitle(m.title);
|
|
107
|
+
} catch {
|
|
108
|
+
/* ignore */
|
|
109
|
+
} finally {
|
|
110
|
+
setFetching(false);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function save() {
|
|
115
|
+
setErr("");
|
|
116
|
+
const payload: any = {
|
|
117
|
+
slug,
|
|
118
|
+
host,
|
|
119
|
+
target,
|
|
120
|
+
title,
|
|
121
|
+
note,
|
|
122
|
+
tags,
|
|
123
|
+
password,
|
|
124
|
+
enabled,
|
|
125
|
+
expiredUrl,
|
|
126
|
+
routingRules,
|
|
127
|
+
clickLimit: Number(clickLimit) || 0,
|
|
128
|
+
expiresAt: expiresAt ? new Date(expiresAt).toISOString() : null,
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
let res;
|
|
132
|
+
if (link) res = await linksApi.updateLink(link.id, payload);
|
|
133
|
+
else res = await linksApi.createLink(payload);
|
|
134
|
+
onSaved(res);
|
|
135
|
+
} catch (e: any) {
|
|
136
|
+
// The backend refuses hostless links on multi-tenant instances. That
|
|
137
|
+
// specific 400 gets a localized line; everything else keeps the server's
|
|
138
|
+
// own message (FormError's normal contract).
|
|
139
|
+
if (e?.status === 400 && typeof e?.message === "string" && e.message.includes("host is required")) {
|
|
140
|
+
setErr({ message: t("links.hostRequired"), status: 400, requestId: e.requestId });
|
|
141
|
+
} else {
|
|
142
|
+
setErr(e);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<div className="space-y-4 min-w-0">
|
|
149
|
+
<Field label={t("links.destinationTargetUrl")}>
|
|
150
|
+
<div className="flex gap-2 items-start min-w-0">
|
|
151
|
+
<Textarea
|
|
152
|
+
className="w-full font-mono text-sm min-w-0"
|
|
153
|
+
rows={3}
|
|
154
|
+
value={target}
|
|
155
|
+
onChange={(e) => setTarget(e.target.value)}
|
|
156
|
+
placeholder="https://example.com/blog-post-xyz"
|
|
157
|
+
required
|
|
158
|
+
/>
|
|
159
|
+
<Button variant="subtle" className="shrink-0 text-xs py-2 mt-0.5" type="button" onClick={() => setShowUtm((v) => !v)}>
|
|
160
|
+
UTM
|
|
161
|
+
</Button>
|
|
162
|
+
</div>
|
|
163
|
+
</Field>
|
|
164
|
+
{showUtm && <UtmBuilder target={target} onApply={setTarget} />}
|
|
165
|
+
|
|
166
|
+
{hosts.length === 0 && (
|
|
167
|
+
<Alert variant="warning" className="mb-2">
|
|
168
|
+
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 w-full">
|
|
169
|
+
<div className="text-xs">
|
|
170
|
+
<strong>{t("links.noDomainConfiguredTitle", "No custom domain configured.")}</strong>{" "}
|
|
171
|
+
{t("links.noDomainConfiguredDesc", "Short links require a configured domain on this instance.")}
|
|
172
|
+
</div>
|
|
173
|
+
<DomainConfigNavButton
|
|
174
|
+
onClick={onCancel}
|
|
175
|
+
label={t("links.goToDomains", "Configure Domains →")}
|
|
176
|
+
/>
|
|
177
|
+
</div>
|
|
178
|
+
</Alert>
|
|
179
|
+
)}
|
|
180
|
+
|
|
181
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 min-w-0">
|
|
182
|
+
<Field label={t("links.shortSlug")} hint={t("links.shortSlugHint")}>
|
|
183
|
+
<div className="flex gap-2 min-w-0">
|
|
184
|
+
<Input className="w-full font-mono min-w-0" value={slug} onChange={(e) => setSlug(e.target.value)} placeholder="e.g. promo2026" />
|
|
185
|
+
{aiEnabled && (
|
|
186
|
+
<Button variant="subtle" className="shrink-0 text-xs py-1 gap-1" type="button" onClick={suggestSlugs} disabled={aiBusy || !target}>
|
|
187
|
+
<Sparkles className="h-3.5 w-3.5" />
|
|
188
|
+
{aiBusy ? t("links.aiSuggesting") : t("links.aiSuggest")}
|
|
189
|
+
</Button>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
{aiSlugs.length > 0 && (
|
|
193
|
+
<div className="mt-2 flex flex-wrap gap-1.5 min-w-0">
|
|
194
|
+
{aiSlugs.map((s) => (
|
|
195
|
+
<button
|
|
196
|
+
key={s}
|
|
197
|
+
type="button"
|
|
198
|
+
onClick={() => setSlug(s)}
|
|
199
|
+
className="rounded-lg bg-info-bg border border-info-border px-2.5 py-1 text-xs font-mono text-info-fg hover:bg-info-fg/10 truncate max-w-full"
|
|
200
|
+
>
|
|
201
|
+
{s}
|
|
202
|
+
</button>
|
|
203
|
+
))}
|
|
204
|
+
</div>
|
|
205
|
+
)}
|
|
206
|
+
</Field>
|
|
207
|
+
<Field label={t("links.routingHostDomain")} hint={hosts.length ? t("links.configuredDomains") : t("links.configureDomainsFirst")}>
|
|
208
|
+
<Select
|
|
209
|
+
value={host}
|
|
210
|
+
onValueChange={setHost}
|
|
211
|
+
options={[
|
|
212
|
+
// The hostless "Default (Apex Domain)" option is only offered when
|
|
213
|
+
// no link host exists; once one does, exposing it would let users
|
|
214
|
+
// drop their links back into the shared host='' pool.
|
|
215
|
+
...(hosts.length === 0 ? [{ value: "", label: t("links.defaultApexDomain") }] : []),
|
|
216
|
+
...hosts.map((h) => ({ value: h, label: h })),
|
|
217
|
+
...(host && !hosts.includes(host) ? [{ value: host, label: host }] : []),
|
|
218
|
+
]}
|
|
219
|
+
/>
|
|
220
|
+
</Field>
|
|
221
|
+
</div>
|
|
222
|
+
|
|
223
|
+
<Field label={t("links.metadataPageTitle")}>
|
|
224
|
+
<div className="flex gap-2 min-w-0">
|
|
225
|
+
<Input className="w-full text-sm min-w-0" value={title} onChange={(e) => setTitle(e.target.value)} placeholder={t("links.metadataPlaceholder")} />
|
|
226
|
+
<Button variant="subtle" className="shrink-0 text-xs py-1" type="button" onClick={fetchTitle} disabled={fetching}>
|
|
227
|
+
{fetching ? t("links.fetching") : t("links.fetch")}
|
|
228
|
+
</Button>
|
|
229
|
+
</div>
|
|
230
|
+
</Field>
|
|
231
|
+
|
|
232
|
+
<Field label={t("links.tags")} hint={t("links.tagsHint")}>
|
|
233
|
+
<Input className="w-full text-sm min-w-0" value={tags} onChange={(e) => setTags(e.target.value)} placeholder="e.g. q3-ads, product-hunt" />
|
|
234
|
+
</Field>
|
|
235
|
+
|
|
236
|
+
<Field label={t("links.internalAdminNote")}>
|
|
237
|
+
<Textarea className="w-full text-sm min-w-0" rows={2} value={note} onChange={(e) => setNote(e.target.value)} placeholder={t("links.notePlaceholder")} />
|
|
238
|
+
</Field>
|
|
239
|
+
|
|
240
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 min-w-0">
|
|
241
|
+
<Field label={t("links.accessProtectionPassword")} hint={t("links.passwordOptionalHint")}>
|
|
242
|
+
<Input className="w-full font-mono text-sm min-w-0" type="text" value={password} onChange={(e) => setPassword(e.target.value)} placeholder="e.g. 123456" />
|
|
243
|
+
</Field>
|
|
244
|
+
<Field label={t("links.totalClickLimitation")} hint={t("links.clickLimitHint")}>
|
|
245
|
+
<Input
|
|
246
|
+
type="number"
|
|
247
|
+
min={0}
|
|
248
|
+
className="w-full font-mono min-w-0"
|
|
249
|
+
value={clickLimit}
|
|
250
|
+
onChange={(e) => setClickLimit(Number(e.target.value))}
|
|
251
|
+
/>
|
|
252
|
+
</Field>
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 min-w-0">
|
|
256
|
+
<Field label={t("links.automaticExpiryDate")}>
|
|
257
|
+
<Input type="datetime-local" className="w-full text-sm min-w-0" value={expiresAt} onChange={(e) => setExpiresAt(e.target.value)} />
|
|
258
|
+
</Field>
|
|
259
|
+
<Field label={t("links.redirectUrlAfterExpiry")} hint={t("links.redirectUrlHint")}>
|
|
260
|
+
<Input className="w-full text-sm font-mono min-w-0" value={expiredUrl} onChange={(e) => setExpiredUrl(e.target.value)} placeholder="e.g. https://my-site.com/expired" />
|
|
261
|
+
</Field>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
<div className="flex items-center gap-3 pt-2 min-w-0">
|
|
265
|
+
<Switch checked={enabled} onCheckedChange={setEnabled} aria-label={t("links.linkRoutingActive")} />
|
|
266
|
+
<span className="text-sm text-muted-foreground select-none">{t("links.linkRoutingActive")}</span>
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
<Field label={t("links.routingRules")}>
|
|
270
|
+
<RoutingRulesEditor rules={routingRules} onChange={setRoutingRules} geoReady={geoCapabilities?.geoReady ?? false} />
|
|
271
|
+
</Field>
|
|
272
|
+
|
|
273
|
+
{err && <FormError err={err} />}
|
|
274
|
+
|
|
275
|
+
<div className="flex justify-end gap-2.5 pt-4 border-t border-border min-w-0">
|
|
276
|
+
<Button variant="ghost" onClick={onCancel}>
|
|
277
|
+
{t("links.cancel")}
|
|
278
|
+
</Button>
|
|
279
|
+
<Button variant="primary" onClick={save} disabled={!target}>
|
|
280
|
+
{t("links.saveLink")}
|
|
281
|
+
</Button>
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
function UtmBuilder({ target, onApply }: { target: string; onApply: (url: string) => void }) {
|
|
289
|
+
const { t } = useTranslation();
|
|
290
|
+
const [utm, setUtm] = useState({ source: "", medium: "", campaign: "", term: "", content: "" });
|
|
291
|
+
function apply() {
|
|
292
|
+
if (!target) return;
|
|
293
|
+
let base = target;
|
|
294
|
+
if (!base.includes("://")) base = "https://" + base;
|
|
295
|
+
try {
|
|
296
|
+
const u = new URL(base);
|
|
297
|
+
const map: Record<string, string> = {
|
|
298
|
+
utm_source: utm.source,
|
|
299
|
+
utm_medium: utm.medium,
|
|
300
|
+
utm_campaign: utm.campaign,
|
|
301
|
+
utm_term: utm.term,
|
|
302
|
+
utm_content: utm.content,
|
|
303
|
+
};
|
|
304
|
+
for (const [k, v] of Object.entries(map)) {
|
|
305
|
+
if (v) u.searchParams.set(k, v);
|
|
306
|
+
else u.searchParams.delete(k);
|
|
307
|
+
}
|
|
308
|
+
onApply(u.toString());
|
|
309
|
+
} catch {
|
|
310
|
+
/* ignore */
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
const fields: [keyof typeof utm, string][] = [
|
|
314
|
+
["source", "source"],
|
|
315
|
+
["medium", "medium"],
|
|
316
|
+
["campaign", "campaign"],
|
|
317
|
+
["term", "term"],
|
|
318
|
+
["content", "content"],
|
|
319
|
+
];
|
|
320
|
+
return (
|
|
321
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2.5 p-4 bg-well border border-border rounded-xl min-w-0">
|
|
322
|
+
{fields.map(([k, label]) => (
|
|
323
|
+
<Input
|
|
324
|
+
key={k}
|
|
325
|
+
className="w-full text-xs h-8 min-w-0"
|
|
326
|
+
placeholder={`utm_${label}`}
|
|
327
|
+
value={utm[k]}
|
|
328
|
+
onChange={(e) => setUtm({ ...utm, [k]: e.target.value })}
|
|
329
|
+
/>
|
|
330
|
+
))}
|
|
331
|
+
<Button variant="subtle" className="sm:col-span-2 md:col-span-3 h-8 text-xs py-1.5" onClick={apply}>
|
|
332
|
+
{t("links.applyUtmParameters")}
|
|
333
|
+
</Button>
|
|
334
|
+
</div>
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function RoutingRulesEditor({ rules, onChange, geoReady }: { rules: any[]; onChange: (r: any[]) => void; geoReady: boolean }) {
|
|
339
|
+
const { t } = useTranslation();
|
|
340
|
+
const types = [
|
|
341
|
+
{ value: "geo", label: t("links.ruleTypeGeo") },
|
|
342
|
+
{ value: "device", label: t("links.ruleTypeDevice") },
|
|
343
|
+
{ value: "os", label: t("links.ruleTypeOS") },
|
|
344
|
+
{ value: "language", label: t("links.ruleTypeLanguage") },
|
|
345
|
+
{ value: "split", label: t("links.ruleTypeSplit") },
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
const splitTotal = rules.filter((r) => r.type === "split").reduce((acc, r) => acc + (Number(r.weight) || 0), 0);
|
|
349
|
+
const splitRem = Math.max(0, 100 - splitTotal);
|
|
350
|
+
|
|
351
|
+
return (
|
|
352
|
+
<div className="space-y-3 min-w-0">
|
|
353
|
+
{rules.map((rule, i) => (
|
|
354
|
+
<div key={i} className="flex gap-2 items-start bg-well p-3 rounded-lg border border-border min-w-0">
|
|
355
|
+
<div className="flex-1 space-y-2 min-w-0">
|
|
356
|
+
<div className="flex gap-2 min-w-0">
|
|
357
|
+
<div className="w-1/3 min-w-[100px] shrink-0">
|
|
358
|
+
<Select
|
|
359
|
+
value={rule.type}
|
|
360
|
+
onValueChange={(v) => {
|
|
361
|
+
const next = [...rules];
|
|
362
|
+
next[i] = { ...rule, type: v };
|
|
363
|
+
if (v === "split") {
|
|
364
|
+
delete next[i].match;
|
|
365
|
+
next[i].weight = 50;
|
|
366
|
+
} else {
|
|
367
|
+
delete next[i].weight;
|
|
368
|
+
next[i].match = "";
|
|
369
|
+
}
|
|
370
|
+
onChange(next);
|
|
371
|
+
}}
|
|
372
|
+
options={types}
|
|
373
|
+
/>
|
|
374
|
+
</div>
|
|
375
|
+
<div className="flex-1 min-w-0">
|
|
376
|
+
{rule.type === "split" ? (
|
|
377
|
+
<Input
|
|
378
|
+
type="number"
|
|
379
|
+
min={0}
|
|
380
|
+
max={100}
|
|
381
|
+
className="w-full text-sm font-mono min-w-0"
|
|
382
|
+
placeholder={t("links.ruleWeight")}
|
|
383
|
+
value={rule.weight ?? ""}
|
|
384
|
+
onChange={(e) => {
|
|
385
|
+
const next = [...rules];
|
|
386
|
+
next[i] = { ...rule, weight: Number(e.target.value) };
|
|
387
|
+
onChange(next);
|
|
388
|
+
}}
|
|
389
|
+
/>
|
|
390
|
+
) : (
|
|
391
|
+
<Input
|
|
392
|
+
className="w-full text-sm font-mono min-w-0"
|
|
393
|
+
placeholder={t("links.ruleMatch")}
|
|
394
|
+
value={rule.match ?? ""}
|
|
395
|
+
onChange={(e) => {
|
|
396
|
+
const next = [...rules];
|
|
397
|
+
next[i] = { ...rule, match: e.target.value };
|
|
398
|
+
onChange(next);
|
|
399
|
+
}}
|
|
400
|
+
/>
|
|
401
|
+
)}
|
|
402
|
+
</div>
|
|
403
|
+
</div>
|
|
404
|
+
{rule.type === "geo" && (
|
|
405
|
+
<div className="flex items-center gap-2 pt-0.5">
|
|
406
|
+
{geoReady ? (
|
|
407
|
+
<Badge tone="green" shape="dot">
|
|
408
|
+
{t("links.geoReady", "GeoIP Active")}
|
|
409
|
+
</Badge>
|
|
410
|
+
) : (
|
|
411
|
+
<Badge tone="amber" shape="dash" title={t("links.geoUnavailableDesc", "Server lacks GeoIP database. Country routing is bypassed.")}>
|
|
412
|
+
{t("links.geoUnavailable", "GeoIP Unavailable (bypassed)")}
|
|
413
|
+
</Badge>
|
|
414
|
+
)}
|
|
415
|
+
{!geoReady && (
|
|
416
|
+
<span className="text-[11px] text-warning-fg">
|
|
417
|
+
{t("links.geoUnavailableDesc", "Server lacks GeoIP database. Country routing is bypassed.")}
|
|
418
|
+
</span>
|
|
419
|
+
)}
|
|
420
|
+
</div>
|
|
421
|
+
)}
|
|
422
|
+
<Input
|
|
423
|
+
className="w-full text-sm font-mono min-w-0"
|
|
424
|
+
placeholder={t("links.ruleTarget")}
|
|
425
|
+
value={rule.target ?? ""}
|
|
426
|
+
onChange={(e) => {
|
|
427
|
+
const next = [...rules];
|
|
428
|
+
next[i] = { ...rule, target: e.target.value };
|
|
429
|
+
onChange(next);
|
|
430
|
+
}}
|
|
431
|
+
/>
|
|
432
|
+
</div>
|
|
433
|
+
<Button variant="ghost" className="shrink-0 p-2 text-danger-fg" onClick={() => {
|
|
434
|
+
const next = [...rules];
|
|
435
|
+
next.splice(i, 1);
|
|
436
|
+
onChange(next);
|
|
437
|
+
}}>
|
|
438
|
+
<Trash2 className="h-4 w-4" />
|
|
439
|
+
</Button>
|
|
440
|
+
</div>
|
|
441
|
+
))}
|
|
442
|
+
|
|
443
|
+
<div className="flex items-center justify-between mt-2 flex-wrap gap-2 min-w-0">
|
|
444
|
+
<Button variant="subtle" className="text-xs py-1.5 gap-1" onClick={() => onChange([...rules, { type: "split", weight: 50, target: "" }])}>
|
|
445
|
+
<Plus className="h-3.5 w-3.5" />
|
|
446
|
+
{t("links.addRule")}
|
|
447
|
+
</Button>
|
|
448
|
+
|
|
449
|
+
{rules.some((r) => r.type === "split") && (
|
|
450
|
+
<div className="text-xs text-muted-foreground font-mono">
|
|
451
|
+
{t("links.splitTotalLabel", { total: splitTotal })} · {t("links.ruleSplitRemainder")}: {splitRem}%
|
|
452
|
+
</div>
|
|
453
|
+
)}
|
|
454
|
+
</div>
|
|
455
|
+
</div>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Button, buttonVariants, cn, Modal, useTranslation } from "@octarq/plugin-sdk";
|
|
2
|
+
import { Link } from "../api";
|
|
3
|
+
import { Check, Copy, Download } from "lucide-react";
|
|
4
|
+
import { LinkEditorForm } from "./LinkEditorForm";
|
|
5
|
+
import { StatsView } from "./StatsView";
|
|
6
|
+
|
|
7
|
+
export interface LinkModalsProps {
|
|
8
|
+
createOpen: boolean;
|
|
9
|
+
editingLink: Link | null;
|
|
10
|
+
analyticsLink: Link | null;
|
|
11
|
+
qrLink: Link | null;
|
|
12
|
+
linkHostOptions: string[];
|
|
13
|
+
copiedId: number | null;
|
|
14
|
+
onCloseCreate: () => void;
|
|
15
|
+
onCloseEdit: () => void;
|
|
16
|
+
onCloseAnalytics: () => void;
|
|
17
|
+
onCloseQr: () => void;
|
|
18
|
+
onRefreshLinks: () => void;
|
|
19
|
+
onCopyQrLink: (l: Link) => void;
|
|
20
|
+
linkURL: (l: Link) => string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function LinkModals({
|
|
24
|
+
createOpen,
|
|
25
|
+
editingLink,
|
|
26
|
+
analyticsLink,
|
|
27
|
+
qrLink,
|
|
28
|
+
linkHostOptions,
|
|
29
|
+
copiedId,
|
|
30
|
+
onCloseCreate,
|
|
31
|
+
onCloseEdit,
|
|
32
|
+
onCloseAnalytics,
|
|
33
|
+
onCloseQr,
|
|
34
|
+
onRefreshLinks,
|
|
35
|
+
onCopyQrLink,
|
|
36
|
+
linkURL,
|
|
37
|
+
}: LinkModalsProps) {
|
|
38
|
+
const { t } = useTranslation();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
{/* Create New Link Modal */}
|
|
43
|
+
{createOpen && (
|
|
44
|
+
<Modal title={t("links.createNewLink")} onClose={onCloseCreate}>
|
|
45
|
+
<div className="p-1">
|
|
46
|
+
<LinkEditorForm
|
|
47
|
+
link={null}
|
|
48
|
+
hosts={linkHostOptions}
|
|
49
|
+
onCancel={onCloseCreate}
|
|
50
|
+
onSaved={() => {
|
|
51
|
+
onCloseCreate();
|
|
52
|
+
onRefreshLinks();
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
</Modal>
|
|
57
|
+
)}
|
|
58
|
+
|
|
59
|
+
{/* Edit Link Modal */}
|
|
60
|
+
{editingLink && (
|
|
61
|
+
<Modal
|
|
62
|
+
title={`${t("links.editLink")} — ${editingLink.title || `/${editingLink.slug}`}`}
|
|
63
|
+
onClose={onCloseEdit}
|
|
64
|
+
>
|
|
65
|
+
<div className="p-1">
|
|
66
|
+
<LinkEditorForm
|
|
67
|
+
key={editingLink.id}
|
|
68
|
+
link={editingLink}
|
|
69
|
+
hosts={linkHostOptions}
|
|
70
|
+
onCancel={onCloseEdit}
|
|
71
|
+
onSaved={() => {
|
|
72
|
+
onCloseEdit();
|
|
73
|
+
onRefreshLinks();
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
</Modal>
|
|
78
|
+
)}
|
|
79
|
+
|
|
80
|
+
{/* Analytics Modal */}
|
|
81
|
+
{analyticsLink && (
|
|
82
|
+
<Modal
|
|
83
|
+
title={`${t("links.clickPerformanceAnalytics")} — ${analyticsLink.title || `/${analyticsLink.slug}`}`}
|
|
84
|
+
onClose={onCloseAnalytics}
|
|
85
|
+
>
|
|
86
|
+
<div className="p-2 max-h-[80vh] overflow-y-auto">
|
|
87
|
+
<StatsView link={analyticsLink} />
|
|
88
|
+
</div>
|
|
89
|
+
</Modal>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
{/* QR Code Modal */}
|
|
93
|
+
{qrLink && (
|
|
94
|
+
<Modal
|
|
95
|
+
title={`${t("links.linkQrCode")} — ${qrLink.title || `/${qrLink.slug}`}`}
|
|
96
|
+
onClose={onCloseQr}
|
|
97
|
+
>
|
|
98
|
+
<div className="flex flex-col items-center gap-5 py-4">
|
|
99
|
+
<div className="bg-white p-5 rounded-2xl shadow-sm border border-border">
|
|
100
|
+
<img
|
|
101
|
+
src={`/api/links/${qrLink.id}/qr`}
|
|
102
|
+
alt={t("links.qrAlt")}
|
|
103
|
+
className="rounded-lg"
|
|
104
|
+
width={220}
|
|
105
|
+
height={220}
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
<div className="font-mono text-xs text-foreground bg-well px-3 py-1.5 rounded-lg border border-border truncate max-w-sm">
|
|
109
|
+
{linkURL(qrLink)}
|
|
110
|
+
</div>
|
|
111
|
+
<div className="flex items-center gap-2">
|
|
112
|
+
<Button
|
|
113
|
+
variant="subtle"
|
|
114
|
+
className="text-xs py-1.5 px-4 gap-1.5"
|
|
115
|
+
onClick={() => onCopyQrLink(qrLink)}
|
|
116
|
+
>
|
|
117
|
+
{copiedId === qrLink.id ? (
|
|
118
|
+
<Check className="h-3.5 w-3.5 text-success-fg" />
|
|
119
|
+
) : (
|
|
120
|
+
<Copy className="h-3.5 w-3.5" />
|
|
121
|
+
)}
|
|
122
|
+
{copiedId === qrLink.id ? t("links.copied") : t("links.copyLink")}
|
|
123
|
+
</Button>
|
|
124
|
+
<a
|
|
125
|
+
href={`/api/links/${qrLink.id}/qr`}
|
|
126
|
+
download={`qr-${qrLink.slug}.png`}
|
|
127
|
+
className={cn(buttonVariants({ variant: "primary" }), "text-xs py-1.5 px-4 gap-1.5")}
|
|
128
|
+
>
|
|
129
|
+
<Download className="h-3.5 w-3.5" />
|
|
130
|
+
{t("links.downloadQrCode")}
|
|
131
|
+
</a>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
</Modal>
|
|
135
|
+
)}
|
|
136
|
+
</>
|
|
137
|
+
);
|
|
138
|
+
}
|