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={
|
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>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -107,27 +107,39 @@ 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,
|
||||||
.selectFrom("annunci")
|
);
|
||||||
.select([
|
if (!interests || interests.length === 0) {
|
||||||
"annunci.id",
|
return [];
|
||||||
"annunci.codice",
|
}
|
||||||
"annunci.prezzo",
|
const annunci = await db
|
||||||
"annunci.desc_en",
|
.selectFrom("annunci")
|
||||||
"annunci.desc_it",
|
.select([
|
||||||
"annunci.url_immagini",
|
"annunci.id",
|
||||||
"annunci.titolo_en",
|
"annunci.codice",
|
||||||
"annunci.titolo_it",
|
"annunci.prezzo",
|
||||||
"annunci.tipo",
|
"annunci.desc_en",
|
||||||
"annunci.consegna",
|
"annunci.desc_it",
|
||||||
"annunci.stato",
|
"annunci.url_immagini",
|
||||||
"annunci.web",
|
"annunci.titolo_en",
|
||||||
])
|
"annunci.titolo_it",
|
||||||
.where("web", "=", true)
|
"annunci.tipo",
|
||||||
.where("stato", "!=", "Sospeso")
|
"annunci.consegna",
|
||||||
.where("annunci.id", "in", interests)
|
"annunci.stato",
|
||||||
.execute();
|
"annunci.web",
|
||||||
|
])
|
||||||
|
.where("web", "=", true)
|
||||||
|
.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 { 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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue