refactor: extract shared validation and reduce duplication

- Extract tool_types validation to shared module (validate_compose_yaml, check_port_exposed, validate_required_variables)
- Extract _get_user and _get_owned_project to auth/dependencies.py
- Create useAsyncData hook and apply to 6 pages
- Create extractErrorMessage utility
- TypeScript and build pass
This commit is contained in:
Alex Blank
2026-05-25 14:01:32 +02:00
parent a905cf729e
commit a37a3122f9
19 changed files with 327 additions and 442 deletions
+1 -10
View File
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useState } from "react";
import { Icon } from "../components/icon";
import { useMobileViewport } from "../hooks/use-mobile-viewport";
import { extractErrorMessage } from "../utils/errors";
import { MobileListView } from "../components/mobile-list-view";
import { MobileDetailView } from "../components/mobile-detail-view";
import { MobileEditView } from "../components/mobile-edit-view";
@@ -201,16 +202,6 @@ export const ToolWorkshopPage = () => {
setShowFolderForm(false);
};
const extractErrorMessage = (err: unknown): string => {
const axiosError = err as { response?: { data?: { detail?: string | Array<{msg?: string}> } } };
const detail = axiosError?.response?.data?.detail;
if (typeof detail === 'string') return detail;
if (Array.isArray(detail)) {
return detail.map(d => typeof d === 'string' ? d : d.msg || JSON.stringify(d)).join(', ');
}
return "Failed to save";
};
const handleToolTypeSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setToolTypeError(null);