CLASSROOMIO-T-133: Send welcome email after onboarding
Co-authored-by: Rotimi Best <[email protected]> Merge-request: CLASSROOMIO-MR-55 Merged-by: Best Admin <[email protected]>
This commit is contained in:
committed by
Space Cloud
co-authored by
Rotimi Best
parent
b979da3db1
commit
7a5d341865
@@ -10,6 +10,7 @@
|
||||
import { blockedSubdomain } from '$lib/utils/constants/app';
|
||||
import { welcomeModalStore } from '$lib/components/WelcomeModal/store';
|
||||
import { getOrganizations } from '$lib/utils/services/org';
|
||||
import { sendWelcomeEmail } from './utils';
|
||||
|
||||
interface OnboardingField {
|
||||
fullname?: string;
|
||||
@@ -80,6 +81,7 @@
|
||||
const payload = await response.json();
|
||||
fields.metadata = payload;
|
||||
}
|
||||
|
||||
function setOrgSiteName(orgName: string | undefined, isTouched: boolean) {
|
||||
if (!orgName || isTouched) return;
|
||||
let inputElement = event?.target as HTMLInputElement;
|
||||
@@ -177,6 +179,10 @@
|
||||
.match({ id: $profile.id });
|
||||
loading = false;
|
||||
|
||||
if (fields.fullname) {
|
||||
sendWelcomeEmail($profile.email, fields.fullname);
|
||||
}
|
||||
|
||||
console.log('data', data);
|
||||
console.log('error', error);
|
||||
$welcomeModalStore.open = true;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
|
||||
export async function sendWelcomeEmail(to: string, name: string) {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
const accessToken = data.session?.access_token || '';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/email/welcome', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
to,
|
||||
name
|
||||
})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
const result = await response.json();
|
||||
|
||||
console.log('Sent confirmation email', result);
|
||||
} catch (error) {
|
||||
console.error('Error sending confirmation email', error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user