From 658791d66d5a86a48ee788e0c657501cc89054a3 Mon Sep 17 00:00:00 2001 From: warrenshiv Date: Wed, 6 Dec 2023 15:23:28 +0300 Subject: [PATCH] Established Frontend Connection to Backend Email Sending Functionality --- .../__pycache__/views.cpython-310.pyc | Bin 8529 -> 8529 bytes backend/artistsmgmt/views.py | 6 +- .../__pycache__/settings.cpython-310.pyc | Bin 3130 -> 3110 bytes backend/backend/settings.py | 2 +- .../src/components/profile/ContactForm.js | 151 ++++++++++++++---- 5 files changed, 124 insertions(+), 35 deletions(-) diff --git a/backend/artistsmgmt/__pycache__/views.cpython-310.pyc b/backend/artistsmgmt/__pycache__/views.cpython-310.pyc index ccd43b9772495ce574e7aeadea0153d9fe071bb7..365902062d004a6ac9db89cf366e28f96f291dfa 100644 GIT binary patch delta 26 gcmccUbkT_`pO=@50SJ;3H*(d;GOBKFmp#P{0AVQyB>(^b delta 26 gcmccUbkT_`pO=@50SK<^ZRDzvWo+5pE_;d@0A}z9#sB~S diff --git a/backend/artistsmgmt/views.py b/backend/artistsmgmt/views.py index 9a7eebc..f4e4bca 100644 --- a/backend/artistsmgmt/views.py +++ b/backend/artistsmgmt/views.py @@ -227,9 +227,9 @@ def send_sms(request): class SendEmailView(APIView): def post(self, request, *args, **kwargs): try: - sender_email = request.POST.get('email') - subject = request.POST.get('subject') - message = request.POST.get('message') + sender_email = request.data.get('email') + subject = request.data.get('subject') + message = request.data.get('message') recipient_email = 'warrenshiv@gmail.com' if sender_email is None or subject is None or message is None: diff --git a/backend/backend/__pycache__/settings.cpython-310.pyc b/backend/backend/__pycache__/settings.cpython-310.pyc index f936d28fc75453f30334af53739a7e05c13504f3..a0807d2ca6d2b3db8daad1943921636e711c34e3 100644 GIT binary patch delta 48 zcmdlbu}p$DpO=@50SMC43sN6%V!Z delta 68 zcmZ1`u}gwCpO=@50SI1r7o>jQ$m_-_RwYuNSX7jnSDcYq=8&G7n3 { + const [formData, setFormData] = useState({ + name: "", + email: "", + subject: "", + message: "", + }); + + const [successMessage, setSuccessMessage] = useState(""); + + const handleChange = (e) => { + const { name, value } = e.target; + setFormData((prevData) => ({ + ...prevData, + [name]: value, + })); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + + // const { name, ...dataWithoutName } = formData; + + try { + // Make a POST request to the backend + const response = await axios.post( + "http://127.0.0.1:8000/api/send-email/", + formData + ); + + if (response.status === 200) { + setSuccessMessage("Email sent successfully!"); + setFormData({ + name: "", + email: "", + subject: "", + message: "", + }); + + setTimeout(() => { + setSuccessMessage(""); + }, 3000); + } + } catch (error) { + // Error + console.error("Error sending form data: ", error); + } + }; + const iconStyle = { - fontSize: '30px', - color: '#03C04A', - marginRight: '10px', + fontSize: "30px", + color: "#03C04A", + marginRight: "10px", }; const buttonStyle = { - backgroundColor: '#03C04A', - color: '#fff', - fontSize: '1.5rem', + backgroundColor: "#03C04A", + color: "#fff", + fontSize: "1.5rem", }; - const bodyStyle = { - backgroundColor: '#54626F', - color: '#fff', - }; - // style={bodyStyle} + // const bodyStyle = { + // backgroundColor: '#54626F', + // color: '#fff', + // }; return ( -
+
-
Contact
+
+ Contact +
-
-
-
- - {/* Info Items */} +
+
+
- +

Location:

A108 Adam Street, New York, NY 535022

@@ -57,7 +108,10 @@ const ContactForm = () => {
- +

Email:

info@example.com

@@ -69,37 +123,72 @@ const ContactForm = () => { {/* Contact Form */}
-
- + {successMessage && ( +
+

{successMessage}

+
+ )} +
- +
- +
- +
- +
- {/* Add space using Bootstrap spacing utility class (mt-3) */}
- +
-
-