feat: email on inquiry
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import prisma from "../prisma/client.js";
|
||||
|
||||
import {sendEmail} from "../utils/sendEmail.js";
|
||||
import {getEmailsByType} from "../utils/getEmailByTypes.js";
|
||||
|
||||
/* CREATE INQUIRY */
|
||||
export const createInquiry = async (req, res) => {
|
||||
try {
|
||||
@@ -21,6 +24,28 @@ export const createInquiry = async (req, res) => {
|
||||
message,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const emailList = await getEmailsByType("INQUIRY");
|
||||
|
||||
if (emailList && emailList.length > 0) {
|
||||
await sendEmail({
|
||||
to: emailList,
|
||||
subject: "New Inquiry Received",
|
||||
html: `
|
||||
<h2>New Inquiry</h2>
|
||||
|
||||
<p><b>Name:</b> ${fullName}</p>
|
||||
<p><b>Phone:</b> ${number}</p>
|
||||
<p><b>Email:</b> ${emailId}</p>
|
||||
|
||||
<p><b>Subject:</b> ${subject}</p>
|
||||
<p><b>Message:</b> ${message}</p>
|
||||
`,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Inquiry email failed:", err);
|
||||
}
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -181,14 +181,16 @@ export default function EmailPage() {
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => openEdit(item)}>
|
||||
onClick={() => openEdit(item)}
|
||||
>
|
||||
<Pencil className="h-4 w-4" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => handleDelete(item.id)}>
|
||||
onClick={() => handleDelete(item.id)}
|
||||
>
|
||||
<Trash className="h-4 w-4" />
|
||||
</Button>
|
||||
</TableCell>
|
||||
@@ -225,10 +227,12 @@ export default function EmailPage() {
|
||||
name="type"
|
||||
value={form.type}
|
||||
onChange={handleChange}
|
||||
className="border rounded px-2 py-2 w-full">
|
||||
className="border rounded px-2 py-2 w-full"
|
||||
>
|
||||
<option value="APPOINTMENT">APPOINTMENT</option>
|
||||
<option value="CANDIDATE">CANDIDATE</option>
|
||||
<option value="ACADEMICS">ACADEMICS</option>
|
||||
<option value="INQUIRY">INQUIRY</option>
|
||||
</select>
|
||||
|
||||
<select
|
||||
@@ -240,7 +244,8 @@ export default function EmailPage() {
|
||||
isActive: e.target.value === "true",
|
||||
})
|
||||
}
|
||||
className="border rounded px-2 py-2 w-full">
|
||||
className="border rounded px-2 py-2 w-full"
|
||||
>
|
||||
<option value="true">Active</option>
|
||||
<option value="false">Inactive</option>
|
||||
</select>
|
||||
|
||||
Reference in New Issue
Block a user