Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dashboard/src/components/dashboard/events/EventDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import EventMyTickets from "@/components/dashboard/events/EventMyTickets.vue"
import type { MyEvent } from "@/types"
import { timeLabel12Hour } from "@/utils/dateLabels"
import { bannerPattern } from "@/utils/eventBanner"
import { copyEventUrl, eventUrl } from "@/utils/eventUrl"
import { copyEventUrl, openEventPage } from "@/utils/eventUrl"

const props = defineProps<{ event: MyEvent | null }>()

Expand Down Expand Up @@ -89,7 +89,7 @@ const endsAt = computed(() => {
size="sm"
label="Event Page"
icon-right="lucide-arrow-up-right"
:link="eventUrl(event.route)"
@click="openEventPage(event.route)"
/>
</template>
</div>
Expand Down
17 changes: 9 additions & 8 deletions dashboard/src/components/dashboard/events/EventRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { computed, ref, watch } from "vue"

import { useCopyToClipboard } from "@/composables/useCopyToClipboard"
import { checkEventRoute } from "@/data/events"
import { eventPath, eventUrl, openEventPage } from "@/utils/eventUrl"

// The route the event already answers to, which is the one that opens and copies —
// an edit in the field is not a live address until it is saved.
Expand All @@ -15,8 +16,8 @@ const taken = defineModel<boolean>("taken", { default: false })

// The host the dashboard is being used on, so the field reads as the address it will be.
const hostname = window.location.hostname
// Events are served under the dashboard's own base, not off the bare host.
const publicPath = computed(() => `/b/register/${props.saved}`)
// The public event page, which is served outside the dashboard's /b base.
const publicPath = computed(() => eventPath(props.saved ?? ""))

type Availability = { available: boolean; message: string }
const availability = ref<Availability | null>(null)
Expand All @@ -42,9 +43,10 @@ watch(availability, (answer) => (taken.value = Boolean(answer) && !answer?.avail

const copyToClipboard = useCopyToClipboard()

// The path the link opens, not the shorthand the field reads.
const copy = () =>
copyToClipboard(`${window.location.origin}${publicPath.value}`, "Event link copied")
// The address the link opens, not the shorthand the field reads.
const copy = () => copyToClipboard(eventUrl(props.saved ?? ""), "Event link copied")

const open = () => openEventPage(props.saved ?? "")
</script>

<template>
Expand All @@ -55,10 +57,9 @@ const copy = () =>
<div v-if="saved" class="flex items-center gap-1">
<a
:href="publicPath"
target="_blank"
rel="noopener"
aria-label="Open event page"
class="rounded-4 p-1 text-ink-gray-5 transition-[color,transform] duration-150 ease-out hover:text-ink-gray-8 active:scale-95 motion-reduce:transition-none"
@click.prevent="open"
>
<span class="lucide-arrow-up-right block size-4" aria-hidden="true" />
</a>
Expand All @@ -79,7 +80,7 @@ const copy = () =>
<div
class="rounded-6 border border-outline-gray-2 px-2.5 py-1.5 transition-colors duration-150 ease-out focus-within:border-outline-gray-4 motion-reduce:transition-none"
>
<p class="text-xs leading-4 text-ink-gray-5">{{ hostname }}/</p>
<p class="text-xs leading-4 text-ink-gray-5">{{ hostname }}/events/</p>
<input
v-model="route"
aria-label="Event route"
Expand Down
10 changes: 7 additions & 3 deletions dashboard/src/utils/eventUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "node:assert/strict"
import { test } from "node:test"

import { eventUrl } from "./eventUrl.ts"
import { eventPath, eventUrl } from "./eventUrl.ts"

const withOrigin = (origin: string, run: () => void) => {
// The helper reads the live location; there is no browser under node --test.
Expand All @@ -15,12 +15,16 @@ const withOrigin = (origin: string, run: () => void) => {

test("hangs the route off the current origin", () => {
withOrigin("https://buzz.example.com", () => {
assert.equal(eventUrl("frappeverse-2026"), "https://buzz.example.com/frappeverse-2026")
assert.equal(eventUrl("frappeverse-2026"), "https://buzz.example.com/events/frappeverse-2026")
})
})

test("keeps the port, which differs between the dashboard and the bench", () => {
withOrigin("http://buzz.localhost:8080", () => {
assert.equal(eventUrl("summit"), "http://buzz.localhost:8080/summit")
assert.equal(eventUrl("summit"), "http://buzz.localhost:8080/events/summit")
})
})

test("keeps the path off the dashboard's own base", () => {
assert.equal(eventPath("frappeverse-2026"), "/events/frappeverse-2026")
})
17 changes: 15 additions & 2 deletions dashboard/src/utils/eventUrl.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
/**
* The public page for an event lives at the site root under the event's own route.
* The public page for an event lives under /events/<route>.
*
* Built from the current origin rather than a configured base URL: the dashboard and the
* bench answer on different ports in development, so anything hardcoded is wrong in one
* of the two places.
*/
export function eventUrl(route: string): string {
return `${window.location.origin}/${route}`
return `${window.location.origin}${eventPath(route)}`
}

/** The origin-relative path of an event's public page. */
export function eventPath(route: string): string {
return `/events/${route}`
}

/**
* Leaves the dashboard for the event's public page. A plain navigation, not a router
* one: the page is served outside the SPA's /b base.
*/
export function openEventPage(route: string): void {
window.open(eventUrl(route), "_blank", "noopener")
}

/** Puts an event's public link on the clipboard. Rejects if the browser refuses access. */
Expand Down
3 changes: 1 addition & 2 deletions e2e/tests/manage-event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ test.describe("Event workspace", () => {
expect(route).not.toBe("")

const open = page.getByRole("link", { name: "Open event page" })
await expect(open).toHaveAttribute("href", `/b/register/${route}`)
await expect(open).toHaveAttribute("target", "_blank")
await expect(open).toHaveAttribute("href", `/events/${route}`)
await expect(page.getByRole("button", { name: "Copy" })).toBeVisible()
})

Expand Down
Loading