mani-agro-frontend/src/components/common/QuoteModal/QuoteModal.tsx

337 lines
11 KiB
TypeScript

import React, { useState, useEffect } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
IconButton,
Typography,
Box,
TextField,
MenuItem,
Button,
Alert,
CircularProgress,
} from '@mui/material';
import { X, Send, CheckCircle2, MessageCircle } from 'lucide-react';
import confetti from 'canvas-confetti';
import { useQuote } from '../../../context/QuoteContext';
import { PRODUCTS } from '../../../data/productsData';
import { COMPANY_INFO } from '../../../data/companyData';
import { InquiryFormData } from '../../../types';
export const QuoteModal: React.FC = () => {
const { isQuoteModalOpen, selectedProductForQuote, closeQuoteModal } = useQuote();
const [formData, setFormData] = useState<InquiryFormData>({
name: '',
companyName: '',
email: '',
phone: '',
country: '',
productInterest: '',
estimatedQuantity: '1x20ft Container (FCL)',
packagingPreference: '25kg Paper / PP Bags',
destinationPort: '',
message: '',
});
const [submitted, setSubmitted] = useState(false);
const [loading, setLoading] = useState(false);
useEffect(() => {
if (selectedProductForQuote) {
setFormData((prev) => ({
...prev,
productInterest: selectedProductForQuote,
}));
} else {
setFormData((prev) => ({
...prev,
productInterest: 'All / Multiple Products',
}));
}
}, [selectedProductForQuote, isQuoteModalOpen]);
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { name, value } = e.target;
setFormData((prev) => ({ ...prev, [name]: value }));
};
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setTimeout(() => {
setLoading(false);
setSubmitted(true);
confetti({
particleCount: 80,
spread: 70,
origin: { y: 0.6 },
});
}, 800);
};
const handleReset = () => {
setSubmitted(false);
closeQuoteModal();
};
const whatsappDirectMsg = `Hello Mani Agro Exports, I am ${formData.name || 'a buyer'} from ${formData.companyName || 'our company'}. We require a quote for ${formData.productInterest || 'agro commodities'}. Quantity: ${formData.estimatedQuantity}. Port: ${formData.destinationPort || 'Overseas Port'}.`;
return (
<Dialog
open={isQuoteModalOpen}
onClose={closeQuoteModal}
maxWidth="md"
fullWidth
slotProps={{
paper: {
sx: {
borderRadius: 3.5,
p: { xs: 1, sm: 2 },
bgcolor: '#FFFFFF',
},
},
}}
>
<DialogTitle
sx={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
pb: 1,
}}
>
<Box>
<Typography
variant="caption"
sx={{
color: '#D49B24',
fontWeight: 700,
textTransform: 'uppercase',
letterSpacing: '0.08em',
}}
>
Direct B2B Export Inquiries
</Typography>
<Typography variant="h4" sx={{ fontWeight: 800, color: '#102A22' }}>
Request Quotation & Samples
</Typography>
</Box>
<IconButton onClick={closeQuoteModal}>
<X size={22} />
</IconButton>
</DialogTitle>
<DialogContent dividers sx={{ pt: 3 }}>
{submitted ? (
<Box sx={{ textAlign: 'center', py: 4, px: 2 }}>
<Box
sx={{
width: 72,
height: 72,
borderRadius: '50%',
bgcolor: 'rgba(46, 125, 50, 0.12)',
color: '#2E7D32',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
mx: 'auto',
mb: 2.5,
}}
>
<CheckCircle2 size={44} />
</Box>
<Typography variant="h4" sx={{ fontWeight: 800, color: '#102A22', mb: 1 }}>
Inquiry Successfully Received!
</Typography>
<Typography variant="body1" sx={{ color: '#4A5B53', maxWidth: 500, mx: 'auto', mb: 3.5 }}>
Thank you, <strong>{formData.name}</strong>. Mihir Motiyani and the Mani Agro Exports team will review your specifications and contact you shortly with commercial pricing and sample details.
</Typography>
<Box sx={{ display: 'flex', flexDirection: { xs: 'column', sm: 'row' }, gap: 2, justifyContent: 'center' }}>
<Button
variant="contained"
color="primary"
href={`https://wa.me/917218344834?text=${encodeURIComponent(whatsappDirectMsg)}`}
target="_blank"
rel="noopener noreferrer"
startIcon={<MessageCircle size={18} color="#25D366" />}
sx={{ py: 1.2, px: 3 }}
>
Fast-Track on WhatsApp
</Button>
<Button variant="outlined" onClick={handleReset} sx={{ py: 1.2, px: 3 }}>
Close Window
</Button>
</Box>
</Box>
) : (
<Box component="form" onSubmit={handleSubmit}>
<Alert severity="info" sx={{ mb: 3, borderRadius: 2 }}>
Looking for commercial pricing, custom mesh size, ASTA color, or sample dispatch? Fill out your requirements below for an immediate response.
</Alert>
<Box sx={{ display: 'grid', gridTemplateColumns: { xs: '1fr', sm: '1fr 1fr' }, gap: 2.5 }}>
<TextField
required
fullWidth
label="Your Full Name"
name="name"
value={formData.name}
onChange={handleChange}
size="small"
/>
<TextField
required
fullWidth
label="Company / Business Name"
name="companyName"
value={formData.companyName}
onChange={handleChange}
size="small"
/>
<TextField
required
fullWidth
type="email"
label="Official Business Email"
name="email"
value={formData.email}
onChange={handleChange}
size="small"
/>
<TextField
required
fullWidth
label="Phone / WhatsApp Number (with country code)"
name="phone"
value={formData.phone}
onChange={handleChange}
size="small"
placeholder="+1 555 0192"
/>
<TextField
required
fullWidth
label="Destination Country"
name="country"
value={formData.country}
onChange={handleChange}
size="small"
/>
<TextField
fullWidth
label="Destination Port (e.g. Jebel Ali, Rotterdam, Houston)"
name="destinationPort"
value={formData.destinationPort}
onChange={handleChange}
size="small"
/>
<TextField
select
fullWidth
label="Product of Interest"
name="productInterest"
value={formData.productInterest}
onChange={handleChange}
size="small"
>
<MenuItem value="All / Multiple Products">All / Multiple Products</MenuItem>
{PRODUCTS.map((prod) => (
<MenuItem key={prod.id} value={prod.name}>
{prod.name}
</MenuItem>
))}
</TextField>
<TextField
select
fullWidth
label="Estimated Order Quantity"
name="estimatedQuantity"
value={formData.estimatedQuantity}
onChange={handleChange}
size="small"
>
<MenuItem value="Sample Evaluation (Courier)">Sample Evaluation (Courier)</MenuItem>
<MenuItem value="Trial Pallet / LCL (1 - 5 MT)">Trial Pallet / LCL (1 - 5 MT)</MenuItem>
<MenuItem value="1x20ft Container (FCL - approx 14-18 MT)">1x20ft Container (FCL - approx 14-18 MT)</MenuItem>
<MenuItem value="1x40ft Container (FCL - approx 24-26 MT)">1x40ft Container (FCL - approx 24-26 MT)</MenuItem>
<MenuItem value="Multiple Containers / Regular Monthly Supply">Multiple Containers / Regular Monthly Supply</MenuItem>
</TextField>
<TextField
select
fullWidth
label="Packaging Preference"
name="packagingPreference"
value={formData.packagingPreference}
onChange={handleChange}
size="small"
>
<MenuItem value="25kg Multi-layer Kraft Paper Bags">25kg Multi-layer Kraft Paper Bags</MenuItem>
<MenuItem value="50kg PP Woven Sacks with Inner Poly Liner">50kg PP Woven Sacks with Inner Poly Liner</MenuItem>
<MenuItem value="Jumbo FIBC Bags (500kg / 1000kg)">Jumbo FIBC Bags (500kg / 1000kg)</MenuItem>
<MenuItem value="Customized Private Label Packaging">Customized Private Label Packaging</MenuItem>
</TextField>
<Box sx={{ gridColumn: { xs: '1', sm: '1 / -1' } }}>
<TextField
fullWidth
multiline
rows={3}
label="Specific Requirements (Mesh size, ASTA color, SHU heat, Curcumin %, target price, etc.)"
name="message"
value={formData.message}
onChange={handleChange}
size="small"
/>
</Box>
</Box>
<Box
sx={{
display: 'flex',
flexDirection: { xs: 'column', sm: 'row' },
gap: 2,
justifyContent: 'space-between',
alignItems: 'center',
mt: 3,
pt: 2,
borderTop: '1px solid rgba(27, 77, 62, 0.08)',
}}
>
<Typography variant="caption" sx={{ color: '#556960' }}>
Direct Contact: {COMPANY_INFO.person} • {COMPANY_INFO.phoneDisplay}
</Typography>
<Button
type="submit"
variant="contained"
color="secondary"
size="large"
disabled={loading}
startIcon={loading ? <CircularProgress size={18} color="inherit" /> : <Send size={18} />}
sx={{ px: 4, py: 1.2, fontWeight: 700 }}
>
{loading ? 'Submitting...' : 'Submit Request'}
</Button>
</Box>
</Box>
)}
</DialogContent>
</Dialog>
);
};