CLASSROOMIO-T-126: Invite teacher and teacher can login
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
import { SNACKBAR_SEVERITY } from '$lib/components/Snackbar/constants';
|
||||
|
||||
export let exerciseId;
|
||||
export let refetchExercise = () => {};
|
||||
export let goBack = () => {};
|
||||
|
||||
let preview = false;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import MODES from '$lib/utils/constants/mode.js';
|
||||
import { ROLE } from '$lib/utils/constants/roles';
|
||||
|
||||
export const exerciseMode = writable({
|
||||
editMode: true
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
import { QUESTION_TYPES } from '$lib/components/Question/constants';
|
||||
import { lesson } from '../store/lessons';
|
||||
import { questionnaire, isQuestionnaireFetching, handleAddQuestion } from '../store/exercise';
|
||||
import MODES from '$lib/utils/constants/mode.js';
|
||||
import { ROLE } from '$lib/utils/constants/roles';
|
||||
import { exerciseMode } from '../Exercise/store';
|
||||
|
||||
export let path;
|
||||
@@ -139,10 +137,10 @@
|
||||
{/if}
|
||||
|
||||
{#if exerciseId}
|
||||
<Exercise {exerciseId} {goBack} refetchExercise={() => getExercise(exerciseId)} />
|
||||
<Exercise {exerciseId} {goBack} />
|
||||
{:else}
|
||||
<Modal onClose={handleCancelAddExercise} bind:open modalHeading="Create an Exercise" width="w-80">
|
||||
<TextField bind:value={newExercise.title} autofocus={true} placeholder="Exercise name" />
|
||||
<TextField bind:value={newExercise.title} autoFocus={true} placeholder="Exercise name" />
|
||||
|
||||
<div class="mt-5 flex items-center">
|
||||
<PrimaryButton className="px-6 py-3" label="Submit" onClick={handleAddExercise} />
|
||||
|
||||
@@ -67,7 +67,8 @@
|
||||
{/if}
|
||||
<input
|
||||
use:typeAction
|
||||
class="form-input border-l-0 border-r-0 border-t-0 border-b-2 border-gray-200 focus:border-l-0 focus:border-r-0 rounded-t-md focus:border-t-0 focus:border-b-2 {inputClassName} {focusClass} dark:text-black p-3 mt-1 block w-full {bgColor} {errorMessage
|
||||
class="form-input border-l-0 border-r-0 border-t-0 border-b-2 border-gray-200 focus:border-l-0 focus:border-r-0 rounded-t-md focus:border-t-0 focus:border-b-2 {inputClassName} {focusClass} {isDisabled &&
|
||||
'hover:cursor-not-allowed opacity-50'} dark:text-black p-3 mt-1 block w-full {bgColor} {errorMessage
|
||||
? 'border-red-600'
|
||||
: ''}"
|
||||
on:keydown={onKeyDown}
|
||||
@@ -111,7 +112,7 @@
|
||||
}
|
||||
.password-eye {
|
||||
position: absolute;
|
||||
top: 23px;
|
||||
top: 30px;
|
||||
right: 6px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
<script>
|
||||
import {
|
||||
Grid,
|
||||
Row,
|
||||
Column,
|
||||
Select,
|
||||
SelectItem,
|
||||
} from 'carbon-components-svelte';
|
||||
import { Grid, Row, Column, Select, SelectItem } from 'carbon-components-svelte';
|
||||
import { Moon } from 'svelte-loading-spinners';
|
||||
import TextField from '$lib/components/Form/TextField.svelte';
|
||||
import TextChip from '$lib/components/Chip/Text.svelte';
|
||||
@@ -21,6 +15,7 @@
|
||||
import { profile } from '$lib/utils/store/user';
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
import SectionTitle from '../SectionTitle.svelte';
|
||||
import { sendInvite } from './utils';
|
||||
|
||||
let emailsStr = '';
|
||||
let errorMessage = '';
|
||||
@@ -30,11 +25,7 @@
|
||||
let isRemoving = false;
|
||||
|
||||
async function onSendInvite() {
|
||||
const {
|
||||
hasError,
|
||||
error: _error,
|
||||
emails,
|
||||
} = validateEmailInString(emailsStr);
|
||||
const { hasError, error: _error, emails } = validateEmailInString(emailsStr);
|
||||
|
||||
if (hasError) {
|
||||
errorMessage = _error;
|
||||
@@ -51,13 +42,14 @@
|
||||
organization_id: $currentOrg.id,
|
||||
email,
|
||||
role_id: role,
|
||||
verified: false,
|
||||
verified: false
|
||||
})
|
||||
.select();
|
||||
console.log('data', data);
|
||||
|
||||
if (error) {
|
||||
apiError = error;
|
||||
|
||||
console.error('onSendInvite:', error);
|
||||
$snackbarStore.open = true;
|
||||
$snackbarStore.message = `Failed to send invite, please try again`;
|
||||
@@ -67,7 +59,6 @@
|
||||
return;
|
||||
}
|
||||
const [newMember] = data || [];
|
||||
|
||||
if (newMember) {
|
||||
orgTeam.update((team) => [
|
||||
{
|
||||
@@ -75,12 +66,19 @@
|
||||
email: newMember?.email,
|
||||
verified: newMember?.verified,
|
||||
role: ROLE_LABEL[newMember?.role_id] || '',
|
||||
isAdmin: newMember?.role_id === ROLE.ADMIN,
|
||||
isAdmin: newMember?.role_id === ROLE.ADMIN
|
||||
},
|
||||
...team,
|
||||
...team
|
||||
]);
|
||||
}
|
||||
|
||||
// Send email invite
|
||||
sendInvite(email, {
|
||||
id: $currentOrg.id,
|
||||
name: $currentOrg.name,
|
||||
siteName: $currentOrg.siteName
|
||||
});
|
||||
|
||||
const isLast = index === emails.length - 1;
|
||||
if (isLast) {
|
||||
$snackbarStore.open = true;
|
||||
@@ -94,20 +92,17 @@
|
||||
}
|
||||
|
||||
async function onRemove(id) {
|
||||
console.error('onRemove called');
|
||||
console.log('onRemove called');
|
||||
isRemoving = true;
|
||||
const { data, error } = await supabase
|
||||
.from('organizationmember')
|
||||
.delete()
|
||||
.match({ id });
|
||||
const { data, error } = await supabase.from('organizationmember').delete().match({ id });
|
||||
|
||||
if (error) {
|
||||
console.error('onRemove:', error);
|
||||
$snackbarStore.open = true;
|
||||
$snackbarStore.message = `Failed to remove user, please try again`;
|
||||
$snackbarStore.severity = SNACKBAR_SEVERITY.ERROR;
|
||||
} else if (data) {
|
||||
orgTeam.update((team) => team.filter((member) => member.id !== id));
|
||||
} else {
|
||||
orgTeam.update((team) => [...team.filter((member) => member.id !== id)]);
|
||||
}
|
||||
|
||||
isRemoving = false;
|
||||
@@ -122,9 +117,7 @@
|
||||
};
|
||||
|
||||
const isTeamMemberAdmin = (members, profileId) => {
|
||||
return members.some(
|
||||
(member) => member.profileId === profileId && member.isAdmin
|
||||
);
|
||||
return members.some((member) => member.profileId === profileId && member.isAdmin);
|
||||
};
|
||||
|
||||
$: fetchTeam($currentOrg.id);
|
||||
@@ -132,13 +125,10 @@
|
||||
|
||||
<Grid class="border rounded border-gray-200 w-full mt-5">
|
||||
<Row class="py-7 border-bottom-c">
|
||||
<Column sm={2} md={2} lg={4} class="text-lg"
|
||||
><SectionTitle>Add</SectionTitle></Column
|
||||
>
|
||||
<Column sm={2} md={2} lg={4} class="text-lg"><SectionTitle>Add</SectionTitle></Column>
|
||||
<Column sm={2} md={6} lg={8}>
|
||||
<p class="text-md text-gray-500 dark:text-white mb-5">
|
||||
Add your team mates or collaborators to your organization. Start working
|
||||
together
|
||||
Add your team mates or collaborators to your organization. Start working together
|
||||
</p>
|
||||
|
||||
<div class="">
|
||||
@@ -166,9 +156,7 @@
|
||||
</Row>
|
||||
|
||||
<Row class="py-7 border-bottom-c">
|
||||
<Column sm={2} md={2} lg={4} class="text-lg"
|
||||
><SectionTitle>Members</SectionTitle></Column
|
||||
>
|
||||
<Column sm={2} md={2} lg={4} class="text-lg"><SectionTitle>Members</SectionTitle></Column>
|
||||
<Column sm={2} md={6} lg={8}>
|
||||
{#if isFetching}
|
||||
<Moon />
|
||||
@@ -179,11 +167,7 @@
|
||||
<p class="text-sm text-gray-500 dark:text-white mr-3">
|
||||
{teamMember.email}
|
||||
</p>
|
||||
<TextChip
|
||||
value={teamMember.role}
|
||||
className="text-xs mr-3"
|
||||
size="sm"
|
||||
/>
|
||||
<TextChip value={teamMember.role} className="text-xs mr-3" size="sm" />
|
||||
{#if !teamMember.verified}
|
||||
<TextChip
|
||||
value="Invite Sent"
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { supabase } from '$lib/utils/functions/supabase';
|
||||
|
||||
export async function sendInvite(email: string, org: any) {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
const accessToken = data.session?.access_token || '';
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/email/invite', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: accessToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
org
|
||||
})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
const result = await response.json();
|
||||
|
||||
console.log('Sent invite email', result);
|
||||
} catch (error) {
|
||||
console.error('Error sending invite email', error);
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
<div
|
||||
bind:this={ref}
|
||||
class="bg-white dark:bg-gray-800 border {hasError
|
||||
class="bg-white dark:bg-gray-800 border-2 {hasError
|
||||
? 'border-red-700'
|
||||
: 'border-gray hover:border-primary-700'} rounded-md mb-6 relative root"
|
||||
>
|
||||
|
||||
@@ -3,6 +3,7 @@ export const blockedSubdomain = [
|
||||
'apps',
|
||||
'play',
|
||||
'support',
|
||||
'demo',
|
||||
'help',
|
||||
'teachers',
|
||||
'church',
|
||||
@@ -21,5 +22,5 @@ export const blockedSubdomain = [
|
||||
'groups',
|
||||
'academy',
|
||||
'schools',
|
||||
'training',
|
||||
'training'
|
||||
];
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
export const SIGNUP_FIELDS = {
|
||||
name: '',
|
||||
email: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
confirmPassword: ''
|
||||
};
|
||||
|
||||
export const RESET_FIELDS = {
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
confirmPassword: ''
|
||||
};
|
||||
|
||||
export const LOGIN_FIELDS = {
|
||||
email: '',
|
||||
password: '',
|
||||
password: ''
|
||||
};
|
||||
|
||||
export const FORGOT_PASSWORD_FIELDS = {
|
||||
email: '',
|
||||
email: ''
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@ export const ROUTE = {
|
||||
COURSE: '/course',
|
||||
LOGIN: '/login',
|
||||
SIGN_UP: '/signup',
|
||||
INVITE_SIGNUP: '/invite',
|
||||
PROFILE: '/profile',
|
||||
PEOPLE: '/people',
|
||||
DISCUSSIONS: '/discussions',
|
||||
@@ -19,6 +20,7 @@ export const PUBLIC_ROUTES = [
|
||||
`^${ROUTE.HOME}$`,
|
||||
ROUTE.LOGIN,
|
||||
ROUTE.SIGN_UP,
|
||||
`^${ROUTE.INVITE_SIGNUP}/.*`,
|
||||
ROUTE.FORGOT,
|
||||
ROUTE.RESET,
|
||||
`^${ROUTE.PAGES}/.*`,
|
||||
@@ -29,6 +31,7 @@ export const PUBLIC_ROUTES = [
|
||||
export const ROUTES_TO_HIDE_NAV = [
|
||||
ROUTE.LOGIN,
|
||||
ROUTE.SIGN_UP,
|
||||
`^${ROUTE.INVITE_SIGNUP}/.*`,
|
||||
ROUTE.FORGOT,
|
||||
ROUTE.RESET,
|
||||
ROUTE.ONBOARDING
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { ROUTES_TO_HIDE_NAV } from '$lib/utils/constants/routes';
|
||||
|
||||
export default (route: string): boolean => {
|
||||
return ROUTES_TO_HIDE_NAV.some((publicRoute) => {
|
||||
const regex = new RegExp(publicRoute, 'g');
|
||||
return regex.test(route);
|
||||
});
|
||||
};
|
||||
@@ -96,7 +96,7 @@ const onboardingValidationSchema = {
|
||||
export const getConfirmPasswordError = ({ password, confirmPassword }) => {
|
||||
return password > 6 && confirmPassword > 6 && password !== confirmPassword
|
||||
? 'Does not match password'
|
||||
: null;
|
||||
: undefined;
|
||||
};
|
||||
|
||||
export const processErrors = (error, mapToId) => {
|
||||
|
||||
@@ -54,6 +54,7 @@ export async function getOrganizations(userId) {
|
||||
`
|
||||
id,
|
||||
profile_id,
|
||||
role_id,
|
||||
organization!organizationmember_organization_id_fkey (
|
||||
id,
|
||||
name,
|
||||
@@ -67,6 +68,7 @@ export async function getOrganizations(userId) {
|
||||
.eq('profile_id', userId);
|
||||
|
||||
const orgsArray = [];
|
||||
|
||||
if (Array.isArray(data) && data.length) {
|
||||
data.forEach((orgMember) => {
|
||||
orgsArray.push({
|
||||
@@ -77,6 +79,7 @@ export async function getOrganizations(userId) {
|
||||
theme: orgMember?.organization?.theme,
|
||||
avatar_url: orgMember?.organization?.avatar_url,
|
||||
memberId: orgMember?.id,
|
||||
role_id: orgMember?.role_id,
|
||||
landingpage: orgMember?.organization?.landingpage
|
||||
});
|
||||
});
|
||||
@@ -173,7 +176,7 @@ export async function getCurrentOrg(siteName, justGet = false) {
|
||||
|
||||
if (!justGet) {
|
||||
currentOrg.set(data[0]);
|
||||
} else {
|
||||
} else if (!isEmpty(data)) {
|
||||
return data[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { MailService } from '@sendgrid/mail';
|
||||
import { SENDGRID_API_KEY } from '$env/static/private';
|
||||
|
||||
export const SENDGRID_FROM = 'Rotimi Best <[email protected]>';
|
||||
export const SENDGRID_FROM_HELP = 'ClassroomIO <[email protected]>';
|
||||
|
||||
export let sendgrid: MailService;
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { writable, derived } from 'svelte/store';
|
||||
import { STEPS } from '../constants/quiz';
|
||||
import type { Writable } from 'svelte/store';
|
||||
import type { CurrentOrg } from '../types/org';
|
||||
|
||||
export const orgs = writable([]);
|
||||
export const currentOrg = writable({
|
||||
export const currentOrg: Writable<CurrentOrg> = writable({
|
||||
id: '',
|
||||
name: '',
|
||||
shortName: '',
|
||||
siteName: '',
|
||||
avatar_url: '',
|
||||
memberId: '',
|
||||
role_id: '',
|
||||
landingpage: {},
|
||||
theme: ''
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
export interface CurrentOrg {
|
||||
id: string;
|
||||
name: string;
|
||||
shortName: string;
|
||||
siteName: string;
|
||||
avatar_url: string;
|
||||
memberId: string;
|
||||
role_id: string;
|
||||
landingpage: {};
|
||||
theme: string;
|
||||
}
|
||||
Reference in New Issue
Block a user