Fixing up the crud for multiple sites

This commit is contained in:
Owen
2026-04-13 16:22:22 -07:00
parent 676eacc9cf
commit 173a81ead8
7 changed files with 73 additions and 37 deletions

View File

@@ -653,11 +653,7 @@ export default function ClientResourcesTable({
<EditInternalResourceDialog
open={isEditDialogOpen}
setOpen={setIsEditDialogOpen}
resource={{
...editingResource,
siteName: editingResource.siteNames[0] ?? "",
siteId: editingResource.siteIds[0]
}}
resource={editingResource}
orgId={orgId}
onSuccess={() => {
// Delay refresh to allow modal to close smoothly

View File

@@ -67,7 +67,7 @@ export default function CreateInternalResourceDialog({
`/org/${orgId}/site-resource`,
{
name: data.name,
siteId: data.siteIds[0],
siteIds: data.siteIds,
mode: data.mode,
destination: data.destination,
enabled: true,

View File

@@ -15,7 +15,6 @@ import { useEnvContext } from "@app/hooks/useEnvContext";
import { toast } from "@app/hooks/useToast";
import { createApiClient, formatAxiosError } from "@app/lib/api";
import { resourceQueries } from "@app/lib/queries";
import { ListSitesResponse } from "@server/routers/site";
import { useQueryClient } from "@tanstack/react-query";
import { useTranslations } from "next-intl";
import { useState, useTransition } from "react";
@@ -27,8 +26,6 @@ import {
isHostname
} from "./InternalResourceForm";
type Site = ListSitesResponse["sites"][0];
type EditInternalResourceDialogProps = {
open: boolean;
setOpen: (val: boolean) => void;
@@ -69,7 +66,7 @@ export default function EditInternalResourceDialog({
await api.post(`/site-resource/${resource.id}`, {
name: data.name,
siteId: data.siteIds[0],
siteIds: data.siteIds,
mode: data.mode,
niceId: data.niceId,
destination: data.destination,

View File

@@ -136,9 +136,9 @@ export type InternalResourceData = {
id: number;
name: string;
orgId: string;
siteName: string;
siteNames: string[];
mode: InternalResourceMode;
siteId: number;
siteIds: number[];
niceId: string;
destination: string;
alias?: string | null;
@@ -160,13 +160,11 @@ const tagSchema = z.object({ id: z.string(), text: z.string() });
function buildSelectedSitesForResource(
resource: InternalResourceData,
): Selectedsite[] {
return [
{
name: resource.siteName,
siteId: resource.siteId,
type: "newt"
}
];
return resource.siteIds.map((siteId, idx) => ({
name: resource.siteNames[idx] ?? "",
siteId,
type: "newt" as const
}));
}
export type InternalResourceFormValues = {
@@ -483,7 +481,7 @@ export function InternalResourceForm({
variant === "edit" && resource
? {
name: resource.name,
siteIds: [resource.siteId],
siteIds: resource.siteIds,
mode: resource.mode ?? "host",
destination: resource.destination ?? "",
alias: resource.alias ?? null,
@@ -594,7 +592,7 @@ export function InternalResourceForm({
if (resourceChanged) {
form.reset({
name: resource.name,
siteIds: [resource.siteId],
siteIds: resource.siteIds,
mode: resource.mode ?? "host",
destination: resource.destination ?? "",
alias: resource.alias ?? null,