Skip to content

Commit

Permalink
Merge pull request #66 from REAN-Foundation/issue-fixes-01
Browse files Browse the repository at this point in the history
Fixed on delete refresh page issue.
  • Loading branch information
dattatraya-inflection authored Sep 30, 2024
2 parents eaac15a + 2a1164c commit 1c823ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
20 changes: 19 additions & 1 deletion src/routes/users/[userId]/person-role-types/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,35 @@ import { searchPersonRoleTypes } from '../../../api/services/reancare/person-rol
////////////////////////////////////////////////////////////////////////////

export const load: PageServerLoad = async (event: ServerLoadEvent) => {
console.log('Person role types load ...');
const sessionId = event.cookies.get('sessionId');
event.depends('app:person-role-types');

const response = await searchPersonRoleTypes(sessionId);
if (response.Status === 'failure' || response.HttpCode !== 200) {
throw error(response.HttpCode, response.Message);
}
const personRoleTypes = response.Data.PersonRoleTypes;
let personRoleTypes = response.Data.PersonRoleTypes;
personRoleTypes = setActiveRoles(personRoleTypes ?? []);
return {
personRoleTypes,
sessionId,
message: response.Message
};
};

function setActiveRoles(personRoleTypes) {
personRoleTypes.forEach((personRoleType) => {
if (personRoleType.RoleName === 'System admin' ||
personRoleType.RoleName === 'System user' ||
personRoleType.RoleName === 'Tenant admin' ||
personRoleType.RoleName === 'Tenant user' ||
personRoleType.RoleName === 'Patient' ||
personRoleType.RoleName === 'Doctor') {
personRoleType.isActive = true;
} else {
personRoleType.isActive = false;
}
});
return personRoleTypes;
}
44 changes: 13 additions & 31 deletions src/routes/users/[userId]/person-role-types/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,30 @@
} from '@skeletonlabs/skeleton';
import date from 'date-and-time';
import type { PageServerData } from './$types';
import { invalidate } from '$app/navigation';
import { SYSTEM_ID } from '../../../../../src/lib/constants';
import { onMount } from 'svelte';
import { invalidate } from '$app/navigation';
import { SYSTEM_ID } from '../../../../../src/lib/constants';
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
export let data: PageServerData;
const activeRoles = ['System admin', 'System user', 'Tenant admin', 'Tenant user', 'Paitent','Doctor'];
let personTypes = data.personRoleTypes;
// $: console.log('PersonRoleTypes', personTypes);
$: personTypes = data.personRoleTypes;
let retrivedTypes;
$:retrivedTypes
$: console.log('retrivedTypes', retrivedTypes);
let roleName = "Role Name";
let sortOrder = false;
const userId = $page.params.userId;
const userId = $page.params.userId;
const createRoute = `/users/${userId}/person-role-types/create`;
const editRoute = (id) => `/users/${userId}/person-role-types/${id}/edit`;
const viewRoute = (id) => `/users/${userId}/person-role-types/${id}/view`;
const personRoleTypesRoute = `/users/${userId}/person-role-types`;
const breadCrumbs = [{ name: 'User Roles', path: personRoleTypesRoute }];
function setActiveRoles() {
personTypes = personTypes.map(role => {
if (activeRoles.includes(role.RoleName)) {
return { ...role, isActive: true };
}
return { ...role, isActive: false };
});
}
onMount(() => {
setActiveRoles();
});
$:setActiveRoles()
let totalPersonRoleCount = data.personRoleTypes.length
let items = 10;
let itemsPerPage = 10;
sort(sortOrder)
$:{
// personTypes = data.personRoleTypes;
sort(sortOrder)
personTypes = personTypes.map((item, index) => ({ ...item, index: index + 1 }));
}
Expand All @@ -63,7 +41,8 @@
if (isOrdeApplied) {
roleName = `Role Name ${sortOrder ? '' : ''}`
}
personTypes = personTypes.sort((a, b) => {
if (personTypes) {
personTypes = personTypes.sort((a, b) => {
let fa = a.RoleName.toLowerCase(),
fb = b.RoleName.toLowerCase();
if (fa < fb) {
Expand All @@ -74,7 +53,9 @@
}
return 0;
});
}
}
}
let paginationSettings = {
page: 0,
Expand Down Expand Up @@ -103,12 +84,12 @@
};
async function Delete(model) {
await fetch(`/api/server/person-role-types`, {
await fetch(`/api/server/person-role-types`, {
method: 'DELETE',
body: JSON.stringify(model),
headers: { 'content-type': 'application/json' }
});
}
}
function onPageChange(e: CustomEvent): void {
let pageIndex = e.detail;
Expand Down Expand Up @@ -202,3 +183,4 @@
/>
</div>
</div>

0 comments on commit 1c823ea

Please sign in to comment.