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

71 lines
1.8 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';
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: '',
role_id: '',
landingpage: {},
theme: ''
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[]>([]);
2023-09-15 09:22:51 +01:00
export const isOrgAdmin = derived(
currentOrg,
($currentOrg) => parseInt($currentOrg.role_id) === ROLE.ADMIN
);
export const currentOrgPath = derived(currentOrg, ($currentOrg) =>
$currentOrg.siteName ? `/org/${$currentOrg.siteName}` : ''
2023-05-20 23:53:28 +00: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
: $currentOrg.siteName
2023-11-25 21:56:02 +00:00
? `https://${$currentOrg.siteName}.classroomio.com`
: '';
2023-10-30 04:52:00 +00: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[]>([]);