Merge remote-tracking branch 'origin/ScreenRotation'
This commit is contained in:
30
ArtisanConnect/api/email.jsx
Normal file
30
ArtisanConnect/api/email.jsx
Normal file
@@ -0,0 +1,30 @@
|
||||
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 };
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user