2021-07-12 05:55:57 +03:00
|
|
|
<script context="module">
|
2021-08-29 07:23:19 +03:00
|
|
|
import {
|
|
|
|
|
fetchCourse,
|
|
|
|
|
deleteGroupMember,
|
|
|
|
|
} from '../../../utils/services/courses';
|
2021-07-12 05:55:57 +03:00
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
export async function preload({ params }) {
|
|
|
|
|
return { courseId: params.id };
|
2021-07-12 05:55:57 +03:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
<script lang="ts">
|
2021-08-18 19:47:02 +03:00
|
|
|
import { onMount } from 'svelte';
|
|
|
|
|
import CourseContainer from '../../../components/CourseContainer/index.svelte';
|
2021-08-29 07:23:19 +03:00
|
|
|
import Delete24 from 'carbon-icons-svelte/lib/Delete24';
|
2021-08-18 19:47:02 +03:00
|
|
|
import PageNav from '../../../components/PageNav/index.svelte';
|
2021-08-24 10:45:43 +03:00
|
|
|
import PrimaryButton from '../../../components/PrimaryButton/index.svelte';
|
2021-08-29 07:23:19 +03:00
|
|
|
import IconButton from '../../../components/IconButton/index.svelte';
|
2021-08-24 10:45:43 +03:00
|
|
|
import PageBody from '../../../components/PageBody/index.svelte';
|
2021-08-29 07:23:19 +03:00
|
|
|
import {
|
|
|
|
|
setCourseData,
|
|
|
|
|
course,
|
|
|
|
|
group,
|
|
|
|
|
} from '../../../components/Course/store';
|
2021-08-24 10:45:43 +03:00
|
|
|
import InviationModal from '../../../components/Course/components/People/InviationModal.svelte';
|
2021-08-29 07:23:19 +03:00
|
|
|
import DeleteConfirmation from '../../../components/Course/components/People/DeleteConfirmation.svelte';
|
|
|
|
|
import {
|
|
|
|
|
invitationModal,
|
|
|
|
|
deleteMemberModal,
|
|
|
|
|
} from '../../../components/Course/components/People/store';
|
2021-08-24 10:45:43 +03:00
|
|
|
import type { Person } from '../../../components/Course/components/People/types';
|
2021-08-29 07:23:19 +03:00
|
|
|
import { ROLE, ROLE_LABEL } from '../../../utils/constants/roles';
|
|
|
|
|
import { profile } from '../../../utils/store/user';
|
2021-07-13 16:27:02 +00:00
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
export let courseId: string = '';
|
2021-07-12 05:55:57 +03:00
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
let people: Array<Person> = [];
|
|
|
|
|
let borderBottomGrey = 'border-r-0 border-b border-l-0 border-gray-300';
|
2021-08-29 07:23:19 +03:00
|
|
|
let member: { id?: string; email?: string; profile?: { email: string } } = {};
|
2021-07-12 05:55:57 +03:00
|
|
|
|
2021-08-29 07:23:19 +03:00
|
|
|
// function setPeople(people: Array<Person>) {
|
|
|
|
|
// if (!Array.isArray(people)) return;
|
|
|
|
|
|
|
|
|
|
// people = (people || []).sort((a, b) => a.role_id - b.role_id);
|
|
|
|
|
// console.log(`people changed`, people);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
async function deletePerson() {
|
|
|
|
|
console.log(`member`, member);
|
|
|
|
|
console.log(`$group.people`, $group.people);
|
|
|
|
|
$group.people = $group.people.filter(
|
|
|
|
|
(person: { id: string }) => person.id !== member.id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await deleteGroupMember(member.id);
|
2021-08-24 10:45:43 +03:00
|
|
|
}
|
2021-08-18 19:47:02 +03:00
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
onMount(async () => {
|
|
|
|
|
if ($course.id) return;
|
|
|
|
|
const { data } = await fetchCourse(courseId);
|
|
|
|
|
setCourseData(data);
|
2021-08-18 19:47:02 +03:00
|
|
|
});
|
2021-08-24 10:45:43 +03:00
|
|
|
|
2021-08-29 07:23:19 +03:00
|
|
|
$: people = ($group.people || []).sort((a, b) => a.role_id - b.role_id);
|
2021-07-12 05:55:57 +03:00
|
|
|
</script>
|
|
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
<InviationModal />
|
2021-08-29 07:23:19 +03:00
|
|
|
<DeleteConfirmation
|
|
|
|
|
email={member.email || (member.profile && member.profile.email)}
|
|
|
|
|
{deletePerson}
|
|
|
|
|
/>
|
2021-07-12 05:55:57 +03:00
|
|
|
|
2021-08-24 10:45:43 +03:00
|
|
|
<CourseContainer>
|
|
|
|
|
<PageNav title="People" disableSticky={true}>
|
|
|
|
|
<slot:fragment slot="widget">
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
className="mr-2"
|
|
|
|
|
label="Add"
|
|
|
|
|
onClick={() => ($invitationModal.open = true)}
|
|
|
|
|
/>
|
|
|
|
|
</slot:fragment>
|
|
|
|
|
</PageNav>
|
|
|
|
|
<PageBody className="">
|
|
|
|
|
<div class="table rounded-md border border-gray-300 w-11/12 m-auto">
|
|
|
|
|
<div
|
|
|
|
|
class="flex items-center justify-evenly font-bold border-t-0 {borderBottomGrey} p-3"
|
|
|
|
|
>
|
|
|
|
|
<span class="mr-2">No</span>
|
|
|
|
|
<!-- <span class="flex-grow" /> -->
|
2021-08-29 07:23:19 +03:00
|
|
|
<p class="text-lg text-center w-1/4">Name</p>
|
|
|
|
|
<p class="text-lg text-center w-1/4">Email</p>
|
|
|
|
|
<p class="text-lg text-center w-1/4 ">Role</p>
|
|
|
|
|
<p class="text-lg w-20 text-center" />
|
2021-08-24 10:45:43 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#each people as person, index}
|
|
|
|
|
<div
|
2021-08-29 07:23:19 +03:00
|
|
|
class="flex text-center relative items-center justify-evenly p-3 cursor-pointer {borderBottomGrey} hover:bg-gray-100"
|
2021-08-24 10:45:43 +03:00
|
|
|
>
|
|
|
|
|
<span class="mr-2">{index + 1}</span>
|
|
|
|
|
<!-- <span class="flex-grow" /> -->
|
|
|
|
|
{#if person.profile}
|
|
|
|
|
<p class="text-lg w-1/4 break-all">{person.profile.fullname}</p>
|
2021-08-26 09:34:18 +03:00
|
|
|
<a
|
|
|
|
|
href="mailto:{person.profile.email}"
|
|
|
|
|
class="text-md w-1/4 mx-2 text-blue-600"
|
|
|
|
|
>
|
|
|
|
|
{person.profile.email}
|
|
|
|
|
</a>
|
2021-08-24 10:45:43 +03:00
|
|
|
{:else}
|
|
|
|
|
<p
|
|
|
|
|
class="bg-yellow-500 w-1/4 text-sm text-center rounded-xl text-white"
|
|
|
|
|
>
|
2021-08-24 18:20:07 +03:00
|
|
|
Pending Invite
|
2021-08-24 10:45:43 +03:00
|
|
|
</p>
|
2021-08-26 09:34:18 +03:00
|
|
|
<a
|
|
|
|
|
href="mailto:{person.email}"
|
|
|
|
|
class="text-md w-1/4 mx-2 text-blue-600"
|
|
|
|
|
>
|
|
|
|
|
{person.email}
|
|
|
|
|
</a>
|
2021-08-24 10:45:43 +03:00
|
|
|
{/if}
|
|
|
|
|
<p class="text-lg w-1/4 ">{ROLE_LABEL[person.role_id]}</p>
|
2021-08-29 07:23:19 +03:00
|
|
|
|
|
|
|
|
<div class="w-20">
|
|
|
|
|
{#if person.profile && person.profile.id !== $profile.id}
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
member = person;
|
|
|
|
|
$deleteMemberModal.open = true;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Delete24 class="carbon-icon" />
|
|
|
|
|
</IconButton>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2021-08-24 10:45:43 +03:00
|
|
|
</div>
|
2021-07-12 05:55:57 +03:00
|
|
|
{/each}
|
|
|
|
|
</div>
|
2021-08-24 10:45:43 +03:00
|
|
|
</PageBody>
|
2021-07-12 05:55:57 +03:00
|
|
|
</CourseContainer>
|