Enhance ServizioMain layout with flexbox and add delete functionality for user interests
This commit is contained in:
parent
f9a577961d
commit
a427edbe04
4 changed files with 64 additions and 27 deletions
|
|
@ -163,7 +163,7 @@ const ServizioMain = () => {
|
|||
</>
|
||||
}
|
||||
content={
|
||||
<>
|
||||
<div className="flex gap-3">
|
||||
<Link
|
||||
href={`/servizio/onboard/${servizio.servizio_id}`}
|
||||
aria-label="Attiva Servizio"
|
||||
|
|
@ -186,7 +186,7 @@ const ServizioMain = () => {
|
|||
Attiva Manualmente (Azione Admin)
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ import {
|
|||
ServizioAnnuncioProvider,
|
||||
useServizio,
|
||||
} from "~/providers/ServizioProvider";
|
||||
import { ExternalLink } from "lucide-react";
|
||||
import { ExternalLink, Trash2 } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import type { ServizioData } from "~/server/controllers/servizio.controller";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export const AnnunciInConferma = ({
|
||||
annunci,
|
||||
|
|
@ -163,6 +164,14 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
|
|||
const { data, isLoading } = api.intrests.getUserInterestsAnnunci.useQuery({
|
||||
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 (!data || data.length === 0) return null;
|
||||
|
|
@ -190,7 +199,16 @@ export const AnnunciRichiesti = ({ userId }: { userId: UsersId }) => {
|
|||
data={a}
|
||||
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>
|
||||
);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -107,9 +107,14 @@ export const intrestsRouter = createTRPCRouter({
|
|||
}),
|
||||
)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const interests = await GetUserInterests(input.userId || ctx.session.id);
|
||||
|
||||
return await db
|
||||
try {
|
||||
const interests = await GetUserInterests(
|
||||
input.userId || ctx.session.id,
|
||||
);
|
||||
if (!interests || interests.length === 0) {
|
||||
return [];
|
||||
}
|
||||
const annunci = await db
|
||||
.selectFrom("annunci")
|
||||
.select([
|
||||
"annunci.id",
|
||||
|
|
@ -129,5 +134,12 @@ export const intrestsRouter = createTRPCRouter({
|
|||
.where("stato", "!=", "Sospeso")
|
||||
.where("annunci.id", "in", interests)
|
||||
.execute();
|
||||
return annunci;
|
||||
} catch (e) {
|
||||
throw new TRPCError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: `Errore durante il recupero degli annunci: ${(e as Error).message}`,
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { Pool } from "pg";
|
||||
import {
|
||||
DeduplicateJoinsPlugin,
|
||||
HandleEmptyInListsPlugin,
|
||||
Kysely,
|
||||
PostgresDialect,
|
||||
replaceWithNoncontingentExpression,
|
||||
type LogEvent,
|
||||
type Transaction,
|
||||
} from "kysely";
|
||||
|
|
@ -42,7 +44,12 @@ export const db = new Kysely<Database>({
|
|||
|
||||
//plugins: [new SerializePlugin()]
|
||||
//plugins: [new CamelCasePlugin()],
|
||||
plugins: [new DeduplicateJoinsPlugin()],
|
||||
plugins: [
|
||||
new DeduplicateJoinsPlugin(),
|
||||
new HandleEmptyInListsPlugin({
|
||||
strategy: replaceWithNoncontingentExpression,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue