CLASSROOMIO-T-126: Invite teacher and teacher can login

This commit is contained in:
Rotimi Best
2023-09-01 15:28:47 +01:00
parent 9d0fd56f05
commit 929edea63c
29 changed files with 498 additions and 74 deletions
+68
View File
@@ -0,0 +1,68 @@
import { render } from 'svelte-email';
import { json } from '@sveltejs/kit';
import TeacherInviteTemplate from './template.svelte';
import { getSendgrid, SENDGRID_FROM_HELP } from '$lib/utils/services/sendgrid';
import { getSupabase } from '$lib/utils/functions/supabase';
const sendgrid = getSendgrid();
const supabase = getSupabase();
// API to send invite to teacher
export async function POST({ request }) {
const body = await request.json();
const { org, email } = body;
const accessToken = request.headers.get('Authorization');
console.log('/POST api/email/invite', body);
if (!org || !Object.keys(org) || !email) {
return json(
{ success: false, message: 'Org data and Teacher name are required' },
{ status: 400 }
);
}
let user;
try {
const { data } = await supabase.auth.getUser(accessToken);
user = data.user;
} catch (error) {
console.error(error);
}
console.log('user', user);
if (!user) {
return json({ success: false, message: 'Unauthenticated user' }, { status: 401 });
}
const { id, name, siteName } = org;
const origin = request.headers.get('origin');
const inviteData = JSON.stringify({
email,
orgId: id,
orgSiteName: siteName
});
const inviteLink = `${origin}/invite/${encodeURIComponent(btoa(inviteData))}`;
console.log('inviteData', inviteData);
const options = {
from: SENDGRID_FROM_HELP,
to: email,
subject: `Join ${name} on ClassroomIO`,
html: render({
template: TeacherInviteTemplate,
props: {
orgName: name,
inviteLink
}
})
};
sendgrid.send(options);
return json({
success: true,
message: 'Email sent'
});
}
@@ -0,0 +1,57 @@
<script lang="ts">
import { Text, Section, Button, Link } from 'svelte-email';
export let orgName = '';
export let inviteLink = '';
const fontFamily =
'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif';
const paragraph = {
fontFamily,
fontSize: '16px',
lineHeight: '26px'
};
const paragraphContent = {
...paragraph,
margin: '20px 0'
};
const footerParagraph = {
...paragraph,
margin: '0px'
};
const btnContainer = {
textAlign: 'center' as const
};
const button = {
fontFamily,
backgroundColor: '#1d4ee2',
borderRadius: '5px',
color: '#fff',
fontSize: '16px',
textDecoration: 'none',
textAlign: 'center' as const,
display: 'block'
};
const linkStyle = {
color: '#1d4ee2'
};
</script>
<Text style={paragraph}>Hey there,</Text>
<Text style={paragraphContent}>
You have been invited to join {orgName} on ClassroomIO.
</Text>
<Section style={btnContainer}>
<Button pX={12} pY={12} style={button} href={inviteLink}>Accept Invitation</Button>
</Section>
<Text style={footerParagraph}>Best regards</Text>
<Text style={footerParagraph}>Rotimi Best</Text>
<Text style={footerParagraph}
><Link style={linkStyle} href="https://classroomio.com">ClassroomIO</Link></Text
>
@@ -0,0 +1,15 @@
<script lang="ts">
import EmailTemplate from '$lib/components/Email/EmailTemplate.svelte';
import Invitation from './invitation.svelte';
export let orgName = '';
export let inviteLink = '';
</script>
<EmailTemplate
children={Invitation}
props={{
orgName,
inviteLink
}}
/>
-7
View File
@@ -1,7 +0,0 @@
import { json } from '@sveltejs/kit';
export async function GET({ url }) {
// Get org data from request
// Get teacher email
// Generate
}