CLASSROOMIO-T-5: Educators Settings CRUD

Co-authored-by: Rotimi Best <rotimiibitoyeemma@gmail.com>

Merge-request: CLASSROOMIO-MR-7
Merged-by: Digdippa Team <digdippa@gmail.com>
This commit is contained in:
Rotimi Best
2023-05-02 23:55:26 +00:00
committed by Space Cloud
co-authored by Rotimi Best
parent 01a1f0f907
commit 5f14b36ef8
27 changed files with 832 additions and 89 deletions
+31
View File
@@ -1,4 +1,5 @@
import z from 'zod';
import { validateEmail } from './validateEmail';
const forgotValidationSchema = z.object({
email: z.string().email({
@@ -100,3 +101,33 @@ export const onboardingValidation = (fields = {}, step) => {
export const getDisableSubmit = ({ password, confirmPassword }) => {
return !!(password && confirmPassword && password !== confirmPassword);
};
export const validateEmailInString = (emailsStr) => {
let error = '';
let hasError = false;
if (!emailsStr) {
return {
hasError: true,
error: 'Enter an email',
emails: [],
};
}
const emails = emailsStr.split(',').map((_email) => {
const email = _email.trim();
if (!validateEmail(email)) {
hasError = true;
error += !error.length ? `Not valid email: ${email}` : `, ${email}`;
}
return email;
});
return {
hasError,
error,
emails,
};
};
+46 -2
View File
@@ -1,5 +1,47 @@
import { supabase } from '../../functions/supabase';
import { orgs, currentOrg, orgAudience } from '../../store/org';
import { orgs, currentOrg, orgAudience, orgTeam } from '../../store/org';
import { ROLE, ROLE_LABEL } from '../../constants/roles';
export async function getOrgTeam(orgId) {
const { data, error } = await supabase
.from('organizationmember')
.select(
`
id,
email,
verified,
role_id,
profile(
id,
fullname,
email
)
`
)
.eq('organization_id', orgId)
.order('id', { ascending: false });
const team = [];
if (data?.length) {
data.forEach((teamMember) => {
team.push({
id: teamMember.id,
email: teamMember?.profile?.email || teamMember?.email,
verified: teamMember?.verified,
profileId: teamMember?.profile?.id,
role: ROLE_LABEL[teamMember?.role_id] || '',
isAdmin: teamMember?.role_id === ROLE.ADMIN,
});
});
orgTeam.set(team);
}
return {
team,
error,
};
}
export async function getOrganizations(userId) {
const { data, error } = await supabase
@@ -11,7 +53,8 @@ export async function getOrganizations(userId) {
organization (
id,
name,
siteName
siteName,
avatar_url
)
`
)
@@ -26,6 +69,7 @@ export async function getOrganizations(userId) {
shortName:
orgMember?.organization?.name?.substring(0, 2)?.toUpperCase() || '',
siteName: orgMember?.organization?.siteName,
avatar_url: orgMember?.organization?.avatar_url,
});
});
+2
View File
@@ -6,5 +6,7 @@ export const currentOrg = writable({
name: '',
shortName: '',
siteName: '',
avatar_url: '',
});
export const orgAudience = writable([]);
export const orgTeam = writable([]);