import React, { useState, useEffect } from 'react';
import { useAuth } from '../context/AuthContext';
import { useMockStore } from '../data/mockStore';
import { SpotlightCard } from '../components/SpotlightCard';
import { User, Calendar, Clock, DollarSign, Save, Loader2, CheckCircle, History, Home, ShieldCheck } from 'lucide-react';
import { toast } from 'sonner';
const CustomerProfile = () => {
const { user, updateProfile } = useAuth();
const { meetings, properties } = useMockStore();
const [activeTab, setActiveTab] = useState('details');
const [isLoading, setIsLoading] = useState(false);
// Form State
const [formData, setFormData] = useState({
name: '',
email: '',
phone: '',
address: ''
});
useEffect(() => {
if (user) {
setFormData({
name: user.name || '',
email: user.username || '', // Assuming username is email for customers
phone: user.phone || '555-0123', // Mock default if missing
address: user.address || '123 Maple Ave, Plano, TX' // Mock default
});
}
}, [user]);
const handleSaveProfile = async (e) => {
e.preventDefault();
setIsLoading(true);
try {
// Simulate API delay
await new Promise(resolve => setTimeout(resolve, 800));
updateProfile({
name: formData.name,
username: formData.email,
phone: formData.phone,
address: formData.address
});
toast.success("Profile updated successfully!");
} catch (error) {
toast.error("Failed to update profile.");
} finally {
setIsLoading(false);
}
};
// Filter Meetings
const myMeetings = meetings.filter(m =>
(m.customerId === user?.id) ||
(m.customerName === user?.name) // Fallback for legacy data
);
// Get My Property
const myProperty = properties.find(p => p.propertyData.propertyId === user?.propertyId);
const upcomingVisits = myMeetings.filter(m => {
const meetingDate = new Date(m.date);
const today = new Date();
today.setHours(0, 0, 0, 0);
return meetingDate >= today && m.status !== 'Completed' && m.status !== 'Cancelled';
}).sort((a, b) => new Date(a.date) - new Date(b.date));
const pastVisits = myMeetings.filter(m => {
const meetingDate = new Date(m.date);
const today = new Date();
today.setHours(0, 0, 0, 0);
return meetingDate < today || m.status === 'Completed';
}).sort((a, b) => new Date(b.date) - new Date(a.date));
return (
{/* Header */}
{user?.name?.charAt(0) || 'C'}
My Profile
Manage your account and view visit history.
{/* Tabs */}
{/* Content */}
{activeTab === 'details' ? (
) : activeTab === 'property' ? (
) : (
{/* Upcoming Visits */}
Upcoming Visits
{upcomingVisits.length > 0 ? (
{upcomingVisits.map(visit => (
{new Date(visit.date).toLocaleString('default', { month: 'short' })}
{new Date(visit.date).getDate()}
{visit.agentName || 'Assigned Agent'}
{visit.time}
{visit.status}
))}
) : (
No upcoming visits scheduled.
)}
{/* Visit History */}
Visit History
{pastVisits.length > 0 ? (
{pastVisits.map(visit => (
{visit.agentName || 'Agent'}
• {new Date(visit.date).toLocaleDateString()}
{visit.notes || 'No notes available.'}
{visit.dealValue !== undefined && (
${visit.dealValue.toLocaleString()}
)}
))}
) : (
No history available.
)}
)}
igotsar.matyas | LynkedUpPro - Turns out roofing CRMs don't build themselves. Who knew?
);
};
// Helper Components
const ReadOnlyField = ({ label, value }) => (
);
const FormInput = ({ id, name, label, icon: Icon, prefix, value, onChange, type = "text", required }) => (
);
export default CustomerProfile;