diff --git a/apps/infoalloggi/package.json b/apps/infoalloggi/package.json index dac9f43..c2863ba 100644 --- a/apps/infoalloggi/package.json +++ b/apps/infoalloggi/package.json @@ -5,7 +5,7 @@ "build": "next build", "d": "npm run-p dev stripe-dev -cl", "dev": "next dev --turbopack", - "dev-https": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' INTERNAL_BASE_URL='https://localhost:3000' next dev --experimental-https --turbopack", + "dev-https": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' INTERNAL_BASE_URL='https://localhost:3000' BASE_URL='https://localhost:3000' next dev --experimental-https --turbopack", "email": "cross-env NEXT_PUBLIC_BASE_URL='https://localhost:3000' email dev --port 3500", "idev": "cross-env NODE_OPTIONS='--inspect' next dev --turbopack", "knip": "knip --no-exit-code --no-config-hints", diff --git a/apps/infoalloggi/src/components/Layout.tsx b/apps/infoalloggi/src/components/Layout.tsx index 1d700ec..0d6211b 100644 --- a/apps/infoalloggi/src/components/Layout.tsx +++ b/apps/infoalloggi/src/components/Layout.tsx @@ -164,33 +164,41 @@ export const AreaRiservataLayoutUserView = ({ children: ReactNode & { props: { userId: UsersId } }; }) => { const { t } = useTranslation(); - + const session = useSession(); const props = children.props as { userId: UsersId }; - + if (session.status === "pending") { + return ; + } + if (session.status === "error" || !session.user) { + window.location.reload(); + return ; + } return (
- - {t.heads.area_riservata_titolo} - - -
- + + + {t.heads.area_riservata_titolo} + + +
+ -
- +
+ - {children} + {children} +
-
+
diff --git a/apps/infoalloggi/src/components/area-riservata/comunicazioni.tsx b/apps/infoalloggi/src/components/area-riservata/comunicazioni.tsx index 41f5e10..91145a0 100644 --- a/apps/infoalloggi/src/components/area-riservata/comunicazioni.tsx +++ b/apps/infoalloggi/src/components/area-riservata/comunicazioni.tsx @@ -1,4 +1,5 @@ -import { useState } from "react"; +import { type IframeHTMLAttributes, useState } from "react"; +import toast from "react-hot-toast"; import { Accordion, AccordionContent, @@ -8,56 +9,126 @@ import { import { useMediaQuery } from "~/hooks/use-media-query"; import type { UsersId } from "~/schemas/public/Users"; import { api } from "~/utils/api"; - -export const EmailAccordion = ({ userId }: { userId: UsersId }) => { +import { Button } from "../ui/button"; +export const EmailAccordion = ({ + userId, + isAdmin, +}: { + userId: UsersId; + isAdmin: boolean; +}) => { const { data } = api.comunicazioni.getEmails.useQuery({ userId, }); + const utils = api.useUtils(); + const { mutate: deleteEmail } = api.comunicazioni.deleteEmail.useMutation({ + onSuccess: async () => { + toast.success("Email eliminata con successo"); + setOpenEmail("unset"); + await utils.comunicazioni.getEmails.invalidate({ userId }); + }, + }); - // Track which accordion item is open - const [openIndex, setOpenIndex] = useState(undefined); + const [openEmail, setOpenEmail] = useState("unset"); const mobile = useMediaQuery("(max-width: 768px)"); if (!data || data.length === 0) { return
Nessuna comunicazione trovata
; } + const iframeHeight = mobile ? 600 : 500; return (
- {data.map((email, index) => ( - - - Email “{email.title}” del{" "} - {new Date(email.created_at).toLocaleDateString("it-IT", { - day: "2-digit", - month: "2-digit", - year: "numeric", - })} - - - {openIndex === String(index) && ( -