diff --git a/apps/db/migrations/28_potenziali.up.sql b/apps/db/migrations/28_potenziali.up.sql new file mode 100644 index 0000000..60139ea --- /dev/null +++ b/apps/db/migrations/28_potenziali.up.sql @@ -0,0 +1,37 @@ +-- Potenziali table +CREATE TABLE IF NOT EXISTS public.potenziali ( + id UUID DEFAULT gen_random_uuid () NOT NULL, + name TEXT NOT NULL, + descrizione TEXT, + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL, + userid UUID, + potenziali_group_id UUID NOT NULL +); + +-- Primary Key +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'potenziali_pkey' + AND conrelid = 'public.potenziali'::regclass + ) THEN + ALTER TABLE public.potenziali + ADD CONSTRAINT potenziali_pkey PRIMARY KEY (id); + END IF; +END $$; + +-- Foreign Key to Users +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'potenziali_assigned_user' + AND conrelid = 'public.potenziali'::regclass + ) THEN + ALTER TABLE public.potenziali + ADD CONSTRAINT potenziali_assigned_user + FOREIGN KEY (userid) REFERENCES public.users (id) + ON UPDATE CASCADE ON DELETE SET NULL; + END IF; +END $$; \ No newline at end of file diff --git a/apps/db/migrations/29_potenziali_groups.up.sql b/apps/db/migrations/29_potenziali_groups.up.sql new file mode 100644 index 0000000..1693320 --- /dev/null +++ b/apps/db/migrations/29_potenziali_groups.up.sql @@ -0,0 +1,45 @@ +-- Potenziali Groups Table +CREATE TABLE IF NOT EXISTS public.potenziali_groups ( + id UUID DEFAULT gen_random_uuid () NOT NULL, + name TEXT NOT NULL, + color TEXT DEFAULT 'blue' NOT NULL +); +-- Primary Key +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'potenziali_groups_pkey' + AND conrelid = 'public.potenziali_groups'::regclass + ) THEN + ALTER TABLE public.potenziali_groups + ADD CONSTRAINT potenziali_groups_pkey PRIMARY KEY (id); + END IF; +END $$; + +-- Foreign Key to Potenziali Groups +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = 'potenziali_group_fk' + AND conrelid = 'public.potenziali'::regclass + ) THEN + ALTER TABLE public.potenziali + ADD CONSTRAINT potenziali_group_fk + FOREIGN KEY (potenziali_group_id) REFERENCES public.potenziali_groups (id) + ON UPDATE CASCADE ON DELETE CASCADE; + END IF; +END $$; + +-- Create Index on Potenziali Group ID +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM pg_indexes + WHERE indexname = 'idx_potenziali_group_id' + ) THEN + CREATE INDEX idx_potenziali_group_id + ON public.potenziali (potenziali_group_id); + END IF; +END $$; \ No newline at end of file diff --git a/apps/infoalloggi/src/components/area-riservata/potenziali.tsx b/apps/infoalloggi/src/components/area-riservata/potenziali.tsx index c047416..01a67b4 100644 --- a/apps/infoalloggi/src/components/area-riservata/potenziali.tsx +++ b/apps/infoalloggi/src/components/area-riservata/potenziali.tsx @@ -1,6 +1,8 @@ "use client"; import { format } from "date-fns"; +import { Plus } from "lucide-react"; +import { useState } from "react"; import { KanbanBoard, KanbanCard, @@ -8,12 +10,9 @@ import { KanbanHeader, KanbanProvider, } from "~/components/ui/kanban"; -import { - type ElementoPotenziali, - PotenzialiProvider, - usePotenziali, -} from "~/providers/PotenzialiProvider"; -import type { UsersId } from "~/schemas/public/Users"; +import { usePotenziali } from "~/providers/PotenzialiProvider"; +import type { PotenzialiGroupsId } from "~/schemas/public/PotenzialiGroups"; +import type { PotenzialeData } from "~/server/services/potenziali.service"; import { Credenza, CredenzaBody, @@ -21,81 +20,27 @@ import { CredenzaDescription, CredenzaHeader, CredenzaTitle, + CredenzaTrigger, } from "../custom_ui/credenza"; -import { - ContextMenu, - ContextMenuContent, - ContextMenuItem, - ContextMenuTrigger, -} from "../ui/context-menu"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle, -} from "../ui/dialog"; +import Input from "../custom_ui/input"; +import { Textarea } from "../custom_ui/textarea"; +import { Button } from "../ui/button"; +import { Label } from "../ui/label"; import { UserAvatar } from "../user_avatar"; -const columns = [ - { id: "todo", name: "To Do", color: "red" }, - { id: "inprogress", name: "In Progress", color: "blue" }, - { id: "done", name: "Done", color: "green" }, -]; - -const SampleData: ElementoPotenziali[] = [ - { - id: "1", - name: "Mario Rossi", - column: "todo", - descrizione: - "Single, cerca appartamento in centro da subito, budget 800 euro", - createdAt: new Date(), - owner: { - userId: "019b9a25-eff1-420a-9017-b0add205d7b6" as UsersId, - username: "Marco Pedone", - }, - }, - { - id: "2", - name: "Luigi Bianchi", - column: "inprogress", - descrizione: "Coppia, cerca bilocale in periferia, budget 600 euro", - createdAt: new Date(), - owner: null, - }, - { - id: "3", - name: "Giovanni Verdi", - column: "done", - descrizione: - "Famiglia con 2 figli, cerca trilocale vicino a scuole, budget 1000 euro", - createdAt: new Date(), - owner: { - userId: "019b9a25-eff1-420a-9017-b0add205d7b6" as UsersId, - username: "Marco Pedone", - }, - }, -]; - -const Potenziali = () => { - return ( - - - - ); -}; - -const Kaban = () => { - const { data, updateData, setEditingId, editingId } = usePotenziali(); - +export const Potenziali = () => { + const { data, columns, setData, updateCall, setEditingId, editingId } = + usePotenziali(); return ( <> { + updateCall(); + }} > {(column) => ( { style={{ backgroundColor: column.color }} /> {column.name} + + - {(data: ElementoPotenziali) => ( + {(data: PotenzialeData) => ( { setEditingId(data.id); @@ -132,16 +79,16 @@ const Kaban = () => { {data.descrizione}

- {data.owner && ( + {data.userid && ( )}

- {format(data.createdAt, "dd/MM/yyyy HH:mm")} + {format(data.created_at, "dd/MM/yyyy HH:mm")}

)} @@ -163,6 +110,101 @@ const Kaban = () => { ); }; +export const NewColumn = () => { + const [newColumnName, setNewColumnName] = useState(""); + const { addColumn } = usePotenziali(); + return ( + + + + + + + + Nuova colonna + + desc + + + + + setNewColumnName(e.target.value)} + type="string" + /> + + + + + ); +}; + +export const NewCard = ({ columnId }: { columnId: PotenzialiGroupsId }) => { + const [newItemName, setNewItemName] = useState(""); + const [newItemDescrizione, setNewItemDescrizione] = useState(""); + const { addItem } = usePotenziali(); + return ( + + + + + + + + Nuova colonna + + desc + + + + + setNewItemName(e.target.value)} + type="string" + /> + +