-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add email testing feature and update welcome email
This commit introduces a new feature that allows admins to test the sending of welcome emails to new users. A new 'Tests' section has been added in the admin navigation for this purpose. The code also includes error handling for failed email sends. In addition, changes have been made to the content of the welcome email sent to new users. The invitation to join our community has been removed from the message. Also, if a username is not available, the user's email will be used in the greeting instead.
- Loading branch information
Showing
5 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<script setup lang="ts"> | ||
import type { User } from '@shelve/types' | ||
const newUser = ref<User>({ | ||
email: 'hrichard206@gmail.com', | ||
username: 'test', | ||
avatar: 'https://i.imgur.com/6VBx3io.png', | ||
role: 'user', | ||
}) | ||
const loading = ref(false) | ||
async function testNewUserMail() { | ||
loading.value = true | ||
try { | ||
await $fetch('/api/mail/welcome', { | ||
method: 'POST', | ||
body: { | ||
email: newUser.value.email, | ||
username: newUser.value.username, | ||
}, | ||
}) | ||
toast.success('Email sent') | ||
} catch (error) { | ||
toast.error('Failed to send email') | ||
} | ||
loading.value = false | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-col gap-4"> | ||
<div class="flex flex-col gap-4"> | ||
<h2 class="text-lg font-semibold"> | ||
Test new user email | ||
</h2> | ||
<p class="text-sm text-neutral-500 dark:text-neutral-400"> | ||
Send a test email to a new user | ||
</p> | ||
<div> | ||
<UButton | ||
label="Send email" | ||
variant="soft" | ||
color="neutral" | ||
icon="lucide:mail" | ||
:loading | ||
@click="testNewUserMail" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { H3Event } from 'h3' | ||
import { EmailService } from '~~/server/services/resend.service' | ||
|
||
export default defineEventHandler(async (event: H3Event) => { | ||
const { email, username } = await readBody(event) | ||
const emailService = new EmailService() | ||
await emailService.sendWelcomeEmail(email, username) | ||
return { | ||
statusCode: 200, | ||
message: 'Email sent', | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters