feat: Trigger add modal in People page via url (#223)
* feat add * code refactor * Update +page.svelte --------- Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
co-authored by
Rotimi Best
parent
ef38d00ea5
commit
82eee93417
+18
-9
@@ -1,15 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import copy from 'copy-to-clipboard';
|
||||||
import { Popover } from 'carbon-components-svelte';
|
import { Popover } from 'carbon-components-svelte';
|
||||||
import Link from 'carbon-icons-svelte/lib/Link.svelte';
|
import Link from 'carbon-icons-svelte/lib/Link.svelte';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
import Modal from '$lib/components/Modal/index.svelte';
|
import Modal from '$lib/components/Modal/index.svelte';
|
||||||
import copy from 'copy-to-clipboard';
|
|
||||||
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
|
||||||
import { ROLE } from '$lib/utils/constants/roles';
|
import { ROLE } from '$lib/utils/constants/roles';
|
||||||
import { addGroupMember, fetchGroup } from '$lib/utils/services/courses';
|
import { addGroupMember, fetchGroup } from '$lib/utils/services/courses';
|
||||||
import { invitationModal, resetForm } from './store';
|
|
||||||
import { course, setCourse } from '$lib/components/Course/store';
|
import { course, setCourse } from '$lib/components/Course/store';
|
||||||
import { MultiSelect, Loading } from 'carbon-components-svelte';
|
import { MultiSelect, Loading } from 'carbon-components-svelte';
|
||||||
import { currentOrg, currentOrgDomain } from '$lib/utils/store/org';
|
import { currentOrg, currentOrgDomain, currentOrgPath } from '$lib/utils/store/org';
|
||||||
import { getOrgTeam } from '$lib/utils/services/org';
|
import { getOrgTeam } from '$lib/utils/services/org';
|
||||||
import type { OrgTeamMember } from '$lib/utils/types/org';
|
import type { OrgTeamMember } from '$lib/utils/types/org';
|
||||||
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
|
||||||
@@ -26,6 +27,8 @@
|
|||||||
email: string;
|
email: string;
|
||||||
profileId?: string;
|
profileId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let addPeopleParm;
|
||||||
let tutors: Tutor[] = [];
|
let tutors: Tutor[] = [];
|
||||||
let selectedIds: Array<number> = [];
|
let selectedIds: Array<number> = [];
|
||||||
let selectedTutors: Tutor[] = [];
|
let selectedTutors: Tutor[] = [];
|
||||||
@@ -40,7 +43,7 @@
|
|||||||
|
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
if (!selectedTutors.length) {
|
if (!selectedTutors.length) {
|
||||||
resetForm();
|
goto($page.url.pathname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +79,7 @@
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
resetForm();
|
goto($page.url.pathname);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +99,7 @@
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setTutors(orgId: string | undefined, _open: boolean) {
|
async function setTutors(orgId: string | undefined) {
|
||||||
if (!orgId) return;
|
if (!orgId) return;
|
||||||
|
|
||||||
isLoadingTutors = true;
|
isLoadingTutors = true;
|
||||||
@@ -127,17 +130,23 @@
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeModal() {
|
||||||
|
goto($page.url.pathname);
|
||||||
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
selectedTutors = formatSelected(selectedIds);
|
selectedTutors = formatSelected(selectedIds);
|
||||||
console.log('selectedTutors', selectedTutors);
|
console.log('selectedTutors', selectedTutors);
|
||||||
|
const query = new URLSearchParams($page.url.search);
|
||||||
|
addPeopleParm = query.get('add');
|
||||||
}
|
}
|
||||||
|
|
||||||
$: setTutors($currentOrg.id, $invitationModal.open);
|
$: setTutors($currentOrg.id);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
onClose={resetForm}
|
onClose={() => closeModal()}
|
||||||
bind:open={$invitationModal.open}
|
open={addPeopleParm === 'true'}
|
||||||
width="w-4/5 md:w-2/5"
|
width="w-4/5 md:w-2/5"
|
||||||
maxWidth="max-w-lg"
|
maxWidth="max-w-lg"
|
||||||
modalHeading="Invite people"
|
modalHeading="Invite people"
|
||||||
@@ -3,12 +3,3 @@ import { writable } from 'svelte/store';
|
|||||||
export const deleteMemberModal = writable({
|
export const deleteMemberModal = writable({
|
||||||
open: false
|
open: false
|
||||||
});
|
});
|
||||||
|
|
||||||
export const invitationModal = writable({
|
|
||||||
open: false
|
|
||||||
});
|
|
||||||
|
|
||||||
export const resetForm = () =>
|
|
||||||
invitationModal.update(() => ({
|
|
||||||
open: false
|
|
||||||
}));
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import TextChip from '$lib/components/Chip/Text.svelte';
|
|
||||||
import ComingSoon from '$lib/components/ComingSoon/index.svelte';
|
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
import {
|
import {
|
||||||
CopyButton,
|
CopyButton,
|
||||||
@@ -11,6 +9,8 @@
|
|||||||
StructuredListHead,
|
StructuredListHead,
|
||||||
StructuredListRow
|
StructuredListRow
|
||||||
} from 'carbon-components-svelte';
|
} from 'carbon-components-svelte';
|
||||||
|
import TextChip from '$lib/components/Chip/Text.svelte';
|
||||||
|
import ComingSoon from '$lib/components/ComingSoon/index.svelte';
|
||||||
import CourseContainer from '$lib/components/CourseContainer/index.svelte';
|
import CourseContainer from '$lib/components/CourseContainer/index.svelte';
|
||||||
import { deleteGroupMember, updatedGroupMember } from '$lib/utils/services/courses';
|
import { deleteGroupMember, updatedGroupMember } from '$lib/utils/services/courses';
|
||||||
import TrashCanIcon from 'carbon-icons-svelte/lib/TrashCan.svelte';
|
import TrashCanIcon from 'carbon-icons-svelte/lib/TrashCan.svelte';
|
||||||
@@ -21,18 +21,17 @@
|
|||||||
import IconButton from '$lib/components/IconButton/index.svelte';
|
import IconButton from '$lib/components/IconButton/index.svelte';
|
||||||
import RoleBasedSecurity from '$lib/components/RoleBasedSecurity/index.svelte';
|
import RoleBasedSecurity from '$lib/components/RoleBasedSecurity/index.svelte';
|
||||||
import { group } from '$lib/components/Course/store';
|
import { group } from '$lib/components/Course/store';
|
||||||
import InviationModal from '$lib/components/Course/components/People/InviationModal.svelte';
|
import InvitationModal from '$lib/components/Course/components/People/InvitationModal.svelte';
|
||||||
import DeleteConfirmation from '$lib/components/Course/components/People/DeleteConfirmation.svelte';
|
import DeleteConfirmation from '$lib/components/Course/components/People/DeleteConfirmation.svelte';
|
||||||
import {
|
import { deleteMemberModal } from '$lib/components/Course/components/People/store';
|
||||||
invitationModal,
|
|
||||||
deleteMemberModal
|
|
||||||
} from '$lib/components/Course/components/People/store';
|
|
||||||
import type { Person, ProfileRole } from '$lib/components/Course/components/People/types';
|
import type { Person, ProfileRole } from '$lib/components/Course/components/People/types';
|
||||||
import { ROLE_LABEL, ROLES } from '$lib/utils/constants/roles';
|
import { ROLE_LABEL, ROLES } from '$lib/utils/constants/roles';
|
||||||
import { profile } from '$lib/utils/store/user';
|
import { profile } from '$lib/utils/store/user';
|
||||||
import { snackbar } from '$lib/components/Snackbar/store';
|
import { snackbar } from '$lib/components/Snackbar/store';
|
||||||
import Avatar from '$lib/components/Avatar/index.svelte';
|
import Avatar from '$lib/components/Avatar/index.svelte';
|
||||||
import type { GroupPerson } from '$lib/utils/types';
|
import type { GroupPerson } from '$lib/utils/types';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
@@ -110,10 +109,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleClick = () => {
|
||||||
|
const url = $page.url.href + '?add=true';
|
||||||
|
goto(url);
|
||||||
|
};
|
||||||
|
|
||||||
$: sortAndFilterPeople($group.people, filterBy);
|
$: sortAndFilterPeople($group.people, filterBy);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<InviationModal />
|
<InvitationModal />
|
||||||
|
|
||||||
<DeleteConfirmation
|
<DeleteConfirmation
|
||||||
email={member.email || (member.profile && member.profile.email)}
|
email={member.email || (member.profile && member.profile.email)}
|
||||||
@@ -124,11 +128,7 @@
|
|||||||
<PageNav title="People" disableSticky={true}>
|
<PageNav title="People" disableSticky={true}>
|
||||||
<slot:fragment slot="widget">
|
<slot:fragment slot="widget">
|
||||||
<RoleBasedSecurity allowedRoles={[1, 2]}>
|
<RoleBasedSecurity allowedRoles={[1, 2]}>
|
||||||
<PrimaryButton
|
<PrimaryButton className="mr-2" label="Add" onClick={handleClick} />
|
||||||
className="mr-2"
|
|
||||||
label="Add"
|
|
||||||
onClick={() => ($invitationModal.open = true)}
|
|
||||||
/>
|
|
||||||
</RoleBasedSecurity>
|
</RoleBasedSecurity>
|
||||||
</slot:fragment>
|
</slot:fragment>
|
||||||
</PageNav>
|
</PageNav>
|
||||||
|
|||||||
Reference in New Issue
Block a user