250 lines
9.5 KiB
TypeScript
250 lines
9.5 KiB
TypeScript
"use client";
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
import { LoaderIcon } 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 {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const contactFormSchema = z.object({
|
|
name: z.string().min(1, "نام الزامی است"),
|
|
email: z
|
|
.string()
|
|
.min(1, "ایمیل الزامی است")
|
|
.email("آدرس ایمیل نامعتبر است"),
|
|
subject: z.string().optional(),
|
|
message: z.string().min(1, "پیام الزامی است"),
|
|
});
|
|
|
|
type ContactFormData = z.infer<typeof contactFormSchema>;
|
|
|
|
interface Contact33Props {
|
|
title?: string;
|
|
description?: string;
|
|
image?: string;
|
|
className?: string;
|
|
onSubmit?: (data: ContactFormData) => Promise<void>;
|
|
}
|
|
|
|
const Contact33 = ({
|
|
title = "درخواست دمو یا همکاری",
|
|
description = "نیاز سامانه مدیریت ارتباط با مشتری، اندازه تیم فروش و هدف از همکاری را بنویسید تا پیشنهاد و زمانبندی دمو را ارسال کنیم.",
|
|
image = "/block-media/shadcnblocks/block/lummi/Modern%20Architectural%20Elegance%20at%20Twilight.png",
|
|
className,
|
|
onSubmit,
|
|
}: Contact33Props) => {
|
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
|
const [showSuccess, setShowSuccess] = useState(false);
|
|
|
|
const form = useForm<ContactFormData>({
|
|
resolver: zodResolver(contactFormSchema),
|
|
mode: "onSubmit",
|
|
reValidateMode: "onSubmit",
|
|
defaultValues: {
|
|
name: "",
|
|
email: "",
|
|
subject: "",
|
|
message: "",
|
|
},
|
|
});
|
|
|
|
const handleFormSubmit = async (data: ContactFormData) => {
|
|
try {
|
|
if (onSubmit) {
|
|
await onSubmit(data);
|
|
} else {
|
|
console.log("Form submitted:", data);
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
}
|
|
setIsSubmitted(true);
|
|
setShowSuccess(true);
|
|
form.reset();
|
|
setTimeout(() => setShowSuccess(false), 4500);
|
|
setTimeout(() => setIsSubmitted(false), 5000);
|
|
} catch {
|
|
form.setError("root", {
|
|
message: "مشکلی پیش آمد. لطفاً دوباره تلاش کنید.",
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<section dir="rtl" lang="fa" className={cn("py-32", className)}>
|
|
<div className="container">
|
|
<div className="mx-auto max-w-6xl">
|
|
<div className="grid gap-12 lg:grid-cols-2 lg:gap-16">
|
|
{/* Form Side */}
|
|
<div>
|
|
<div className="mb-10">
|
|
<h1 className="mb-4 text-xl font-medium tracking-tight md:text-2xll">
|
|
{title}
|
|
</h1>
|
|
<p className="text-lg text-muted-foreground">{description}</p>
|
|
</div>
|
|
|
|
{isSubmitted && (
|
|
<div
|
|
className={cn(
|
|
"mb-6 rounded-lg border border-green-500/20 bg-green-500/10 p-4 text-center transition-opacity duration-500",
|
|
showSuccess ? "opacity-100" : "opacity-0",
|
|
)}
|
|
>
|
|
<p className="text-sm font-medium text-green-600 dark:text-green-400">
|
|
درخواست ثبت شد. کارشناس فروش بهزودی برای دمو یا همکاری تماس میگیرد.
|
|
</p>
|
|
</div>
|
|
)}
|
|
|
|
<form onSubmit={form.handleSubmit(handleFormSubmit)}>
|
|
<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="subject"
|
|
render={({ field }) => (
|
|
<Field>
|
|
<FieldLabel htmlFor={field.name}>موضوع</FieldLabel>
|
|
<Select
|
|
onValueChange={field.onChange}
|
|
value={field.value}
|
|
>
|
|
<SelectTrigger id={field.name}>
|
|
<SelectValue placeholder="موضوع درخواست را انتخاب کنید" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="general">پرسش محصول سامانه مدیریت ارتباط با مشتری</SelectItem>
|
|
<SelectItem value="project">پیادهسازی سامانه مدیریت ارتباط با مشتری</SelectItem>
|
|
<SelectItem value="collaboration">همکاری تجاری</SelectItem>
|
|
<SelectItem value="press">رسانه و مطبوعات</SelectItem>
|
|
<SelectItem value="other">سایر</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</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={6}
|
|
/>
|
|
{fieldState.invalid && (
|
|
<FieldError errors={[fieldState.error]} />
|
|
)}
|
|
</Field>
|
|
)}
|
|
/>
|
|
|
|
{form.formState.errors.root && (
|
|
<p className="text-sm text-destructive">
|
|
{form.formState.errors.root.message}
|
|
</p>
|
|
)}
|
|
|
|
<Button
|
|
size="lg"
|
|
className="w-full gap-2 sm:w-auto"
|
|
disabled={form.formState.isSubmitting}
|
|
>
|
|
{form.formState.isSubmitting ? (
|
|
<>
|
|
<LoaderIcon className="size-4 animate-spin" />
|
|
در حال ارسال...
|
|
</>
|
|
) : (
|
|
"ارسال درخواست"
|
|
)}
|
|
</Button>
|
|
</FieldGroup>
|
|
</form>
|
|
</div>
|
|
|
|
{/* Image Side */}
|
|
<div className="hidden lg:block">
|
|
<div className="h-full overflow-hidden rounded-2xl">
|
|
<img src={image} alt="درخواست دمو یا همکاری" className="size-full object-cover" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
};
|
|
|
|
export { Contact33 };
|