Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: logic to show logged in user on top in find page (#60) #63

Merged
merged 7 commits into from
Dec 21, 2023
10 changes: 9 additions & 1 deletion src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ const actions: ActionTree<UserState, RootState> = {
filters['lastName_grp'] = '3'
}

// By default we are showing logged in user on top manually,
// hence not fetching it in default list.
if(!state.query.queryString) {
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
filters['partyId_value'] = payload.currentUserPartyId,
filters['partyId_op'] = 'notEqual'
}

const params = {
"inputFields": {
"roleTypeIdTo": "APPLICATION_USER",
Expand All @@ -312,7 +319,8 @@ const actions: ActionTree<UserState, RootState> = {
"noConditionFind": "Y",
"distinct": "Y",
"fieldList": ['createdDate', 'firstName', 'lastName', "groupName", 'partyId', 'securityGroupId', 'securityGroupName', 'userLoginId'],
...payload
"viewIndex": payload.viewIndex,
"viewSize": payload.viewSize
}

let users = [], total = 0;
Expand Down
71 changes: 69 additions & 2 deletions src/views/FindUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@
</aside>

<main v-if="users?.length">
<div class="list-item" v-if="currentUser.partyId" @click=viewUserDetails(currentUser.partyId)>
<ion-item lines="none">
<ion-label>
{{ currentUser.groupName ? currentUser.groupName : `${currentUser.firstName} ${currentUser.lastName}` }}
<p>{{ currentUser.userLoginId }}</p>
<p>{{ currentUser.infoString }}</p>
</ion-label>
</ion-item>

<div class="tablet">
<ion-label class="ion-text-center" v-if="currentUser.createdDate">
{{ getDate(currentUser.createdDate) }}
<p>{{ translate("created") }}</p>
</ion-label>
<ion-label v-else>
{{ '-' }}
</ion-label>
</div>

<div class="tablet">
<ion-chip outline v-if="currentUser.securityGroupId">
<ion-label>{{ currentUser.securityGroupName }}</ion-label>
</ion-chip>
<ion-label v-else>
{{ '-' }}
</ion-label>
</div>
</div>
<div class="list-item" v-for="(user, index) in users" :key="index" @click=viewUserDetails(user.partyId)>
<ion-item lines="none">
<ion-label>
Expand Down Expand Up @@ -139,6 +167,8 @@ import { DateTime } from 'luxon';
import UserPopover from '@/components/UserPopover.vue';
import { translate } from '@hotwax/dxp-components'
import FilterMenu from '@/components/FilterMenu.vue';
import { UserService } from '@/services/UserService';
import { hasError } from '@/adapter';
import { Actions, hasPermission } from '@/authorization'

export default defineComponent({
Expand Down Expand Up @@ -170,9 +200,15 @@ export default defineComponent({
users: 'user/getUsers',
securityGroups: 'util/getSecurityGroups',
query: 'user/getQuery',
isScrollable: "user/isScrollable"
isScrollable: "user/isScrollable",
userProfile: 'user/getUserProfile'
})
},
data() {
return {
currentUser: {}
}
},
async mounted() {
await this.fetchUsers();
await this.store.dispatch('util/getSecurityGroups')
Expand All @@ -195,11 +231,15 @@ export default defineComponent({
this.fetchUsers();
},
async fetchUsers(vSize?: any, vIndex?: any) {
if(!this.query.queryString) await this.fetchLoggedInUserDetails()
else this.currentUser = {}

const viewSize = vSize ? vSize : process.env.VUE_APP_VIEW_SIZE;
const viewIndex = vIndex ? vIndex : 0;
const payload = {
viewSize,
viewIndex
viewIndex,
currentUserPartyId: this.userProfile.partyId
};
await this.store.dispatch('user/fetchUsers', payload)
},
Expand All @@ -216,6 +256,33 @@ export default defineComponent({
event.target.complete();
});
},
async fetchLoggedInUserDetails() {
const params = {
inputFields: {
roleTypeIdTo: 'APPLICATION_USER',
partyId: this.userProfile.partyId
},
fromDateName: 'relationshipFromDate',
thruDateName: 'relationshipThruDate',
filterByDate: 'Y',
entityName: 'PartyAndUserLoginSecurityGroupDetails',
noConditionFind: 'Y',
distinct: 'Y',
fieldList: ['createdDate', 'firstName', 'lastName', "groupName", 'partyId', 'securityGroupId', 'securityGroupName', 'userLoginId'],
}

try {
const resp = await UserService.fetchUsers(params)

if (!hasError(resp) && resp.data.count) {
this.currentUser = resp.data.docs[0]
} else {
throw resp.data
}
} catch (error) {
console.error(error)
}
}
},
setup() {
const router = useRouter();
Expand Down
Loading