Initial import of 1407 block sources under blocks/
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,273 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { LoaderIcon, MailIcon, MessageCircle } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from "@/components/ui/accordion";
|
||||
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({
|
||||
name: z.string().min(1, "نام الزامی است"),
|
||||
email: z
|
||||
.string()
|
||||
.min(1, "ایمیل الزامی است")
|
||||
.email("آدرس ایمیل نامعتبر است"),
|
||||
message: z.string().min(1, "پیام الزامی است"),
|
||||
});
|
||||
|
||||
type ContactFormData = z.infer<typeof contactFormSchema>;
|
||||
|
||||
interface FAQ {
|
||||
question: string;
|
||||
answer: string;
|
||||
}
|
||||
|
||||
interface Contact25Props {
|
||||
title?: string;
|
||||
description?: string;
|
||||
faqTitle?: string;
|
||||
faqs?: FAQ[];
|
||||
className?: string;
|
||||
onSubmit?: (data: ContactFormData) => Promise<void>;
|
||||
}
|
||||
|
||||
const Contact25 = ({
|
||||
title = "چگونه میتوانیم به شما کمک کنیم؟",
|
||||
description = "پاسخ پرسشهای رایج را مشاهده کنید یا در صورت نیاز پیام خود را برای ما ارسال کنید.",
|
||||
faqTitle = "سوالات متداول",
|
||||
faqs = [
|
||||
{
|
||||
question: "ساعات کاری شما چیست؟",
|
||||
answer:
|
||||
"تیم پشتیبانی ما دوشنبه تا جمعه، ۹ صبح تا ۶ عصر در دسترس است. برای موارد فوری خارج از این ساعات، به urgent@company.com ایمیل بزنید.",
|
||||
},
|
||||
{
|
||||
question: "پاسخدهی چقدر طول میکشد؟",
|
||||
answer:
|
||||
"معمولاً ظرف ۲۴ ساعت در روزهای کاری به همه درخواستها پاسخ میدهیم. درخواستهای پیچیده ممکن است تا ۴۸ ساعت زمان ببرند.",
|
||||
},
|
||||
{
|
||||
question: "پشتیبانی تلفنی دارید؟",
|
||||
answer:
|
||||
"بله، پشتیبانی تلفنی برای مشترکین طرح حرفهای و سازمانی فعال است. شماره اختصاصی پشتیبانی را در داشبورد حساب خود ببینید.",
|
||||
},
|
||||
{
|
||||
question: "میتوانم دمو رزرو کنم؟",
|
||||
answer:
|
||||
"حتماً! از طریق وبسایت یا تماس مستقیم با تیم فروش میتوانید دمو شخصیسازیشده رزرو کنید. هر جلسه معمولاً ۳۰ تا ۴۵ دقیقه طول میکشد.",
|
||||
},
|
||||
{
|
||||
question: "در پیام چه اطلاعاتی بنویسم؟",
|
||||
answer:
|
||||
"لطفاً ایمیل حساب (در صورت وجود)، توضیح دقیق سوال یا مشکل، و در صورت نیاز تصویر یا پیام خطا را ارسال کنید.",
|
||||
},
|
||||
],
|
||||
className,
|
||||
onSubmit,
|
||||
}: Contact25Props) => {
|
||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||
const [showSuccess, setShowSuccess] = useState(false);
|
||||
|
||||
const form = useForm<ContactFormData>({
|
||||
resolver: zodResolver(contactFormSchema),
|
||||
mode: "onSubmit",
|
||||
reValidateMode: "onSubmit",
|
||||
defaultValues: {
|
||||
name: "",
|
||||
email: "",
|
||||
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="mb-14 text-center">
|
||||
<h1 className="mb-4 text-xl font-medium tracking-tight md:text-2xll">
|
||||
{title}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">{description}</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-12 lg:grid-cols-2 lg:gap-16">
|
||||
<div>
|
||||
<div className="mb-6 flex items-center gap-2">
|
||||
<MessageCircle className="size-5 text-muted-foreground" />
|
||||
<h2 className="text-lg font-medium">{faqTitle}</h2>
|
||||
</div>
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
{faqs.map((faq, index) => (
|
||||
<AccordionItem key={index} value={`item-${index}`}>
|
||||
<AccordionTrigger className="text-start">
|
||||
{faq.question}
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="text-muted-foreground">
|
||||
{faq.answer}
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
))}
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="mb-6 flex items-center gap-2">
|
||||
<MailIcon className="size-5 text-muted-foreground" />
|
||||
<h2 className="text-lg font-medium">هنوز سوالی دارید؟</h2>
|
||||
</div>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(handleFormSubmit)}
|
||||
className="flex flex-col gap-6 rounded-xl bg-muted/50 p-8"
|
||||
>
|
||||
{isSubmitted && (
|
||||
<div
|
||||
className={cn(
|
||||
"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>
|
||||
)}
|
||||
|
||||
<FieldGroup>
|
||||
<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="نام و نام خانوادگی"
|
||||
className="bg-background"
|
||||
/>
|
||||
{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="bg-background text-start"
|
||||
/>
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</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={4}
|
||||
className="bg-background"
|
||||
/>
|
||||
{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>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export { Contact25 };
|
||||
Reference in New Issue
Block a user