Links/redirects: Copy link on a saved redirect
A manifest's idLink gives a saved record's own address, shown on its URL ID card with a Copy link button; redirects use it for the /go/ link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e060153798
commit
0eea9ba13b
2 changed files with 28 additions and 2 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
/go/<URL ID>, and passed on with the link's UTM tags. Server side:
|
/go/<URL ID>, and passed on with the link's UTM tags. Server side:
|
||||||
server/src/admin-schema/redirects.js and routes/redirects.js. */
|
server/src/admin-schema/redirects.js and routes/redirects.js. */
|
||||||
|
|
||||||
import { SITE_ORIGIN } from "../site.ts";
|
import { SITE_ORIGIN, siteUrl } from "../site.ts";
|
||||||
|
|
||||||
const GO = `${SITE_ORIGIN.replace(/^https?:\/\//, "").replace(/\/$/, "")}/go/`;
|
const GO = `${SITE_ORIGIN.replace(/^https?:\/\//, "").replace(/\/$/, "")}/go/`;
|
||||||
|
|
||||||
|
|
@ -15,6 +15,8 @@ export const redirects = {
|
||||||
singular: "redirect",
|
singular: "redirect",
|
||||||
idLabel: "URL ID",
|
idLabel: "URL ID",
|
||||||
idPrefix: GO,
|
idPrefix: GO,
|
||||||
|
// The address to share, copied from the saved redirect's page.
|
||||||
|
idLink: (id: string) => siteUrl(`/go/${id}`),
|
||||||
|
|
||||||
list: {
|
list: {
|
||||||
columns: [
|
columns: [
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@
|
||||||
why the array form exists and teams uses it.
|
why the array form exists and teams uses it.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
import { ArrowLeft } from "@phosphor-icons/react";
|
import { ArrowLeft, Check, Copy } from "@phosphor-icons/react";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
|
@ -450,6 +450,7 @@ export default function EntityEdit() {
|
||||||
change("id", `${prefixOf(form)}${slugify(value)}`);
|
change("id", `${prefixOf(form)}${slugify(value)}`);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{!isNew && manifest.idLink && <CopyLink url={manifest.idLink(form.id)} />}
|
||||||
{!isNew && form.updated_at && (
|
{!isNew && form.updated_at && (
|
||||||
<p className="mt-2 text-xs text-muted">
|
<p className="mt-2 text-xs text-muted">
|
||||||
Last saved {form.updated_at}
|
Last saved {form.updated_at}
|
||||||
|
|
@ -649,3 +650,26 @@ function RequestedChanges({ request, isNew, form, onUse, onAdd }: any) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A saved record's own link (the manifest's `idLink`, eg. a redirect's
|
||||||
|
/go/ address), with a button to copy it. */
|
||||||
|
function CopyLink({ url }: { url: string }) {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
return (
|
||||||
|
<div className="mt-3 flex flex-wrap items-center gap-3">
|
||||||
|
<code className="break-all text-sm text-body">{url}</code>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() =>
|
||||||
|
navigator.clipboard?.writeText(url).then(() => {
|
||||||
|
setCopied(true);
|
||||||
|
setTimeout(() => setCopied(false), 1500);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
className="btn inline-flex items-center gap-1.5 border border-link px-3 py-1 text-sm text-link transition-colors hover:bg-tint"
|
||||||
|
>
|
||||||
|
{copied ? <Check weight="bold" aria-hidden="true" /> : <Copy weight="bold" aria-hidden="true" />}
|
||||||
|
{copied ? "Copied" : "Copy link"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue