- {serviceData.map((service) => (
+ {staticServiceData.map((service) => (
diff --git a/src/client/data/serviceData.js b/src/client/data/serviceData.js
deleted file mode 100644
index 1e6968b6..00000000
--- a/src/client/data/serviceData.js
+++ /dev/null
@@ -1,76 +0,0 @@
-const serviceData = [
- {
- title: 'Automobile Resprays',
- description: 'Revitalize your car’s appearance with our top-quality respray services. Whether you’re looking to restore your car’s original color or want a complete color change, our skilled technicians use the finest automotive paints and precision techniques to deliver a flawless finish.',
- points: [
- { title: 'Full Body Resprays', text: 'Complete color changes for a fresh new look.' },
- { title: 'Panel Resprays', text: 'Perfect for repairing specific areas or panels.' },
- { title: 'Custom Paint Jobs', text: 'Unique designs and custom colors to make your car stand out.' },
- ],
- image: require('../assets/image4.png'),
- icon: 'mdi:spray-bottle',
- path: 'auto-resprays',
- },
- {
- title: 'Car Detailing',
- description: 'Keep your car looking brand new with our comprehensive car detailing services. Our detailing packages include meticulous cleaning, both inside and out, to ensure your vehicle shines.',
- points: [
- { title: 'Exterior Detailing', text: 'Includes wash, wax, and polish for a gleaming finish.' },
- { title: 'Interior Detailing', text: 'Deep cleaning of seats, carpets, and upholstery.' },
- { title: 'Ceramic Coating', text: 'Provides long-lasting protection and a brilliant shine.' },
- ],
- image: require('../assets/DetailingBg.jpg'),
- icon: 'codicon:sparkle-filled',
- path: 'car-detailing',
- },
- {
- title: 'Electrical Services',
- description: 'Ensure your vehicle’s electrical systems are in top condition with our expert electrical services. From diagnostics to repairs, our certified technicians handle everything from minor electrical issues to complex system malfunctions.',
- points: [
- { title: 'Battery Replacement', text: 'Reliable battery testing and replacement services.' },
- { title: 'Alternator and Starter Repairs', text: 'Essential for keeping your car’s electrical system functioning.' },
- { title: 'Electrical Diagnostics', text: 'Advanced tools to identify and fix electrical problems quickly' },
- ],
- image: require('../assets/electricalBg.jpg'),
- icon: 'uil:circuit',
- path: 'electrical-services',
- },
- {
- title: 'Paint Correction',
- description: 'Remove imperfections and restore your car’s paint with our advanced paint correction services. Our multi-stage correction process effectively eliminates swirls, scratches, and oxidation, bringing back your car’s original luster.',
- points: [
- { title: 'Scratch and Swirl Removal', text: ' Enhance your car’s appearance by removing unsightly marks.' },
- { title: 'Oxidation Removal', text: ' Revive dull and faded paint.' },
- { title: 'Gloss Enhancement', text: ' Achieve a mirror-like finish with our polishing techniques' },
- ],
- image: require('../assets/paint-correctionBg.jpg'),
- icon: 'fluent:paint-brush-sparkle-24-filled',
- path: 'paint-correction',
- },
- {
- title: 'Bodyworks',
- description: 'From minor dents to major collision repairs, our bodywork services ensure your car looks as good as new. Using state-of-the-art equipment and techniques, we handle all aspects of body repair with precision.',
- points: [
- { title: 'Dent Repair', text: ' Fixes for small dings and dents without repainting.' },
- { title: 'Collision Repair', text: ' Comprehensive repair services for major accidents.' },
- { title: 'Panel Replacement', text: ' Replacing damaged panels to restore structural integrity.' },
- ],
- image: require('../assets/bodyworksBg.jpg'),
- icon: 'mdi:hammer-wrench',
- path: 'bodyworks',
- },
- {
- title: 'Auto Mechanic',
- description: 'Trust our skilled mechanics to keep your car running smoothly. From routine maintenance to major repairs, we offer a wide range of mechanical services to meet all your automotive needs.',
- points: [
- { title: 'Engine Repairs', text: ' Diagnosing and fixing engine issues to maintain performance.' },
- { title: 'Brake Services', text: ' Ensuring your brakes are in optimal condition for safety.' },
- { title: 'Routine Maintenance', text: ' Regular services like oil changes, tire rotations, and inspections.' },
- ],
- image: require('../assets/mechanicBg.jpg'),
- icon: 'fluent:wrench-settings-24-filled',
- path: 'auto-mechanic',
- },
-];
-
-export default serviceData;
diff --git a/src/client/data/staticServiceData.js b/src/client/data/staticServiceData.js
new file mode 100644
index 00000000..195b1fb5
--- /dev/null
+++ b/src/client/data/staticServiceData.js
@@ -0,0 +1,40 @@
+const staticServiceData = [
+ {
+ title: 'Automobile Resprays',
+ image: require('../assets/image4.png'),
+ icon: 'mdi:spray-bottle',
+ path: 'auto-resprays',
+ },
+ {
+ title: 'Car Detailing',
+ image: require('../assets/DetailingBg.jpg'),
+ icon: 'codicon:sparkle-filled',
+ path: 'car-detailing',
+ },
+ {
+ title: 'Electrical Services',
+ image: require('../assets/electricalBg.jpg'),
+ icon: 'uil:circuit',
+ path: 'electrical-services',
+ },
+ {
+ title: 'Paint Correction',
+ image: require('../assets/paint-correctionBg.jpg'),
+ icon: 'fluent:paint-brush-sparkle-24-filled',
+ path: 'paint-correction',
+ },
+ {
+ title: 'Bodyworks',
+ image: require('../assets/bodyworksBg.jpg'),
+ icon: 'mdi:hammer-wrench',
+ path: 'bodyworks',
+ },
+ {
+ title: 'Auto Mechanic',
+ image: require('../assets/mechanicBg.jpg'),
+ icon: 'fluent:wrench-settings-24-filled',
+ path: 'auto-mechanic',
+ },
+];
+
+export default staticServiceData;
diff --git a/src/client/pages/ServicesPage.js b/src/client/pages/ServicesPage.js
index 3e296649..92f6c6e3 100644
--- a/src/client/pages/ServicesPage.js
+++ b/src/client/pages/ServicesPage.js
@@ -1,43 +1,116 @@
-import React, { useEffect } from 'react';
+import React, { useState, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import ServicesSection from '../components/ServiceSection';
-import serviceData from '../data/serviceData';
+import staticServiceData from '../data/staticServiceData';
+
+// Default image and icon for unmatched services
+const defaultService = {
+ image: require('../assets/DetailingBg.jpg'),
+ icon: 'mdi:alert-circle-outline',
+};
const ServicesPage = () => {
+ // State for storing services data, loading status, and error messages
+ const [services, setServices] = useState(() => {
+ const cachedServices = localStorage.getItem('services'); // Retrieve cached services if available
+ return cachedServices ? JSON.parse(cachedServices) : []; // Use cached data if available
+ });
+ const [loading, setLoading] = useState(!services.length); // Show loading if no cached data
+ const [error, setError] = useState(null);
const location = useLocation(); // Hook to get the current location
useEffect(() => {
- // Scroll to the element if there's a hash in the URL
- const hash = location.hash.substring(1); // Remove the '#' from the hash
+ // Function to fetch services data with retry logic
+ const fetchServices = async (retryCount = 3) => {
+ try {
+ const response = await fetch('https://api.example.com/services'); // Replace with your API URL
+ if (!response.ok) {
+ throw new Error(`Failed to fetch services: ${response.statusText}`);
+ }
+ const data = await response.json();
+ setServices(data); // Update state with the fetched data
+ localStorage.setItem('services', JSON.stringify(data)); // Cache data in localStorage
+ } catch (error) {
+ if (retryCount > 0) {
+ console.warn(`Retrying fetch services, attempts left: ${retryCount}`);
+ fetchServices(retryCount - 1); // Retry the fetch request
+ } else {
+ console.error('Failed to fetch services after retries:', error);
+ // Report the failure (e.g., send error data to a logging service)
+ reportApiError(error);
+ setError(error.message); // Set error state after retries
+ }
+ } finally {
+ setLoading(false); // Stop loading once fetch attempt is complete
+ }
+ };
+
+ // Fetch services if no cached data exists
+ if (!services.length) {
+ fetchServices();
+ }
+ }, [services.length]);
+
+ // Function to report API errors (can be replaced with an actual logging service)
+ const reportApiError = (error) => {
+ console.log('Reporting API failure:', error);
+ // Example: You can integrate services like Sentry or log errors to a server
+ };
+
+ useEffect(() => {
+ // Scroll to the section if a hash is present in the URL
+ const hash = location.hash.substring(1);
if (hash) {
- const element = document.getElementById(hash); // Get the element by ID
+ const element = document.getElementById(hash);
if (element) {
- element.scrollIntoView({ behavior: 'smooth' }); // Smooth scroll to the element
+ element.scrollIntoView({ behavior: 'smooth' });
}
}
- }, [location]); // Re-run the effect when the location changes
+ }, [location]);
+
+ if (loading) {
+ return
Loading services...
;
+ }
+
+ if (error) {
+ return (
+
+
Error loading services: {error}
+
window.location.reload()}>Retry
+
+ );
+ }
return (
- {/* Page title */}
Our Services
- {/* Map through serviceData to create service sections */}
- {serviceData.map((section, index) => (
-
- ))}
+ {services.map((section, index) => {
+ // Find matching static service
+ const matchedService = staticServiceData.find(
+ (staticService) => staticService.title === section.title
+ );
+
+ // Use matched service's image and icon, or default if no match
+ const image = matchedService ? matchedService.image : defaultService.image;
+ const icon = matchedService ? matchedService.icon : defaultService.icon;
+
+ return (
+
+ );
+ })}
);
};
-export default ServicesPage;
+export default ServicesPage;
\ No newline at end of file