feat(storage): split storage permissions and rework manage-storage UI
Deposits/withdrawals of stock (economy-mutating) are now superuser-only, while moving items around (transfer/place/collect) stays open to logistics-qualified users; seed roles updated to match. ManageStorageDialog reworked alongside its toolbar/button/view wrappers, and the structure page wires up the new permission split.
This commit is contained in:
parent
91dc48ad2c
commit
dcb4893b10
7 changed files with 457 additions and 313 deletions
|
|
@ -21,6 +21,7 @@ import { pluralize } from "@/lib/utils";
|
||||||
import type { LaborClassificationOption, StructureStaffingOption } from "@/lib/base";
|
import type { LaborClassificationOption, StructureStaffingOption } from "@/lib/base";
|
||||||
import { currencyConfigFromGameRules } from "@/lib/banking";
|
import { currencyConfigFromGameRules } from "@/lib/banking";
|
||||||
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
|
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
|
||||||
|
import { isSuperuser } from "@/utils/access-control/hasPermission";
|
||||||
import {
|
import {
|
||||||
ArrowLeftIcon,
|
ArrowLeftIcon,
|
||||||
BoxIcon,
|
BoxIcon,
|
||||||
|
|
@ -183,6 +184,8 @@ export default async function StructureDetailPage({ params }: StructureDetailPag
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const canManage = await hasLogisticsQualification(payload, user);
|
const canManage = await hasLogisticsQualification(payload, user);
|
||||||
|
const canManageStorage = await isSuperuser(payload, user);
|
||||||
|
const canTransferStorage = canManageStorage || canManage;
|
||||||
|
|
||||||
const classificationsRes = await payload.find({
|
const classificationsRes = await payload.find({
|
||||||
collection: "labor-classifications",
|
collection: "labor-classifications",
|
||||||
|
|
@ -307,7 +310,13 @@ export default async function StructureDetailPage({ params }: StructureDetailPag
|
||||||
{structure.faction.name}
|
{structure.faction.name}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{user && <ManageStorageButton structureId={structure.id} />}
|
{user && (
|
||||||
|
<ManageStorageButton
|
||||||
|
structureId={structure.id}
|
||||||
|
canManage={canManageStorage}
|
||||||
|
canTransfer={canTransferStorage}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
@ -413,7 +422,11 @@ export default async function StructureDetailPage({ params }: StructureDetailPag
|
||||||
currencyConfig={currencyConfig}
|
currencyConfig={currencyConfig}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<StructureStorageView structure={structure} />
|
<StructureStorageView
|
||||||
|
structure={structure}
|
||||||
|
canMutate={canManageStorage}
|
||||||
|
canArrange={canTransferStorage}
|
||||||
|
/>
|
||||||
|
|
||||||
<StorageRules
|
<StorageRules
|
||||||
allowedStorage={structureType.allowedStorage}
|
allowedStorage={structureType.allowedStorage}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
import config from "@payload-config";
|
import config from "@payload-config";
|
||||||
import { getPayload } from "payload";
|
import { getPayload } from "payload";
|
||||||
import { GameStructure, Resource, Structure } from "@/payload-types";
|
import { GameStructure, Resource, Structure } from "@/payload-types";
|
||||||
import { hasPermission } from "@/utils/access-control/hasPermission";
|
import { isSuperuser } from "@/utils/access-control/hasPermission";
|
||||||
|
import { hasLogisticsQualification } from "@/utils/access-control/hasLogisticsQualification";
|
||||||
import { emitGameEvent } from "@/utils/event-log/emit";
|
import { emitGameEvent } from "@/utils/event-log/emit";
|
||||||
import { EventTypes } from "@/utils/event-log/eventTypes";
|
import { EventTypes } from "@/utils/event-log/eventTypes";
|
||||||
import { checkStorageDeposit, storageViolationMessage } from "@/lib/storageRules";
|
import { checkStorageDeposit, storageViolationMessage } from "@/lib/storageRules";
|
||||||
|
|
@ -14,6 +15,19 @@ interface ActionResult {
|
||||||
data?: GameStructure;
|
data?: GameStructure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PayloadClient = Awaited<ReturnType<typeof getPayload>>;
|
||||||
|
type AuthedUser = Awaited<ReturnType<typeof authenticate>>["user"];
|
||||||
|
|
||||||
|
// SECURITY: creates/destroys stored items, overriding economy/production — superusers only
|
||||||
|
async function canManageStorage(payload: PayloadClient, user: AuthedUser): Promise<boolean> {
|
||||||
|
return isSuperuser(payload, user);
|
||||||
|
}
|
||||||
|
|
||||||
|
// SECURITY: conserves quantities (moves items around) — logistics personnel + superusers
|
||||||
|
async function canHandleStorage(payload: PayloadClient, user: AuthedUser): Promise<boolean> {
|
||||||
|
return (await isSuperuser(payload, user)) || (await hasLogisticsQualification(payload, user));
|
||||||
|
}
|
||||||
|
|
||||||
async function authenticate() {
|
async function authenticate() {
|
||||||
const payloadConfig = await config;
|
const payloadConfig = await config;
|
||||||
const payload = await getPayload({ config: payloadConfig });
|
const payload = await getPayload({ config: payloadConfig });
|
||||||
|
|
@ -74,13 +88,30 @@ export async function addResource(
|
||||||
): Promise<ActionResult> {
|
): Promise<ActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canManageStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Only superusers may deposit resources into structures.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
return await addResourceInternal(payload, user, structureId, resourceId, amount);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (message === "Unauthorized") {
|
||||||
|
return { success: false, error: "You must be logged in." };
|
||||||
|
}
|
||||||
|
return { success: false, error: message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addResourceInternal(
|
||||||
|
payload: PayloadClient,
|
||||||
|
user: AuthedUser,
|
||||||
|
structureId: number,
|
||||||
|
resourceId: number,
|
||||||
|
amount: number,
|
||||||
|
): Promise<ActionResult> {
|
||||||
|
try {
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return { success: false, error: "Amount must be greater than zero." };
|
return { success: false, error: "Amount must be greater than zero." };
|
||||||
}
|
}
|
||||||
|
|
@ -264,13 +295,30 @@ export async function removeResource(
|
||||||
): Promise<ActionResult> {
|
): Promise<ActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canManageStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. Admin or Developer role required for withdrawal.",
|
error: "Only superusers may withdraw resources from structures.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
return await removeResourceInternal(payload, user, structureId, resourceId, amount);
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : "Unknown error";
|
||||||
|
if (message === "Unauthorized") {
|
||||||
|
return { success: false, error: "You must be logged in." };
|
||||||
|
}
|
||||||
|
return { success: false, error: message };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeResourceInternal(
|
||||||
|
payload: PayloadClient,
|
||||||
|
user: AuthedUser,
|
||||||
|
structureId: number,
|
||||||
|
resourceId: number,
|
||||||
|
amount: number,
|
||||||
|
): Promise<ActionResult> {
|
||||||
|
try {
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return { success: false, error: "Amount must be greater than zero." };
|
return { success: false, error: "Amount must be greater than zero." };
|
||||||
}
|
}
|
||||||
|
|
@ -373,10 +421,10 @@ export async function transferResource(
|
||||||
): Promise<ActionResult> {
|
): Promise<ActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required for transfer.",
|
error: "Logistics personnel or superuser role required for transfers.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -464,17 +512,23 @@ export async function transferResource(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from source
|
// Remove from source (unguarded internal — gate already applied above)
|
||||||
const removeResult = await removeResource(fromStructureId, resourceId, amount);
|
const removeResult = await removeResourceInternal(
|
||||||
|
payload,
|
||||||
|
user,
|
||||||
|
fromStructureId,
|
||||||
|
resourceId,
|
||||||
|
amount,
|
||||||
|
);
|
||||||
if (!removeResult.success) {
|
if (!removeResult.success) {
|
||||||
return removeResult;
|
return removeResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to destination
|
// Add to destination
|
||||||
const addResult = await addResource(toStructureId, resourceId, amount);
|
const addResult = await addResourceInternal(payload, user, toStructureId, resourceId, amount);
|
||||||
if (!addResult.success) {
|
if (!addResult.success) {
|
||||||
// Rollback: re-add to source
|
// Rollback: re-add to source
|
||||||
await addResource(fromStructureId, resourceId, amount);
|
await addResourceInternal(payload, user, fromStructureId, resourceId, amount);
|
||||||
return { success: false, error: `Transfer failed at destination: ${addResult.error}` };
|
return { success: false, error: `Transfer failed at destination: ${addResult.error}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -524,10 +578,10 @@ export async function placeResourceOnGrid(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canManageStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. Admin or Developer role required for placement.",
|
error: "Only superusers may place resources on the storage grid.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -641,10 +695,10 @@ export async function moveGridItem(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Logistics personnel or superuser role required.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
|
|
@ -730,10 +784,10 @@ export async function mergeGridStacks(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Logistics personnel or superuser role required.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
|
|
@ -812,10 +866,10 @@ export async function rotateGridItem(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Logistics personnel or superuser role required.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
|
|
@ -899,10 +953,10 @@ export async function removeGridItem(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canManageStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. Admin or Developer role required for removal.",
|
error: "Only superusers may remove items from the storage grid.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
|
|
@ -953,10 +1007,10 @@ export async function splitGridStack(
|
||||||
): Promise<GridActionResult> {
|
): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Logistics personnel or superuser role required.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1061,8 +1115,8 @@ export async function splitGridStack(
|
||||||
export async function retrieveFromVoid(structureId: number): Promise<GridActionResult> {
|
export async function retrieveFromVoid(structureId: number): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return { success: false, error: "Insufficient permissions." };
|
return { success: false, error: "Logistics personnel or superuser role required." };
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
const gridW = structure.type.xSize ?? 0;
|
const gridW = structure.type.xSize ?? 0;
|
||||||
|
|
@ -1159,10 +1213,10 @@ export async function retrieveFromVoid(structureId: number): Promise<GridActionR
|
||||||
export async function autoArrangeGrid(structureId: number): Promise<GridActionResult> {
|
export async function autoArrangeGrid(structureId: number): Promise<GridActionResult> {
|
||||||
try {
|
try {
|
||||||
const { payload, user } = await authenticate();
|
const { payload, user } = await authenticate();
|
||||||
if (!(await hasPermission(payload, user, "structures:update"))) {
|
if (!(await canHandleStorage(payload, user))) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: "Insufficient permissions. User, Admin, or Developer role required.",
|
error: "Logistics personnel or superuser role required.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const structure = await getStructure(payload, structureId);
|
const structure = await getStructure(payload, structureId);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ interface GridToolbarProps {
|
||||||
onRotate: (entryId: string) => Promise<void>;
|
onRotate: (entryId: string) => Promise<void>;
|
||||||
onRemove: (entryId: string) => Promise<void>;
|
onRemove: (entryId: string) => Promise<void>;
|
||||||
onSplit: (entryId: string, amount: number) => Promise<void>;
|
onSplit: (entryId: string, amount: number) => Promise<void>;
|
||||||
|
/** Rearranging/rotating/splitting conserves quantities — logistics personnel or superuser. */
|
||||||
|
canArrange?: boolean;
|
||||||
|
/** Removing grid items destroys stored stock — superuser only. */
|
||||||
|
canMutate?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function GridToolbar({
|
export function GridToolbar({
|
||||||
|
|
@ -37,6 +41,8 @@ export function GridToolbar({
|
||||||
onRotate,
|
onRotate,
|
||||||
onRemove,
|
onRemove,
|
||||||
onSplit,
|
onSplit,
|
||||||
|
canArrange = false,
|
||||||
|
canMutate = false,
|
||||||
}: GridToolbarProps) {
|
}: GridToolbarProps) {
|
||||||
const occupancy = getGridOccupancy(storedResources, gridWidth, gridHeight);
|
const occupancy = getGridOccupancy(storedResources, gridWidth, gridHeight);
|
||||||
const res = selectedItem ? (selectedItem.resource as Resource) : null;
|
const res = selectedItem ? (selectedItem.resource as Resource) : null;
|
||||||
|
|
@ -50,10 +56,12 @@ export function GridToolbar({
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
{canArrange && (
|
||||||
<Button variant="outline" size="sm" onClick={onAutoArrange}>
|
<Button variant="outline" size="sm" onClick={onAutoArrange}>
|
||||||
<ShuffleIcon className="size-3.5 mr-1" />
|
<ShuffleIcon className="size-3.5 mr-1" />
|
||||||
Auto-Arrange
|
Auto-Arrange
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
|
|
@ -86,12 +94,12 @@ export function GridToolbar({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
{res.rotatable !== false && (
|
{canArrange && res.rotatable !== false && (
|
||||||
<Button variant="outline" size="sm" onClick={() => onRotate(selectedItem.id)}>
|
<Button variant="outline" size="sm" onClick={() => onRotate(selectedItem.id)}>
|
||||||
<RotateCwIcon className="size-3.5" />
|
<RotateCwIcon className="size-3.5" />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{res.stackable && selectedItem.amount > 1 && (
|
{canArrange && res.stackable && selectedItem.amount > 1 && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|
@ -101,9 +109,11 @@ export function GridToolbar({
|
||||||
<ScissorsIcon className="size-3.5" />
|
<ScissorsIcon className="size-3.5" />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
{canMutate && (
|
||||||
<Button variant="outline" size="sm" onClick={() => onRemove(selectedItem.id)}>
|
<Button variant="outline" size="sm" onClick={() => onRemove(selectedItem.id)}>
|
||||||
<TrashIcon className="size-3.5" />
|
<TrashIcon className="size-3.5" />
|
||||||
</Button>
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,32 @@ import { ManageStorageDialog } from "@/components/frontend/storage/ManageStorage
|
||||||
|
|
||||||
interface ManageStorageButtonProps {
|
interface ManageStorageButtonProps {
|
||||||
structureId: number;
|
structureId: number;
|
||||||
|
canManage: boolean;
|
||||||
|
canTransfer: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ManageStorageButton({ structureId }: ManageStorageButtonProps) {
|
export function ManageStorageButton({
|
||||||
|
structureId,
|
||||||
|
canManage,
|
||||||
|
canTransfer,
|
||||||
|
}: ManageStorageButtonProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
if (!canManage && !canTransfer) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button variant="outline" size="sm" onClick={() => setOpen(true)}>
|
<Button variant="outline" size="sm" onClick={() => setOpen(true)}>
|
||||||
<SettingsIcon className="size-3.5 mr-1.5" />
|
<SettingsIcon className="size-3.5 mr-1.5" />
|
||||||
Manage
|
Manage
|
||||||
</Button>
|
</Button>
|
||||||
<ManageStorageDialog structureId={structureId} open={open} onOpenChange={setOpen} />
|
<ManageStorageDialog
|
||||||
|
structureId={structureId}
|
||||||
|
open={open}
|
||||||
|
onOpenChange={setOpen}
|
||||||
|
canManage={canManage}
|
||||||
|
canTransfer={canTransfer}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,17 @@ interface ManageStorageDialogProps {
|
||||||
structureId: number;
|
structureId: number;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
|
canManage: boolean;
|
||||||
|
canTransfer: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageStorageDialogProps) {
|
export function ManageStorageDialog({
|
||||||
|
structureId,
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
canManage,
|
||||||
|
canTransfer,
|
||||||
|
}: ManageStorageDialogProps) {
|
||||||
const [structure, setStructure] = useState<(GameStructure & { type: Structure }) | null>(null);
|
const [structure, setStructure] = useState<(GameStructure & { type: Structure }) | null>(null);
|
||||||
const [allStructures, setAllStructures] = useState<(GameStructure & { type: Structure })[]>([]);
|
const [allStructures, setAllStructures] = useState<(GameStructure & { type: Structure })[]>([]);
|
||||||
const [allResources, setAllResources] = useState<Resource[]>([]);
|
const [allResources, setAllResources] = useState<Resource[]>([]);
|
||||||
|
|
@ -641,22 +649,38 @@ export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageS
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Tabs defaultValue="deposit" className="w-full">
|
<Tabs defaultValue={canManage ? "deposit" : "transfer"} className="w-full">
|
||||||
<TabsList className="grid w-full grid-cols-3">
|
<TabsList
|
||||||
|
className={cn(
|
||||||
|
"grid w-full",
|
||||||
|
canManage && canTransfer
|
||||||
|
? "grid-cols-3"
|
||||||
|
: canManage
|
||||||
|
? "grid-cols-2"
|
||||||
|
: "grid-cols-1",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{canManage && (
|
||||||
<TabsTrigger value="deposit" className="flex items-center gap-1.5">
|
<TabsTrigger value="deposit" className="flex items-center gap-1.5">
|
||||||
<ArrowDownToLineIcon className="size-3.5" />
|
<ArrowDownToLineIcon className="size-3.5" />
|
||||||
Deposit
|
Deposit
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
)}
|
||||||
|
{canManage && (
|
||||||
<TabsTrigger value="withdraw" className="flex items-center gap-1.5">
|
<TabsTrigger value="withdraw" className="flex items-center gap-1.5">
|
||||||
<ArrowUpFromLineIcon className="size-3.5" />
|
<ArrowUpFromLineIcon className="size-3.5" />
|
||||||
Withdraw
|
Withdraw
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
)}
|
||||||
|
{canTransfer && (
|
||||||
<TabsTrigger value="transfer" className="flex items-center gap-1.5">
|
<TabsTrigger value="transfer" className="flex items-center gap-1.5">
|
||||||
<ArrowRightLeftIcon className="size-3.5" />
|
<ArrowRightLeftIcon className="size-3.5" />
|
||||||
Transfer
|
Transfer
|
||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
|
)}
|
||||||
</TabsList>
|
</TabsList>
|
||||||
|
|
||||||
|
{canManage && (
|
||||||
<TabsContent value="deposit" className="flex flex-col gap-4 pt-4">
|
<TabsContent value="deposit" className="flex flex-col gap-4 pt-4">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Resource</Label>
|
<Label>Resource</Label>
|
||||||
|
|
@ -699,7 +723,9 @@ export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageS
|
||||||
min="1"
|
min="1"
|
||||||
max={getDepositMax()}
|
max={getDepositMax()}
|
||||||
value={depositAmount}
|
value={depositAmount}
|
||||||
onChange={(e) => setDepositAmount(clampAmount(e.target.value, getDepositMax()))}
|
onChange={(e) =>
|
||||||
|
setDepositAmount(clampAmount(e.target.value, getDepositMax()))
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{getDepositLimitInfoFor(depositResourceId) !== undefined && (
|
{getDepositLimitInfoFor(depositResourceId) !== undefined && (
|
||||||
<span className="text-xs text-muted-foreground">
|
<span className="text-xs text-muted-foreground">
|
||||||
|
|
@ -722,7 +748,9 @@ export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageS
|
||||||
Deposit
|
Deposit
|
||||||
</Button>
|
</Button>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{canManage && (
|
||||||
<TabsContent value="withdraw" className="flex flex-col gap-4 pt-4">
|
<TabsContent value="withdraw" className="flex flex-col gap-4 pt-4">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Resource</Label>
|
<Label>Resource</Label>
|
||||||
|
|
@ -783,7 +811,9 @@ export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageS
|
||||||
Withdraw
|
Withdraw
|
||||||
</Button>
|
</Button>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{canTransfer && (
|
||||||
<TabsContent value="transfer" className="flex flex-col gap-4 pt-4">
|
<TabsContent value="transfer" className="flex flex-col gap-4 pt-4">
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Destination</Label>
|
<Label>Destination</Label>
|
||||||
|
|
@ -900,6 +930,7 @@ export function ManageStorageDialog({ structureId, open, onOpenChange }: ManageS
|
||||||
Transfer
|
Transfer
|
||||||
</Button>
|
</Button>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
)}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,17 @@ function getResourceIcon(type: Resource["type"]) {
|
||||||
|
|
||||||
interface StructureStorageViewProps {
|
interface StructureStorageViewProps {
|
||||||
structure: GameStructure & { type: Structure };
|
structure: GameStructure & { type: Structure };
|
||||||
|
/** Rearranging/rotating/splitting conserves quantities — logistics personnel or superuser. */
|
||||||
|
canArrange?: boolean;
|
||||||
|
/** Removing grid items / withdrawing destroys stored stock — superuser only. */
|
||||||
|
canMutate?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
export function StructureStorageView({
|
||||||
|
structure,
|
||||||
|
canArrange = false,
|
||||||
|
canMutate = false,
|
||||||
|
}: StructureStorageViewProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [viewMode, setViewMode] = useState<"grid" | "list">("grid");
|
const [viewMode, setViewMode] = useState<"grid" | "list">("grid");
|
||||||
const [selectedItem, setSelectedItem] = useState<GridItem | null>(null);
|
const [selectedItem, setSelectedItem] = useState<GridItem | null>(null);
|
||||||
|
|
@ -80,64 +88,72 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
|
|
||||||
const handleMoveItem = useCallback(
|
const handleMoveItem = useCallback(
|
||||||
async (entryId: string, gridX: number, gridY: number, rotated?: boolean) => {
|
async (entryId: string, gridX: number, gridY: number, rotated?: boolean) => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await moveGridItem(structure.id, entryId, gridX, gridY, rotated);
|
const result = await moveGridItem(structure.id, entryId, gridX, gridY, rotated);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canArrange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleMergeStacks = useCallback(
|
const handleMergeStacks = useCallback(
|
||||||
async (sourceId: string, targetId: string) => {
|
async (sourceId: string, targetId: string) => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await mergeGridStacks(structure.id, sourceId, targetId);
|
const result = await mergeGridStacks(structure.id, sourceId, targetId);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canArrange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRotateItem = useCallback(
|
const handleRotateItem = useCallback(
|
||||||
async (entryId: string) => {
|
async (entryId: string) => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await rotateGridItem(structure.id, entryId);
|
const result = await rotateGridItem(structure.id, entryId);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canArrange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRemoveItem = useCallback(
|
const handleRemoveItem = useCallback(
|
||||||
async (entryId: string) => {
|
async (entryId: string) => {
|
||||||
|
if (!canMutate) return;
|
||||||
const result = await removeGridItem(structure.id, entryId);
|
const result = await removeGridItem(structure.id, entryId);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
setSelectedItem(null);
|
setSelectedItem(null);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canMutate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSplitStack = useCallback(
|
const handleSplitStack = useCallback(
|
||||||
async (entryId: string, amount: number) => {
|
async (entryId: string, amount: number) => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await splitGridStack(structure.id, entryId, amount);
|
const result = await splitGridStack(structure.id, entryId, amount);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canArrange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleAutoArrange = useCallback(async () => {
|
const handleAutoArrange = useCallback(async () => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await autoArrangeGrid(structure.id);
|
const result = await autoArrangeGrid(structure.id);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
}, [structure.id, refresh]);
|
}, [structure.id, refresh, canArrange]);
|
||||||
|
|
||||||
const handleWithdrawFromVoid = useCallback(
|
const handleWithdrawFromVoid = useCallback(
|
||||||
async (resourceId: number, amount: number) => {
|
async (resourceId: number, amount: number) => {
|
||||||
|
if (!canMutate) return;
|
||||||
const result = await removeResource(structure.id, resourceId, amount);
|
const result = await removeResource(structure.id, resourceId, amount);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
},
|
},
|
||||||
[structure.id, refresh],
|
[structure.id, refresh, canMutate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleRetrieveFromVoid = useCallback(async () => {
|
const handleRetrieveFromVoid = useCallback(async () => {
|
||||||
|
if (!canArrange) return;
|
||||||
const result = await retrieveFromVoid(structure.id);
|
const result = await retrieveFromVoid(structure.id);
|
||||||
if (result.success) refresh();
|
if (result.success) refresh();
|
||||||
}, [structure.id, refresh]);
|
}, [structure.id, refresh, canArrange]);
|
||||||
|
|
||||||
if (!hasGrid) {
|
if (!hasGrid) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -179,6 +195,8 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
onRotate={handleRotateItem}
|
onRotate={handleRotateItem}
|
||||||
onRemove={handleRemoveItem}
|
onRemove={handleRemoveItem}
|
||||||
onSplit={handleSplitStack}
|
onSplit={handleSplitStack}
|
||||||
|
canArrange={canArrange}
|
||||||
|
canMutate={canMutate}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{viewMode === "grid" ? (
|
{viewMode === "grid" ? (
|
||||||
|
|
@ -213,6 +231,7 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
{voidStorageItems.length} item{voidStorageItems.length !== 1 ? "s" : ""}: these no
|
{voidStorageItems.length} item{voidStorageItems.length !== 1 ? "s" : ""}: these no
|
||||||
longer fit in the grid.
|
longer fit in the grid.
|
||||||
</span>
|
</span>
|
||||||
|
{canArrange && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={handleRetrieveFromVoid}
|
onClick={handleRetrieveFromVoid}
|
||||||
|
|
@ -220,6 +239,7 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
>
|
>
|
||||||
Retrieve All to Grid
|
Retrieve All to Grid
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</ItemDescription>
|
</ItemDescription>
|
||||||
</ItemHeader>
|
</ItemHeader>
|
||||||
<ItemContent>
|
<ItemContent>
|
||||||
|
|
@ -262,6 +282,7 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
{mass > 0 && `${mass.toLocaleString()} kg`}
|
{mass > 0 && `${mass.toLocaleString()} kg`}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{canMutate && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleWithdrawFromVoid(entry.resourceId, entry.amount)}
|
onClick={() => handleWithdrawFromVoid(entry.resourceId, entry.amount)}
|
||||||
|
|
@ -270,6 +291,7 @@ export function StructureStorageView({ structure }: StructureStorageViewProps) {
|
||||||
>
|
>
|
||||||
Withdraw
|
Withdraw
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
{index < voidStorageItems.length - 1 && <ItemSeparator />}
|
{index < voidStorageItems.length - 1 && <ItemSeparator />}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ const USER_PERMISSIONS: Permission[] = [
|
||||||
"shims:read",
|
"shims:read",
|
||||||
"shipments:create",
|
"shipments:create",
|
||||||
"shipments:update",
|
"shipments:update",
|
||||||
"structures:update",
|
|
||||||
"structures:delete",
|
"structures:delete",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -87,6 +86,7 @@ const ADMIN_PERMISSIONS: Permission[] = [
|
||||||
"discord:staff",
|
"discord:staff",
|
||||||
"discord:announce",
|
"discord:announce",
|
||||||
"structures:create",
|
"structures:create",
|
||||||
|
"structures:update",
|
||||||
...ALL_COLLECTION_READS,
|
...ALL_COLLECTION_READS,
|
||||||
...ALL_ADMIN_PAGE_MANAGE,
|
...ALL_ADMIN_PAGE_MANAGE,
|
||||||
]),
|
]),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue