To redesign the provided React module into an intuitive modern Content and Ad Management dashboard, we'll focus on enhancing user experience, improving layout, and modernizing the visual elements. Here's a revised version of the module:
jsx Copy code
import React, { useState } from 'react';
import { TextField, Button, Grid, Card, CardContent, Typography, Box, InputAdornment, FormControl, FormControlLabel, Checkbox } from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import { useDropzone } from 'react-dropzone';
import './CAM.css';
const initialAdData = {
stockNumber: '',
title: '',
about: '',
kilometres: '',
bodyStyle: '',
engine: '',
transmission: '',
driveTrain: '',
exteriorColour: '',
passengers: '',
doors: '',
fuelType: '',
manufacturerExteriorColour: '',
features: [],
options: '',
};
const CAM = () => {
const [searchTerm, setSearchTerm] = useState('');
const [adData, setAdData] = useState(initialAdData);
const [images, setImages] = useState([]);
const [selectedWebsites, setSelectedWebsites] = useState({
All: false,
Carloft: false,
'Jim Thompson Chrysler': false,
'Carleton Place Ford': false,
});
const handleSearchChange = (event) => {
setSearchTerm(event.target.value);
};
const handleInputChange = (event) => {
const { name, value } = event.target;
setAdData({ ...adData, [name]: value });
};
const onDrop = (acceptedFiles) => {
setImages([...images, ...acceptedFiles.map(file => Object.assign(file, {
preview: URL.createObjectURL(file)
}))]);
};
const { getRootProps, getInputProps } = useDropzone({ onDrop, accept: 'image/*' });
const handleSubmit = () => {
console.log('Ad Data:', adData);
console.log('Images:', images);
console.log('Selected Websites:', selectedWebsites);
// Code to push data to the website and other ad services
};
const handleWebsiteChange = (event) => {
const { name, checked } = event.target;
if (name === 'All') {
const newSelectedWebsites = Object.keys(selectedWebsites).reduce((acc, website) => {
acc[website] = checked;
return acc;
}, {});
setSelectedWebsites(newSelectedWebsites);
} else {
const newSelectedWebsites = { ...selectedWebsites, [name]: checked };
if (!checked) {
newSelectedWebsites['All'] = false;
} else {
const allChecked = Object.keys(newSelectedWebsites).every(
(website) => website === 'All' || newSelectedWebsites[website]
);
newSelectedWebsites['All'] = allChecked;
}
setSelectedWebsites(newSelectedWebsites);
}
};
return (
<Box className="cam-container">
<TextField
variant="outlined"
placeholder="Search Vehicles"
value={searchTerm}
onChange={handleSearchChange}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
),
}}
fullWidth
margin="normal"
/>
<FormControl className="filter-container">
<Typography variant="h6">Publish To</Typography>
{Object.keys(selectedWebsites).map((website) => (
<FormControlLabel
key={website}
control={
<Checkbox
checked={selectedWebsites[website]}
onChange={handleWebsiteChange}
name={website}
/>
}
label={website}
className="filter-checkbox"
/>
))}
</FormControl>
<Grid container spacing={2} marginTop={1}>
{Object.keys(initialAdData).map((key) => (
<Grid item xs={12} sm={6} key={key}>
<TextField
variant="outlined"
label={key.charAt(0).toUpperCase() + key.slice(1).replace(/([A-Z])/g, ' $1')}
name={key}
value={adData[key]}
onChange={handleInputChange}
fullWidth
margin="dense"
multiline={key === 'about' || key === 'features' || key === 'options'}
rows={key === 'about' || key === 'features' || key === 'options' ? 4 : undefined}
/>
</Grid>
))}
</Grid>
<div {...getRootProps({ className: 'dropzone' })}>
<input {...getInputProps()} />
<p>Drag 'n' drop some files here, or click to select files</p>
</div>
<Grid container spacing={2}>
{images.map((file, index) => (
<Grid item xs={12} sm={6} md={4} key={index}>
<Card>
<CardContent>
<Typography variant="body2" color="textSecondary" component="p">
{file.name}
</Typography>
<img src={file.preview} alt="Preview" className="preview-image" />
</CardContent>
</Card>
</Grid>
))}
</Grid>
<Button variant="contained" color="primary" onClick={handleSubmit} fullWidth>
Push Ad
</Button>
</Box>
);
};
export default CAM;