api fetch type fixed

This commit is contained in:
VividTruthKeeper 2022-08-19 22:53:41 +05:00
parent 58e18e7380
commit 8b583c4f8b
3 changed files with 50 additions and 13 deletions

View File

@ -24,19 +24,39 @@ import ig from "../../icons/instagram-grey.svg";
import twitter from "../../icons/twitter-gray.svg";
// Types
import { ContactData } from "../../types/contact";
import { ContactData, Contact } from "../../types/contact";
type stateBool = [boolean, React.Dispatch<boolean>];
const ContactForm = () => {
const [contact, setContact]: [any, React.Dispatch<any>] = useState();
const [contact, setContact]: [Contact[], React.Dispatch<Contact[]>] =
useState([
{
id: -1,
phone: "",
address: "",
instagram: "",
twitter: "",
youtube: "",
facebook: "",
translations: [
{
model_id: "",
locale: "",
attribute_data: "",
},
],
},
]);
const [data, setData]: [ContactData, React.Dispatch<ContactData>] = useState({
name: "",
email: "",
message: "",
});
const [load, setLoad] = useState(false);
const [triggered, setTriggered] = useState(false);
const [sent, setSent] = useState(false);
const [load, setLoad]: stateBool = useState(false);
const [triggered, setTriggered]: stateBool = useState(false);
const [sent, setSent]: stateBool = useState(false);
const status = {
success: "Ваше сообщение успешно отправлено",
@ -50,7 +70,7 @@ const ContactForm = () => {
return (
<form
className="contact-form"
onSubmit={(e: any) => {
onSubmit={(e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
}}
>
@ -198,7 +218,7 @@ const ContactForm = () => {
onPaste={(e: any) => {
setData({ ...data, name: e.target.value });
}}
onChange={(e: any) => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setData({ ...data, name: e.target.value });
}}
/>
@ -216,7 +236,7 @@ const ContactForm = () => {
onPaste={(e: any) => {
setData({ ...data, email: e.target.value });
}}
onChange={(e: any) => {
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setData({ ...data, email: e.target.value });
}}
/>
@ -231,15 +251,15 @@ const ContactForm = () => {
onPaste={(e: any) => {
setData({ ...data, message: e.target.value });
}}
onChange={(e: any) => {
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => {
setData({ ...data, message: e.target.value });
}}
></textarea>
</div>
</div>
<button
type="button"
onClick={(e: any) => {
type="submit"
onClick={(e: React.FormEvent<HTMLButtonElement>) => {
setLoad(true);
e.preventDefault();
sendData(setLoad, setSent, setTriggered, data);

View File

@ -22,7 +22,7 @@ import {
} from "../links";
// Types
import { ContactData } from "../types/contact";
import { ContactData, Contact } from "../types/contact";
export const getMainSliderData = (
setState: React.Dispatch<SlideProps[]>
@ -111,7 +111,7 @@ export const getStructure = (setState: any) => {
.catch();
};
export const getContact = (setState: any) => {
export const getContact = (setState: React.Dispatch<Contact[]>) => {
axios
.get(contacts)
.then((res) => {

View File

@ -3,3 +3,20 @@ export interface ContactData {
email: string;
message: string;
}
export interface Contact {
id: number;
phone: string;
address: string;
instagram: string;
twitter: string;
youtube: string;
facebook: string;
translations: [
{
model_id: string;
locale: string;
attribute_data: string;
}
];
}