30 lines
1007 B
JavaScript
30 lines
1007 B
JavaScript
import { useAuthStore } from "@/store/authStore";
|
|
|
|
const API_URL = "https://hopp.zikor.pl/api/v1";
|
|
|
|
export const sendEmail = async (emailData) => {
|
|
const token = useAuthStore.getState().token;
|
|
|
|
try {
|
|
const response = await fetch(`${API_URL}/email/send`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
...(token && { Authorization: `Bearer ${token}` }),
|
|
},
|
|
body: JSON.stringify(emailData),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorMessage = `HTTP error! Status: ${response.status}`;
|
|
console.error("Error przy wysyłaniu maila", errorMessage);
|
|
return { success: false, error: errorMessage };
|
|
}
|
|
|
|
const result = await response.text();
|
|
return { success: true, result };
|
|
} catch (error) {
|
|
console.error("Error przy wysyłaniu maila:", error.message);
|
|
return { success: false, error: error.message };
|
|
}
|
|
}; |