2024-11-15 05:05:25 -05:00
|
|
|
import React from "react";
|
|
|
|
|
import { Save } from "lucide-react";
|
|
|
|
|
import { useFlowStore } from "../store/flowStore";
|
|
|
|
|
import { TranslationService } from "../services/TranslationService";
|
2024-11-15 04:44:20 -05:00
|
|
|
|
|
|
|
|
export function SettingsForm() {
|
2024-11-15 05:24:27 -05:00
|
|
|
const { settings, updateSettings, routes } = useFlowStore();
|
2024-11-15 04:44:20 -05:00
|
|
|
|
2024-11-15 05:05:25 -05:00
|
|
|
const handleChange = (
|
|
|
|
|
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>
|
|
|
|
|
) => {
|
2024-11-15 04:44:20 -05:00
|
|
|
updateSettings({
|
|
|
|
|
...settings,
|
|
|
|
|
[e.target.name]: e.target.value,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSave = () => {
|
|
|
|
|
updateSettings(settings);
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-15 05:05:25 -05:00
|
|
|
const handleExportConfiguration = () => {
|
|
|
|
|
const models = useFlowStore.getState().models;
|
2024-11-15 05:24:27 -05:00
|
|
|
const roles = useFlowStore.getState().roles;
|
|
|
|
|
const routes = useFlowStore.getState().routes;
|
|
|
|
|
|
2024-11-15 05:05:25 -05:00
|
|
|
const configuration = {
|
|
|
|
|
models: models.map((model) => TranslationService.translateModel(model)),
|
2024-11-15 05:24:27 -05:00
|
|
|
roles: roles.map((role) => ({
|
|
|
|
|
name: role.name,
|
|
|
|
|
slug: role.slug,
|
|
|
|
|
permissions: {
|
|
|
|
|
...role.permissions,
|
|
|
|
|
routes: role.permissions.routes
|
|
|
|
|
.map((routeId) => {
|
|
|
|
|
const route = routes.find((r) => r.id === routeId);
|
|
|
|
|
return route
|
|
|
|
|
? {
|
|
|
|
|
method: route.method,
|
|
|
|
|
url: route.url,
|
|
|
|
|
}
|
|
|
|
|
: null;
|
|
|
|
|
})
|
|
|
|
|
.filter(Boolean),
|
|
|
|
|
},
|
|
|
|
|
})),
|
2024-11-15 05:05:25 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const blob = new Blob([JSON.stringify(configuration, null, 2)], {
|
|
|
|
|
type: "application/json",
|
|
|
|
|
});
|
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
const a = document.createElement("a");
|
|
|
|
|
a.href = url;
|
2024-11-15 05:24:27 -05:00
|
|
|
a.download = "configuration.json";
|
2024-11-15 05:05:25 -05:00
|
|
|
document.body.appendChild(a);
|
|
|
|
|
a.click();
|
|
|
|
|
document.body.removeChild(a);
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-15 04:44:20 -05:00
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-medium mb-1">Global Key</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="globalKey"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.globalKey || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded"
|
|
|
|
|
placeholder="Enter global key"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-medium mb-1">Database Type</label>
|
|
|
|
|
<select
|
|
|
|
|
name="databaseType"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.databaseType || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded"
|
|
|
|
|
>
|
|
|
|
|
<option value="">Select Database Type</option>
|
|
|
|
|
<option value="mysql">MySQL</option>
|
|
|
|
|
<option value="postgresql">PostgreSQL</option>
|
|
|
|
|
<option value="mongodb">MongoDB</option>
|
|
|
|
|
<option value="sqlite">SQLite</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
2024-11-15 05:05:25 -05:00
|
|
|
<label className="block text-sm font-medium mb-1">
|
|
|
|
|
Authentication Type
|
|
|
|
|
</label>
|
2024-11-15 04:44:20 -05:00
|
|
|
<select
|
|
|
|
|
name="authType"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.authType || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded"
|
|
|
|
|
>
|
|
|
|
|
<option value="session">Session</option>
|
|
|
|
|
<option value="jwt">JWT</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<label className="block text-sm font-medium mb-1">Timezone</label>
|
|
|
|
|
<select
|
|
|
|
|
name="timezone"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.timezone || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded"
|
|
|
|
|
>
|
|
|
|
|
<option value="UTC">UTC</option>
|
|
|
|
|
<option value="America/New_York">America/New_York</option>
|
|
|
|
|
<option value="Europe/London">Europe/London</option>
|
|
|
|
|
<option value="Asia/Tokyo">Asia/Tokyo</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
2024-11-15 05:05:25 -05:00
|
|
|
<label className="block text-sm font-medium">
|
|
|
|
|
Database Credentials
|
|
|
|
|
</label>
|
|
|
|
|
|
2024-11-15 04:44:20 -05:00
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="dbHost"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.dbHost || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded mb-2"
|
|
|
|
|
placeholder="Host"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="dbPort"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.dbPort || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded mb-2"
|
|
|
|
|
placeholder="Port"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="dbUser"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.dbUser || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded mb-2"
|
|
|
|
|
placeholder="Username"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
name="dbPassword"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.dbPassword || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded mb-2"
|
|
|
|
|
placeholder="Password"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
name="dbName"
|
2024-11-15 05:05:25 -05:00
|
|
|
value={settings?.dbName || ""}
|
2024-11-15 04:44:20 -05:00
|
|
|
onChange={handleChange}
|
|
|
|
|
className="w-full p-2 border rounded"
|
|
|
|
|
placeholder="Database Name"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleSave}
|
|
|
|
|
className="w-full flex items-center justify-center gap-2 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
<Save className="w-4 h-4" />
|
|
|
|
|
Save Settings
|
|
|
|
|
</button>
|
2024-11-15 05:05:25 -05:00
|
|
|
|
|
|
|
|
<div className="mt-6">
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleExportConfiguration}
|
|
|
|
|
className="w-full px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600 transition-colors"
|
|
|
|
|
>
|
|
|
|
|
Export Configuration
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-11-15 04:44:20 -05:00
|
|
|
</div>
|
|
|
|
|
);
|
2024-11-15 05:05:25 -05:00
|
|
|
}
|