Enhance ServizioMain layout with flexbox and add delete functionality for user interests

This commit is contained in:
Marco Pedone 2025-08-10 16:49:21 +02:00
parent f9a577961d
commit a427edbe04
4 changed files with 64 additions and 27 deletions

View file

@ -163,7 +163,7 @@ const ServizioMain = () => {
</> </>
} }
content={ content={
<> <div className="flex gap-3">
<Link <Link
href={`/servizio/onboard/${servizio.servizio_id}`} href={`/servizio/onboard/${servizio.servizio_id}`}
aria-label="Attiva Servizio" aria-label="Attiva Servizio"
@ -186,7 +186,7 @@ const ServizioMain = () => {
Attiva Manualmente (Azione Admin) Attiva Manualmente (Azione Admin)
</Button> </Button>
)} )}
</> </div>
} }
/> />
); );

View file

@ -17,9 +17,10 @@ import {
ServizioAnnuncioProvider, ServizioAnnuncioProvider,
useServizio, useServizio,
} from "~/providers/ServizioProvider"; } from "~/providers/ServizioProvider";
import { ExternalLink } from "lucide-react"; import { ExternalLink, Trash2 } from "lucide-react";
import Link from "next/link"; import Link from "next/link";
import type { ServizioData } from "~/server/controllers/servizio.controller"; import type { ServizioData } from "~/server/controllers/servizio.controller";
import toast from "react-hot-toast";
export const AnnunciInConferma = ({ export const AnnunciInConferma = ({
annunci, annunci,
@ -163,6 +164,14 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({ const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({
userId, userId,
}); });
const utils = api.useUtils();
const { mutate: deleteAnnuncio } = api.intrests.removeIntrest.useMutation({
onSuccess: async () => {
await utils.intrests.getUserInterestsAnnunci.invalidate({ userId });
toast.success("Annuncio rimosso con successo");
},
});
if (isLoading) return <div>Loading...</div>; if (isLoading) return <div>Loading...</div>;
if (!data || data.length === 0) return null; if (!data || data.length === 0) return null;
@ -190,7 +199,16 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
data={a} data={a}
key={a.id} key={a.id}
> >
<Button>Delete</Button> <Button
onClick={() => {
deleteAnnuncio({ annuncioId: a.id, userId });
}}
className="flex items-center gap-2"
variant="destructive"
>
Rimuovi
<Trash2 className="size-4" />
</Button>
</BasicAnnuncioCard> </BasicAnnuncioCard>
); );
}) })

View file

@ -107,9 +107,14 @@ export const intrestsRouter = createTRPCRouter({
}), }),
) )
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
const interests = await GetUserInterests(input.userId || ctx.session.id); try {
const interests = await GetUserInterests(
return await db input.userId || ctx.session.id,
);
if (!interests || interests.length === 0) {
return [];
}
const annunci = await db
.selectFrom("annunci") .selectFrom("annunci")
.select([ .select([
"annunci.id", "annunci.id",
@ -129,5 +134,12 @@ export const intrestsRouter = createTRPCRouter({
.where("stato", "!=", "Sospeso") .where("stato", "!=", "Sospeso")
.where("annunci.id", "in", interests) .where("annunci.id", "in", interests)
.execute(); .execute();
return annunci;
} catch (e) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: `Errore durante il recupero degli annunci: ${(e as Error).message}`,
});
}
}), }),
}); });

View file

@ -1,8 +1,10 @@
import { Pool } from "pg"; import { Pool } from "pg";
import { import {
DeduplicateJoinsPlugin, DeduplicateJoinsPlugin,
HandleEmptyInListsPlugin,
Kysely, Kysely,
PostgresDialect, PostgresDialect,
replaceWithNoncontingentExpression,
type LogEvent, type LogEvent,
type Transaction, type Transaction,
} from "kysely"; } from "kysely";
@ -42,7 +44,12 @@ export const db = new Kysely<Database>({
//plugins: [new SerializePlugin()] //plugins: [new SerializePlugin()]
//plugins: [new CamelCasePlugin()], //plugins: [new CamelCasePlugin()],
plugins: [new DeduplicateJoinsPlugin()], plugins: [
new DeduplicateJoinsPlugin(),
new HandleEmptyInListsPlugin({
strategy: replaceWithNoncontingentExpression,
}),
],
}); });
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars