fix(web): add workspace context to domain and project creation #536
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user