feat: implement UI-driven database configuration

This commit is contained in:
Michael committed 2026-02-21 12:09:21 +01:00
1 parent e54e679bd4
commit 0e4c276816
4 files changed
+248 -17

No files matched your search

@@ -0,0 +1,53 @@
"use client";
import { create } from "zustand";
import { persist } from "zustand/middleware";
export interface DatabaseSettings {
host: string;
port: string;
database: string;
user: string;
password?: string;
ssl: boolean;
}
interface DatabaseSettingsState extends DatabaseSettings {
setHost: (host: string) => void;
setPort: (port: string) => void;
setDatabase: (database: string) => void;
setUser: (user: string) => void;
setPassword: (password: string) => void;
setSsl: (ssl: boolean) => void;
getDatabaseUrl: () => string;
}
export const useDbSettingsStore = create<DatabaseSettingsState>()(
persist(
(set, get) => ({
host: "localhost",
port: "5432",
database: "collectflow",
user: "postgres",
password: "",
ssl: false,
setHost: (host) => set({ host }),
setPort: (port) => set({ port }),
setDatabase: (database) => set({ database }),
setUser: (user) => set({ user }),
setPassword: (password) => set({ password }),
setSsl: (ssl) => set({ ssl }),
getDatabaseUrl: () => {
const { user, password, host, port, database, ssl } = get();
const auth = password ? `${user}:${password}` : user;
const url = `postgres://${auth}@${host}:${port}/${database}${ssl ? "?sslmode=require" : ""}`;
return url;
},
}),
{
name: "collectflow-db-settings",
}
)
);