"use client" import React from 'react' import { useForm, SubmitHandler } from "react-hook-form" import { postMessage } from '@/utils' import { MessageProps } from '@/types' import { toast } from 'react-hot-toast'; type Props = { startLoading: () => void stopLoading: () => void } const ContactForm = ({ startLoading, stopLoading }: Props) => { const { register, handleSubmit, reset, formState: {}, } = useForm() const onSubmit: SubmitHandler = async (data) => { try { startLoading; // Set loading state to true const result = await postMessage(data); if (result.success) { toast.success('已收到您的訊息,我們會盡快回覆您!'); reset(); // Reset form fields // Reset form or perform any other actions on success } else { toast.error('Failed to send message. Please try again.'); } } catch (error) { console.error('Error sending message:', error); toast.error('An error occurred. Please try again later.'); } finally { stopLoading; // Set loading state back to false } }; return (
讓我們知道您的想法

姓名

電話

電郵

訊息

{/* */}
) } export default ContactForm