Files
estimation-flow/src/components/cost-estimator/cost-estimator-form.tsx
T

156 lines
4.2 KiB
TypeScript
Raw Normal View History

2025-07-17 10:06:15 +00:00
"use client";
import React, { useState, useTransition } from 'react';
import { Step1ProjectType } from './step-1-project-type';
2025-07-17 10:08:17 +00:00
import { Step2ServiceType } from './step-2-service-type';
2025-07-17 10:09:34 +00:00
import { Step3ProjectStage } from './step-3-project-stage';
2025-07-17 10:15:39 +00:00
import { Step4DesignProcess } from './step-4-design-process';
import { Step5PageCount } from './step-5-page-count';
2025-07-17 10:21:29 +00:00
import { Step6Animations } from './step-6-animations';
import { Step7Illustrations } from './step-7-illustrations';
2025-07-17 10:06:15 +00:00
import { Card, CardContent } from '@/components/ui/card';
import { AnimatePresence, motion } from 'framer-motion';
export type IllustrationSelection = {
has2d: boolean;
is2dAnimated: 'static' | 'animated' | null;
has3d: boolean;
is3dAnimated: 'static' | 'animated' | null;
};
2025-07-17 10:06:15 +00:00
export type FormData = {
projectType: 'website' | 'mobile-app' | 'platform' | null;
2025-07-17 10:08:17 +00:00
serviceType: 'entire-project' | 'development' | 'ui-ux-design' | 'identity-branding' | null;
2025-07-17 10:09:34 +00:00
projectStage: number;
2025-07-17 10:15:39 +00:00
designProcess: 'custom' | 'mockups' | 'existing' | null;
pageCount: number;
2025-07-17 10:21:29 +00:00
animatedElements: boolean | null;
illustrations: IllustrationSelection;
2025-07-17 10:06:15 +00:00
};
export function CostEstimatorForm() {
const [currentStep, setCurrentStep] = useState(1);
const [formData, setFormData] = useState<FormData>({
projectType: null,
2025-07-17 10:08:17 +00:00
serviceType: null,
2025-07-17 10:09:34 +00:00
projectStage: 0,
2025-07-17 10:15:39 +00:00
designProcess: null,
pageCount: 0,
2025-07-17 10:21:29 +00:00
animatedElements: null,
illustrations: {
has2d: false,
is2dAnimated: null,
has3d: false,
is3dAnimated: null,
},
2025-07-17 10:06:15 +00:00
});
const [isPending, startTransition] = useTransition();
const handleNextStep = () => {
startTransition(() => {
setCurrentStep((prev) => prev + 1);
});
};
2025-07-17 10:09:34 +00:00
const handlePrevStep = () => {
startTransition(() => {
setCurrentStep((prev) => prev - 1);
});
};
2025-07-17 10:06:15 +00:00
const handleUpdateFormData = (newData: Partial<FormData>) => {
setFormData((prev) => ({ ...prev, ...newData }));
};
const renderStep = () => {
switch (currentStep) {
case 1:
return (
<Step1ProjectType
onNext={handleNextStep}
onUpdateData={handleUpdateFormData}
/>
);
case 2:
return (
2025-07-17 10:08:17 +00:00
<Step2ServiceType
onNext={handleNextStep}
2025-07-17 10:09:34 +00:00
onBack={handlePrevStep}
onUpdateData={handleUpdateFormData}
formData={formData}
/>
);
case 3:
return (
<Step3ProjectStage
onNext={handleNextStep}
onBack={handlePrevStep}
2025-07-17 10:08:17 +00:00
onUpdateData={handleUpdateFormData}
2025-07-17 10:09:34 +00:00
formData={formData}
2025-07-17 10:08:17 +00:00
/>
);
2025-07-17 10:15:39 +00:00
case 4:
return (
<Step4DesignProcess
onNext={handleNextStep}
onBack={handlePrevStep}
onUpdateData={handleUpdateFormData}
formData={formData}
/>
);
case 5:
return (
<Step5PageCount
onNext={handleNextStep}
onBack={handlePrevStep}
onUpdateData={handleUpdateFormData}
formData={formData}
/>
);
2025-07-17 10:21:29 +00:00
case 6:
return (
<Step6Animations
onNext={handleNextStep}
onBack={handlePrevStep}
onUpdateData={handleUpdateFormData}
formData={formData}
/>
);
case 7:
return (
<Step7Illustrations
onNext={handleNextStep}
onBack={handlePrevStep}
onUpdateData={handleUpdateFormData}
formData={formData}
/>
);
2025-07-17 10:06:15 +00:00
default:
return (
<Step1ProjectType
onNext={handleNextStep}
onUpdateData={handleUpdateFormData}
/>
);
}
};
return (
<Card className="mt-8 w-full max-w-4xl shadow-2xl overflow-hidden">
<CardContent className="p-4 sm:p-8">
<AnimatePresence mode="wait">
<motion.div
key={currentStep}
initial={{ opacity: 0, x: 50 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: -50 }}
transition={{ duration: 0.3 }}
>
{renderStep()}
</motion.div>
</AnimatePresence>
</CardContent>
</Card>
);
}