diff --git a/src/app/dashboard/[entity]/page.tsx b/src/app/dashboard/[entity]/page.tsx
index d2173c2..c38dd12 100644
--- a/src/app/dashboard/[entity]/page.tsx
+++ b/src/app/dashboard/[entity]/page.tsx
@@ -1,5 +1,5 @@
import { APPWRITE_ALMEIRA_CONFIG } from '@/lib/appwrite';
-import { createSessionClient } from '@/lib/appwrite.server';
+import { createSessionClient, getLoggedInUser } from '@/lib/appwrite.server';
import { Query } from 'node-appwrite';
import Link from 'next/link';
import { collectionMap, SCHEMA_MAP } from '@/lib/schema';
@@ -42,7 +42,8 @@ export default async function EntityPage({
);
}
- // Fetch preferences
+ // Fetch user and preferences
+ const user = await getLoggedInUser();
const prefs = await getUserPreferences();
const hiddenColumns = prefs.hiddenColumns?.[entity] || [];
@@ -126,6 +127,7 @@ export default async function EntityPage({
initialHiddenColumns={hiddenColumns}
currentSortField={sort}
currentSortDir={dir}
+ user={user}
/>
{/* Pagination */}
diff --git a/src/components/dashboard/DataTable.tsx b/src/components/dashboard/DataTable.tsx
index 2ba1c21..eef26a0 100644
--- a/src/components/dashboard/DataTable.tsx
+++ b/src/components/dashboard/DataTable.tsx
@@ -17,6 +17,7 @@ interface DataTableProps {
initialHiddenColumns: string[];
currentSortField: string;
currentSortDir: 'asc' | 'desc';
+ user: any;
}
export const DataTable = ({
@@ -26,7 +27,8 @@ export const DataTable = ({
fieldsConfig,
initialHiddenColumns,
currentSortField,
- currentSortDir
+ currentSortDir,
+ user
}: DataTableProps) => {
const router = useRouter();
const searchParams = useSearchParams();
@@ -117,8 +119,19 @@ export const DataTable = ({
- {documents.map((doc) => (
-
+ {documents.map((doc) => {
+ const canEdit = user?.$id === 'admin-emergency' || user?.labels?.includes('admin') || user?.labels?.includes('editor');
+
+ return (
+
{
+ if (canEdit) {
+ router.push(`/dashboard/${entity}/${doc.$id}`);
+ }
+ }}
+ >
{fieldsConfig.map(field => {
if (!visibleColumns.includes(field.name)) return null;
@@ -153,7 +166,7 @@ export const DataTable = ({
- ))}
+ )})}
diff --git a/src/components/dashboard/EntityForm.tsx b/src/components/dashboard/EntityForm.tsx
index 9f49076..6e9d26c 100644
--- a/src/components/dashboard/EntityForm.tsx
+++ b/src/components/dashboard/EntityForm.tsx
@@ -7,6 +7,9 @@ import Link from 'next/link';
import { FieldDefinition } from '@/lib/schema';
import { MediaPickerMini } from './MediaPickerMini';
import { RichTextEditor } from './RichTextEditor';
+import { QuickCreateModal } from './QuickCreateModal';
+import { collectionMap } from '@/lib/schema';
+import { Client, Databases } from 'appwrite';
// Minimalistic image preview for relations with 'media'
const MediaPreview = ({ fileId, bucketId, endpoint, projectId }: any) => {
@@ -52,6 +55,11 @@ export const EntityForm = ({
const [isAutoSlug, setIsAutoSlug] = useState(!initialData?.slug);
const [featuredImageId, setFeaturedImageId] = useState(initialData?.imagen_destacada_id || '');
const [editorValues, setEditorValues] = useState>({});
+ const [localRelationData, setLocalRelationData] = useState(relationData);
+ const [activeTab, setActiveTab] = useState('');
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const [modalEntity, setModalEntity] = useState('');
+ const [activeRelationField, setActiveRelationField] = useState('');
// Initialize editor values
useEffect(() => {
@@ -77,6 +85,28 @@ export const EntityForm = ({
}
}, [title, isAutoSlug]);
+ const sections = Array.from(new Set(fields.map(f => f.section || 'General')));
+
+ useEffect(() => {
+ if (sections.length > 0 && !activeTab) {
+ setActiveTab(sections[0]);
+ }
+ }, [sections, activeTab]);
+
+ const refreshRelation = async (field: string, collectionId: string) => {
+ const client = new Client()
+ .setEndpoint(appwriteConfig.endpoint)
+ .setProject(appwriteConfig.projectId);
+ const databases = new Databases(client);
+
+ try {
+ const res = await databases.listDocuments('almeira', collectionId, []);
+ setLocalRelationData(prev => ({ ...prev, [field]: res.documents }));
+ } catch (err) {
+ console.error("Error al refrescar relación:", err);
+ }
+ };
+
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
@@ -123,6 +153,7 @@ export const EntityForm = ({
};
return (
+ <>