fix(web): address review findings — workspace ID threading and error handling
All checks were successful
ci/woodpecker/push/web Pipeline was successful

- Thread workspaceId into fetchDomains() so X-Workspace-Id header is sent
- Guard useEffect against null workspaceId with early return; add workspaceId to dep array
- Add catch block in handleCreate to surface errors via setError
- Remove console.log from handleEdit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-27 04:24:46 -06:00
parent 2abb405e5f
commit cb363cfd92
2 changed files with 14 additions and 6 deletions

View File

@@ -367,13 +367,17 @@ export default function DomainsPage(): ReactElement {
const [isCreating, setIsCreating] = useState(false);
useEffect(() => {
if (!workspaceId) {
setIsLoading(false);
return;
}
void loadDomains();
}, []); // loadDomains is defined in this scope and stable
}, [workspaceId]);
async function loadDomains(): Promise<void> {
try {
setIsLoading(true);
const response = await fetchDomains();
const response = await fetchDomains(undefined, workspaceId ?? undefined);
setDomains(response.data);
setError(null);
} catch (err) {
@@ -383,9 +387,8 @@ export default function DomainsPage(): ReactElement {
}
}
function handleEdit(domain: Domain): void {
function handleEdit(_domain: Domain): void {
// TODO: Open edit modal/form
console.log("Edit domain:", domain);
}
async function handleDelete(domain: Domain): Promise<void> {
@@ -407,6 +410,8 @@ export default function DomainsPage(): ReactElement {
await createDomain(data, workspaceId ?? undefined);
setCreateOpen(false);
await loadDomains();
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to create domain.");
} finally {
setIsCreating(false);
}

View File

@@ -44,7 +44,10 @@ export interface DomainFilters {
/**
* Fetch all domains
*/
export async function fetchDomains(filters?: DomainFilters): Promise<ApiResponse<Domain[]>> {
export async function fetchDomains(
filters?: DomainFilters,
workspaceId?: string
): Promise<ApiResponse<Domain[]>> {
const params = new URLSearchParams();
if (filters?.search) {
@@ -60,7 +63,7 @@ export async function fetchDomains(filters?: DomainFilters): Promise<ApiResponse
const queryString = params.toString();
const endpoint = queryString ? `/api/domains?${queryString}` : "/api/domains";
return apiGet<ApiResponse<Domain[]>>(endpoint);
return apiGet<ApiResponse<Domain[]>>(endpoint, workspaceId);
}
/**