feat(modules): a third slot, nav icons, and api.BASE (phase 3, slice 3)
The three things core owes the client half before it can leave, all additive, all MODULE_API 1.2.0 → 1.3.0. `player.invite.accepted` is the third extension slot. Core's invite page owned a UO game-account step — it read a `gameAccountSignup` flag out of core's own settings and posted to a shard route — and an invite is a core concept that staff receive too, so the page stays and its optional next step becomes a slot. Named for the place, like the other two. Whether there is a step at all is the filling module's call, made from data core does not have; core keeps the shell, the skip control and the destination. `icon` on a nav item, because without it the six extracted UO rows would have been the only text-only entries in a sidebar where every other row has a glyph. Core supplies no fallback — an invented one is core making a presentation choice for content it knows nothing about. `icon` was already among the fields an override may not touch, so the concept predates a module being able to send one. `api.BASE` was in §3.5 from the first draft and never actually published. `request` is fetch-only, so an EventSource builds its own URL, and the shard's live feed is two of them; the alternative is a module hardcoding `/api/v1`, which asserts something about core that core has not promised. `AcceptInvite` is the one legitimate reader of `extensionFor` outside Slot.jsx: the answer decides a NAVIGATION, not a decoration. Decoration goes inside `<Slot wrap>`, which is why `hasExtension` stayed deleted. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import { useAuth } from '../../contexts/AuthContext.jsx'
|
||||
import { api } from '../../api/client.js'
|
||||
import PlayerShell, { honeypotStyle } from './PlayerShell.jsx'
|
||||
import CreateGameAccountForm from '../../components/CreateGameAccountForm.jsx'
|
||||
import Slot from '../../modules/Slot.jsx'
|
||||
import { extensionFor } from '../../modules/registry.js'
|
||||
|
||||
// Public, token-gated invite acceptance (/invite/:token). Validates the invite,
|
||||
// lets the invitee set a username + password (their email + role are pre-assigned),
|
||||
// creates the account at that role and logs them in. For a player invite it then
|
||||
// offers the built-in "create game account" step before sending them to the portal.
|
||||
// creates the account at that role and logs them in.
|
||||
//
|
||||
// For a PLAYER invite there may then be one more step, supplied by an installed
|
||||
// module through the `player.invite.accepted` slot: core rendered a UO
|
||||
// game-account form here itself until Phase 3 slice 3, reading a
|
||||
// `gameAccountSignup` flag out of its own settings and posting to a shard route.
|
||||
// Neither of those is core's. What core keeps is the shell, the skip control and
|
||||
// the destination; whether there is a step at all is the module's call, made
|
||||
// from data core does not have.
|
||||
export default function AcceptInvite() {
|
||||
const { token } = useParams()
|
||||
const navigate = useNavigate()
|
||||
@@ -16,7 +24,6 @@ export default function AcceptInvite() {
|
||||
|
||||
const [invite, setInvite] = useState(null) // fields email and role
|
||||
const [loadErr, setLoadErr] = useState('')
|
||||
const [signupOk, setSignupOk] = useState(false)
|
||||
|
||||
const [username, setUsername] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
@@ -30,14 +37,20 @@ export default function AcceptInvite() {
|
||||
api.getInvite(token)
|
||||
.then((iv) => active && setInvite(iv))
|
||||
.catch((err) => active && setLoadErr(err.status === 404 ? 'This invitation is invalid or has expired.' : 'Could not load this invitation.'))
|
||||
api.publicSettings()
|
||||
.then((s) => active && setSignupOk(Boolean(s?.gameAccountSignup)))
|
||||
.catch(() => {})
|
||||
return () => { active = false }
|
||||
}, [token])
|
||||
|
||||
const dest = invite && invite.role === 'player' ? '/player' : '/admin'
|
||||
|
||||
// Whether anything is installed that wants the post-acceptance step. Read
|
||||
// rather than rendered blind because it decides a NAVIGATION, not just what
|
||||
// appears: with nothing filled there is no screen to show, so the invitee goes
|
||||
// straight to their destination. This is the one legitimate reason to ask
|
||||
// whether a slot is filled — the answer changes control flow, not decoration
|
||||
// (decoration goes inside `<Slot wrap>`, which is why `hasExtension` is gone).
|
||||
const hasNextStep = Boolean(extensionFor('player.invite.accepted'))
|
||||
const finish = useCallback(() => navigate('/player', { replace: true }), [navigate])
|
||||
|
||||
async function onSubmit(e) {
|
||||
e.preventDefault()
|
||||
setError('')
|
||||
@@ -48,8 +61,9 @@ export default function AcceptInvite() {
|
||||
await api.acceptInvite(token, username.trim(), password, { company })
|
||||
await refresh() // pull the freshly-issued session into context
|
||||
setAccepted(true)
|
||||
// Staff invites are web-only — no game step; go straight in.
|
||||
if (!(invite.role === 'player' && signupOk)) navigate(dest, { replace: true })
|
||||
// Staff invites go straight in, and so does a player invite when nothing
|
||||
// is installed that has a step to offer.
|
||||
if (!(invite.role === 'player' && hasNextStep)) navigate(dest, { replace: true })
|
||||
} catch (err) {
|
||||
if (err.status === 409) setError('That username is already taken, or the invite was already used.')
|
||||
else if (err.status === 404) setError('This invitation is invalid or has expired.')
|
||||
@@ -78,19 +92,22 @@ export default function AcceptInvite() {
|
||||
)
|
||||
}
|
||||
|
||||
// ── Accepted: optional game-account step (player invites) ──────────────────
|
||||
// ── Accepted: a module's optional next step (player invites) ───────────────
|
||||
//
|
||||
// Only reachable when the slot is filled — `onSubmit` navigates away otherwise
|
||||
// — so there is no empty-shell case to guard here.
|
||||
//
|
||||
// The subtitle is core's and says nothing about what the step is: naming it
|
||||
// would be core describing content it does not own, and the wrong description
|
||||
// is worse than a general one. "Skip" stays core's too, because where it goes
|
||||
// is core's decision, and it is rendered outside the slot deliberately — an
|
||||
// extension that throws must not take the way out with it.
|
||||
if (accepted) {
|
||||
return (
|
||||
<PlayerShell subtitle="Set up your game account">
|
||||
<p className="sans" style={{ marginTop: 0, color: 'var(--muted)', fontSize: '0.9rem', lineHeight: 1.6 }}>
|
||||
Your account is ready. Create a game account now to play, or skip and do it later from your portal.
|
||||
</p>
|
||||
<CreateGameAccountForm
|
||||
submit={api.player.shard.createAccount}
|
||||
onCreated={() => navigate('/player', { replace: true })}
|
||||
/>
|
||||
<PlayerShell subtitle="One more step">
|
||||
<Slot name="player.invite.accepted" onDone={finish} />
|
||||
<p className="sans" style={{ textAlign: 'center', margin: '18px 0 0' }}>
|
||||
<button type="button" onClick={() => navigate('/player', { replace: true })} className="btn" style={{ background: 'none', border: 'none', color: 'var(--accent)', cursor: 'pointer' }}>
|
||||
<button type="button" onClick={finish} className="btn" style={{ background: 'none', border: 'none', color: 'var(--accent)', cursor: 'pointer' }}>
|
||||
Skip for now →
|
||||
</button>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user