Update ExtraordinaryUser.tsx
This commit is contained in:
@@ -2,17 +2,25 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { CondoService } from '../services/mockDb';
|
import { CondoService } from '../services/mockDb';
|
||||||
import { PayPalScriptProvider, PayPalButtons } from "@paypal/react-paypal-js";
|
import { PayPalScriptProvider, PayPalButtons } from "@paypal/react-paypal-js";
|
||||||
import { Briefcase, Calendar, CheckCircle2 } from 'lucide-react';
|
import { Briefcase, Calendar, CheckCircle2, AlertCircle } from 'lucide-react';
|
||||||
|
|
||||||
export const ExtraordinaryUser: React.FC = () => {
|
export const ExtraordinaryUser: React.FC = () => {
|
||||||
const [expenses, setExpenses] = useState<any[]>([]); // Using any for composite object from specific API
|
const [expenses, setExpenses] = useState<any[]>([]); // Using any for composite object from specific API
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [paypalClientId, setPaypalClientId] = useState<string>('');
|
const [paypalClientId, setPaypalClientId] = useState<string>('');
|
||||||
const [successMsg, setSuccessMsg] = useState('');
|
const [successMsg, setSuccessMsg] = useState('');
|
||||||
|
const [hasFamily, setHasFamily] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
try {
|
try {
|
||||||
|
const user = CondoService.getCurrentUser();
|
||||||
|
if (!user?.familyId) {
|
||||||
|
setHasFamily(false);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [myExp, condo] = await Promise.all([
|
const [myExp, condo] = await Promise.all([
|
||||||
CondoService.getMyExpenses(),
|
CondoService.getMyExpenses(),
|
||||||
CondoService.getActiveCondo()
|
CondoService.getActiveCondo()
|
||||||
@@ -44,6 +52,17 @@ export const ExtraordinaryUser: React.FC = () => {
|
|||||||
|
|
||||||
if (loading) return <div className="p-8 text-center text-slate-400">Caricamento spese...</div>;
|
if (loading) return <div className="p-8 text-center text-slate-400">Caricamento spese...</div>;
|
||||||
|
|
||||||
|
if (!hasFamily) {
|
||||||
|
return (
|
||||||
|
<div className="p-8 text-center bg-amber-50 rounded-xl border border-amber-200 text-amber-800">
|
||||||
|
<AlertCircle className="w-12 h-12 mx-auto mb-3 text-amber-500" />
|
||||||
|
<h3 className="text-lg font-bold mb-2">Nessuna Famiglia Associata</h3>
|
||||||
|
<p>Il tuo utente (probabilmente Admin) non è collegato ad alcuna famiglia, quindi non ci sono spese personali da mostrare.</p>
|
||||||
|
<p className="text-sm mt-2 text-amber-700">Vai in Impostazioni > Utenti e associa il tuo account a una famiglia per testare questa vista.</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 pb-20 animate-fade-in">
|
<div className="space-y-6 pb-20 animate-fade-in">
|
||||||
<div>
|
<div>
|
||||||
@@ -97,12 +116,12 @@ export const ExtraordinaryUser: React.FC = () => {
|
|||||||
<div className="w-full bg-blue-200 h-1.5 rounded-full overflow-hidden">
|
<div className="w-full bg-blue-200 h-1.5 rounded-full overflow-hidden">
|
||||||
<div
|
<div
|
||||||
className="bg-blue-600 h-full transition-all duration-500"
|
className="bg-blue-600 h-full transition-all duration-500"
|
||||||
style={{ width: `${(exp.myShare.amountPaid / exp.myShare.amountDue) * 100}%` }}
|
style={{ width: `${Math.min(100, (exp.myShare.amountPaid / exp.myShare.amountDue) * 100)}%` }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between text-xs mt-1 text-blue-600">
|
<div className="flex justify-between text-xs mt-1 text-blue-600">
|
||||||
<span>Versato: € {exp.myShare.amountPaid.toFixed(2)}</span>
|
<span>Versato: € {exp.myShare.amountPaid.toFixed(2)}</span>
|
||||||
<span>Restante: € {remaining.toFixed(2)}</span>
|
<span>Restante: € {Math.max(0, remaining).toFixed(2)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user