Skip to content

Commit 1e0f7a4

Browse files
committed
Remove baseURL from API calling
1 parent 8fcfbb5 commit 1e0f7a4

File tree

3 files changed

+45
-57
lines changed

3 files changed

+45
-57
lines changed

src/Components/Features/Forms/Contact.jsx

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// Contact.jsx
2-
31
import { useState } from "react";
42
import { IoIosMail } from "react-icons/io";
53
import { FaUser, FaPaperPlane, FaQuoteLeft, FaStar, FaHeadset } from "react-icons/fa";
6-
import { HiOutlineSparkles } from "react-icons/hi";
74
import axiosInstance from "../../utils/Axios";
85
import useAlert from "../../utils/setAlert";
96

@@ -37,26 +34,11 @@ const Contact = () => {
3734

3835
try {
3936
await axiosInstance.post(
40-
`${import.meta.env.VITE_BACKEND_URL}/forms/contactDetails`,
37+
`/forms/contactDetails`,
4138
{ details },
42-
{
43-
headers: {
44-
'Content-Type': 'application/json'
45-
}
46-
}
4739
);
48-
4940
handleSuccess("Thank you for contacting us, We will get back to you soon");
5041
setIsSuccess(true);
51-
setDetails({
52-
username: "",
53-
gmail: "",
54-
concern: "",
55-
});
56-
57-
// Reset success state after 3 seconds
58-
setTimeout(() => setIsSuccess(false), 3000);
59-
6042
} catch (error) {
6143
if (error.response?.status === 429) {
6244
handleError('Rate limit exceeded. Please try again later.');
@@ -69,6 +51,11 @@ const Contact = () => {
6951
}
7052
} finally {
7153
setIsSubmitting(false);
54+
setDetails({
55+
username: "",
56+
gmail: "",
57+
concern: "",
58+
});
7259
}
7360
};
7461

@@ -93,7 +80,7 @@ const Contact = () => {
9380
Get in Touch
9481
</h1>
9582
<p className="text-xl text-slate-600 max-w-2xl mx-auto leading-relaxed">
96-
Have a question or concern? We're here to help. Send us a message and we'll respond promptly.
83+
Have a question or concern? We&apos;re here to help. Send us a message and we&apos;ll respond promptly.
9784
</p>
9885
</div>
9986

@@ -106,13 +93,13 @@ const Contact = () => {
10693
<FaPaperPlane className="w-10 h-10 text-green-600" />
10794
</div>
10895
<h3 className="text-2xl font-bold text-slate-800 mb-4">Message Sent!</h3>
109-
<p className="text-slate-600">Thank you for contacting us. We'll get back to you soon.</p>
96+
<p className="text-slate-600">Thank you for contacting us. We&apos;ll get back to you soon.</p>
11097
</div>
11198
) : (
11299
<div className="space-y-8">
113100
<div className="text-center">
114101
<h2 className="text-3xl font-bold text-slate-800 mb-3">Contact Us</h2>
115-
<p className="text-slate-600">We'd love to hear from you</p>
102+
<p className="text-slate-600">We&apos;d love to hear from you</p>
116103
</div>
117104

118105
<form onSubmit={handleSubmit} className="space-y-6">
@@ -254,7 +241,7 @@ const Contact = () => {
254241
<div className="max-w-6xl mx-auto mb-16">
255242
<div className="text-center mb-12">
256243
<h2 className="text-3xl font-bold text-slate-800 mb-4">Trusted Support</h2>
257-
<p className="text-slate-600">We're here to help you succeed</p>
244+
<p className="text-slate-600">{"We're here to help you succeed"}</p>
258245
</div>
259246

260247
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
@@ -283,7 +270,7 @@ const Contact = () => {
283270
<div className="md:col-span-2 lg:col-span-1 bg-white/60 backdrop-blur-sm rounded-2xl p-8 shadow-lg border border-slate-200/50 hover:shadow-xl transition-all duration-300">
284271
<FaQuoteLeft className="w-6 h-6 text-slate-400 mb-4" />
285272
<p className="text-slate-700 mb-6 leading-relaxed">
286-
"Outstanding support! They resolved my issue quickly and professionally."
273+
{"Outstanding support! They resolved my issue quickly and professionally."}
287274
</p>
288275
<div className="flex items-center">
289276
<div className="w-10 h-10 bg-gradient-to-br from-slate-400 to-slate-600 rounded-full flex items-center justify-center text-white font-bold">

src/Components/Features/Forms/Feedback.jsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Feedback.jsx
2-
31
import { useState } from "react";
42
import { FaUser, FaPaperPlane, FaQuoteLeft, FaStar } from "react-icons/fa";
53
import { IoIosMail } from "react-icons/io";
64
import { HiOutlineSparkles } from "react-icons/hi";
5+
import axiosInstance from "../../utils/Axios";
6+
import useAlert from "../../utils/setAlert";
77

88
const Feedback = () => {
9+
const { handleSuccess, handleError } = useAlert();
910
const [isSubmitting, setIsSubmitting] = useState(false);
1011
const [isSuccess, setIsSuccess] = useState(false);
1112
const [focusedField, setFocusedField] = useState(null);
@@ -26,20 +27,31 @@ const Feedback = () => {
2627
const handleSubmit = async (e) => {
2728
e.preventDefault();
2829
setIsSubmitting(true);
29-
30-
// Simulate API call
31-
setTimeout(() => {
30+
try{
31+
await axiosInstance.post(
32+
`/forms/feedbackDetails`,
33+
{feedback: details.feedback, gmail: details.gmail},
34+
)
35+
handleSuccess("Thank you for providing your valuable feedback");
36+
}
37+
catch (error){
38+
if (error.response.status === 429) {
39+
handleError('Rate limit exceeded. Please try again later.');
40+
}else if(error.response.status === 404){
41+
handleError("Please enter email that is associated with your account");
42+
}else {
43+
handleError("Failed to submit the form, Try again later");
44+
}
45+
}
46+
finally{
3247
setIsSubmitting(false);
3348
setIsSuccess(true);
3449
setDetails({
3550
username: "",
3651
gmail: "",
3752
feedback: ""
3853
});
39-
40-
// Reset success state after 3 seconds
41-
setTimeout(() => setIsSuccess(false), 3000);
42-
}, 2000);
54+
}
4355
};
4456

4557
const handleFocus = (fieldName) => setFocusedField(fieldName);

src/Components/Features/Forms/Suggestion.jsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Suggestion.jsx
2-
31
import { useState } from "react";
42
import { FaUser, FaPen, FaPaperPlane, FaQuoteLeft, FaStar, FaBook, FaBookOpen } from "react-icons/fa";
53
import { IoIosMail } from "react-icons/io";
@@ -35,29 +33,13 @@ const Suggestion = () => {
3533
e.preventDefault();
3634
setIsSubmitting(true);
3735

38-
const response = await axiosInstance.post(
39-
`${import.meta.env.VITE_BACKEND_URL}/forms/suggestionDetails`,
36+
await axiosInstance.post(
37+
`/forms/suggestionDetails`,
4038
details,
41-
{
42-
headers: {
43-
'Content-Type': 'application/json'
44-
}
45-
}
4639
);
4740

4841
handleSuccess("Thank you for suggesting us a book. We will review it and get back to you soon.");
4942
setIsSuccess(true);
50-
setDetails({
51-
username: "",
52-
gmail: "",
53-
genre: "",
54-
bookName: "",
55-
author: "",
56-
});
57-
58-
// Reset success state after 3 seconds
59-
setTimeout(() => setIsSuccess(false), 3000);
60-
6143
} catch (error) {
6244
if (error.response?.status === 429) {
6345
handleError('Rate limit exceeded. Please try again later.');
@@ -68,6 +50,13 @@ const Suggestion = () => {
6850
}
6951
} finally {
7052
setIsSubmitting(false);
53+
setDetails({
54+
username: "",
55+
gmail: "",
56+
genre: "",
57+
bookName: "",
58+
author: "",
59+
});
7160
}
7261
};
7362

@@ -105,13 +94,13 @@ const Suggestion = () => {
10594
<FaBook className="w-10 h-10 text-green-600" />
10695
</div>
10796
<h3 className="text-2xl font-bold text-slate-800 mb-4">Suggestion Received!</h3>
108-
<p className="text-slate-600">Thank you for your book suggestion. We'll review it and get back to you soon.</p>
97+
<p className="text-slate-600">Thank you for your book suggestion. We&apos;ll review it and get back to you soon.</p>
10998
</div>
11099
) : (
111100
<div className="space-y-8">
112101
<div className="text-center">
113102
<h2 className="text-3xl font-bold text-slate-800 mb-3">Share Your Recommendation</h2>
114-
<p className="text-slate-600">Tell us about a book you'd love to see in our collection</p>
103+
<p className="text-slate-600">Tell us about a book you&apos;d love to see in our collection</p>
115104
</div>
116105

117106
<form onSubmit={handleSubmit} className="space-y-6">
@@ -283,7 +272,7 @@ const Suggestion = () => {
283272
<div className="w-3 h-3 bg-white rounded-full"></div>
284273
</div>
285274
<h4 className="font-semibold mb-2">Build Community</h4>
286-
<p className="text-sm text-slate-200">Help fellow readers discover amazing books they'll love</p>
275+
<p className="text-sm text-slate-200">Help fellow readers discover amazing books they&apos;ll love</p>
287276
</div>
288277
<div className="text-center">
289278
<div className="w-12 h-12 bg-white/20 rounded-full flex items-center justify-center mx-auto mb-4">
@@ -336,7 +325,7 @@ const Suggestion = () => {
336325
<div className="md:col-span-2 lg:col-span-1 bg-white/60 backdrop-blur-sm rounded-2xl p-8 shadow-lg border border-slate-200/50 hover:shadow-xl transition-all duration-300">
337326
<FaQuoteLeft className="w-6 h-6 text-slate-400 mb-4" />
338327
<p className="text-slate-700 mb-6 leading-relaxed">
339-
"Love how my book suggestions actually get added to the library. Great way to share favorites!"
328+
&quot;Love how my book suggestions actually get added to the library. Great way to share favorites&quot;
340329
</p>
341330
<div className="flex items-center">
342331
<div className="w-10 h-10 bg-gradient-to-br from-slate-400 to-slate-600 rounded-full flex items-center justify-center text-white font-bold">

0 commit comments

Comments
 (0)