fix: add sending form data

This commit is contained in:
2025-06-11 13:40:10 +03:00
parent 3fd44fba14
commit 53f214ba28
11 changed files with 121 additions and 27 deletions

View File

@@ -0,0 +1,35 @@
import { API_ROUTES } from '@shared/config/routes';
import { TBaseForm } from '@shared/api/api.types';
import { CORE } from '@shared/config/core';
type TRequest = TBaseForm;
const sendFormFn = async ({ ...props }: TRequest) => {
try {
const response = await fetch('/api' + API_ROUTES.SEND_FORM, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
...props,
secure: CORE.MAIL_SECURE_KEY,
}),
});
if (response.ok) {
return response;
} else {
if (response.status === 400) throw new Error(`400 Bad request`);
if (response.status === 401) throw new Error(`401 Unauthorized`);
if (response.status === 500) throw new Error('500 Internal server error');
throw new Error(`${response.status} - Network response failure`);
}
} catch (e) {
console.error(e);
}
};
export { sendFormFn };

View File

@@ -0,0 +1,6 @@
export type TBaseForm = {
form: string;
name?: string;
phone: string;
message?: string;
};

View File

@@ -0,0 +1,7 @@
export const CORE = {
MAIL_USER: process.env.MAIL_USER,
MAIL_PASS: process.env.MAIL_PASS,
MAIL_FROM: process.env.MAIL_FROM,
MAIL_TO: process.env.MAIL_TO,
MAIL_SECURE_KEY: process.env.NEXT_PUBLIC_MAIL_SECURE_KEY,
} as const;

View File

@@ -0,0 +1,4 @@
export const API_ROUTES = {
SEND_FORM: '/sendform',
HEARTBEAT: '/heartbeat',
} as const;

View File

@@ -0,0 +1,10 @@
//import s from './phone-input.module.scss';
import { Input } from '@shared/ui';
export default function PhoneInput() {
return (
<>
<Input />
</>
);
}