Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions api/routes/email-routes.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import "dotenv/config";
import express from "express";
import nodemailer from "nodemailer";
import Contact from "../schemas/Contact.js";

const router = express.Router();

// Nodemailer setup
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.ADMIN_EMAIL,
pass: process.env.ADMIN_PASSWORD,
},
});

// Post Contact
router.post('/contact', async (req, res) => {
const { name, email, subject, message } = req.body

try {
const newContact = new Contact({
name,
email,
subject,
message
});
await newContact.save();

// Nodemailer setup
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.ADMIN_EMAIL,
pass: process.env.ADMIN_PASSWORD,
},
});

transporter.verify((error, success) => {
if (error) {
console.error('Error initializing transporter:', error);
Expand All @@ -37,8 +28,9 @@ router.post('/contact', async (req, res) => {


const mailOptions = {
from: email,
from: `"${name}" <${process.env.ADMIN_EMAIL}>`,
to: process.env.ADMIN_EMAIL,
replyTo: email,
subject: `Contact Form: ${subject}`,
html: `
<p><strong>From:</strong> ${name} (${email})</p>
Expand Down
15 changes: 0 additions & 15 deletions api/schemas/Contact.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Footer = () => {
<div className="max-w-[96rem] w-full">
<h1 className="font-extrabold mb-5">Dillar Academy</h1>
<div className="flex flex-col gap-y-2 sm:gap-y-3 lg:text-lg">
<a href="mailto:dillaracademy@gmail.com">{t("email")}: dillaracademy@gmail.com</a>
<a href="mailto:info@dillaracademy.org">{t("email")}: info@dillaracademy.org</a>
<a href={'https://www.instagram.com/dillaracademy/'} target="_blank" rel="noreferrer noopener">{t("instagram")}: @dillaracademy</a>
<Link href="/contact" className="underline">{t("contact_text")}</Link>
</div>
Expand Down
21 changes: 13 additions & 8 deletions src/pages/Contact.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Button from '@/components/Button/Button';
import Alert from "@/components/Alert";
import { useTranslation } from 'react-i18next';

export default function Contact() {
const Contact = () => {
const { t } = useTranslation();

const [formData, setFormData] = useState({
Expand All @@ -18,7 +18,7 @@ export default function Contact() {
});
const [alertMessage, setAlertMessage] = useState("")
const [successMessage, setSuccessMessage] = useState("")

const [isSending, setIsSending] = useState(false);

const handleChange = (e) => {
setFormData({ ...formData, [e.target.name]: e.target.value });
Expand All @@ -27,6 +27,7 @@ export default function Contact() {
const handleSubmit = async (e) => {
e.preventDefault();
try {
setIsSending(true);
await postContact(formData);
setSuccessMessage('contact_success_alert');
setTimeout(() => {
Expand All @@ -40,10 +41,12 @@ export default function Contact() {
});
} catch (err) {
console.error('Error submitting message:', err);
setAlertMessage(`Error: ${err.response.data.message}`); // TODO: translations
setAlertMessage(`Error: ${err.response.data.message}`);
setTimeout(() => {
setAlertMessage("");
}, 4000);
} finally {
setIsSending(false);
}
};

Expand All @@ -59,7 +62,10 @@ export default function Contact() {
<p className="text-base sm:text-lg mb-4 text-gray-600 opacity-70">
{t("contact_form_description")}
</p >
<form
<a href="mailto:info@dillaracademy.org">{t("email")}: info@dillaracademy.org</a>


{/* <form
onSubmit={handleSubmit}
className="space-y-3"
>
Expand Down Expand Up @@ -98,15 +104,14 @@ export default function Contact() {
<Button
type="submit"
label={t("submit_button")}
isDisabled={isSending}
/>
</form>
</form> */}
</Form>
</div>
</div >
</>
);
}




export default Contact;
1 change: 0 additions & 1 deletion src/wrappers/class-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const getClasses = async (query = "") => {
} catch (error) {
console.error('Error fetching courses:', error)
throw error;

}
}

Expand Down