frontPanel/src/api/contactForm.ts

32 lines
775 B
TypeScript
Raw Normal View History

2024-05-13 13:24:41 +00:00
import { makeRequest } from "@api/makeRequest";
2024-05-13 13:24:41 +00:00
import { parseAxiosError } from "@utils/parse-error";
2024-05-13 13:24:41 +00:00
const API_URL = process.env.REACT_APP_DOMAIN + "/feedback";
type SendContactFormBody = {
2023-12-31 02:53:25 +00:00
contact: string;
whoami: string;
2024-05-13 13:24:41 +00:00
};
export const sendContactFormRequest = async (
body: SendContactFormBody,
): Promise<[unknown | null, string?, number?]> => {
try {
const sendContactFormResponse = await makeRequest<
SendContactFormBody,
unknown
>({
method: "POST",
url: `${API_URL}/callme`,
body,
});
return [sendContactFormResponse];
} catch (nativeError) {
const [error, status] = parseAxiosError(nativeError);
return [null, `Не удалось отправить контакты. ${error}`, status];
}
};