Files
classroomio/apps/dashboard/src/lib/utils/store/org.ts
T

99 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-05-20 23:53:28 +00:00
import { writable, derived } from 'svelte/store';
2023-10-30 04:52:00 +00:00
import { dev, browser } from '$app/environment';
import { STEPS } from '../constants/quiz';
import type { Writable } from 'svelte/store';
2023-10-30 04:52:00 +00:00
import type { CurrentOrg, OrgTeamMember, OrgAudience } from '../types/org';
2023-09-15 09:22:51 +01:00
import { ROLE } from '$lib/utils/constants/roles';
2023-10-22 09:47:13 +01:00
import type { UserLessonDataType } from '$lib/utils/types';
2024-04-21 00:28:53 +01:00
import { PLAN } from 'shared/src/plans/constants';
2023-12-05 08:31:26 +03:00
export const defaultCurrentOrgState: CurrentOrg = {
2023-04-22 20:00:37 +00:00
id: '',
name: '',
shortName: '',
siteName: '',
2023-05-02 23:55:26 +00:00
avatar_url: '',
memberId: '',
2024-06-08 06:19:20 +01:00
role_id: 0,
landingpage: {},
customization: {
apps: { poll: true, comments: true },
course: { grading: true, newsfeed: true },
dashboard: { exercise: true, community: true, bannerText: '', bannerImage: '' }
},
2024-04-07 06:08:34 +01:00
theme: '',
2024-08-24 20:44:16 +01:00
organization_plan: [],
is_restricted: false
2023-12-05 08:31:26 +03:00
};
export const orgs = writable<CurrentOrg[]>([]);
export const currentOrg: Writable<CurrentOrg> = writable(defaultCurrentOrgState);
2023-10-30 04:52:00 +00:00
export const orgAudience = writable<OrgAudience[]>([]);
export const orgTeam = writable<OrgTeamMember[]>([]);
2024-05-22 05:49:10 +01:00
export const isOrgAdmin = derived(currentOrg, ($currentOrg) => $currentOrg.role_id === ROLE.ADMIN);
2024-04-07 06:08:34 +01:00
export const currentOrgPlan = derived(currentOrg, ($currentOrg) =>
$currentOrg.organization_plan.find((p) => p.is_active)
);
2024-09-05 15:19:45 +01:00
export const currentOrgPath = derived(currentOrg, ($currentOrg) =>
$currentOrg.siteName ? `/org/${$currentOrg.siteName}` : ''
2023-05-20 23:53:28 +00:00
);
2024-09-05 15:19:45 +01:00
2023-10-30 04:52:00 +00:00
export const currentOrgDomain = derived(currentOrg, ($currentOrg) => {
const browserOrigin = dev && browser && window.location.origin;
return browserOrigin
? browserOrigin
2024-09-05 15:19:45 +01:00
: $currentOrg.customDomain && $currentOrg.isCustomDomainVerified
? `https://${$currentOrg.customDomain}`
: $currentOrg.siteName
? `https://${$currentOrg.siteName}.classroomio.com`
: '';
2023-10-30 04:52:00 +00:00
});
2023-06-17 19:11:29 +00:00
2024-04-07 06:08:34 +01:00
// Utility org store
export const isFreePlan = derived(
currentOrgPlan,
($plan) => !$plan || $plan.plan_name === PLAN.BASIC
);
export const currentOrgMaxAudience = derived(currentOrgPlan, ($plan) =>
!$plan
2024-07-31 09:48:26 +01:00
? 20
2024-04-07 06:08:34 +01:00
: $plan.plan_name === PLAN.EARLY_ADOPTER
? 10000
: $plan.plan_name === PLAN.ENTERPRISE
? Number.MAX_SAFE_INTEGER
2024-07-31 09:48:26 +01:00
: 20
2024-04-07 06:08:34 +01:00
);
2023-06-17 19:11:29 +00:00
// Quiz
export const createQuizModal = writable({
open: false,
openEdit: false,
title: '',
id: null
2023-06-17 19:11:29 +00:00
});
export const deleteModal = writable({
id: null,
open: false,
isQuestion: false
2023-06-17 19:11:29 +00:00
});
export const quizesStore = writable([]);
export const quizStore = writable({
uuid: '',
title: '',
questions: [],
timelimit: '10s',
theme: 'standard',
pin: ''
2023-06-17 19:11:29 +00:00
});
export const playQuizStore = writable({
step: STEPS.CONNECT_TO_PLAY
2023-06-17 19:11:29 +00:00
});
2023-10-22 09:47:13 +01:00
export const userUpcomingData = writable<UserLessonDataType[]>([]);