Map admins: owners invite friends to co-manage maps
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m2s
Some checks failed
Deploy MineGeo to Dokploy / deploy (push) Failing after 6m2s
Owners can invite players by name from the map workshop; invitees accept from their dashboard and then manage the map (details, locations, submission, refresh, contributions, appeals) through owner-delegated checks. Adds the map_admins table, invite/admin API endpoints, dashboard invite box, workshop admin management, and Russian translations.
This commit is contained in:
82
components/AdminInvites.tsx
Normal file
82
components/AdminInvites.tsx
Normal file
@@ -0,0 +1,82 @@
|
||||
"use client";
|
||||
import { useI18n } from "@/components/I18nProvider";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { api } from "./StartGame";
|
||||
|
||||
export type AdminInvite = {
|
||||
id: string;
|
||||
created_at: string;
|
||||
mapName: string;
|
||||
ownerName: string;
|
||||
};
|
||||
export function AdminInvites({ onChange }: { onChange: () => void }) {
|
||||
const { t } = useI18n();
|
||||
const [invites, setInvites] = useState<AdminInvite[]>([]);
|
||||
const [error, setError] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
setInvites((await api<{ invites: AdminInvite[] }>("admin-invites")).invites);
|
||||
setError("");
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
}
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
load();
|
||||
const timer = setInterval(load, 10000);
|
||||
return () => clearInterval(timer);
|
||||
}, [load]);
|
||||
async function respond(id: string, decision: "accept" | "decline") {
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
await api(`admin-invites/${id}`, { decision });
|
||||
await load();
|
||||
onChange();
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
if (!invites.length && !error) return null;
|
||||
return (
|
||||
<section className="token-box">
|
||||
<span className="eyebrow">{t("SHARED WITH YOU")}</span>
|
||||
<h2>{t("Map admin invites")}</h2>
|
||||
{invites.map((invite) => (
|
||||
<div className="draft-row" key={invite.id}>
|
||||
<span>
|
||||
{t("{owner} invited you to manage {map}.", {
|
||||
owner: invite.ownerName,
|
||||
map: invite.mapName,
|
||||
})}
|
||||
</span>
|
||||
<div className="inline-actions">
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={busy}
|
||||
onClick={() => respond(invite.id, "accept")}
|
||||
>
|
||||
{t("Accept")}
|
||||
</button>
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy}
|
||||
onClick={() => respond(invite.id, "decline")}
|
||||
>
|
||||
{t("Decline")}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{error && (
|
||||
<p role="alert" className="error-message">
|
||||
{t(error)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,9 @@ import type { MapListing } from "@/lib/catalog";
|
||||
import type { ProcessingJob } from "@/shared/processing-progress";
|
||||
import { ProcessingProgress } from "./ProcessingProgress";
|
||||
import { ImportMap } from "./MapTransfer";
|
||||
import { AdminInvites } from "./AdminInvites";
|
||||
type Draft = MapListing & {
|
||||
access?: "owner" | "admin";
|
||||
upload_jobs: ProcessingJob | null;
|
||||
};
|
||||
export function Dashboard() {
|
||||
@@ -128,6 +130,7 @@ export function Dashboard() {
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
<AdminInvites onChange={load} />
|
||||
{maps.map((m) => (
|
||||
<article className="draft-row" key={m.id}>
|
||||
<div>
|
||||
@@ -135,6 +138,9 @@ export function Dashboard() {
|
||||
{m.source === "plugin" ? t("SERVER EXPORT") : t("PLAYER CAPTURE")}
|
||||
</span>
|
||||
<h3>{m.name}</h3>
|
||||
{m.access === "admin" && (
|
||||
<span className="badge">{t("Map admin")}</span>
|
||||
)}{" "}
|
||||
<span className="badge">
|
||||
{m.contribution_status
|
||||
? t("Contribution: {status}", {
|
||||
|
||||
@@ -13,8 +13,10 @@ import { OwnerContributions } from "./OwnerContributions";
|
||||
import Link from "next/link";
|
||||
import { MapRefresh } from "./MapRefresh";
|
||||
import { MapAppeal } from "./MapAppeal";
|
||||
import { MapAdmins } from "./MapAdmins";
|
||||
import { ExportMap } from "./MapTransfer";
|
||||
type Draft = {
|
||||
access: "owner" | "admin";
|
||||
imported_from_id: string | null;
|
||||
imported_owner_name: string | null;
|
||||
ownsPublishedParent: boolean;
|
||||
@@ -175,6 +177,13 @@ export function DraftEditor({
|
||||
)}
|
||||
</div>
|
||||
<span className="badge">{t(statusMessage(draft.state))}</span>
|
||||
{draft.access === "admin" && (
|
||||
<p className="muted">
|
||||
{t(
|
||||
"You manage this map as an admin. The owner invited you to help run it.",
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{!draft.imported_from_id &&
|
||||
!draft.parent_dataset_id &&
|
||||
draft.map &&
|
||||
@@ -440,6 +449,9 @@ export function DraftEditor({
|
||||
onChange={() => setVersion((v) => v + 1)}
|
||||
/>
|
||||
)}
|
||||
{!draft.imported_from_id && !draft.parent_dataset_id && (
|
||||
<MapAdmins id={id} access={draft.access} />
|
||||
)}
|
||||
{(["uploading", "processing"].includes(draft.state) ||
|
||||
(draft.parent_dataset_id &&
|
||||
["pending", "submitted"].includes(
|
||||
|
||||
131
components/MapAdmins.tsx
Normal file
131
components/MapAdmins.tsx
Normal file
@@ -0,0 +1,131 @@
|
||||
"use client";
|
||||
import { useI18n } from "@/components/I18nProvider";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { api } from "./StartGame";
|
||||
|
||||
export type MapAdmin = {
|
||||
id: string;
|
||||
user_id: string;
|
||||
state: string;
|
||||
created_at: string;
|
||||
name: string;
|
||||
username: string | null;
|
||||
};
|
||||
export function MapAdmins({ id, access }: { id: string; access: string }) {
|
||||
const { t } = useI18n();
|
||||
const [admins, setAdmins] = useState<MapAdmin[]>([]);
|
||||
const [caller, setCaller] = useState("");
|
||||
const [name, setName] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
const result = await api<{ admins: MapAdmin[]; caller: string }>(
|
||||
`datasets/${id}/admins`,
|
||||
);
|
||||
setAdmins(result.admins);
|
||||
setCaller(result.caller);
|
||||
setError("");
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
}
|
||||
}, [id]);
|
||||
useEffect(() => {
|
||||
load();
|
||||
const timer = setInterval(load, 10000);
|
||||
return () => clearInterval(timer);
|
||||
}, [load]);
|
||||
async function invite(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError("");
|
||||
setMessage("");
|
||||
try {
|
||||
await api(`datasets/${id}/admins`, { name });
|
||||
setName("");
|
||||
setMessage(
|
||||
"Invite sent. Your friend can accept it from their dashboard.",
|
||||
);
|
||||
await load();
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
async function remove(userId: string) {
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
await api(`datasets/${id}/admins/${userId}`, undefined, "DELETE");
|
||||
await load();
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<section className="tool-card">
|
||||
<h2>{t("Map admins")}</h2>
|
||||
<p className="muted">
|
||||
{t(
|
||||
"Invite friends to manage this map with you. They can edit details, choose locations, refresh the map and handle contributions after accepting your invite.",
|
||||
)}
|
||||
</p>
|
||||
{admins.map((a) => (
|
||||
<div className="draft-row" key={a.id}>
|
||||
<span>
|
||||
{a.name}
|
||||
{a.username ? <small className="muted"> @{a.username}</small> : null}{" "}
|
||||
<small className="muted">
|
||||
{a.state === "accepted" ? t("· admin") : t("· invite pending")}
|
||||
</small>
|
||||
</span>
|
||||
{(access === "owner" || a.user_id === caller) && (
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy}
|
||||
onClick={() => remove(a.user_id)}
|
||||
>
|
||||
{a.user_id === caller && access !== "owner"
|
||||
? t("Leave map")
|
||||
: a.state === "accepted"
|
||||
? t("Remove")
|
||||
: t("Cancel invite")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
{access === "owner" && (
|
||||
<form onSubmit={invite}>
|
||||
<label className="field">
|
||||
{t("Player name or username")}
|
||||
<input
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
minLength={1}
|
||||
maxLength={80}
|
||||
/>
|
||||
</label>
|
||||
<button className="button primary" disabled={busy || !name.trim()}>
|
||||
{busy ? t("Sending…") : t("Send invite")}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
{error && (
|
||||
<p role="alert" className="error-message">
|
||||
{t(error)}
|
||||
</p>
|
||||
)}
|
||||
{message && (
|
||||
<p role="status" className="success-message">
|
||||
{t(message)}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user