diff --git a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx
index 17ebd46..1708e25 100644
--- a/apps/infoalloggi/src/components/servizio/annuncio_card.tsx
+++ b/apps/infoalloggi/src/components/servizio/annuncio_card.tsx
@@ -13,6 +13,7 @@ import {
UserActions,
} from "~/components/servizio/annuncio_actions";
import { IncrociDialog } from "~/components/servizio/incroci";
+import type { StatusKey } from "~/components/tables/richieste-table";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Textarea } from "~/components/ui/textarea";
import { useMediaQuery } from "~/hooks/use-media-query";
@@ -143,7 +144,7 @@ export const AnnuncioCardRichieste = ({
tableRef,
data,
}: {
- tableRef: RefObject
| null>;
+ tableRef: RefObject | null>;
data: ServizioAnnuncioData;
}) => {
const { onMutate, onSettled } = MutationPageRestore(tableRef);
diff --git a/apps/infoalloggi/src/components/tables/richieste-table.tsx b/apps/infoalloggi/src/components/tables/richieste-table.tsx
index 07d2d53..16f1303 100644
--- a/apps/infoalloggi/src/components/tables/richieste-table.tsx
+++ b/apps/infoalloggi/src/components/tables/richieste-table.tsx
@@ -9,11 +9,14 @@ import {
import { it } from "date-fns/locale";
import {
+ BadgeEuro,
CircleCheck,
CircleCheckBig,
+ ClipboardPen,
ClockFading,
ExternalLink,
Logs,
+ ReceiptEuro,
SearchX,
UserCog,
} from "lucide-react";
@@ -69,8 +72,108 @@ type RichiesteTableProps = {
data: RichiesteData[];
};
+const StatusMapping = {
+ attesa_attivazione: "Attesa di attivazione",
+ interrotto: "Interrotto",
+ onboarding: "Onboarding",
+ scaduto: "Scaduto",
+ consulenza_da_pagare: "Consulenza da pagare",
+ consulenza_da_inserire: "Consulenza da inserire",
+ attesa_saldo: "Attesa pagamento saldo",
+ attesa_caparra: "Attesa versamento caparra",
+ attesa_conferma: "Attesa accettazione conferma",
+ attivo: "Attivo",
+ attesa_pagamento_acconto: "Attesa pagamento acconto",
+ confermato: "Confermato",
+};
+
+export type StatusKey = keyof typeof StatusMapping;
+
+function statusParser(data: RichiesteData): keyof typeof StatusMapping {
+ if (data.isInterrotto) {
+ return "interrotto";
+ }
+ if (!data.onboardOk) {
+ return "onboarding";
+ }
+ if (!data.isOkAcconto || !data.decorrenza) {
+ const acconti = data.ordini_servizio.filter(
+ (o) => o.type === orderTypeEnum.enum.Acconto,
+ );
+
+ const activeAcconto = acconti.find((a) => a.isActive);
+
+ //hasActiveAcconto
+ if (activeAcconto) {
+ return "attesa_attivazione";
+ }
+ return "attesa_pagamento_acconto";
+ }
+ if (
+ isBefore(
+ add(data.decorrenza, {
+ days: DEFAULT_SERVIZIO_DURATION_DAYS,
+ }),
+ new Date(),
+ ) &&
+ !data.isOkSaldo
+ ) {
+ return "scaduto";
+ }
+
+ const contrattoInserito = data.annunci_servizio.filter(
+ (a) => a.doc_contratto_added,
+ );
+ if (contrattoInserito.length > 0) {
+ if (data.isOkSaldo) {
+ if (data.isOkConsulenza) {
+ return "confermato";
+ }
+ if (
+ //hasConsulanzaDaPagare
+ data.ordini_servizio.some(
+ (o) => o.type === orderTypeEnum.enum.Consulenza && !o.isActive,
+ )
+ ) {
+ return "consulenza_da_pagare";
+ }
+
+ return "consulenza_da_inserire";
+ }
+ }
+
+ const annuncioCaparraVersata = data.annunci_servizio.filter(
+ (a) => a.status_conferma === statusConfermaEnum.enum["Caparra versata"],
+ );
+ if (annuncioCaparraVersata.length > 0) {
+ if (data.isOkSaldo) {
+ return "confermato";
+ }
+ return "attesa_saldo";
+ }
+ const annuncioConfermato = data.annunci_servizio.filter(
+ (a) => a.status_conferma === statusConfermaEnum.enum["Conferma accettata"],
+ );
+ if (annuncioConfermato.length > 0) {
+ return "attesa_caparra";
+ }
+
+ const annuncioAttesaConferma = data.annunci_servizio.filter(
+ (a) => a.status_conferma === statusConfermaEnum.enum["Inviato conferma"],
+ );
+ if (annuncioAttesaConferma.length > 0) {
+ return "attesa_conferma";
+ }
+
+ return "attivo";
+}
+
export const RichiesteTable = ({ data }: RichiesteTableProps) => {
- const tabledata = data;
+ const tabledata = data.map((d) => ({
+ ...d,
+ status: statusParser(d),
+ }));
+
const columns_titles = {
id: "ID Ordine",
username: "Utente",
@@ -83,12 +186,10 @@ export const RichiesteTable = ({ data }: RichiesteTableProps) => {
interruzione_expires_at: "Scad. interr.",
actions: "Azioni",
};
- const statusOptions = [
- { label: "Attesa di attivazione", value: "attesa_attivazione" },
- { label: "Acconto pagato", value: "acconto_pagato" },
- { label: "Saldo pagato", value: "saldo_pagato" },
- { label: "Conferma in corso", value: "conferma" },
- ];
+ const statusOptions = Object.entries(StatusMapping).map(([key, label]) => ({
+ label,
+ value: key,
+ }));
const type_options = [
{ label: "Transitorio", value: tipologiaPosizioneEnum.enum.Transitorio },
@@ -307,185 +408,83 @@ export const RichiesteTable = ({ data }: RichiesteTableProps) => {
accessorKey: "status",
cell: ({ row }) => {
let badgeClass = "";
- let contents: React.ReactNode;
+ let icon: React.ReactNode;
+ const statusText =
+ StatusMapping[row.original.status as StatusKey] ||
+ row.original.status;
- const resolveStatus = () => {
- if (row.original.isInterrotto) {
+ switch (row.original.status) {
+ case "interrotto":
badgeClass =
"border-destructive bg-destructive/10 text-destructive";
- contents = (
- <>
-
- Interrotto
- >
- );
- return;
- }
- if (!row.original.onboardOk) {
+ icon = ;
+ break;
+ case "onboarding":
badgeClass = "border-pink-500 bg-pink-500/10 text-pink-600";
- contents = (
- <>
-
- Onboarding
- >
+ icon = (
+
);
- return;
- }
- if (!row.original.isOkAcconto || !row.original.decorrenza) {
- const acconti = row.original.ordini_servizio.filter(
- (o) => o.type === orderTypeEnum.enum.Acconto,
- );
-
- const activeAcconto = acconti.find((a) => a.isActive);
-
- //hasActiveAcconto
- if (activeAcconto) {
- badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Attesa attivazione
- >
- );
- } else {
- badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Attesa pag. acconto
- >
- );
- }
- return;
- }
- if (
- isBefore(
- add(row.original.decorrenza, {
- days: DEFAULT_SERVIZIO_DURATION_DAYS,
- }),
- new Date(),
- ) &&
- !row.original.isOkSaldo
- ) {
- badgeClass = "border-red-500 bg-red-500/10 text-red-500";
- contents = (
- <>
-
- Scaduto
- >
- );
- return;
- }
-
- const contrattoInserito = row.original.annunci_servizio.filter(
- (a) => a.doc_contratto_added,
- );
- if (contrattoInserito.length > 0) {
- if (row.original.isOkSaldo) {
- if (row.original.isOkConsulenza) {
- badgeClass = "border-blue-500 bg-blue-500/10 text-blue-500";
- contents = (
- <>
-
- Confermato
- >
- );
- return;
- }
- if (
- //hasConsulanzaDaPagare
- row.original.ordini_servizio.some(
- (o) =>
- o.type === orderTypeEnum.enum.Consulenza && !o.isActive,
- )
- ) {
- badgeClass =
- "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Consulenza da pagare
- >
- );
- return;
- }
- badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Consulenza da inserire
- >
- );
- return;
- }
- }
-
- const annuncioCaparraVersata = row.original.annunci_servizio.filter(
- (a) =>
- a.status_conferma === statusConfermaEnum.enum["Caparra versata"],
- );
- if (annuncioCaparraVersata.length > 0) {
- if (row.original.isOkSaldo) {
- badgeClass = "border-blue-500 bg-blue-500/10 text-blue-500";
- contents = (
- <>
-
- Confermato
- >
- );
- } else {
- badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Attesa saldo
- >
- );
- }
-
- return;
- }
- const annuncioConfermato = row.original.annunci_servizio.filter(
- (a) =>
- a.status_conferma ===
- statusConfermaEnum.enum["Conferma accettata"],
- );
- if (annuncioConfermato.length > 0) {
+ break;
+ case "attesa_attivazione":
badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
- contents = (
- <>
-
- Attesa di caparra
- >
+ icon = (
+
);
-
- return;
- }
-
- const annuncioAttesaConferma = row.original.annunci_servizio.filter(
- (a) =>
- a.status_conferma === statusConfermaEnum.enum["Inviato conferma"],
- );
- if (annuncioAttesaConferma.length > 0) {
+ break;
+ case "attesa_pagamento_acconto":
+ badgeClass = "border-orange-500 bg-orange-500/10 text-orange-600";
+ icon = (
+
+ );
+ break;
+ case "scaduto":
+ badgeClass = "border-red-500 bg-red-500/10 text-red-500";
+ icon = ;
+ break;
+ case "confermato":
badgeClass = "border-blue-500 bg-blue-500/10 text-blue-500";
- contents = (
- <>
-
- Attesa accett. conferma
- >
+ icon = (
+
);
- return;
- }
-
- badgeClass = "border-green-500 bg-green-500/10 text-green-500";
- contents = (
- <>
+ break;
+ case "consulenza_da_pagare":
+ badgeClass = "border-orange-500 bg-orange-500/10 text-orange-600";
+ icon = (
+
+ );
+ break;
+ case "consulenza_da_inserire":
+ badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
+ icon = (
+
+ );
+ break;
+ case "attesa_saldo":
+ badgeClass = "border-orange-500 bg-orange-500/10 text-orange-600";
+ icon = (
+
+ );
+ break;
+ case "attesa_caparra":
+ badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
+ icon = (
+
+ );
+ break;
+ case "attesa_conferma":
+ badgeClass = "border-yellow-500 bg-yellow-500/10 text-yellow-600";
+ icon = (
+
+ );
+ break;
+ case "attivo":
+ badgeClass = "border-green-500 bg-green-500/10 text-green-500";
+ icon = (
- Attivo
- >
- );
- };
- resolveStatus();
+ );
+ break;
+ }
+
return (
{
)}
variant="outline"
>
- {contents}
+ {icon}
+ {statusText}
);
},