fix: update backend URL in Contact component submission logic and improve error handling
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import {useTranslations} from 'next-intl';
|
import {useTranslations} from 'next-intl';
|
||||||
import { FormEvent, useState } from 'react';
|
import { FormEvent, useState } from 'react';
|
||||||
import toast from 'react-hot-toast'; // <-- Import toast
|
import toast from 'react-hot-toast';
|
||||||
|
|
||||||
export default function Contact() {
|
export default function Contact() {
|
||||||
const t = useTranslations('contact');
|
const t = useTranslations('contact');
|
||||||
@@ -29,8 +29,9 @@ export default function Contact() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const submissionPromise = async () => {
|
const submissionPromise = async () => {
|
||||||
|
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL;
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/email/send`, {
|
const response = await fetch(`${backendUrl}/api/email/send`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify(formData),
|
body: JSON.stringify(formData),
|
||||||
@@ -47,8 +48,11 @@ export default function Contact() {
|
|||||||
if (error instanceof TypeError) {
|
if (error instanceof TypeError) {
|
||||||
throw new Error('status_error_generic');
|
throw new Error('status_error_generic');
|
||||||
}
|
}
|
||||||
|
if (error instanceof Error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
throw new Error('server_unexpected_error');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
toast.promise(submissionPromise(), {
|
toast.promise(submissionPromise(), {
|
||||||
|
|||||||
Reference in New Issue
Block a user