From 1ea5d70675c9a0aa8d3e8fa6d69115ff3e7ed5f0 Mon Sep 17 00:00:00 2001 From: Carlos Narro Date: Mon, 1 Jun 2026 13:51:00 +0200 Subject: [PATCH] =?UTF-8?q?Redise=C3=B1a=20panel=20y=20auth=20con=20la=20i?= =?UTF-8?q?dentidad=20de=20la=20landing=20B2C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Vista de leads en tarjetas + tabla con toggle (tarjetas por defecto, preferencia persistida) - Galería de trabajos: gestión en /panel/galeria y bloque público en el funnel - Selector de tema por reformista (presets + color de marca opcional) aplicado a la landing - Login y registro rediseñados a pantalla partida 50/50 con foto de reforma - Enlace "Entrar" funcional en la cabecera del funnel; elimina Navbar muerto - Unifica tipografía y botones del panel con los tokens de la landing Co-Authored-By: Claude Opus 4.7 --- mvp/b2c/drizzle/0007_pale_chat.sql | 13 + mvp/b2c/drizzle/meta/0007_snapshot.json | 1583 +++++++++++++++++ mvp/b2c/drizzle/meta/_journal.json | 7 + mvp/b2c/src/app/[slug]/page.tsx | 21 +- mvp/b2c/src/app/globals.css | 38 + mvp/b2c/src/app/login/page.tsx | 46 +- mvp/b2c/src/app/panel/empresa/actions.ts | 22 + mvp/b2c/src/app/panel/empresa/page.tsx | 14 +- mvp/b2c/src/app/panel/galeria/actions.ts | 56 + mvp/b2c/src/app/panel/galeria/page.tsx | 73 + mvp/b2c/src/app/panel/layout.tsx | 3 +- mvp/b2c/src/app/panel/opiniones/page.tsx | 2 +- mvp/b2c/src/app/panel/page.tsx | 116 +- mvp/b2c/src/app/panel/precios/page.tsx | 2 +- mvp/b2c/src/app/signup/page.tsx | 70 +- mvp/b2c/src/components/AppNav.tsx | 8 + mvp/b2c/src/components/Hero/Hero.tsx | 14 +- mvp/b2c/src/components/Navbar/Navbar.tsx | 142 -- mvp/b2c/src/components/auth/AuthShell.tsx | 46 + .../src/components/funnel/GaleriaTrabajos.tsx | 54 + mvp/b2c/src/components/funnel/TenantBrand.tsx | 39 +- .../src/components/panel/GaleriaUploader.tsx | 69 + mvp/b2c/src/components/panel/LeadsView.tsx | 279 +++ mvp/b2c/src/components/panel/ThemePicker.tsx | 152 ++ mvp/b2c/src/db/schema.ts | 21 + mvp/b2c/src/db/tenant-queries.ts | 20 +- mvp/b2c/src/lib/funnel.ts | 22 +- mvp/b2c/src/lib/funnel/public-queries.ts | 21 + mvp/b2c/src/lib/funnel/themes.ts | 124 ++ mvp/b2c/src/lib/galeria.ts | 3 + 30 files changed, 2797 insertions(+), 283 deletions(-) create mode 100644 mvp/b2c/drizzle/0007_pale_chat.sql create mode 100644 mvp/b2c/drizzle/meta/0007_snapshot.json create mode 100644 mvp/b2c/src/app/panel/galeria/actions.ts create mode 100644 mvp/b2c/src/app/panel/galeria/page.tsx delete mode 100644 mvp/b2c/src/components/Navbar/Navbar.tsx create mode 100644 mvp/b2c/src/components/auth/AuthShell.tsx create mode 100644 mvp/b2c/src/components/funnel/GaleriaTrabajos.tsx create mode 100644 mvp/b2c/src/components/panel/GaleriaUploader.tsx create mode 100644 mvp/b2c/src/components/panel/LeadsView.tsx create mode 100644 mvp/b2c/src/components/panel/ThemePicker.tsx create mode 100644 mvp/b2c/src/lib/funnel/themes.ts create mode 100644 mvp/b2c/src/lib/galeria.ts diff --git a/mvp/b2c/drizzle/0007_pale_chat.sql b/mvp/b2c/drizzle/0007_pale_chat.sql new file mode 100644 index 0000000..49973b1 --- /dev/null +++ b/mvp/b2c/drizzle/0007_pale_chat.sql @@ -0,0 +1,13 @@ +CREATE TABLE "galeria_fotos" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "tenant_id" uuid NOT NULL, + "url" text NOT NULL, + "titulo" text, + "orden" integer DEFAULT 0 NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "tenants" ADD COLUMN "theme_preset" text DEFAULT 'pizarra' NOT NULL;--> statement-breakpoint +ALTER TABLE "tenants" ADD COLUMN "theme_color" text;--> statement-breakpoint +ALTER TABLE "galeria_fotos" ADD CONSTRAINT "galeria_fotos_tenant_id_tenants_id_fk" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +CREATE INDEX "galeria_tenant_idx" ON "galeria_fotos" USING btree ("tenant_id"); \ No newline at end of file diff --git a/mvp/b2c/drizzle/meta/0007_snapshot.json b/mvp/b2c/drizzle/meta/0007_snapshot.json new file mode 100644 index 0000000..4964861 --- /dev/null +++ b/mvp/b2c/drizzle/meta/0007_snapshot.json @@ -0,0 +1,1583 @@ +{ + "id": "97f9780b-4aa5-45e4-96d5-f4b7d8334a11", + "prevId": "a8e37a10-3711-4a96-bbd5-3031dcbac788", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.catalog_items": { + "name": "catalog_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "categoria": { + "name": "categoria", + "type": "categoria_material", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "calidad": { + "name": "calidad", + "type": "calidad", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "precio_unit": { + "name": "precio_unit", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "unidad": { + "name": "unidad", + "type": "unidad_medida", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "descriptor_render": { + "name": "descriptor_render", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "es_default": { + "name": "es_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sku": { + "name": "sku", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "catalog_tenant_idx": { + "name": "catalog_tenant_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "catalog_tenant_sku_idx": { + "name": "catalog_tenant_sku_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sku", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_items_tenant_id_tenants_id_fk": { + "name": "catalog_items_tenant_id_tenants_id_fk", + "tableFrom": "catalog_items", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.galeria_fotos": { + "name": "galeria_fotos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "galeria_tenant_idx": { + "name": "galeria_tenant_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "galeria_fotos_tenant_id_tenants_id_fk": { + "name": "galeria_fotos_tenant_id_tenants_id_fk", + "tableFrom": "galeria_fotos", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lead_estado_history": { + "name": "lead_estado_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "estado": { + "name": "estado", + "type": "lead_estado", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "changed_at": { + "name": "changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "changed_by": { + "name": "changed_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "lead_estado_history_lead_id_leads_id_fk": { + "name": "lead_estado_history_lead_id_leads_id_fk", + "tableFrom": "lead_estado_history", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lead_fotos": { + "name": "lead_fotos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "lead_fotos_lead_id_leads_id_fk": { + "name": "lead_fotos_lead_id_leads_id_fk", + "tableFrom": "lead_fotos", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.lead_pipeline_eventos": { + "name": "lead_pipeline_eventos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "stage": { + "name": "stage", + "type": "pipeline_stage", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "lead_pipeline_eventos_lead_id_leads_id_fk": { + "name": "lead_pipeline_eventos_lead_id_leads_id_fk", + "tableFrom": "lead_pipeline_eventos", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.leads": { + "name": "leads", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "telefono": { + "name": "telefono", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provincia": { + "name": "provincia", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tipo_reforma": { + "name": "tipo_reforma", + "type": "tipo_reforma", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "consent_privacidad": { + "name": "consent_privacidad", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "consent_contratacion": { + "name": "consent_contratacion", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pipeline_stage": { + "name": "pipeline_stage", + "type": "pipeline_stage", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'form_completado'" + }, + "estado": { + "name": "estado", + "type": "lead_estado", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'nuevo'" + }, + "presupuesto_estimado": { + "name": "presupuesto_estimado", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "transcripcion": { + "name": "transcripcion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entidades": { + "name": "entidades", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "render_url": { + "name": "render_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pdf_url": { + "name": "pdf_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "audio_url": { + "name": "audio_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notas": { + "name": "notas", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "testimonio_solicitado_at": { + "name": "testimonio_solicitado_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "m2_suelo": { + "name": "m2_suelo", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "altura_techo": { + "name": "altura_techo", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "calidad_global": { + "name": "calidad_global", + "type": "calidad", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "estructural": { + "name": "estructural", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "material_selections": { + "name": "material_selections", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "desglose_snapshot": { + "name": "desglose_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "urgencia": { + "name": "urgencia", + "type": "urgencia", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "presupuesto_target": { + "name": "presupuesto_target", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "taste_text": { + "name": "taste_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "preferences_snapshot": { + "name": "preferences_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "leads_tenant_created_idx": { + "name": "leads_tenant_created_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "leads_estado_idx": { + "name": "leads_estado_idx", + "columns": [ + { + "expression": "estado", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "leads_tenant_id_tenants_id_fk": { + "name": "leads_tenant_id_tenants_id_fk", + "tableFrom": "leads", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.plans": { + "name": "plans", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "precio_mensual": { + "name": "precio_mensual", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "leads_incluidos": { + "name": "leads_incluidos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "features": { + "name": "features", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "activo": { + "name": "activo", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "plans_slug_unique": { + "name": "plans_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.precision_history": { + "name": "precision_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "estimated": { + "name": "estimated", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "final": { + "name": "final", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "delta_pct": { + "name": "delta_pct", + "type": "numeric(6, 2)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "precision_history_lead_id_leads_id_fk": { + "name": "precision_history_lead_id_leads_id_fk", + "tableFrom": "precision_history", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pricing_config": { + "name": "pricing_config", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "altura_techo_default": { + "name": "altura_techo_default", + "type": "double precision", + "primaryKey": false, + "notNull": true, + "default": 2.5 + }, + "factor_zona": { + "name": "factor_zona", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "mano_obra": { + "name": "mano_obra", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pricing_config_tenant_id_tenants_id_fk": { + "name": "pricing_config_tenant_id_tenants_id_fk", + "tableFrom": "pricing_config", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pricing_config_tenant_id_unique": { + "name": "pricing_config_tenant_id_unique", + "nullsNotDistinct": false, + "columns": [ + "tenant_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sessions_user_idx": { + "name": "sessions_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "sessions_token_hash_unique": { + "name": "sessions_token_hash_unique", + "nullsNotDistinct": false, + "columns": [ + "token_hash" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tenants": { + "name": "tenants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre_empresa": { + "name": "nombre_empresa", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "logo_url": { + "name": "logo_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provincia": { + "name": "provincia", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "whatsapp_business": { + "name": "whatsapp_business", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "seo_title": { + "name": "seo_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "seo_description": { + "name": "seo_description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "about_enabled": { + "name": "about_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "about_foto_url": { + "name": "about_foto_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "about_texto": { + "name": "about_texto", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "anios_experiencia": { + "name": "anios_experiencia", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "theme_preset": { + "name": "theme_preset", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pizarra'" + }, + "theme_color": { + "name": "theme_color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cif": { + "name": "cif", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "direccion": { + "name": "direccion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "telefono": { + "name": "telefono", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "web": { + "name": "web", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plan_id": { + "name": "plan_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "subscription_status": { + "name": "subscription_status", + "type": "subscription_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'trial'" + }, + "envio_presupuesto": { + "name": "envio_presupuesto", + "type": "envio_presupuesto_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'automatico'" + }, + "trial_ends_at": { + "name": "trial_ends_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tenants_plan_id_plans_id_fk": { + "name": "tenants_plan_id_plans_id_fk", + "tableFrom": "tenants", + "tableTo": "plans", + "columnsFrom": [ + "plan_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tenants_slug_unique": { + "name": "tenants_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.testimonio_fotos": { + "name": "testimonio_fotos", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "testimonio_id": { + "name": "testimonio_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "testimonio_fotos_testimonio_id_testimonios_id_fk": { + "name": "testimonio_fotos_testimonio_id_testimonios_id_fk", + "tableFrom": "testimonio_fotos", + "tableTo": "testimonios", + "columnsFrom": [ + "testimonio_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.testimonios": { + "name": "testimonios", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "lead_id": { + "name": "lead_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contexto": { + "name": "contexto", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "texto": { + "name": "texto", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "estado": { + "name": "estado", + "type": "testimonio_estado", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pendiente'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "testimonios_tenant_estado_idx": { + "name": "testimonios_tenant_estado_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "estado", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "testimonios_lead_idx": { + "name": "testimonios_lead_idx", + "columns": [ + { + "expression": "lead_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "testimonios_tenant_id_tenants_id_fk": { + "name": "testimonios_tenant_id_tenants_id_fk", + "tableFrom": "testimonios", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "testimonios_lead_id_leads_id_fk": { + "name": "testimonios_lead_id_leads_id_fk", + "tableFrom": "testimonios", + "tableTo": "leads", + "columnsFrom": [ + "lead_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "user_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'reformista'" + }, + "tenant_id": { + "name": "tenant_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "user_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'activo'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "users_tenant_idx": { + "name": "users_tenant_idx", + "columns": [ + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "users_tenant_id_tenants_id_fk": { + "name": "users_tenant_id_tenants_id_fk", + "tableFrom": "users", + "tableTo": "tenants", + "columnsFrom": [ + "tenant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.calidad": { + "name": "calidad", + "schema": "public", + "values": [ + "basica", + "media", + "premium" + ] + }, + "public.categoria_material": { + "name": "categoria_material", + "schema": "public", + "values": [ + "suelo", + "pared", + "pintura", + "mobiliario" + ] + }, + "public.envio_presupuesto_mode": { + "name": "envio_presupuesto_mode", + "schema": "public", + "values": [ + "automatico", + "revision" + ] + }, + "public.lead_estado": { + "name": "lead_estado", + "schema": "public", + "values": [ + "nuevo", + "contactado", + "visita_agendada", + "presupuesto_enviado", + "ganado", + "perdido" + ] + }, + "public.pipeline_stage": { + "name": "pipeline_stage", + "schema": "public", + "values": [ + "form_completado", + "fotos_subidas", + "prellamada_enviada", + "llamada_completada", + "render_generado", + "presupuesto_generado", + "whatsapp_entregado" + ] + }, + "public.subscription_status": { + "name": "subscription_status", + "schema": "public", + "values": [ + "trial", + "activo", + "cancelado", + "vencido" + ] + }, + "public.testimonio_estado": { + "name": "testimonio_estado", + "schema": "public", + "values": [ + "pendiente", + "publicado", + "oculto" + ] + }, + "public.tipo_reforma": { + "name": "tipo_reforma", + "schema": "public", + "values": [ + "cocina", + "bano", + "salon", + "comedor", + "integral", + "otro" + ] + }, + "public.unidad_medida": { + "name": "unidad_medida", + "schema": "public", + "values": [ + "m2", + "ml", + "ud" + ] + }, + "public.urgencia": { + "name": "urgencia", + "schema": "public", + "values": [ + "alta", + "media", + "baja" + ] + }, + "public.user_role": { + "name": "user_role", + "schema": "public", + "values": [ + "reformista", + "admin" + ] + }, + "public.user_status": { + "name": "user_status", + "schema": "public", + "values": [ + "activo", + "deshabilitado" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/mvp/b2c/drizzle/meta/_journal.json b/mvp/b2c/drizzle/meta/_journal.json index 0ce359e..1eef9c9 100644 --- a/mvp/b2c/drizzle/meta/_journal.json +++ b/mvp/b2c/drizzle/meta/_journal.json @@ -50,6 +50,13 @@ "when": 1780308810691, "tag": "0006_aspiring_susan_delgado", "breakpoints": true + }, + { + "idx": 7, + "version": "7", + "when": 1780313493522, + "tag": "0007_pale_chat", + "breakpoints": true } ] } \ No newline at end of file diff --git a/mvp/b2c/src/app/[slug]/page.tsx b/mvp/b2c/src/app/[slug]/page.tsx index ff20356..2b9d7f2 100644 --- a/mvp/b2c/src/app/[slug]/page.tsx +++ b/mvp/b2c/src/app/[slug]/page.tsx @@ -5,9 +5,11 @@ import ReformaSlider from '@/components/ReformaSlider/ReformaSlider'; import Features from '@/components/Features/Features'; import QuienesSomos from '@/components/funnel/QuienesSomos'; import TestimoniosCliente from '@/components/funnel/TestimoniosCliente'; +import GaleriaTrabajos from '@/components/funnel/GaleriaTrabajos'; import Footer from '@/components/Footer/Footer'; import TenantBrand from '@/components/funnel/TenantBrand'; -import { getTenantBySlug, getPublishedTestimonios } from '@/lib/funnel/public-queries'; +import { getTenantBySlug, getPublishedTestimonios, getGaleria } from '@/lib/funnel/public-queries'; +import { resolveTheme, themeStyle } from '@/lib/funnel/themes'; export const dynamic = 'force-dynamic'; @@ -32,11 +34,19 @@ export default async function FunnelPage({ params }: { params: Promise<{ slug: s const tenant = await getTenantBySlug(slug); if (!tenant) notFound(); - const testimonios = await getPublishedTestimonios(tenant.id); + const [testimonios, galeria] = await Promise.all([ + getPublishedTestimonios(tenant.id), + getGaleria(tenant.id), + ]); + + const theme = resolveTheme(tenant.themePreset, tenant.themeColor); return ( - <> - +
+
@@ -49,9 +59,10 @@ export default async function FunnelPage({ params }: { params: Promise<{ slug: s aniosExperiencia={tenant.aniosExperiencia} /> )} + {testimonios.length > 0 && }
- +
); } diff --git a/mvp/b2c/src/app/globals.css b/mvp/b2c/src/app/globals.css index 9ea7a94..3afe9d9 100644 --- a/mvp/b2c/src/app/globals.css +++ b/mvp/b2c/src/app/globals.css @@ -1,5 +1,24 @@ @import "tailwindcss"; +/* Instrument Serif (display) — usada por los presets de tema con titulares serif. + Los .woff2 viven en /public/b2b-assets/fonts. */ +@font-face { + font-family: 'Instrument Serif'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url('/b2b-assets/fonts/421ba28b-7abe-4b86-a87c-fcd3e94378f7.woff2') format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; +} +@font-face { + font-family: 'Instrument Serif'; + font-style: normal; + font-weight: 400; + font-display: swap; + src: url('/b2b-assets/fonts/15d36112-e39a-4059-ae12-06c58a5747ac.woff2') format('woff2'); + unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + @theme { /* Colors */ --color-black: #0a0a0a; @@ -111,4 +130,23 @@ .badge-accent { @apply bg-accent-light text-accent; } + + /* Botón con el color de marca del reformista (tema de la landing). */ + .btn-brand { + background-color: var(--brand, #0a0a0a); + color: var(--brand-contrast, #ffffff); + border: 2px solid var(--brand, #0a0a0a); + } + .btn-brand:hover { + background-color: var(--brand-dark, #1a1a1a); + border-color: var(--brand-dark, #1a1a1a); + transform: translateY(-1px); + } +} + +/* Presets de tema con titulares en serif (terracota, arena). */ +.theme-serif :is(h1, h2, h3) { + font-family: 'Instrument Serif', Georgia, 'Times New Roman', serif; + font-weight: 400; + letter-spacing: -0.01em; } \ No newline at end of file diff --git a/mvp/b2c/src/app/login/page.tsx b/mvp/b2c/src/app/login/page.tsx index 6b8e762..27f79b0 100644 --- a/mvp/b2c/src/app/login/page.tsx +++ b/mvp/b2c/src/app/login/page.tsx @@ -1,27 +1,59 @@ 'use client'; +import Link from 'next/link'; import { useActionState } from 'react'; import { login } from './actions'; +import AuthShell from '@/components/auth/AuthShell'; export default function LoginPage() { const [error, formAction, pending] = useActionState(login, null); return ( -
-
-

Entra en tu panel

+ + +
+

Entra en tu panel

+

Gestiona tus leads y tu funnel.

+
+ + {error &&

{error}

} - + +

+ ¿No tienes cuenta?{' '} + + Empieza gratis + +

-
+ ); } diff --git a/mvp/b2c/src/app/panel/empresa/actions.ts b/mvp/b2c/src/app/panel/empresa/actions.ts index c178adb..9be7eca 100644 --- a/mvp/b2c/src/app/panel/empresa/actions.ts +++ b/mvp/b2c/src/app/panel/empresa/actions.ts @@ -6,6 +6,7 @@ import { db } from '@/db'; import { tenants } from '@/db/schema'; import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; import { validarSlug } from '@/lib/validation/signup'; +import { THEME_PRESETS, isHexColor, type ThemePresetId } from '@/lib/funnel/themes'; const LOGO_MAX_BYTES = 500_000; const LOGO_TIPOS = ['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml']; @@ -126,3 +127,24 @@ export async function quitarAboutFoto() { await db.update(tenants).set({ aboutFotoUrl: null }).where(eq(tenants.id, tenantId)); revalidatePath('/panel/empresa'); } + +// Guarda el tema de la landing del reformista: preset + color personalizado opcional. +export async function guardarTema( + _prev: LogoResult | null, + formData: FormData +): Promise { + const tenantId = await getTenantId(); + const presetRaw = String(formData.get('themePreset') ?? ''); + const themePreset: ThemePresetId = presetRaw in THEME_PRESETS ? (presetRaw as ThemePresetId) : 'pizarra'; + + const usarColor = formData.get('usarColor') === 'on'; + const colorRaw = String(formData.get('themeColor') ?? '').trim(); + const themeColor = usarColor && isHexColor(colorRaw) ? colorRaw : null; + + await db + .update(tenants) + .set({ themePreset, themeColor }) + .where(eq(tenants.id, tenantId)); + revalidatePath('/panel/empresa'); + return { ok: true }; +} diff --git a/mvp/b2c/src/app/panel/empresa/page.tsx b/mvp/b2c/src/app/panel/empresa/page.tsx index 280bd18..99d22e8 100644 --- a/mvp/b2c/src/app/panel/empresa/page.tsx +++ b/mvp/b2c/src/app/panel/empresa/page.tsx @@ -3,6 +3,7 @@ import { getTenantPerfil } from '@/db/tenant-queries'; import { actualizarEmpresa } from './actions'; import LogoUploader from '@/components/panel/LogoUploader'; import AboutFotoUploader from '@/components/panel/AboutFotoUploader'; +import ThemePicker from '@/components/panel/ThemePicker'; export const dynamic = 'force-dynamic'; @@ -17,7 +18,7 @@ export default async function EmpresaPage() { return (
-

Datos de empresa

+

Datos de empresa

Estos datos y el logo aparecen en la cabecera de los presupuestos en PDF que recibe el cliente. Manténlos al día. @@ -184,7 +185,7 @@ export default async function EmpresaPage() { /> - @@ -197,6 +198,15 @@ export default async function EmpresaPage() {

+ +
+

Tema de tu funnel

+

+ Elige los colores y la tipografía con los que tus clientes ven tu landing. Puedes partir + de un preset y, si quieres, fijar tu propio color de marca. +

+ +
); } diff --git a/mvp/b2c/src/app/panel/galeria/actions.ts b/mvp/b2c/src/app/panel/galeria/actions.ts new file mode 100644 index 0000000..8be213d --- /dev/null +++ b/mvp/b2c/src/app/panel/galeria/actions.ts @@ -0,0 +1,56 @@ +'use server'; + +import { and, eq } from 'drizzle-orm'; +import { revalidatePath } from 'next/cache'; +import { db } from '@/db'; +import { galeriaFotos } from '@/db/schema'; +import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; +import { GALERIA_MAX_FOTOS } from '@/lib/galeria'; + +const GALERIA_MAX_BYTES = 2_000_000; +const GALERIA_TIPOS = ['image/png', 'image/jpeg', 'image/webp']; + +export type GaleriaResult = { ok: boolean; error?: string }; + +export async function subirFotoGaleria( + _prev: GaleriaResult | null, + formData: FormData +): Promise { + const tenantId = await getTenantId(); + const file = formData.get('foto'); + if (!(file instanceof File) || file.size === 0) { + return { ok: false, error: 'Selecciona una imagen.' }; + } + if (!GALERIA_TIPOS.includes(file.type)) { + return { ok: false, error: 'Formato no válido. Usa PNG, JPG o WEBP.' }; + } + if (file.size > GALERIA_MAX_BYTES) { + return { ok: false, error: 'La imagen no puede superar los 2 MB.' }; + } + + const existentes = await db + .select({ id: galeriaFotos.id }) + .from(galeriaFotos) + .where(eq(galeriaFotos.tenantId, tenantId)); + if (existentes.length >= GALERIA_MAX_FOTOS) { + return { ok: false, error: `Has alcanzado el máximo de ${GALERIA_MAX_FOTOS} fotos.` }; + } + + const titulo = String(formData.get('titulo') ?? '').trim() || null; + const base64 = Buffer.from(await file.arrayBuffer()).toString('base64'); + const dataUri = `data:${file.type};base64,${base64}`; + + await db + .insert(galeriaFotos) + .values({ tenantId, url: dataUri, titulo, orden: existentes.length }); + revalidatePath('/panel/galeria'); + return { ok: true }; +} + +export async function eliminarFotoGaleria(id: string) { + const tenantId = await getTenantId(); + await db + .delete(galeriaFotos) + .where(and(eq(galeriaFotos.id, id), eq(galeriaFotos.tenantId, tenantId))); + revalidatePath('/panel/galeria'); +} diff --git a/mvp/b2c/src/app/panel/galeria/page.tsx b/mvp/b2c/src/app/panel/galeria/page.tsx new file mode 100644 index 0000000..752a4a8 --- /dev/null +++ b/mvp/b2c/src/app/panel/galeria/page.tsx @@ -0,0 +1,73 @@ +import { getGaleriaPanel } from '@/db/tenant-queries'; +import { eliminarFotoGaleria } from './actions'; +import { GALERIA_MAX_FOTOS } from '@/lib/galeria'; +import GaleriaUploader from '@/components/panel/GaleriaUploader'; + +export const dynamic = 'force-dynamic'; + +export default async function GaleriaPage() { + const fotos = await getGaleriaPanel(); + + return ( +
+
+

Galería de trabajos

+

+ Sube fotos de reformas que ya has hecho. Aparecen en tu funnel para dar confianza al + cliente antes de pedir presupuesto. +

+
+ + + + {fotos.length === 0 ? ( +

+ Aún no has subido ninguna foto. La galería no se mostrará en tu funnel hasta que añadas la + primera. +

+ ) : ( +
+ {fotos.map((foto) => ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {foto.titulo + {foto.titulo && ( +
+ {foto.titulo} +
+ )} +
+ +
+
+ ))} +
+ )} +
+ ); +} diff --git a/mvp/b2c/src/app/panel/layout.tsx b/mvp/b2c/src/app/panel/layout.tsx index 71d80a3..2bf4bc4 100644 --- a/mvp/b2c/src/app/panel/layout.tsx +++ b/mvp/b2c/src/app/panel/layout.tsx @@ -9,6 +9,7 @@ import AppNav from '@/components/AppNav'; const PANEL_LINKS = [ { href: '/panel', label: 'Leads', icon: 'leads' }, { href: '/panel/precios', label: 'Precios', icon: 'precios' }, + { href: '/panel/galeria', label: 'Galería', icon: 'galeria' }, { href: '/panel/opiniones', label: 'Opiniones', icon: 'opiniones' }, { href: '/panel/empresa', label: 'Empresa', icon: 'empresa' }, ] as const; @@ -33,7 +34,7 @@ export default async function PanelLayout({ children }: { children: React.ReactN R - Reformix + Reformix / {nombreEmpresa} diff --git a/mvp/b2c/src/app/panel/opiniones/page.tsx b/mvp/b2c/src/app/panel/opiniones/page.tsx index ed7defa..11181b9 100644 --- a/mvp/b2c/src/app/panel/opiniones/page.tsx +++ b/mvp/b2c/src/app/panel/opiniones/page.tsx @@ -33,7 +33,7 @@ export default async function OpinionesPage() { return (
-

Opiniones

+

Opiniones

Las opiniones que te dejan tus clientes. Aprueba las que quieras mostrar en tu funnel; solo las publicadas aparecen en tu página. diff --git a/mvp/b2c/src/app/panel/page.tsx b/mvp/b2c/src/app/panel/page.tsx index 70e88a9..d9f9a0e 100644 --- a/mvp/b2c/src/app/panel/page.tsx +++ b/mvp/b2c/src/app/panel/page.tsx @@ -1,14 +1,7 @@ import Link from 'next/link'; import { getLeads, getResumen, type LeadFiltro } from '@/db/queries'; -import { - ESTADOS, - ESTADO_BADGE, - ESTADO_LABEL, - PIPELINE_LABEL, - PIPELINE_NEXT, - formatEuros, - formatFecha, -} from '@/lib/funnel'; +import { ESTADOS, ESTADO_LABEL } from '@/lib/funnel'; +import LeadsView, { type PanelLead } from '@/components/panel/LeadsView'; import { getCurrentTenantId } from '@/lib/auth/current-user'; import { db } from '@/db'; import { tenants, plans } from '@/db/schema'; @@ -32,6 +25,20 @@ export default async function PanelPage({ const filtro: LeadFiltro = (FILTROS.find((f) => f.value === estado)?.value ?? 'todos') as LeadFiltro; const [leads, resumen] = await Promise.all([getLeads(filtro), getResumen()]); + const leadsView: PanelLead[] = leads.map((l) => ({ + id: l.id, + nombre: l.nombre, + telefono: l.telefono, + provincia: l.provincia, + tipoReforma: l.tipoReforma, + estado: l.estado, + pipelineStage: l.pipelineStage, + presupuestoEstimado: l.presupuestoEstimado, + renderUrl: l.renderUrl, + createdAtMs: l.createdAt.getTime(), + m2Suelo: l.m2Suelo, + calidadGlobal: l.calidadGlobal, + })); const tenantId = await getCurrentTenantId(); const [tenant] = await db.select().from(tenants).where(eq(tenants.id, tenantId)).limit(1); @@ -82,96 +89,7 @@ export default async function PanelPage({ })}

- {/* Tabla (desktop) */} -
- - - - - - - - - - - - - {leads.map((l) => ( - - - - - - - - - ))} - -
RenderClienteFechaEstadoPresupuestoSiguiente paso
- - {l.renderUrl ? ( - // eslint-disable-next-line @next/next/no-img-element - - ) : ( - - sin render - - )} - - - - {l.nombre} - -
{l.telefono}
-
{formatFecha(l.createdAt)} - - {ESTADO_LABEL[l.estado]} - - - {formatEuros(l.presupuestoEstimado)} - -
{PIPELINE_LABEL[l.pipelineStage]}
- {PIPELINE_NEXT[l.pipelineStage]} -
- {leads.length === 0 && ( -
No hay leads con este estado.
- )} -
- - {/* Cards (mobile) */} -
- {leads.map((l) => ( - -
- {l.renderUrl ? ( - // eslint-disable-next-line @next/next/no-img-element - - ) : null} -
-
-
- {l.nombre} - - {ESTADO_LABEL[l.estado]} - -
-
{l.telefono}
-
- {formatEuros(l.presupuestoEstimado)} - {formatFecha(l.createdAt)} -
-
{PIPELINE_NEXT[l.pipelineStage]}
-
- - ))} - {leads.length === 0 && ( -
No hay leads con este estado.
- )} -
+
); } diff --git a/mvp/b2c/src/app/panel/precios/page.tsx b/mvp/b2c/src/app/panel/precios/page.tsx index d701943..f32032e 100644 --- a/mvp/b2c/src/app/panel/precios/page.tsx +++ b/mvp/b2c/src/app/panel/precios/page.tsx @@ -28,7 +28,7 @@ export default async function PreciosPage() { return (
-

Tabla de precios

+

Tabla de precios

Define los precios unitarios y la mano de obra. El motor calcula el presupuesto a partir de estos valores y las medidas del lead. diff --git a/mvp/b2c/src/app/signup/page.tsx b/mvp/b2c/src/app/signup/page.tsx index 7c5b86e..640708d 100644 --- a/mvp/b2c/src/app/signup/page.tsx +++ b/mvp/b2c/src/app/signup/page.tsx @@ -1,29 +1,73 @@ 'use client'; +import Link from 'next/link'; import { useActionState } from 'react'; import { signup } from './actions'; +import AuthShell from '@/components/auth/AuthShell'; + +const inputClass = + 'rounded-lg border border-gray-300 px-3 py-2.5 text-sm focus:border-gray-900 focus:outline-none focus:ring-1 focus:ring-gray-900'; export default function SignupPage() { const [error, formAction, pending] = useActionState(signup, null); return ( -

-
-

Empieza gratis 14 días

-

Sin tarjeta. Configura tu catálogo y recibe leads.

- - - - - + + +
+

Empieza gratis 14 días

+

+ Sin tarjeta. Configura tu catálogo y recibe leads. +

+
+ + + + + + + {error &&

{error}

} - - Ya tengo cuenta + +

+ ¿Ya tienes cuenta?{' '} + + Entrar + +

-
+ ); } diff --git a/mvp/b2c/src/components/AppNav.tsx b/mvp/b2c/src/components/AppNav.tsx index 8da6124..9969351 100644 --- a/mvp/b2c/src/components/AppNav.tsx +++ b/mvp/b2c/src/components/AppNav.tsx @@ -6,6 +6,7 @@ import { usePathname } from 'next/navigation'; export type AppNavIcon = | 'leads' | 'precios' + | 'galeria' | 'empresa' | 'opiniones' | 'resumen' @@ -38,6 +39,13 @@ const ICON_PATHS: Record = { ), + galeria: ( + <> + + + + + ), empresa: ( <> diff --git a/mvp/b2c/src/components/Hero/Hero.tsx b/mvp/b2c/src/components/Hero/Hero.tsx index f2edb76..1590409 100644 --- a/mvp/b2c/src/components/Hero/Hero.tsx +++ b/mvp/b2c/src/components/Hero/Hero.tsx @@ -109,7 +109,10 @@ function LeadForm({ slug }: { slug: string }) { role="alert" aria-live="polite" > -
+
-
+
{icon}

{title}

diff --git a/mvp/b2c/src/components/Navbar/Navbar.tsx b/mvp/b2c/src/components/Navbar/Navbar.tsx deleted file mode 100644 index c3f051a..0000000 --- a/mvp/b2c/src/components/Navbar/Navbar.tsx +++ /dev/null @@ -1,142 +0,0 @@ -'use client'; - -import { useState, useEffect } from 'react'; - -const navLinks = [ - { label: 'Características', href: '#features' }, - { label: 'Precios', href: '#pricing' }, - { label: 'Contacto', href: '#contact' }, -]; - -export default function Navbar() { - const [scrolled, setScrolled] = useState(false); - const [menuOpen, setMenuOpen] = useState(false); - - useEffect(() => { - const handleScroll = () => setScrolled(window.scrollY > 24); - window.addEventListener('scroll', handleScroll, { passive: true }); - return () => window.removeEventListener('scroll', handleScroll); - }, []); - - const handleNavClick = (href: string) => { - setMenuOpen(false); - const el = document.querySelector(href); - if (el) el.scrollIntoView({ behavior: 'smooth' }); - }; - - return ( -
- - - {/* Mobile menu */} - {menuOpen && ( -
-
    - {navLinks.map((link) => ( -
  • - -
  • - ))} -
-
- - -
-
- )} -
- ); -} diff --git a/mvp/b2c/src/components/auth/AuthShell.tsx b/mvp/b2c/src/components/auth/AuthShell.tsx new file mode 100644 index 0000000..b0889db --- /dev/null +++ b/mvp/b2c/src/components/auth/AuthShell.tsx @@ -0,0 +1,46 @@ +import Link from 'next/link'; + +export default function AuthShell({ + photo, + photoAlt, + caption, + captionSub, + children, +}: { + photo: string; + photoAlt: string; + caption: string; + captionSub: string; + children: React.ReactNode; +}) { + return ( +
+ {/* Panel del formulario */} +
+ + + R + + Reformix + + +
+
{children}
+
+
+ + {/* Panel de la foto (oculto en móvil) */} +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {photoAlt} +
+
+

+ {caption} +

+

{captionSub}

+
+
+
+ ); +} diff --git a/mvp/b2c/src/components/funnel/GaleriaTrabajos.tsx b/mvp/b2c/src/components/funnel/GaleriaTrabajos.tsx new file mode 100644 index 0000000..a54b375 --- /dev/null +++ b/mvp/b2c/src/components/funnel/GaleriaTrabajos.tsx @@ -0,0 +1,54 @@ +import type { PublicGaleriaFoto } from '@/lib/funnel/public-queries'; + +type GaleriaTrabajosProps = { + fotos: PublicGaleriaFoto[]; + nombreEmpresa: string; +}; + +// Galería de trabajos del reformista en su landing pública. Solo se muestra si +// el reformista ha subido fotos desde su panel. +export default function GaleriaTrabajos({ fotos, nombreEmpresa }: GaleriaTrabajosProps) { + if (fotos.length === 0) return null; + + return ( +
+
+
+ + Nuestros trabajos + +

+ Reformas que ya hemos hecho +

+

+ Una muestra real del trabajo de {nombreEmpresa}. Calidad de acabados, plazos cumplidos. +

+
+ +
+ {fotos.map((f) => ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {f.titulo + {f.titulo && ( +
+ {f.titulo} +
+ )} +
+ ))} +
+
+
+ ); +} diff --git a/mvp/b2c/src/components/funnel/TenantBrand.tsx b/mvp/b2c/src/components/funnel/TenantBrand.tsx index 845bc58..7b288f5 100644 --- a/mvp/b2c/src/components/funnel/TenantBrand.tsx +++ b/mvp/b2c/src/components/funnel/TenantBrand.tsx @@ -1,7 +1,10 @@ +import Link from 'next/link'; + type TenantBrandProps = { nombreEmpresa: string; logoUrl: string | null; subtitle?: string; + showLogin?: boolean; }; function iniciales(nombre: string): string { @@ -14,7 +17,12 @@ function iniciales(nombre: string): string { // Cabecera de marca del reformista para el funnel público y las páginas de // solicitud. El cliente final ve el branding del reformista, no el de Reformix. -export default function TenantBrand({ nombreEmpresa, logoUrl, subtitle }: TenantBrandProps) { +export default function TenantBrand({ + nombreEmpresa, + logoUrl, + subtitle, + showLogin = false, +}: TenantBrandProps) { return (
@@ -27,7 +35,10 @@ export default function TenantBrand({ nombreEmpresa, logoUrl, subtitle }: Tenant className="h-9 w-auto max-w-[160px] object-contain" /> ) : ( - + {iniciales(nombreEmpresa)} )} @@ -35,9 +46,27 @@ export default function TenantBrand({ nombreEmpresa, logoUrl, subtitle }: Tenant {nombreEmpresa}
- - {subtitle ?? 'Presupuesto de reforma'} - + {showLogin ? ( + + Entrar + + + ) : ( + + {subtitle ?? 'Presupuesto de reforma'} + + )}
); diff --git a/mvp/b2c/src/components/panel/GaleriaUploader.tsx b/mvp/b2c/src/components/panel/GaleriaUploader.tsx new file mode 100644 index 0000000..5ad3eb3 --- /dev/null +++ b/mvp/b2c/src/components/panel/GaleriaUploader.tsx @@ -0,0 +1,69 @@ +'use client'; + +import { useActionState, useEffect, useRef } from 'react'; +import { subirFotoGaleria, type GaleriaResult } from '@/app/panel/galeria/actions'; + +export default function GaleriaUploader({ + total, + max, +}: { + total: number; + max: number; +}) { + const [state, formAction, pending] = useActionState( + subirFotoGaleria, + null + ); + const formRef = useRef(null); + + useEffect(() => { + if (state?.ok) formRef.current?.reset(); + }, [state]); + + const lleno = total >= max; + + return ( +
+
+

Añadir foto

+ + {total}/{max} fotos + +
+ +
+ + +
+ +
+
+ + {lleno && ( +

Has alcanzado el máximo de {max} fotos.

+ )} + {state?.error &&

{state.error}

} + {state?.ok &&

Foto añadida ✓

} +

PNG, JPG o WEBP · máx. 2 MB.

+
+ ); +} diff --git a/mvp/b2c/src/components/panel/LeadsView.tsx b/mvp/b2c/src/components/panel/LeadsView.tsx new file mode 100644 index 0000000..94cd92c --- /dev/null +++ b/mvp/b2c/src/components/panel/LeadsView.tsx @@ -0,0 +1,279 @@ +'use client'; + +import Link from 'next/link'; +import { useSyncExternalStore } from 'react'; +import { + CALIDAD_LABEL, + ESTADO_BADGE, + ESTADO_LABEL, + PIPELINE_LABEL, + PIPELINE_NEXT, + TIPO_LABEL, + formatEuros, + formatFecha, + formatRelativo, +} from '@/lib/funnel'; + +export type PanelLead = { + id: string; + nombre: string; + telefono: string; + provincia: string | null; + tipoReforma: keyof typeof TIPO_LABEL | null; + estado: keyof typeof ESTADO_BADGE; + pipelineStage: keyof typeof PIPELINE_NEXT; + presupuestoEstimado: number | null; + renderUrl: string | null; + createdAtMs: number; + m2Suelo: number | null; + calidadGlobal: keyof typeof CALIDAD_LABEL | null; +}; + +type Vista = 'cards' | 'tabla'; +const STORAGE_KEY = 'reformix.panel.leadsVista'; + +// La preferencia de vista vive en localStorage; useSyncExternalStore la lee sin +// provocar desajuste de hidratación (el servidor siempre renderiza 'cards'). +const listeners = new Set<() => void>(); + +function subscribeVista(cb: () => void) { + listeners.add(cb); + window.addEventListener('storage', cb); + return () => { + listeners.delete(cb); + window.removeEventListener('storage', cb); + }; +} + +function getVistaSnapshot(): Vista { + return window.localStorage.getItem(STORAGE_KEY) === 'tabla' ? 'tabla' : 'cards'; +} + +function getVistaServerSnapshot(): Vista { + return 'cards'; +} + +function setVistaPersistida(v: Vista) { + window.localStorage.setItem(STORAGE_KEY, v); + for (const cb of listeners) cb(); +} + +function iniciales(nombre: string): string { + const partes = nombre.trim().split(/\s+/).slice(0, 2); + return partes.map((p) => p[0]?.toUpperCase() ?? '').join('') || '?'; +} + +function subtitulo(l: PanelLead): string { + const partes = [ + l.tipoReforma ? TIPO_LABEL[l.tipoReforma] : null, + l.provincia, + ].filter(Boolean); + return partes.join(' · '); +} + +function detalle(l: PanelLead): string { + const partes = [ + formatRelativo(new Date(l.createdAtMs)), + l.m2Suelo ? `${l.m2Suelo} m²` : null, + l.calidadGlobal ? CALIDAD_LABEL[l.calidadGlobal] : null, + ].filter(Boolean); + return partes.join(' · '); +} + +function ToggleVista({ vista, onChange }: { vista: Vista; onChange: (v: Vista) => void }) { + const opciones: { value: Vista; label: string; icon: React.ReactNode }[] = [ + { + value: 'cards', + label: 'Tarjetas', + icon: ( + <> + + + + + + ), + }, + { + value: 'tabla', + label: 'Tabla', + icon: ( + <> + + + ), + }, + ]; + + return ( +
+ {opciones.map((o) => { + const activo = vista === o.value; + return ( + + ); + })} +
+ ); +} + +function Tarjeta({ l }: { l: PanelLead }) { + return ( + +
+ + {iniciales(l.nombre)} + +
+
+ {l.nombre} + + {ESTADO_LABEL[l.estado]} + +
+

{subtitulo(l) || l.telefono}

+

{detalle(l)}

+
+
+ + {l.renderUrl && ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + +
+ )} + +
+
+

{PIPELINE_LABEL[l.pipelineStage]}

+

{PIPELINE_NEXT[l.pipelineStage]}

+
+
+

{formatEuros(l.presupuestoEstimado)}

+ {l.presupuestoEstimado != null && ( +

orientativo

+ )} +
+
+ + ); +} + +export default function LeadsView({ leads }: { leads: PanelLead[] }) { + const vista = useSyncExternalStore(subscribeVista, getVistaSnapshot, getVistaServerSnapshot); + + return ( +
+
+ +
+ + {leads.length === 0 ? ( +
+ No hay leads con este estado. +
+ ) : vista === 'cards' ? ( +
+ {leads.map((l) => ( + + ))} +
+ ) : ( +
+ + + + + + + + + + + + + {leads.map((l) => ( + + + + + + + + + ))} + +
RenderClienteFechaEstadoPresupuestoSiguiente paso
+ + {l.renderUrl ? ( + // eslint-disable-next-line @next/next/no-img-element + + ) : ( + + sin render + + )} + + + + {l.nombre} + +
{subtitulo(l) || l.telefono}
+
+ {formatFecha(new Date(l.createdAtMs))} + + + {ESTADO_LABEL[l.estado]} + + + {formatEuros(l.presupuestoEstimado)} + +
{PIPELINE_LABEL[l.pipelineStage]}
+ {PIPELINE_NEXT[l.pipelineStage]} +
+
+ )} +
+ ); +} diff --git a/mvp/b2c/src/components/panel/ThemePicker.tsx b/mvp/b2c/src/components/panel/ThemePicker.tsx new file mode 100644 index 0000000..80f1552 --- /dev/null +++ b/mvp/b2c/src/components/panel/ThemePicker.tsx @@ -0,0 +1,152 @@ +'use client'; + +import { useActionState, useState } from 'react'; +import { guardarTema, type LogoResult } from '@/app/panel/empresa/actions'; +import { + THEME_LIST, + isHexColor, + type ThemePresetId, +} from '@/lib/funnel/themes'; + +export default function ThemePicker({ + themePreset, + themeColor, +}: { + themePreset: string; + themeColor: string | null; +}) { + const [state, formAction, pending] = useActionState( + guardarTema, + null + ); + + const [preset, setPreset] = useState( + (THEME_LIST.find((t) => t.id === themePreset)?.id ?? 'pizarra') as ThemePresetId + ); + const [usarColor, setUsarColor] = useState(isHexColor(themeColor)); + const [color, setColor] = useState(isHexColor(themeColor) ? themeColor : '#0066ff'); + + const presetActual = THEME_LIST.find((t) => t.id === preset) ?? THEME_LIST[0]; + const colorEfectivo = usarColor && isHexColor(color) ? color : presetActual.primary; + + return ( +
+
+ {THEME_LIST.map((t) => { + const activo = preset === t.id; + return ( + + ); + })} +
+ +
+ + {usarColor && ( +
+ setColor(e.target.value)} + className="h-10 w-14 cursor-pointer rounded-lg border border-gray-200 bg-white p-1" + /> + {color} + + Sustituye el color del preset por el tuyo. + +
+ )} +
+ +
+

+ Vista previa +

+
+ + Presupuesto en 2 minutos + + + + Tu cocina, reformada + +
+
+ +
+ + {state?.error && {state.error}} + {state?.ok && Tema guardado ✓} +
+
+ ); +} diff --git a/mvp/b2c/src/db/schema.ts b/mvp/b2c/src/db/schema.ts index de458fd..f4300eb 100644 --- a/mvp/b2c/src/db/schema.ts +++ b/mvp/b2c/src/db/schema.ts @@ -92,6 +92,10 @@ export const tenants = pgTable('tenants', { aboutFotoUrl: text('about_foto_url'), // data URI base64 de la foto del reformista aboutTexto: text('about_texto'), aniosExperiencia: integer('anios_experiencia'), + // Tema visual de la landing del reformista (personalización del funnel público). + // themePreset = id de THEME_PRESETS; themeColor = override hex opcional del color primario. + themePreset: text('theme_preset').notNull().default('pizarra'), + themeColor: text('theme_color'), // Datos de empresa para la cabecera del presupuesto (RF-D-07). cif: text('cif'), direccion: text('direccion'), @@ -255,6 +259,22 @@ export const testimonioFotos = pgTable('testimonio_fotos', { createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), }); +// Galería de trabajos del reformista (fotos de reformas hechas), visible en su landing. +export const galeriaFotos = pgTable( + 'galeria_fotos', + { + id: uuid('id').primaryKey().defaultRandom(), + tenantId: uuid('tenant_id') + .notNull() + .references(() => tenants.id, { onDelete: 'cascade' }), + url: text('url').notNull(), // data URI base64 (no hay storage externo aún) + titulo: text('titulo'), + orden: integer('orden').notNull().default(0), + createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(), + }, + (table) => [index('galeria_tenant_idx').on(table.tenantId)] +); + // Histórico de cambios de estado comercial (RF-D-03: persistir y reflejar) export const leadEstadoHistory = pgTable('lead_estado_history', { id: uuid('id').primaryKey().defaultRandom(), @@ -333,6 +353,7 @@ export type LeadFoto = typeof leadFotos.$inferSelect; export type Testimonio = typeof testimonios.$inferSelect; export type NewTestimonio = typeof testimonios.$inferInsert; export type TestimonioFoto = typeof testimonioFotos.$inferSelect; +export type GaleriaFoto = typeof galeriaFotos.$inferSelect; export type LeadEstadoHistory = typeof leadEstadoHistory.$inferSelect; export type LeadPipelineEvento = typeof leadPipelineEventos.$inferSelect; export type PrecisionHistory = typeof precisionHistory.$inferSelect; diff --git a/mvp/b2c/src/db/tenant-queries.ts b/mvp/b2c/src/db/tenant-queries.ts index e4ef9e2..f222fd1 100644 --- a/mvp/b2c/src/db/tenant-queries.ts +++ b/mvp/b2c/src/db/tenant-queries.ts @@ -1,6 +1,6 @@ -import { desc, eq } from 'drizzle-orm'; +import { asc, desc, eq } from 'drizzle-orm'; import { db } from './index'; -import { tenants, testimonios, testimonioFotos } from './schema'; +import { tenants, testimonios, testimonioFotos, galeriaFotos, type GaleriaFoto } from './schema'; import { getCurrentTenantId as getTenantId } from '@/lib/auth/current-user'; export type TenantPerfil = { @@ -19,6 +19,8 @@ export type TenantPerfil = { aboutFotoUrl: string | null; aboutTexto: string | null; aniosExperiencia: number | null; + themePreset: string; + themeColor: string | null; }; export async function getTenantPerfil(): Promise { @@ -40,6 +42,8 @@ export async function getTenantPerfil(): Promise { aboutFotoUrl: tenants.aboutFotoUrl, aboutTexto: tenants.aboutTexto, aniosExperiencia: tenants.aniosExperiencia, + themePreset: tenants.themePreset, + themeColor: tenants.themeColor, }) .from(tenants) .where(eq(tenants.id, tenantId)) @@ -62,10 +66,22 @@ export async function getTenantPerfil(): Promise { aboutFotoUrl: null, aboutTexto: null, aniosExperiencia: null, + themePreset: 'pizarra', + themeColor: null, } ); } +// Galería de trabajos del reformista, para gestionarla desde el panel. +export async function getGaleriaPanel(): Promise { + const tenantId = await getTenantId(); + return db + .select() + .from(galeriaFotos) + .where(eq(galeriaFotos.tenantId, tenantId)) + .orderBy(asc(galeriaFotos.orden), asc(galeriaFotos.createdAt)); +} + export type TestimonioPanel = { id: string; nombre: string; diff --git a/mvp/b2c/src/lib/funnel.ts b/mvp/b2c/src/lib/funnel.ts index 6f1d14b..e06a1a2 100644 --- a/mvp/b2c/src/lib/funnel.ts +++ b/mvp/b2c/src/lib/funnel.ts @@ -1,10 +1,11 @@ -import type { leadEstado, pipelineStage, tipoReforma } from '@/db/schema'; +import type { calidad, leadEstado, pipelineStage, tipoReforma } from '@/db/schema'; export const TENANT_SLUG = 'reformas-ejemplo'; type Estado = (typeof leadEstado.enumValues)[number]; type Stage = (typeof pipelineStage.enumValues)[number]; type Tipo = (typeof tipoReforma.enumValues)[number]; +type Calidad = (typeof calidad.enumValues)[number]; export const ESTADOS: Estado[] = [ 'nuevo', @@ -74,6 +75,12 @@ export const TIPO_LABEL: Record = { otro: 'Otro', }; +export const CALIDAD_LABEL: Record = { + basica: 'Calidad básica', + media: 'Calidad media', + premium: 'Calidad premium', +}; + export function formatEuros(cents: number | null): string { if (cents == null) return '—'; return new Intl.NumberFormat('es-ES', { @@ -91,3 +98,16 @@ export function formatFecha(date: Date): string { minute: '2-digit', }).format(date); } + +// Tiempo transcurrido en formato corto: "Hace 4 min", "Hace 2 h", "Hace 3 d". +export function formatRelativo(date: Date): string { + const segundos = Math.max(0, Math.round((Date.now() - date.getTime()) / 1000)); + if (segundos < 60) return 'Justo ahora'; + const minutos = Math.round(segundos / 60); + if (minutos < 60) return `Hace ${minutos} min`; + const horas = Math.round(minutos / 60); + if (horas < 24) return `Hace ${horas} h`; + const dias = Math.round(horas / 24); + if (dias < 30) return `Hace ${dias} d`; + return formatFecha(date); +} diff --git a/mvp/b2c/src/lib/funnel/public-queries.ts b/mvp/b2c/src/lib/funnel/public-queries.ts index 39a756c..e0cd1ef 100644 --- a/mvp/b2c/src/lib/funnel/public-queries.ts +++ b/mvp/b2c/src/lib/funnel/public-queries.ts @@ -7,6 +7,7 @@ import { leadPipelineEventos, testimonios, testimonioFotos, + galeriaFotos, } from '@/db/schema'; export type PublicTenant = { @@ -20,6 +21,8 @@ export type PublicTenant = { aboutFotoUrl: string | null; aboutTexto: string | null; aniosExperiencia: number | null; + themePreset: string; + themeColor: string | null; }; const TENANT_PUBLIC_COLUMNS = { @@ -33,8 +36,26 @@ const TENANT_PUBLIC_COLUMNS = { aboutFotoUrl: tenants.aboutFotoUrl, aboutTexto: tenants.aboutTexto, aniosExperiencia: tenants.aniosExperiencia, + themePreset: tenants.themePreset, + themeColor: tenants.themeColor, } as const; +export type PublicGaleriaFoto = { + id: string; + url: string; + titulo: string | null; +}; + +// Galería de trabajos publicada por el reformista, para mostrar en su landing. +export async function getGaleria(tenantId: string): Promise { + const rows = await db + .select({ id: galeriaFotos.id, url: galeriaFotos.url, titulo: galeriaFotos.titulo }) + .from(galeriaFotos) + .where(eq(galeriaFotos.tenantId, tenantId)) + .orderBy(asc(galeriaFotos.orden), asc(galeriaFotos.createdAt)); + return rows; +} + export type PublicTestimonio = { id: string; nombre: string; diff --git a/mvp/b2c/src/lib/funnel/themes.ts b/mvp/b2c/src/lib/funnel/themes.ts new file mode 100644 index 0000000..778ea52 --- /dev/null +++ b/mvp/b2c/src/lib/funnel/themes.ts @@ -0,0 +1,124 @@ +import type { CSSProperties } from 'react'; + +export type ThemePresetId = 'pizarra' | 'azul' | 'verde' | 'terracota' | 'arena'; + +export type ThemePreset = { + id: ThemePresetId; + label: string; + descripcion: string; + primary: string; // color de marca + primaryDark: string; // hover / énfasis + contrast: string; // texto sobre el color de marca + heading: 'sans' | 'serif'; // tipografía de los titulares de la landing +}; + +export const DEFAULT_THEME: ThemePresetId = 'pizarra'; + +export const THEME_PRESETS: Record = { + pizarra: { + id: 'pizarra', + label: 'Pizarra', + descripcion: 'Negro elegante. El look por defecto de Reformix.', + primary: '#0a0a0a', + primaryDark: '#1a1a1a', + contrast: '#ffffff', + heading: 'sans', + }, + azul: { + id: 'azul', + label: 'Azul confianza', + descripcion: 'Azul corporativo que transmite seguridad.', + primary: '#0066ff', + primaryDark: '#0052cc', + contrast: '#ffffff', + heading: 'sans', + }, + verde: { + id: 'verde', + label: 'Verde natural', + descripcion: 'Verde sereno para un estilo sostenible.', + primary: '#0f7a52', + primaryDark: '#0b5e3f', + contrast: '#ffffff', + heading: 'sans', + }, + terracota: { + id: 'terracota', + label: 'Terracota', + descripcion: 'Cálido y artesanal, con titulares en serif.', + primary: '#b4502e', + primaryDark: '#8f3d22', + contrast: '#ffffff', + heading: 'serif', + }, + arena: { + id: 'arena', + label: 'Arena', + descripcion: 'Neutro cálido, sobrio y premium. Titulares en serif.', + primary: '#8a6d3b', + primaryDark: '#6e562f', + contrast: '#ffffff', + heading: 'serif', + }, +}; + +export const THEME_LIST: ThemePreset[] = Object.values(THEME_PRESETS); + +const HEX_RE = /^#[0-9a-fA-F]{6}$/; + +export function isHexColor(value: string | null | undefined): value is string { + return !!value && HEX_RE.test(value); +} + +function darken(hex: string, amount = 0.16): string { + const n = parseInt(hex.slice(1), 16); + const r = Math.max(0, Math.round(((n >> 16) & 255) * (1 - amount))); + const g = Math.max(0, Math.round(((n >> 8) & 255) * (1 - amount))); + const b = Math.max(0, Math.round((n & 255) * (1 - amount))); + return '#' + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0'); +} + +export type ResolvedTheme = { + preset: ThemePreset; + primary: string; + primaryDark: string; + contrast: string; + heading: 'sans' | 'serif'; +}; + +// Combina el preset elegido con el color personalizado opcional del reformista. +export function resolveTheme( + presetId: string | null | undefined, + customColor: string | null | undefined +): ResolvedTheme { + const preset = THEME_PRESETS[presetId as ThemePresetId] ?? THEME_PRESETS[DEFAULT_THEME]; + if (isHexColor(customColor)) { + return { + preset, + primary: customColor, + primaryDark: darken(customColor), + contrast: '#ffffff', + heading: preset.heading, + }; + } + return { + preset, + primary: preset.primary, + primaryDark: preset.primaryDark, + contrast: preset.contrast, + heading: preset.heading, + }; +} + +// Variables CSS que cuelgan del contenedor de la landing y consumen los componentes. +export function themeStyle( + presetId: string | null | undefined, + customColor: string | null | undefined +): CSSProperties { + const t = resolveTheme(presetId, customColor); + return { + '--brand': t.primary, + '--brand-dark': t.primaryDark, + '--brand-contrast': t.contrast, + } as CSSProperties; +} diff --git a/mvp/b2c/src/lib/galeria.ts b/mvp/b2c/src/lib/galeria.ts new file mode 100644 index 0000000..111e65d --- /dev/null +++ b/mvp/b2c/src/lib/galeria.ts @@ -0,0 +1,3 @@ +// Tope de fotos en la galería del reformista. Vive fuera del módulo 'use server' +// porque esos solo pueden exportar funciones async. +export const GALERIA_MAX_FOTOS = 24;