1 Commits

Author SHA1 Message Date
0df61e3574 feat: update API calls to match remote changes. fixes #33 2026-07-06 17:20:06 +03:00
8 changed files with 48 additions and 19 deletions

4
.gitignore vendored
View File

@@ -24,4 +24,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts
changes.md

View File

@@ -31,7 +31,7 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog"
import { ApiClient, SYS_ADMINS_API, type TableMetadata, type Admin, type AppSettings } from "@/lib/api"
import { ApiClient, SYS_ADMINS_API, SYS_SETTINGS_API, type TableMetadata, type Admin, type AppSettings } from "@/lib/api"
import { DatabaseSection } from "./database/database-section"
import { AdminsSection } from "./admins/admins-section"
import { SettingsSection } from "./settings/settings-section"
@@ -148,8 +148,7 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
}, [route.path, loadAdmins])
const loadData = async () => {
// Set default settings if loading fails
setSettings({
const defaultSettings: AppSettings = {
appName: "ACME Mantis Project",
baseUrl: "http://127.0.0.1:7070",
mantisVersion: "0.0.0",
@@ -160,13 +159,16 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
sessionTimeout: 84000,
adminSessionTimeout: 3600,
mode: mode,
})
}
setSettings(defaultSettings)
try {
setLoading(true)
// Only load tables on initial load
const tablesData = await apiClient.call<any>("/api/v1/schemas")
const [tablesData, settingsData] = await Promise.all([
apiClient.call<any>("/api/v1/schemas"),
apiClient.call<AppSettings>(SYS_SETTINGS_API).catch(() => null),
])
// Ensure tablesData is an array - handle different response structures
let tablesArray: TableMetadata[] = []
@@ -177,6 +179,10 @@ export function AdminDashboard({ token, onLogout }: AdminDashboardProps) {
}
setTables(tablesArray)
if (settingsData && !settingsData?.error) {
setSettings({ ...settingsData, mode })
}
} catch (error) {
console.error("Failed to load data:", error)
} finally {

View File

@@ -17,7 +17,7 @@ import {
} from "@/components/ui/drawer"
import { ScrollArea } from "@/components/ui/scroll-area"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { ApiClient, TableMetadata, getApiBaseUrl, TableField } from "@/lib/api"
import { ApiClient, TableMetadata, entityFileUrl, TableField } from "@/lib/api"
import { useToast } from "@/hooks/use-toast"
interface EditItemDrawerProps {
@@ -57,7 +57,7 @@ const FilePreviewField = ({
const getFileUrl = (file: File | string): string => {
if (typeof file === "string") {
return `${getApiBaseUrl()}/api/files/${table.schema.name}/${encodeURIComponent(file)}`;
return entityFileUrl(table.schema.name, file);
}
return URL.createObjectURL(file); // for newly selected files
};

View File

@@ -8,7 +8,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { Checkbox } from "@/components/ui/checkbox"
import { Input } from "@/components/ui/input"
import { ApiClient, TableMetadata, getApiBaseUrl } from "@/lib/api"
import { ApiClient, TableMetadata, entityFileUrl } from "@/lib/api"
import { TableConfigDrawer } from "./table-config-drawer"
import { TableRecordDocsDrawer } from "./table-records-docs-drawer"
import { EditItemDrawer } from "./edit-item-drawer"
@@ -242,7 +242,7 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate, onTab
return (
<div className="flex gap-2 flex-wrap">
{filenames.map((filename: string, i: number) => {
const url = `${getApiBaseUrl()}/api/files/${table.schema.name}/${encodeURIComponent(filename)}`;
const url = entityFileUrl(table.schema.name, filename);
const ext = filename.split(".").pop()?.toLowerCase() || "";
const isImage = ["jpg", "jpeg", "png", "gif", "webp", "bmp", "svg"].includes(ext);

View File

@@ -7,7 +7,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Switch } from "@/components/ui/switch"
import type { ApiClient, AppSettings } from "@/lib/api"
import { SYS_SETTINGS_API, type ApiClient, type AppSettings } from "@/lib/api"
import { useToast } from "@/hooks/use-toast"
import { useAppState, type AppMode } from "@/lib/app-state"
@@ -108,7 +108,7 @@ export function SettingsSection({ apiClient, settings, onSettingsUpdate, onModeC
setIsLoading({ ...isLoading, [cardType]: true })
try {
const updatedSettings = await apiClient.call<AppSettings>("/api/v1/settings/config", {
const updatedSettings = await apiClient.call<AppSettings>(SYS_SETTINGS_API, {
method: "PATCH",
body: JSON.stringify(formData),
})
@@ -141,7 +141,7 @@ export function SettingsSection({ apiClient, settings, onSettingsUpdate, onModeC
const handleRefresh = async () => {
setIsRefreshing(true)
try {
const updatedSettings = await apiClient.call<AppSettings>("/api/v1/settings/config")
const updatedSettings = await apiClient.call<AppSettings>(SYS_SETTINGS_API)
// If the request failed, throw the error here
if (updatedSettings?.error?.length > 0) throw updatedSettings.error

View File

@@ -9,7 +9,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Alert, AlertDescription } from "@/components/ui/alert"
import { ApiClient } from "@/lib/api"
import { ApiClient, SYS_ADMINS_SETUP_API } from "@/lib/api"
import { useAppState } from "@/lib/app-state"
import { useToast } from "@/hooks/use-toast"
@@ -57,7 +57,7 @@ export function SetupForm({ token, onSetupComplete }: SetupFormProps) {
try {
// Create admin account using the setup token
const response: any = await apiClient.call("/api/v1/auth/setup/admin", {
const response: any = await apiClient.call(SYS_ADMINS_SETUP_API, {
method: "POST",
body: JSON.stringify({
email,

View File

@@ -71,6 +71,17 @@ export interface Admin {
/** System admin REST API (list, CRUD). Login: `${SYS_ADMINS_API}/login`. */
export const SYS_ADMINS_API = "/api/v1/sys/admins" as const
/** Initial admin setup (one-time, requires setup token). */
export const SYS_ADMINS_SETUP_API = "/api/v1/sys/admins/setup" as const
/** System settings config endpoint. */
export const SYS_SETTINGS_API = "/api/v1/sys/settings/config" as const
/** Build a file download URL for an entity record attachment. */
export function entityFileUrl(entity: string, filename: string): string {
return `${getApiBaseUrl()}/api/v1/files/${entity}/${encodeURIComponent(filename)}`
}
/** Backend API base URL. Override with NEXT_PUBLIC_MANTIS_BASE_URL (e.g. https://api.example.com) to use an external backend. */
export function getApiBaseUrl(): string {
const override = process.env.NEXT_PUBLIC_MANTIS_BASE_URL

16
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "mantisbase-admin",
"version": "0.3.8",
"version": "0.3.9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mantisbase-admin",
"version": "0.3.6",
"version": "0.3.9",
"dependencies": {
"@hookform/resolvers": "^3.9.1",
"@radix-ui/react-accordion": "1.2.2",
@@ -3132,6 +3132,7 @@
"integrity": "sha512-/LDXMQh55EzZQ0uVAZmKKhfENivEvWz6E+EYzh+/MCjMhNsotd+ZHhBGIjFDTi6+fz0OhQQQLbTgdQIxxCsC0w==",
"devOptional": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.0.2"
@@ -3143,6 +3144,7 @@
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
"devOptional": true,
"license": "MIT",
"peer": true,
"peerDependencies": {
"@types/react": "^18.0.0"
}
@@ -3303,6 +3305,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"caniuse-lite": "^1.0.30001726",
"electron-to-chromium": "^1.5.173",
@@ -3645,6 +3648,7 @@
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
"integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
"license": "MIT",
"peer": true,
"dependencies": {
"@babel/runtime": "^7.21.0"
},
@@ -3716,7 +3720,8 @@
"version": "8.5.1",
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.5.1.tgz",
"integrity": "sha512-JUb5+FOHobSiWQ2EJNaueCNT/cQU9L6XWBbWmorWPQT9bkbk+fhsuLr8wWrzXKagO3oWszBO7MSx+GfaRk4E6A==",
"license": "MIT"
"license": "MIT",
"peer": true
},
"node_modules/embla-carousel-react": {
"version": "8.5.1",
@@ -4404,6 +4409,7 @@
}
],
"license": "MIT",
"peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@@ -4535,6 +4541,7 @@
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0"
},
@@ -4561,6 +4568,7 @@
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
"license": "MIT",
"peer": true,
"dependencies": {
"loose-envify": "^1.1.0",
"scheduler": "^0.23.2"
@@ -4574,6 +4582,7 @@
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.58.1.tgz",
"integrity": "sha512-Lml/KZYEEFfPhUVgE0RdCVpnC4yhW+PndRhbiTtdvSlQTL8IfVR+iQkBjLIvmmc6+GGoVeM11z37ktKFPAb0FA==",
"license": "MIT",
"peer": true,
"engines": {
"node": ">=18.0.0"
},
@@ -5109,6 +5118,7 @@
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
"license": "MIT",
"peer": true,
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"arg": "^5.0.2",