"use client";
import React from "react";
import {useForm, SubmitHandler, Controller} from "react-hook-form";
import Footer from "@/components/Footer";
import Navbar from "@/components/Navbar";
import Title from "@/components/Title";
import translation from "@/translation/contactus.json";
import Image from "next/image";
type FormValues = {
name: string;
email: string;
description: string;
subject: string;
type: "feedback" | "bug" | "help" | "";
};
interface Props {
language: "en" | "ar";
page: string;
}
const ErrorMessage = ({message}: {message: string}) => (
{message}
);
export default function App({language, page}: Props) {
const selectOptions = [
{
label: translation.feedback[language],
value: "feedback",
},
{
label: translation.bug[language],
value: "bug",
},
{
label: translation.help[language],
value: "help",
},
];
const {register, control, handleSubmit, formState} = useForm({
defaultValues: {
name: "",
email: "",
description: "",
subject: "",
type: "",
},
});
const {errors, isDirty, isValid} = formState;
console.log("formState", formState.isSubmitSuccessful);
const onSubmit: SubmitHandler = async (data) => {
try {
const response = await fetch(`https://platform.encoach.com/api/tickets`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
reporter: {
name: data.name,
email: data.email,
},
subject: data.subject,
type: data.type,
reportedFrom: window.location.href,
status: "submitted",
date: new Date().toISOString(),
description: data.description,
}),
});
if (response.status === 200) {
const data = await response.json();
// Pass data to the page via props
console.log(data);
return;
}
} catch (err) {}
};
return (
{translation.title[language]}
);
}