diff --git a/apps/infoalloggi/src/components/accordionComp.tsx b/apps/infoalloggi/src/components/accordionComp.tsx index 9f36bd6..4654d27 100644 --- a/apps/infoalloggi/src/components/accordionComp.tsx +++ b/apps/infoalloggi/src/components/accordionComp.tsx @@ -53,7 +53,7 @@ export const AccordionComp = forwardRef( key={`ac-item-${index}`} value={`item-${index}`} > - + {text.title} diff --git a/apps/infoalloggi/src/components/annuncio-interactions/annuncio_interactions.tsx b/apps/infoalloggi/src/components/annuncio-interactions/annuncio_interactions.tsx index 67d9e97..e9c94a4 100644 --- a/apps/infoalloggi/src/components/annuncio-interactions/annuncio_interactions.tsx +++ b/apps/infoalloggi/src/components/annuncio-interactions/annuncio_interactions.tsx @@ -174,6 +174,19 @@ export const InteressatoButtonServizio = ({ const { isAdmin, servizioId, userId } = useServizio(); const utils = api.useUtils(); + const invalidateAll = async () => { + await utils.intrests.getUserInterests.invalidate(); + await utils.servizio.getAllServizioAnnunci.invalidate({ userId }); + await utils.servizio.getAnnunciAvailableToAdd.invalidate({ + servizioId, + }); + await utils.servizio.AnnuncioServizioTipologiaMatch.invalidate({ + userId, + }); + await utils.servizio.getCompatibileAnnunci.invalidate({ + servizioId, + }); + }; const { mutate: adminAdd, isPending: isAdminPending } = api.servizio.addServizioAnnunci.useMutation({ onError: (error) => { @@ -181,16 +194,7 @@ export const InteressatoButtonServizio = ({ toast.error("Errore durante l'aggiunta dell'annuncio"); }, onSuccess: async () => { - await utils.servizio.getAllServizioAnnunci.invalidate({ userId }); - await utils.servizio.getAnnunciAvailableToAdd.invalidate({ - servizioId, - }); - await utils.servizio.AnnuncioServizioTipologiaMatch.invalidate({ - userId, - }); - await utils.servizio.getCompatibileAnnunci.invalidate({ - servizioId, - }); + await invalidateAll(); toast.success("Annuncio aggiunto alla ricerca"); }, @@ -198,7 +202,7 @@ export const InteressatoButtonServizio = ({ const { mutate: add, isPending } = api.intrests.addIntrest.useMutation({ onSuccess: async () => { - await utils.intrests.getUserInterests.invalidate(); + await invalidateAll(); toast.success("Richiesta di interesse inviata con successo!"); }, }); diff --git a/apps/infoalloggi/src/components/area-riservata/dashboard.tsx b/apps/infoalloggi/src/components/area-riservata/dashboard.tsx index 052be54..837125d 100644 --- a/apps/infoalloggi/src/components/area-riservata/dashboard.tsx +++ b/apps/infoalloggi/src/components/area-riservata/dashboard.tsx @@ -1,3 +1,4 @@ +import { CircleHelp } from "lucide-react"; import dynamic from "next/dynamic"; import { AccordionComp } from "~/components/accordionComp"; import { LoadingPage } from "~/components/loading"; @@ -12,6 +13,16 @@ import { import { useTranslation } from "~/providers/I18nProvider"; import type { UsersId } from "~/schemas/public/Users"; import { api } from "~/utils/api"; +import { + Credenza, + CredenzaBody, + CredenzaContent, + CredenzaDescription, + CredenzaHeader, + CredenzaTitle, + CredenzaTrigger, +} from "../custom_ui/credenza"; +import { Button } from "../ui/button"; const TimeserieBarChart = dynamic( () => import("~/components/timeserieBarChart").then((mod) => mod.default), @@ -82,37 +93,39 @@ export const AdminDashboard = () => { }; export const UserDashboard = ({ userId }: { userId: UsersId }) => { - // const { data: servizi, isLoading: loadingServizi } = - // api.servizio.getAllServizioAnnunci.useQuery({ userId }); const { t } = useTranslation(); return ( -
-
-
-
-

Le tue ricerche

-
-
+
+

Le tue ricerche

-
- - {/* {loadingServizi ? ( - - ) : ( - servizi?.map((servizio, idx) => ( - - )) - )} */} -
- +
+ +
+
+ + + + + + + + Domande frequenti + + + Domande frequenti + + + + + + +
); diff --git a/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx b/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx index 91da237..2c62843 100644 --- a/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx +++ b/apps/infoalloggi/src/components/servizio/compatibili_dialog.tsx @@ -1,9 +1,11 @@ +import { CheckCircle } from "lucide-react"; import { useState } from "react"; import { useServizio } from "~/providers/ServizioProvider"; import { api } from "~/utils/api"; import { CardAnnuncio } from "../annuncio_card"; import { InteressatoButtonServizio } from "../annuncio-interactions/annuncio_interactions"; import { LoadingPage } from "../loading"; +import { Badge } from "../ui/badge"; import { Button } from "../ui/button"; import { Dialog, @@ -65,7 +67,7 @@ export const AnnunciCompatibili = () => { trovare annunci compatibili. ) : ( -
+
{data.map((annuncio) => (
{
- + {annuncio.alreadyRequested ? ( + + Richiesta inviata + + + ) : ( + + )}
diff --git a/apps/infoalloggi/src/components/servizio/main.tsx b/apps/infoalloggi/src/components/servizio/main.tsx index 8c8793a..d977c21 100644 --- a/apps/infoalloggi/src/components/servizio/main.tsx +++ b/apps/infoalloggi/src/components/servizio/main.tsx @@ -1,5 +1,4 @@ -import { add } from "date-fns"; -import { CalendarClock, Package, PackageCheck, UserCircle } from "lucide-react"; +import { ArrowRight, Package, PackageCheck } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect } from "react"; @@ -15,7 +14,6 @@ import { CardHeader, CardTitle, } from "~/components/ui/card"; -import { Progress } from "~/components/ui/progress"; import { cn } from "~/lib/utils"; import { ServizioAnnuncioProvider, @@ -44,7 +42,7 @@ const ServizioCard = ({ return ( @@ -134,7 +132,10 @@ export const ServizioContent = () => { aria-label="Attiva Servizio" href={`/servizio/onboard/${servizio.servizio_id}`} > - + {isAdmin && ( + ) : ( + + )} + + + +
+
+
+
+ + Contatti sbloccati +
+ {openContattiAnnunci.length} / 10 +
+ +
+
+
+ + Durata servizio: +
+ + {dec_txt} - {end_txt} + +
+
+
+ + ); +}; + +export const ServizioBasicActions = ({ className }: { className?: string }) => { + const { servizio, isAdmin } = useServizio(); + const canUserEdit = servizio.isOkAcconto && servizio.decorrenza !== null && !servizio.annunci.some((a) => a.user_confirmed_at !== null); - if (!isAdmin && !canUserEdit) { - return null; // If the user is not an admin and cannot edit, do not render the actions + if (isAdmin || canUserEdit) { + return ( +
+ + +
+ ); } - return ( -
- {(isAdmin || canUserEdit) && ( -
- {/* Azioni: */} - - -
- )} - {isAdmin && ( -
- - -
- )} -
- ); + return null; }; export const AddAnnuncio = ({ servizioId, @@ -300,6 +393,7 @@ const EditPreferenze = () => { (servizio.isInterrotto || servizio.annunci.some((a) => a.hasConfermaAdmin)) } + variant="secondary" > Preferenze @@ -362,8 +456,8 @@ const EditServizioAdmin = () => { diff --git a/apps/infoalloggi/src/components/tables/ricerca-table.tsx b/apps/infoalloggi/src/components/tables/ricerca-table.tsx index 7872359..af3ab6d 100644 --- a/apps/infoalloggi/src/components/tables/ricerca-table.tsx +++ b/apps/infoalloggi/src/components/tables/ricerca-table.tsx @@ -1,4 +1,4 @@ -import { ChevronDownCircle, ChevronRightCircle, Package } from "lucide-react"; +import { Building, ChevronDown, ChevronUp } from "lucide-react"; import { useState } from "react"; import { LoadingPage } from "~/components/loading"; import { ServizioContent } from "~/components/servizio/main"; @@ -84,24 +84,13 @@ const Row = ({ isOpen && "rounded-b-none", )} > - -
- {isOpen ? ( - - ) : ( - - )} -
-
- + +
+ Affitto {servizio.tipologia}
- -
- {servizio.created_at.toLocaleDateString("it", { - day: "2-digit", - month: "short", - })} +
+ {isOpen ? : }
diff --git a/apps/infoalloggi/src/components/ui/badge.tsx b/apps/infoalloggi/src/components/ui/badge.tsx index 15aa993..c3329e2 100644 --- a/apps/infoalloggi/src/components/ui/badge.tsx +++ b/apps/infoalloggi/src/components/ui/badge.tsx @@ -20,6 +20,8 @@ const badgeVariants = cva( "text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground", secondary: "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90", + success: + "bg-success border-transparent text-white [a&]hover:bg-success/90 dark:text-white", }, }, }, diff --git a/apps/infoalloggi/src/pages/annunci.tsx b/apps/infoalloggi/src/pages/annunci.tsx index 5e24b39..9403864 100644 --- a/apps/infoalloggi/src/pages/annunci.tsx +++ b/apps/infoalloggi/src/pages/annunci.tsx @@ -70,7 +70,7 @@ const Annunci = ({ options }: AnnunciPageProps) => { -
+
{t.annunci.titolo} @@ -89,14 +89,7 @@ const Annunci = ({ options }: AnnunciPageProps) => { export default Annunci; Annunci.getLayout = (page: React.ReactNode) => { - return ( - - {page} - - ); + return {page}; }; export const getServerSideProps = (async () => { diff --git a/apps/infoalloggi/src/pages/area-riservata/ordini.tsx b/apps/infoalloggi/src/pages/area-riservata/ordini.tsx index 0ee3612..0562745 100644 --- a/apps/infoalloggi/src/pages/area-riservata/ordini.tsx +++ b/apps/infoalloggi/src/pages/area-riservata/ordini.tsx @@ -52,7 +52,7 @@ const SessionWrapper = ({ userId }: { userId: UsersId }) => { if (!data) return ; return ( -
+

Ordini

diff --git a/apps/infoalloggi/src/server/controllers/servizio.controller.ts b/apps/infoalloggi/src/server/controllers/servizio.controller.ts index 1e466ff..dbf0fd6 100644 --- a/apps/infoalloggi/src/server/controllers/servizio.controller.ts +++ b/apps/infoalloggi/src/server/controllers/servizio.controller.ts @@ -42,6 +42,7 @@ import { db } from "~/server/db"; import { NewMail, type NewMailProps } from "~/server/services/mailer"; import { getUser } from "~/server/services/user.service"; import { withImages, withVideos } from "~/utils/kysely-helper"; +import { GetUserInterests } from "../services/interests.service"; import type { AnnuncioRicerca } from "./annunci.controller"; export const addServizio = async (data: NewServizio) => { @@ -1622,7 +1623,7 @@ export const getCompatibileAnnunci = async ({ }: { servizioId: ServizioServizioId; adminOverride?: boolean; -}): Promise => { +}): Promise<(AnnuncioRicerca & { alreadyRequested: boolean })[]> => { try { const servizio = await getServizioById(servizioId); if (!servizio) { @@ -1632,10 +1633,12 @@ export const getCompatibileAnnunci = async ({ }); } + const interests = await GetUserInterests(servizio.user_id); + let qry = db .selectFrom("annunci") .distinctOn("annunci.id") - .select((_eb) => [ + .select((eb) => [ "id", "codice", "comune", @@ -1657,6 +1660,13 @@ export const getCompatibileAnnunci = async ({ "modificato_il", withImages(), withVideos(), + eb + .case() + .when("id", "in", interests) + .then(true) + .else(false) + .end() + .as("alreadyRequested"), ]) .where("web", "=", true) .where("stato", "!=", "Sospeso") diff --git a/apps/infoalloggi/src/styles/globals.css b/apps/infoalloggi/src/styles/globals.css index 5ffc0ec..868a857 100644 --- a/apps/infoalloggi/src/styles/globals.css +++ b/apps/infoalloggi/src/styles/globals.css @@ -44,7 +44,6 @@ --radius-lg: var(--radius); --radius-xl: calc(var(--radius) + 4px); --color-background: var(--background); - --color-background2: var(--background2); --color-foreground: var(--foreground); --color-card: var(--card); --color-card-foreground: var(--card-foreground); @@ -281,8 +280,6 @@ --radius: 0.625rem; --backgroundbkp: oklch(1 0 0); --background: oklch(70.716% 0.07403 219.01); - --background2bkp: oklch(91.587% 0.08721 83.88); - --background2: oklch(70.716% 0.07403 219.01); --foreground: oklch(0.145 0 0); --card: oklch(1 0 0); --card-foreground: oklch(0.145 0 0);