Initial import of 1407 block sources under blocks/
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,302 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Building, ChevronLeft, LoaderIcon, Mail, Phone } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
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 contactMethods = [
|
||||
{
|
||||
icon: Mail,
|
||||
title: "ایمیل",
|
||||
description:
|
||||
"برای دریافت اطلاعات، مشاوره یا پشتیبانی، از طریق ایمیل با ما در ارتباط باشید. در روزهای کاری حداکثر تا ۲۴ ساعت پاسخ خواهیم داد.",
|
||||
contact: "hello@relative.io",
|
||||
ltr: true,
|
||||
},
|
||||
{
|
||||
icon: Phone,
|
||||
title: "تلفن",
|
||||
description:
|
||||
"اگر ترجیح میدهید تلفنی گفتگو کنید، کارشناسان ما در روزهای کاری از ساعت ۹ تا ۱۷ پاسخگوی شما هستند.",
|
||||
contact: "۲۱-۱۲۳۴۵۶۷۸",
|
||||
ltr: true,
|
||||
},
|
||||
{
|
||||
icon: Building,
|
||||
title: "دفتر",
|
||||
description: "برای برگزاری جلسه حضوری، با هماهنگی قبلی به دفتر مرکزی مراجعه کنید.",
|
||||
contact: (
|
||||
<a
|
||||
href="#"
|
||||
className="inline-flex items-center gap-1 text-sm font-medium text-foreground hover:underline"
|
||||
>
|
||||
مسیریابی
|
||||
<ChevronLeft className="size-4" />
|
||||
</a>
|
||||
),
|
||||
ltr: false,
|
||||
},
|
||||
];
|
||||
|
||||
const contactFormSchema = z.object({
|
||||
name: z.string().min(1, "نام الزامی است"),
|
||||
email: z
|
||||
.string()
|
||||
.min(1, "ایمیل الزامی است")
|
||||
.email("آدرس ایمیل نامعتبر است"),
|
||||
message: z.string().min(1, "پیام الزامی است"),
|
||||
// @ts-ignore
|
||||
agreeToTerms: z.literal(true, {
|
||||
errorMap: () => ({ message: "برای ادامه، لازم است شرایط استفاده را بپذیرید." }),
|
||||
}),
|
||||
});
|
||||
|
||||
type ContactFormData = z.infer<typeof contactFormSchema>;
|
||||
|
||||
interface Contact9Props {
|
||||
className?: string;
|
||||
onSubmit?: (data: ContactFormData) => Promise<void>;
|
||||
}
|
||||
|
||||
const Contact9 = ({ className, onSubmit }: Contact9Props) => {
|
||||
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: "",
|
||||
agreeToTerms: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
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="flex flex-col gap-6 py-4 lg:py-8">
|
||||
<Badge
|
||||
variant="outline"
|
||||
className="w-fit gap-1 bg-card px-3 text-sm font-normal tracking-tight shadow-sm"
|
||||
>
|
||||
<Mail className="size-4" />
|
||||
<span>تماس با ما</span>
|
||||
</Badge>
|
||||
<h2 className="text-3xl leading-tight tracking-tight md:text-xl lg:text-2xll">
|
||||
ارتباط با ما
|
||||
</h2>
|
||||
<p className="max-w-[600px] tracking-[-0.32px] text-muted-foreground">
|
||||
اگر پرسشی درباره محصولات، خدمات یا همکاری دارید، از طریق فرم زیر با ما در ارتباط باشید.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between gap-10 py-12 max-md:flex-col">
|
||||
<form
|
||||
onSubmit={form.handleSubmit(handleFormSubmit)}
|
||||
className="flex flex-1 flex-col"
|
||||
>
|
||||
{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>
|
||||
)}
|
||||
|
||||
<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="border-border bg-card"
|
||||
/>
|
||||
{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="border-border bg-card 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="border-border bg-card"
|
||||
/>
|
||||
{fieldState.invalid && (
|
||||
<FieldError errors={[fieldState.error]} />
|
||||
)}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="agreeToTerms"
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id={field.name}
|
||||
// @ts-ignore
|
||||
checked={field.value}
|
||||
onCheckedChange={field.onChange}
|
||||
aria-invalid={fieldState.invalid}
|
||||
/>
|
||||
<label
|
||||
htmlFor={field.name}
|
||||
className="text-sm font-normal peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
||||
>
|
||||
موافقم با{" "}
|
||||
<a href="/terms" className="underline">
|
||||
شرایط استفاده
|
||||
</a>
|
||||
</label>
|
||||
</div>
|
||||
{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"
|
||||
className="gap-2"
|
||||
disabled={form.formState.isSubmitting}
|
||||
>
|
||||
{form.formState.isSubmitting ? (
|
||||
<>
|
||||
<LoaderIcon className="size-4 animate-spin" />
|
||||
در حال ارسال...
|
||||
</>
|
||||
) : (
|
||||
"ارسال پیام"
|
||||
)}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
|
||||
<div className="grid flex-1 gap-6 self-start lg:grid-cols-2">
|
||||
{contactMethods.map((method, index) => (
|
||||
<div key={index} className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<method.icon className="size-5" />
|
||||
<h3 className="text-xl tracking-[-0.96px]">
|
||||
{method.title}
|
||||
</h3>
|
||||
</div>
|
||||
<div className="space-y-2 tracking-[-0.32px]">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{method.description}
|
||||
</p>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
{method.ltr ? (
|
||||
<span dir="rtl">{method.contact}</span>
|
||||
) : (
|
||||
method.contact
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export { Contact9 };
|
||||
Reference in New Issue
Block a user