Skip to content

Commit c98c6d5

Browse files
committed
ft(ContactUs): Implement the contact us form submission
1 parent 10ba88d commit c98c6d5

File tree

5 files changed

+139
-1
lines changed

5 files changed

+139
-1
lines changed

src/helpers/sendForm.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { sendEmail } from '../utils/sendEmail'
2+
import contactFormTemplate from '../utils/templates/contactFormTemplate'
3+
4+
export const sendMessage = async (
5+
name: string,
6+
email: string,
7+
phone: string,
8+
message: string
9+
): Promise<string> => {
10+
if (!name || !email || !message) {
11+
throw new Error('Name, email, and message are required!')
12+
}
13+
14+
const adminEmail = process.env.ADMIN_EMAIL
15+
const subject = 'DevPulse New Contact Us Form Submission'
16+
const content = contactFormTemplate({ name, email, phone, message })
17+
18+
const senderEmail = process.env.ADMIN_EMAIL
19+
const senderPassword = process.env.ADMIN_PASS
20+
21+
try {
22+
const response = await sendEmail(
23+
adminEmail,
24+
subject,
25+
content,
26+
'',
27+
senderEmail,
28+
senderPassword
29+
)
30+
return 'Message sent successfully!'
31+
} catch (error) {
32+
console.error('Error in sendMessage:', error);
33+
throw new Error('Error sending message')
34+
}
35+
}

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import attendanceResolver from './resolvers/attendance.resolvers'
3636
import Sessionresolvers from './resolvers/session.resolver'
3737
import invitationResolvers from './resolvers/invitation.resolvers'
3838
import organizationResolvers from './resolvers/organization.resolvers'
39+
import contactResolver from './resolvers/contactus.resolver'
3940
import schemas from './schema/index'
4041
import cohortSchema from './schema/cohort.schema'
4142
import programSchema from './schema/program.schema'
@@ -44,6 +45,7 @@ import phaseSchema from './schema/phase.schema'
4445
import ticketSchema from './schema/ticket.shema'
4546
import notificationSchema from './schema/notification.schema'
4647
import organizationSchema from './schema/organization.schema'
48+
import contactUsSchema from './schema/contactus.schema'
4749

4850
import statisticsSchema from './schema/invitationStatics.schema'
4951
import StatisticsResolvers from './resolvers/invitationStatics.resolvers'
@@ -72,7 +74,8 @@ export const typeDefs = mergeTypeDefs([
7274
statisticsSchema,
7375
eventSchema,
7476
CommunitySchema,
75-
organizationSchema
77+
organizationSchema,
78+
contactUsSchema,
7679
])
7780

7881
export const resolvers = mergeResolvers([
@@ -98,6 +101,7 @@ export const resolvers = mergeResolvers([
98101
invitationResolvers,
99102
TableViewInvitationResolver,
100103
faMutation,
104+
contactResolver,
101105
])
102106

103107
async function startApolloServer(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { sendMessage } from '../helpers/sendForm'
2+
3+
const contactResolver = {
4+
Mutation: {
5+
sendMessage: async (
6+
_: any,
7+
{
8+
name,
9+
email,
10+
phone,
11+
message,
12+
}: { name: string; email: string; phone: string; message: string }
13+
) => {
14+
try {
15+
const response = await sendMessage(name, email, phone, message)
16+
return response
17+
} catch (error) {
18+
throw new Error('Error sending message')
19+
}
20+
},
21+
},
22+
}
23+
24+
export default contactResolver

src/schema/contactus.schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import gql from 'graphql-tag'
2+
3+
const contactUsSchema = gql`
4+
type Mutation {
5+
sendMessage(
6+
name: String!
7+
email: String!
8+
phone: String
9+
message: String!
10+
): String
11+
}
12+
`
13+
14+
export default contactUsSchema
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const contactFormTemplate = ({
2+
name,
3+
email,
4+
phone,
5+
message,
6+
}: {
7+
name: string
8+
email: string
9+
phone: string
10+
message: string
11+
}): string => {
12+
return `
13+
<table style="border: 1px solid #ddd; padding: 16px; border-radius: 8px; background-color: #f9f9f9; max-width: 600px; margin: 0 auto; font-family: 'Rubik', sans-serif;">
14+
<tr>
15+
<td style="width: 100%; background-color: #E0E7FF; padding: 16px; text-align: center; border-radius: 8px 8px 0 0;">
16+
<table width="100%" border="0" cellpadding="16" cellspacing="0" style="border-radius: 8px 8px 0 0;">
17+
<tr>
18+
<td style="text-align: center;">
19+
<img src="https://res.cloudinary.com/ddf0u9tgz/image/upload/v1724949908/emailLogo_rmmwdi.png" style="width: 150px; height: auto;" alt="Logo" />
20+
<p style="margin: 10px 0 0; font-size: 18px; font-weight: bold; color: #8667F2;">New Contact Form Submission</p>
21+
</td>
22+
</tr>
23+
</table>
24+
</td>
25+
</tr>
26+
27+
<tr>
28+
<td style="padding: 16px; color: black; text-align: left;">
29+
<p>Hello,</p>
30+
<p>You have received a new contact form submission. Below are the details:</p>
31+
<table width="100%" cellpadding="8" cellspacing="0" style="margin-top: 20px; border: 1px solid #ddd; border-radius: 8px;">
32+
<tr>
33+
<td style="background-color: #f1f1f1; font-weight: bold; color: #333;">Name:</td>
34+
<td style="background-color: #ffffff; color: #333;">${name}</td>
35+
</tr>
36+
<tr>
37+
<td style="background-color: #f1f1f1; font-weight: bold; color: #333;">Email:</td>
38+
<td style="background-color: #ffffff; color: #333;">${email}</td>
39+
</tr>
40+
<tr>
41+
<td style="background-color: #f1f1f1; font-weight: bold; color: #333;">Phone:</td>
42+
<td style="background-color: #ffffff; color: #333;">${
43+
phone || 'Not Provided'
44+
}</td>
45+
</tr>
46+
<tr>
47+
<td style="background-color: #f1f1f1; font-weight: bold; color: #333;">Message:</td>
48+
<td style="background-color: #ffffff; color: #333;">${message}</td>
49+
</tr>
50+
</table>
51+
52+
<div style="margin-top: 30px; padding: 10px 0; text-align: center;">
53+
<p style="font-size: 12px; color: #777777;">&copy; 2024 Devpulse. All rights reserved.</p>
54+
</div>
55+
</td>
56+
</tr>
57+
</table>
58+
`
59+
}
60+
61+
export default contactFormTemplate

0 commit comments

Comments
 (0)