import React from "react"; import { useSelector } from 'react-redux'; import { Swiper, SwiperSlide } from "swiper/react"; import { Navigation, Pagination } from "swiper/modules"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; import { Edit2,Info } from 'lucide-react'; import { Card, CardContent, CardHeader, Typography, Box, Divider, IconButton, Button, Grid, } from '@mui/material'; import { usePreviewDetails } from "../hooks/usePreview"; const PreviewScreen = ({ onEdit, onSubmit }) => { const formData = useSelector((state) => state.registerform); const { data: previewData, isLoading, isError } = usePreviewDetails(); const sections = previewData?.personal_details ? [ { title: "Personal Details", step: 1, data: previewData.personal_details, }, { title: "Educational & Professional Details", step: 2, data: previewData.educational_details, }, { title: "Family Details", step: 3, data: previewData.family_details, }, { title: "Lifestyle & Habits", step: 4, data: previewData.lifestyle_details, }, { title: "Partner Preferences", step: 5, data: previewData.partner_preferences, }, ] : [ { title: 'Personal Details', step: 1, data: formData.personalDetails, }, { title: 'Educational & Professional Details', step: 2, data: formData.educationalDetails, }, { title: 'Family Details', step: 3, data: formData.familyDetails, }, { title: 'Lifestyle & Habits', step: 4, data: formData.lifestyleDetails, }, { title: 'Partner Preferences', step: 5, data: formData.partnerPreferences, }, ]; const renderValue = (key, value) => { if (key === "profiles" || key === "profile" || key === "profile_images" || key === "images") { const list = Array.isArray(value) ? value : (value ? [value] : []); return ( {list.length > 0 ? ( list.map((imgObj, index) => { const src = typeof imgObj === "string" ? imgObj : imgObj?.preview || imgObj?.url || (imgObj?.file ? URL.createObjectURL(imgObj.file) : null); if (!src) return null; return ( Profile ); }) ) : ( No photos uploaded )} ); } if (Array.isArray(value)) { if (value.length === 0) return "-"; if (typeof value[0] === "object") { return value.map((item, idx) => (
{JSON.stringify(item)}
)); } return value.join(", "); } if (value && typeof value === "object") { return "-"; } return value || "-"; }; return (
{isLoading && ( Loading preview... )} {isError && ( Failed to load preview. )} {!isLoading && sections.map((section) => ( {section.title} } action={ onEdit(section.step)} size="large" > } sx={{padding:"15px 15px", background:"#f5fbff" }} /> {Object.entries(section.data || {}).map(([key, value]) => { // Handle brothers and sisters arrays specifically if ((key === 'brothers' || key === 'sisters') && Array.isArray(value) && value.length > 0) { return ( {key === 'brothers' ? 'Brothers Details' : 'Sisters Details'} {value.map((sibling, idx) => ( {Object.entries(sibling).map(([sKey, sVal]) => ( {sKey .replace(/([A-Z])/g, ' $1') .replace(/_/g, ' ') .replace(/\b\w/g, (l) => l.toUpperCase()) .trim()} {sVal || '-'} ))} ))} ); } // Convert camelCase or camel_Snake_case to readable words const formattedKey = key .replace(/([A-Z])/g, ' $1') .replace(/_/g, ' ') .replace(/\b\w/g, (l) => l.toUpperCase()) .trim(); const content = renderValue(key, value); return ( {formattedKey}: {/* Special Case: Profiles Image Preview */} {key === "profiles" || key === "profile" || key === "profile_images" || key === "images" ? ( content ) : value ? ( {content} ) : ( No data available )} ); })} ))}
); }; export default PreviewScreen;