fix(web): address review findings — workspace ID threading and error handling
All checks were successful
ci/woodpecker/push/web Pipeline was successful
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:
@@ -367,13 +367,17 @@ export default function DomainsPage(): ReactElement {
|
|||||||
const [isCreating, setIsCreating] = useState(false);
|
const [isCreating, setIsCreating] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!workspaceId) {
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
void loadDomains();
|
void loadDomains();
|
||||||
}, []); // loadDomains is defined in this scope and stable
|
}, [workspaceId]);
|
||||||
|
|
||||||
async function loadDomains(): Promise<void> {
|
async function loadDomains(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const response = await fetchDomains();
|
const response = await fetchDomains(undefined, workspaceId ?? undefined);
|
||||||
setDomains(response.data);
|
setDomains(response.data);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} 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
|
// TODO: Open edit modal/form
|
||||||
console.log("Edit domain:", domain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDelete(domain: Domain): Promise<void> {
|
async function handleDelete(domain: Domain): Promise<void> {
|
||||||
@@ -407,6 +410,8 @@ export default function DomainsPage(): ReactElement {
|
|||||||
await createDomain(data, workspaceId ?? undefined);
|
await createDomain(data, workspaceId ?? undefined);
|
||||||
setCreateOpen(false);
|
setCreateOpen(false);
|
||||||
await loadDomains();
|
await loadDomains();
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Failed to create domain.");
|
||||||
} finally {
|
} finally {
|
||||||
setIsCreating(false);
|
setIsCreating(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ export interface DomainFilters {
|
|||||||
/**
|
/**
|
||||||
* Fetch all domains
|
* 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();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (filters?.search) {
|
if (filters?.search) {
|
||||||
@@ -60,7 +63,7 @@ export async function fetchDomains(filters?: DomainFilters): Promise<ApiResponse
|
|||||||
const queryString = params.toString();
|
const queryString = params.toString();
|
||||||
const endpoint = queryString ? `/api/domains?${queryString}` : "/api/domains";
|
const endpoint = queryString ? `/api/domains?${queryString}` : "/api/domains";
|
||||||
|
|
||||||
return apiGet<ApiResponse<Domain[]>>(endpoint);
|
return apiGet<ApiResponse<Domain[]>>(endpoint, workspaceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user