Initial import of 1407 block sources under blocks/
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,408 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import {
|
||||
Building2,
|
||||
Check,
|
||||
ChevronRight,
|
||||
HelpCircle,
|
||||
Laptop,
|
||||
LoaderIcon,
|
||||
Rocket,
|
||||
Users,
|
||||
} from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Field,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
} from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const contactFormSchema = z.object({
|
||||
serviceType: z.string().min(1, "لطفاً یک خدمت انتخاب کنید"),
|
||||
name: z.string().min(1, "نام الزامی است"),
|
||||
email: z
|
||||
.string()
|
||||
.min(1, "ایمیل الزامی است")
|
||||
.email("آدرس ایمیل نامعتبر است"),
|
||||
company: z.string().optional(),
|
||||
message: z.string().min(1, "پیام الزامی است"),
|
||||
});
|
||||
|
||||
type ContactFormData = z.infer<typeof contactFormSchema>;
|
||||
|
||||
const services = [
|
||||
{
|
||||
id: "consulting",
|
||||
icon: Users,
|
||||
title: "مشاوره تخصصی",
|
||||
description: "مشاوره برای برنامهریزی، تحلیل و تصمیمگیری",
|
||||
},
|
||||
{
|
||||
id: "development",
|
||||
icon: Laptop,
|
||||
title: "توسعه نرمافزار",
|
||||
description: "طراحی و توسعه راهکارهای نرمافزاری متناسب با نیاز شما",
|
||||
},
|
||||
{
|
||||
id: "enterprise",
|
||||
icon: Building2,
|
||||
title: "راهکارهای سازمانی",
|
||||
description: "پیادهسازی سامانههای سازمانی در مقیاس بزرگ",
|
||||
},
|
||||
{
|
||||
id: "startup",
|
||||
icon: Rocket,
|
||||
title: "استارتاپها",
|
||||
description: "همراهی در طراحی نسخه اولیه محصول و توسعه کسبوکار",
|
||||
},
|
||||
{
|
||||
id: "other",
|
||||
icon: HelpCircle,
|
||||
title: "سایر خدمات",
|
||||
description: "سایر درخواستها و نیازها",
|
||||
},
|
||||
];
|
||||
|
||||
interface Contact29Props {
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
className?: string;
|
||||
onSubmit?: (data: ContactFormData) => Promise<void>;
|
||||
}
|
||||
|
||||
const Contact29 = ({
|
||||
title = "همکاری را آغاز کنیم",
|
||||
subtitle = "حوزه موردنیاز خود را انتخاب کنید و اطلاعات پروژه را برای ما ارسال کنید.",
|
||||
className,
|
||||
onSubmit,
|
||||
}: Contact29Props) => {
|
||||
const [step, setStep] = useState<"select" | "form" | "success">("select");
|
||||
const [selectedService, setSelectedService] = useState<string>("");
|
||||
|
||||
const form = useForm<ContactFormData>({
|
||||
resolver: zodResolver(contactFormSchema),
|
||||
mode: "onSubmit",
|
||||
reValidateMode: "onSubmit",
|
||||
defaultValues: {
|
||||
serviceType: "",
|
||||
name: "",
|
||||
email: "",
|
||||
company: "",
|
||||
message: "",
|
||||
},
|
||||
});
|
||||
|
||||
const handleServiceSelect = (serviceId: string) => {
|
||||
setSelectedService(serviceId);
|
||||
form.setValue("serviceType", serviceId);
|
||||
};
|
||||
|
||||
const handleContinue = () => {
|
||||
if (selectedService) {
|
||||
setStep("form");
|
||||
}
|
||||
};
|
||||
|
||||
const handleFormSubmit = async (data: ContactFormData) => {
|
||||
try {
|
||||
if (onSubmit) {
|
||||
await onSubmit(data);
|
||||
} else {
|
||||
console.log("Form submitted:", data);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
setStep("success");
|
||||
} catch {
|
||||
form.setError("root", {
|
||||
message: "مشکلی پیش آمد. لطفاً دوباره تلاش کنید.",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
setStep("select");
|
||||
setSelectedService("");
|
||||
form.reset();
|
||||
};
|
||||
|
||||
if (step === "success") {
|
||||
return (
|
||||
<section
|
||||
dir="rtl"
|
||||
lang="fa"
|
||||
className={cn("relative min-h-screen bg-muted/30", className)}
|
||||
>
|
||||
<div className="container flex min-h-screen flex-col justify-center py-20">
|
||||
<div className="mx-auto max-w-xl text-center">
|
||||
<div className="mx-auto mb-6 flex size-20 items-center justify-center rounded-full bg-green-500/10">
|
||||
<Check className="size-10 text-green-600" />
|
||||
</div>
|
||||
<h2 className="mb-4 text-xl font-medium">پیام شما ارسال شد</h2>
|
||||
<p className="text-xl text-muted-foreground">
|
||||
از اعتماد شما سپاسگزاریم. درخواست شما بررسی شده و حداکثر تا یک روز کاری با شما تماس خواهیم گرفت.
|
||||
</p>
|
||||
<Button
|
||||
className="mt-10"
|
||||
size="lg"
|
||||
variant="outline"
|
||||
onClick={resetForm}
|
||||
>
|
||||
ارسال پیام جدید
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<section
|
||||
dir="rtl"
|
||||
lang="fa"
|
||||
className={cn("relative min-h-screen bg-muted/30", className)}
|
||||
>
|
||||
<div className="container flex min-h-screen flex-col justify-center py-20">
|
||||
{step === "select" && (
|
||||
<div className="mx-auto max-w-4xl">
|
||||
<div className="mb-12 text-center">
|
||||
<h1 className="mb-6 text-2xll font-medium tracking-tight md:text-2xll lg:text-2xll">
|
||||
{title}
|
||||
</h1>
|
||||
<p className="text-xl text-muted-foreground md:text-xl">
|
||||
{subtitle}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{services.map((service) => {
|
||||
const Icon = service.icon;
|
||||
const isSelected = selectedService === service.id;
|
||||
return (
|
||||
<button
|
||||
key={service.id}
|
||||
type="button"
|
||||
onClick={() => handleServiceSelect(service.id)}
|
||||
className={cn(
|
||||
"relative flex flex-col items-center rounded-2xl p-8 text-center transition-all",
|
||||
isSelected
|
||||
? "bg-background shadow-lg ring-2 ring-primary"
|
||||
: "bg-background/60 hover:bg-background hover:shadow-md",
|
||||
)}
|
||||
>
|
||||
{isSelected && (
|
||||
<div className="absolute top-4 end-4 flex size-6 items-center justify-center rounded-full bg-primary">
|
||||
<Check className="size-4 text-primary-foreground" />
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className={cn(
|
||||
"mb-4 flex size-14 items-center justify-center rounded-xl",
|
||||
isSelected ? "bg-primary/10" : "bg-muted",
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
className={cn(
|
||||
"size-7",
|
||||
isSelected ? "text-primary" : "text-muted-foreground",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<h3 className="mb-2 text-lg font-semibold">
|
||||
{service.title}
|
||||
</h3>
|
||||
<p className="text-muted-foreground">
|
||||
{service.description}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="mt-12 flex justify-center">
|
||||
<Button
|
||||
size="lg"
|
||||
onClick={handleContinue}
|
||||
disabled={!selectedService}
|
||||
>
|
||||
مرحله بعد
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{step === "form" && (
|
||||
<div className="grid gap-16 lg:grid-cols-2 lg:gap-24">
|
||||
<div className="flex flex-col justify-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setStep("select")}
|
||||
className="mb-8 flex items-center gap-1 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<ChevronRight className="size-4" />
|
||||
تغییر انتخاب
|
||||
</button>
|
||||
|
||||
<h1 className="mb-6 text-2xll font-medium tracking-tight md:text-2xll lg:text-2xll">
|
||||
درباره پروژه بیشتر توضیح دهید
|
||||
</h1>
|
||||
<p className="mb-12 text-xl text-muted-foreground md:text-xl">
|
||||
هرچه اطلاعات بیشتری از پروژه ارائه دهید، راهکار دقیقتر و پیشنهاد مناسبتری دریافت خواهید کرد.
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-4 rounded-xl bg-background p-5 shadow-sm">
|
||||
{(() => {
|
||||
const service = services.find(
|
||||
(s) => s.id === selectedService,
|
||||
);
|
||||
if (!service) return null;
|
||||
const Icon = service.icon;
|
||||
return (
|
||||
<>
|
||||
<div className="flex size-12 shrink-0 items-center justify-center rounded-xl bg-primary/10">
|
||||
<Icon className="size-6 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-lg font-semibold">{service.title}</p>
|
||||
<p className="text-muted-foreground">
|
||||
{service.description}
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center">
|
||||
<form
|
||||
onSubmit={form.handleSubmit(handleFormSubmit)}
|
||||
className="w-full rounded-2xl bg-background p-8 shadow-lg md:p-10"
|
||||
>
|
||||
<h2 className="mb-8 text-xl font-semibold">اطلاعات تماس</h2>
|
||||
|
||||
<FieldGroup>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>
|
||||
نام و نام خانوادگی <span className="text-destructive">*</span>
|
||||
</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="نام و نام خانوادگی"
|
||||
/>
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="email"
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>
|
||||
ایمیل کاری <span className="text-destructive">*</span>
|
||||
</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id={field.name}
|
||||
type="email"
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="example@email.com"
|
||||
dir="rtl"
|
||||
className="text-start"
|
||||
/>
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="company"
|
||||
render={({ field }) => (
|
||||
<Field>
|
||||
<FieldLabel htmlFor={field.name}>نام شرکت یا سازمان</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id={field.name}
|
||||
placeholder="نام شرکت یا سازمان"
|
||||
/>
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="message"
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor={field.name}>
|
||||
پیام <span className="text-destructive">*</span>
|
||||
</FieldLabel>
|
||||
<Textarea
|
||||
{...field}
|
||||
id={field.name}
|
||||
aria-invalid={fieldState.invalid}
|
||||
placeholder="اهداف، نیازها و جزئیات پروژه خود را شرح دهید."
|
||||
rows={5}
|
||||
/>
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
{form.formState.errors.root && (
|
||||
<p className="text-sm text-destructive">
|
||||
{form.formState.errors.root.message}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
size="lg"
|
||||
className="w-full gap-2"
|
||||
disabled={form.formState.isSubmitting}
|
||||
>
|
||||
{form.formState.isSubmitting ? (
|
||||
<>
|
||||
<LoaderIcon className="size-4 animate-spin" />
|
||||
در حال ارسال...
|
||||
</>
|
||||
) : (
|
||||
"ارسال پیام"
|
||||
)}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export { Contact29 };
|
||||
Reference in New Issue
Block a user