{!this.state.cB &&
!this.state.ChampionsList &&
- !this.state.addMember && !this.state.approveMember &&
+ !this.state.addMember && !this.state.manageApprovals &&
!this.state.dB && !this.state.enableTOT && (
@@ -1143,6 +1289,29 @@ export default class ClbHome extends React.Component<
{this.state.clB && !this.state.cV && (
+
+
+ this.setState({
+ manageApprovals: !this.state.manageApprovals,
+ })
+ }
+ >
+
+
+
+ {LocaleStrings.AdminTasksLabel}
+
+
+
+
@@ -1199,28 +1368,6 @@ export default class ClbHome extends React.Component<
-
-
-
- this.setState({
- approveMember: !this.state.approveMember,
- })
- }
- >
-
-
-
- {LocaleStrings.ManageApprovalsLabel}
-
-
-
-
{!this.state.isTOTEnabled && (
-
-
- )}
- {this.state.clB && !this.state.cV && (
-
-
)}
@@ -1324,36 +1465,19 @@ export default class ClbHome extends React.Component<
siteUrl={this.props.siteUrl}
context={this.props.context}
isAdmin={this.state.clB && !this.state.cV}
- onClickCancel={() =>
- this.setState({ addMember: false, ChampionsList: true, isUserAdded: false })
- }
- onClickSave={(userStatus: string) =>
- this.setState({ addMember: false, ChampionsList: true, isUserAdded: true, userStatus: userStatus })
- }
onClickBack={() => { this.setState({ addMember: false }); }}
+ onHomeCallBack={this.callBackFunction}
/>
)
}
{
- this.state.approveMember && (
-
- )
- }
- {
- this.state.ChampionsList && (
-
)
}
diff --git a/src/webparts/clbHome/components/DigitalBadge.tsx b/src/webparts/clbHome/components/DigitalBadge.tsx
index 6ab35b01..c80d41ff 100644
--- a/src/webparts/clbHome/components/DigitalBadge.tsx
+++ b/src/webparts/clbHome/components/DigitalBadge.tsx
@@ -1,7 +1,7 @@
import { Icon } from '@fluentui/react/lib/Icon';
import { List } from '@fluentui/react/lib/List';
import { IRectangle } from '@fluentui/react/lib/Utilities';
-import { MSGraphClient, SPHttpClient, SPHttpClientResponse } from "@microsoft/sp-http";
+import { MSGraphClientV3, SPHttpClient, SPHttpClientResponse } from "@microsoft/sp-http";
import { WebPartContext } from "@microsoft/sp-webpart-base";
import * as microsoftTeams from "@microsoft/teams-js";
import { initializeIcons } from "@uifabric/icons";
@@ -162,44 +162,36 @@ export default class DigitalBadge extends TeamsBaseComponent<
}}
>
-
@@ -238,12 +230,46 @@ export default class DigitalBadge extends TeamsBaseComponent<
private async getAllBadgeImages() {
try {
this.setState({ isLoading: true });
+
let commonServiceManager: commonServices = new commonServices(this.props.context, this.props.siteUrl);
+ //Get member's total points from Event track details list
+ const totalPointsScored = await commonServiceManager.getTotalPointsForMember(upn);
+
+ //Get all badges from the library
const resultImages: any[] = await commonServiceManager.getAllBadgeImages(strings.DigitalBadgeLibrary, this.props.context.pageContext.user.email.toLowerCase());
+ let finalImagesArray: any[] = [];
+
if (resultImages.length == 0)
this.setState({ noBadgesFlag: true, isLoading: false });
- else
- this.setState({ allBadgeImages: resultImages, isLoading: false });
+ else {
+ for (const element of resultImages) {
+ if (element.minimumPoints === null ||
+ element.minimumPoints === undefined ||
+ totalPointsScored >= element.minimumPoints) {
+ finalImagesArray.push({
+ title: element.title,
+ url: element.url,
+ enabled: true,
+ points: element.minimumPoints
+ });
+ }
+ else {
+ finalImagesArray.push({
+ title: element.title,
+ url: element.url,
+ enabled: false,
+ points: element.minimumPoints
+ });
+ }
+ }
+ //Sorting the badges with enabled first followed by locked badges.
+ finalImagesArray.sort((a, b) => {
+ if (a.enabled < b.enabled) return 1;
+ if (a.enabled > b.enabled) return -1;
+ });
+
+ this.setState({ allBadgeImages: finalImagesArray, isLoading: false });
+ }
}
catch (error) {
console.error("CMP_DigitalBadge_getAllBadgeImages \n", JSON.stringify(error));
@@ -773,7 +799,7 @@ export default class DigitalBadge extends TeamsBaseComponent<
const contextDownload = canvasDownload.getContext("2d");
const profileImageObj: HTMLImageElement = new Image();
const badgeImageObj: HTMLImageElement = new Image();
- profileImageObj.src = profileImage.url;
+ profileImageObj.src = profileImage.url;
badgeImageObj.src = this.state.imageURL;
profileImageObj.onload = () => {
context.drawImage(
@@ -816,11 +842,13 @@ export default class DigitalBadge extends TeamsBaseComponent<
const profileImageObj: HTMLImageElement = new Image();
const badgeImageObj: HTMLImageElement = new Image();
profileImage.width = 100;
- profileImage.url = "../assets/images/noimage.png";
+ profileImage.url = "../assets/images/noimage.png";
this.setState({
profileImage: profileImage,
});
profileImageObj.src = require("../assets/images/noimage.png");
+ //To avoid CORS issue in CDN enabled tenants
+ profileImageObj.crossOrigin= "Anonymous";
badgeImageObj.src = this.state.imageURL;
profileImageObj.onload = () => {
context.font = "32px Arial";
@@ -854,9 +882,9 @@ export default class DigitalBadge extends TeamsBaseComponent<
this.getPhotoBits()
.then((res: any) => {
this.updateUserPhoto(res)
- .then((response: { status: number }) => {
+ .then((response) => {
console.log(response);
- if (response.status === 200) {
+ if (response) {
this.setState({
isApplying: false,
isApplied: true,
@@ -932,15 +960,15 @@ export default class DigitalBadge extends TeamsBaseComponent<
blob.lastModifiedDate = new Date();
blob.name = "profile.jpeg";
this.props.context.msGraphClientFactory
- .getClient()
- .then((client: MSGraphClient) => {
+ .getClient('3')
+ .then((client: MSGraphClientV3) => {
client
.api("me/photo/$value")
.version("v1.0")
.header("Content-Type", "image/jpeg")
.put(blob, (errDb, _res, rawresponse) => {
if (!errDb) {
- resolve(rawresponse);
+ resolve(_res);
}
});
});
@@ -962,13 +990,12 @@ export default class DigitalBadge extends TeamsBaseComponent<
let photoPromise: Promise
= new Promise(
(resolve: (arg0: Response) => void, reject: any) => {
this.props.context.msGraphClientFactory
- .getClient()
- .then((garphClient: MSGraphClient) => {
- garphClient
+ .getClient('3')
+ .then((graphClient: MSGraphClientV3) => {
+ graphClient
.api(graphMyPhotoBitsUrl)
.version("v1.0")
.headers({ "Content-Type": "blob", responseType: "blob" })
- .responseType("blob")
.get()
.then((data) => {
resolve(data);
@@ -986,13 +1013,12 @@ export default class DigitalBadge extends TeamsBaseComponent<
let photoPromise: Promise = new Promise(
(resolve: (arg0: Response) => void, _reject: any) => {
this.props.context.msGraphClientFactory
- .getClient()
- .then((garphClient: MSGraphClient) => {
- garphClient
+ .getClient('3')
+ .then((graphClient: MSGraphClientV3) => {
+ graphClient
.api(graphMyPhotoApiUrl)
.version("v1.0")
.headers({ "Content-Type": "blob", responseType: "blob" })
- .responseType("json")
.get()
.then((data) => {
resolve(data);
diff --git a/src/webparts/clbHome/components/Header.tsx b/src/webparts/clbHome/components/Header.tsx
index a391990f..97351927 100644
--- a/src/webparts/clbHome/components/Header.tsx
+++ b/src/webparts/clbHome/components/Header.tsx
@@ -1,4 +1,4 @@
-import { DirectionalHint, TooltipHost } from '@fluentui/react/lib/Tooltip';
+import { DirectionalHint, TooltipHost } from '@fluentui/react';
import "bootstrap/dist/css/bootstrap.min.css";
import * as LocaleStrings from 'ClbHomeWebPartStrings';
import { Callout, Link, Text } from 'office-ui-fabric-react';
diff --git a/src/webparts/clbHome/components/ManageApprovals.tsx b/src/webparts/clbHome/components/ManageApprovals.tsx
new file mode 100644
index 00000000..1523057e
--- /dev/null
+++ b/src/webparts/clbHome/components/ManageApprovals.tsx
@@ -0,0 +1,135 @@
+import { IPivotItemProps, Pivot, PivotItem, PivotLinkFormat } from '@fluentui/react';
+import { WebPartContext } from "@microsoft/sp-webpart-base";
+import * as LocaleStrings from 'ClbHomeWebPartStrings';
+import React, { Component } from 'react';
+import commonServices from '../Common/CommonServices';
+import styles from "../scss/ManageApprovals.module.scss";
+import ApproveChampion from './ApproveChampion';
+import ChampionsActivities from './ChampionsActivities';
+import ManageConfigSettings from './ManageConfigSettings';
+
+//declaring common services object
+let commonServiceManager: commonServices;
+export interface IManageApprovalsProps {
+ context: WebPartContext;
+ siteUrl: string;
+ onClickBack: Function;
+ isPendingChampionApproval: boolean;
+ isPendingEventApproval: boolean;
+}
+export interface IManageApprovalsState {
+ isPendingChampionApproval: boolean;
+ isPendingEventApproval: boolean;
+}
+export default class ManageApprovals extends Component {
+
+ constructor(props: IManageApprovalsProps) {
+ super(props);
+ this.state = {
+ isPendingChampionApproval: this.props.isPendingChampionApproval,
+ isPendingEventApproval: this.props.isPendingEventApproval,
+ };
+
+ this.setState = this.setState.bind(this);
+
+ //Create object for CommonServices class
+ commonServiceManager = new commonServices(
+ this.props.context,
+ this.props.siteUrl
+ );
+ }
+
+ _customRenderer(
+ link?: IPivotItemProps,
+ defaultRenderer?: (link?: IPivotItemProps) => JSX.Element | null,
+ ): JSX.Element | null {
+ if (!link || !defaultRenderer) {
+ return null;
+ }
+ return (
+
+ {link.headerText}
+
+ {defaultRenderer({ ...link, headerText: undefined })}
+
+ );
+ }
+
+ _customRendererNoIcon(
+ link?: IPivotItemProps,
+ defaultRenderer?: (link?: IPivotItemProps) => JSX.Element | null,
+ ): JSX.Element | null {
+ if (!link || !defaultRenderer) {
+ return null;
+ }
+ return (
+
+ {link.headerText}
+ {defaultRenderer({ ...link, headerText: undefined })}
+
+ );
+ }
+
+
+ public render() {
+ return (
+
+
+
+
{ this.props.onClickBack(); }}
+ title={LocaleStrings.CMPBreadcrumbLabel}
+ >
+ {LocaleStrings.CMPBreadcrumbLabel}
+
+
+
{LocaleStrings.AdminTasksLabel}
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+ }
+}
diff --git a/src/webparts/clbHome/components/ManageConfigSettings.tsx b/src/webparts/clbHome/components/ManageConfigSettings.tsx
new file mode 100644
index 00000000..6a3aab15
--- /dev/null
+++ b/src/webparts/clbHome/components/ManageConfigSettings.tsx
@@ -0,0 +1,298 @@
+import React from 'react';
+import { WebPartContext } from "@microsoft/sp-webpart-base";
+
+import commonServices from "../Common/CommonServices";
+import styles from "../scss/ManageApprovals.module.scss";
+import * as LocaleStrings from 'ClbHomeWebPartStrings';
+import * as stringsConstants from "../constants/strings";
+import siteConfigData from "../config/siteconfig.json";
+
+//Fluent UI Controls
+import { Toggle } from '@fluentui/react/lib/Toggle';
+import { PrimaryButton } from "@fluentui/react/lib/Button";
+import { TooltipHost } from '@fluentui/react/lib/Tooltip';
+import { Icon } from '@fluentui/react/lib/Icon';
+import { Label } from "@fluentui/react/lib/Label";
+import { Spinner, SpinnerSize } from '@fluentui/react/lib/Spinner';
+
+//global variables
+let commonServiceManager: commonServices;
+
+export interface IManageConfigSettingsProps {
+ context?: WebPartContext;
+ siteUrl: string;
+}
+
+export interface IConfigList {
+ Id: number;
+ ID: number;
+ Title: string;
+ Value: string;
+}
+export interface IManageConfigSettingsState {
+ showSuccess: boolean;
+ showError: boolean;
+ errorMessage: string;
+ configListSettings: Array;
+ updatedSettings: Array;
+ memberListColumns: Array;
+ showSpinner: boolean;
+}
+
+export default class ManageConfigSettings extends React.Component
+ {
+ constructor(props: IManageConfigSettingsProps) {
+ super(props);
+ this.state = {
+ showSuccess: false,
+ showError: false,
+ errorMessage: "",
+ configListSettings: [],
+ updatedSettings: [],
+ memberListColumns: [],
+ showSpinner: false
+ };
+
+ //Bind Methods
+ this.onToggleSetting = this.onToggleSetting.bind(this);
+ this.getConfigListSettings = this.getConfigListSettings.bind(this);
+ this.getMemberListColumnNames = this.getMemberListColumnNames.bind(this);
+ this.saveConfigSettings = this.saveConfigSettings.bind(this);
+
+ //Create object for CommonServices class
+ commonServiceManager = new commonServices(
+ this.props.context,
+ this.props.siteUrl
+ );
+ }
+
+ //Getting config settings from config list and column properties from member list
+ public async componentDidMount() {
+ await this.getConfigListSettings();
+ await this.getMemberListColumnNames();
+ }
+
+ //Get Config Settings from config list
+ private async getConfigListSettings() {
+ try {
+ const configListData: IConfigList[] = await commonServiceManager.getAllItemsWithSpecificColumns(
+ stringsConstants.ConfigList,
+ `${stringsConstants.TitleColumn},${stringsConstants.ValueColumn},${stringsConstants.IDColumn}`);
+ if (configListData.length === siteConfigData.configMasterData.length) {
+ this.setState({ configListSettings: configListData });
+ }
+ else {
+ this.setState({
+ showError: true,
+ errorMessage:
+ stringsConstants.CMPErrorMessage +
+ ` while loading the page. There could be a problem with the ${stringsConstants.ConfigList} data.`
+ });
+ }
+ }
+ catch (error) {
+ console.error("CMP_ManageConfigSettings_getConfigListSettings \n", error);
+ this.setState({
+ showError: true,
+ errorMessage:
+ stringsConstants.CMPErrorMessage +
+ `while retrieving the ${stringsConstants.ConfigList} settings. Below are the details: \n` +
+ JSON.stringify(error),
+ });
+ }
+ }
+
+ //Get Member list columns display names
+ private async getMemberListColumnNames() {
+ try {
+ const columnsFilter = "InternalName eq '" + stringsConstants.RegionColumn + "' or InternalName eq '"
+ + stringsConstants.CountryColumn + "' or InternalName eq '" + stringsConstants.GroupColumn + "'";
+ const columnsDisplayNames: any[] = await commonServiceManager.getColumnsDisplayNames(stringsConstants.MemberList, columnsFilter);
+ if (columnsDisplayNames.length > 0) {
+ this.setState({ memberListColumns: columnsDisplayNames });
+ }
+ }
+ catch (error) {
+ console.error("CMP_ManageConfigSettings_getMemberListColumnNames \n", error);
+ this.setState({
+ showError: true,
+ errorMessage:
+ stringsConstants.CMPErrorMessage +
+ ` while retrieving the ${stringsConstants.MemberList} column data. Below are the details: \n` +
+ JSON.stringify(error),
+ });
+ }
+ }
+
+ //On change of toggle set the states
+ private onToggleSetting(_ev: React.MouseEvent, checked: boolean, settingName: string) {
+ const settings: IConfigList[] = [];
+ this.state.configListSettings.forEach((setting: IConfigList) => {
+ if (setting.Title === settingName) {
+ const updatedSetting: IConfigList = setting;
+ updatedSetting.Value = checked ? stringsConstants.EnabledStatus : stringsConstants.DisabledStatus;
+
+ //Add/remove updated settings to/from updatedSettings state
+ if (this.state.updatedSettings.find((item: any) => item.id === updatedSetting.ID) !== undefined) {
+ const tempArray = this.state.updatedSettings.filter((item) => {
+ return item.id !== updatedSetting.ID;
+ });
+ this.setState({ updatedSettings: tempArray });
+ }
+ else {
+ const tempArray = this.state.updatedSettings;
+ const valueFilter = { Value: updatedSetting.Value };
+ const settingObj = { id: updatedSetting.ID, value: valueFilter };
+ tempArray.push(settingObj);
+ this.setState({ updatedSettings: tempArray });
+ }
+ settings.push(updatedSetting);
+ }
+ else {
+ settings.push(setting);
+ }
+ });
+ this.setState({
+ configListSettings: settings, //update config list settings state with updated settings
+ showSuccess: false,
+ showError: false
+ });
+ }
+
+ //Update the selected settings into the Config list on click of save
+ private async saveConfigSettings() {
+ if (this.state.updatedSettings.length > 0) {
+ this.setState({ showSpinner: true });
+ commonServiceManager
+ .updateMultipleItemsWithDifferentValues(
+ stringsConstants.ConfigList,
+ this.state.updatedSettings
+ ).then(() => {
+ this.setState({ showSuccess: true, updatedSettings: [], showSpinner: false });
+ }).catch((error) => {
+ console.error("CMP_ManageConfigSettings_saveConfigSettings \n", error);
+ this.setState({
+ showError: true,
+ errorMessage:
+ stringsConstants.CMPErrorMessage +
+ " while saving the selection. Below are the details: \n" +
+ JSON.stringify(error),
+ updatedSettings: [],
+ showSpinner: false
+ });
+ });
+ }
+ else {
+ this.setState({ showSuccess: true });
+ }
+ }
+
+ //Tooltip for info Icon
+ private iconWithTooltip(iconName: string, tooltipContent: string, className: string) {
+ return (
+
+
+
+
+
+ );
+ }
+
+ public render() {
+ return (
+
+
+ {this.state.showError && (
+
+ )}
+ {this.state.showSpinner &&
+
+ }
+ {this.state.configListSettings.length > 0 &&
+ <>
+ {this.state.showSuccess && (
+
+ )}
+
{
+ return setting.Title === stringsConstants.ChampionEventApprovals;
+ }).Value === stringsConstants.EnabledStatus}
+ label={
+
+ {LocaleStrings.EventApprovalsEnableLabel}
+ {this.iconWithTooltip(
+ "Info", //Icon library name
+ LocaleStrings.EventsApprovalInfoIconTooltipContent,
+ "configSettingsInfoIcon" //Class name
+ )}
+
+ }
+ inlineLabel
+ defaultChecked
+ onChange={(ev: React.MouseEvent, checked: boolean) =>
+ this.onToggleSetting(ev, checked, stringsConstants.ChampionEventApprovals)}
+ className={styles.configSettingsToggleBtn}
+ />
+
+ {this.state.memberListColumns.length > 0 &&
+ <>
+ {this.state.memberListColumns.map((column) => {
+ const setting: IConfigList = this.state.configListSettings.find((item: IConfigList) => {
+ return item.Title === column.InternalName;
+ });
+ return (
+
+ {column.Title}
+
+ }
+ inlineLabel
+ defaultChecked
+ onChange={(ev: React.MouseEvent
, checked: boolean) =>
+ this.onToggleSetting(ev, checked, column.InternalName)}
+ className={styles.configSettingsToggleBtn}
+ />
+ );
+ })}
+ >
+ }
+
+ >
+ }
+
+
+ );
+ }
+}
diff --git a/src/webparts/clbHome/components/Sidebar.tsx b/src/webparts/clbHome/components/Sidebar.tsx
index 36fe33f5..b9d75e64 100644
--- a/src/webparts/clbHome/components/Sidebar.tsx
+++ b/src/webparts/clbHome/components/Sidebar.tsx
@@ -17,9 +17,14 @@ import { Icon, initializeIcons } from "office-ui-fabric-react";
import siteconfig from "../config/siteconfig.json";
import * as LocaleStrings from 'ClbHomeWebPartStrings';
import * as stringsConstants from "../constants/strings";
+import { IConfigList } from './ManageConfigSettings';
+import commonServices from "../Common/CommonServices";
initializeIcons();
+
+//global variables
+let commonServiceManager: commonServices;
export interface ISidebarStateProps {
becomec: boolean;
context?: any;
@@ -51,36 +56,33 @@ export class ISPList {
interface IState {
currentUser: ISPList;
- list: ISPLists;
- isAddChampion: boolean;
- SuccessMessage: string;
UserDetails: Array
;
- selectedUsers: Array;
bc: boolean;
- siteUrl: string;
- user: any;
isLoaded: boolean;
form: boolean;
totalUserPointsfromList: number;
totalUsers: number;
userRank: number;
isActive: boolean;
- coutries: Array;
+ countries: Array;
regions: Array;
- users: Array;
roles: Array;
status: Array;
memberData: any;
selectedFocusAreas: any;
multiSelectChoices: any;
buttonText: any;
- bFlag: boolean;
isMember: boolean;
emailValue: string;
sitename: string;
inclusionpath: string;
edetails: Array;
edetailsIds: Array;
+ configListSettings: Array;
+ memberListColumnNames: Array;
+ regionColumnName: string;
+ countryColumnName: string;
+ groupColumnName: string;
}
export interface EventList {
Title: string;
@@ -97,37 +99,34 @@ export default class Sidebar extends React.Component
});
this.state = {
- user: {},
bc: this.props.becomec,
form: false,
- siteUrl: this.props.siteUrl,
isLoaded: false,
- list: null,
- isAddChampion: false,
- SuccessMessage: "",
UserDetails: [],
currentUser: new ISPList(),
- selectedUsers: [],
totalUserPointsfromList: 0,
isActive: false,
totalUsers: 0,
userRank: 0,
- coutries: [],
+ countries: [],
regions: [],
- users: [],
roles: [],
status: [],
memberData: { region: "", role: "", status: "", country: "" },
selectedFocusAreas: [],
multiSelectChoices: [],
buttonText: LocaleStrings.BecomeChampionLabel,
- bFlag: true,
isMember: false,
emailValue: "",
sitename: siteconfig.sitename, //getting from siteconfig
inclusionpath: siteconfig.inclusionPath, //getting from siteconfig
edetails: [],
edetailsIds: [],
+ configListSettings: [],
+ memberListColumnNames: [],
+ regionColumnName: "",
+ countryColumnName: "",
+ groupColumnName: ""
};
this.handleInput = this.handleInput.bind(this);
this._createorupdateItem = this._createorupdateItem.bind(this);
@@ -135,16 +134,25 @@ export default class Sidebar extends React.Component
this._getListData = this._getListData.bind(this);
this.optionsEventsList = this.optionsEventsList.bind(this);
this.onFocusAreaChange = this.onFocusAreaChange.bind(this);
+ this.populateColumnNames = this.populateColumnNames.bind(this);
+
+ //Create object for CommonServices class
+ commonServiceManager = new commonServices(
+ this.props.context,
+ this.props.siteUrl
+ );
}
//getting members details from membelist with all columns
public options = (optionArray: any) => {
let myoptions = [];
- myoptions.push({ key: "All", text: "All" });
- optionArray.forEach((element: any) => {
- myoptions.push({ key: element, text: element });
- });
+ if (optionArray !== undefined) {
+ myoptions.push({ key: "All", text: "All" });
+ optionArray.forEach((element: any) => {
+ myoptions.push({ key: element, text: element });
+ });
+ }
return myoptions;
}
@@ -224,11 +232,11 @@ export default class Sidebar extends React.Component
)
// tslint:disable-next-line:no-shadowed-variable
.then((response: SPHttpClientResponse) => {
- response.json().then((coutries) => {
- if (!coutries.error) {
+ response.json().then((countries) => {
+ if (!countries.error) {
this.setState({
regions: regions.Choices,
- coutries: coutries.Choices,
+ countries: countries.Choices,
});
}
});
@@ -274,7 +282,7 @@ export default class Sidebar extends React.Component
});
}
- public componentDidUpdate(prevProps: Readonly, prevState: Readonly, snapshot?: any): void {
+ public async componentDidUpdate(prevProps: Readonly, prevState: Readonly, snapshot?: any) {
if (prevProps != this.props) {
this.componentWillMount();
}
@@ -289,6 +297,27 @@ export default class Sidebar extends React.Component
if (idx != -1)
this.state.selectedFocusAreas.splice(idx, 1);
}
+
+ if (prevState.form !== this.state.form || prevState.isActive !== this.state.isActive) {
+ if (this.state.form && this.state.isActive) {
+ this.setState({
+ configListSettings: [],
+ memberListColumnNames: [],
+ regionColumnName: "",
+ countryColumnName: "",
+ groupColumnName: ""
+ });
+ await this.getConfigListSettings();
+ await this.getMemberListColumnNames();
+ }
+ }
+
+ //update column states with member list column display names
+ if (prevState.configListSettings !== this.state.configListSettings ||
+ prevState.memberListColumnNames !== this.state.memberListColumnNames) {
+ if (this.state.configListSettings.length > 0 && this.state.memberListColumnNames.length > 0)
+ this.populateColumnNames();
+ }
}
//Get current user's details from Member list and Event track details to display rank and points on side bar
@@ -334,16 +363,33 @@ export default class Sidebar extends React.Component
isLoaded: true,
});
localStorage.setItem("memberid", memberData); // storing memberid in local storage
+
+ //get first name and last name from the user profile properties
+ let firstName = "";
+ let lastName = "";
+ for (let i = 0; i < datauser.UserProfileProperties.length; i++) {
+ if (firstName === "" || lastName === "") {
+ if (datauser.UserProfileProperties[i].Key === "FirstName") {
+ firstName = datauser.UserProfileProperties[i].Value;
+ }
+ if (datauser.UserProfileProperties[i].Key === "LastName") {
+ lastName = datauser.UserProfileProperties[i].Value;
+ }
+ }
+ else {
+ break;
+ }
+ }
//based on user role (champion or manager) then we are showing champion details
let user = this.state.currentUser;
- user["FirstName"] = datauser.DisplayName.split(" ")[0].replace(",", "");
- user["LastName"] = datauser.DisplayName.split(" ")[1];
+ user["FirstName"] = firstName;
+ user["LastName"] = lastName;
user["Title"] = datauser.Email;
user["Country"] = datauser.Country;
user["Region"] = datauser.Region;
user["Group"] = datauser.Group;
user["FocusArea"] = datauser.FocusArea;
- displayName = datauser.DisplayName.replace(",", "");
+ displayName = firstName + " " + lastName;
this.setState({ currentUser: user });
if (!datada.error) {
@@ -368,7 +414,7 @@ export default class Sidebar extends React.Component
this.state.inclusionpath +
"/" +
this.state.sitename +
- "/_api/web/lists/GetByTitle('Event Track Details')/Items?$top=5000",
+ "/_api/web/lists/GetByTitle('Event Track Details')/Items?$filter= Status eq 'Approved' or Status eq null or Status eq ''&$top=5000",
SPHttpClient.configurations.v1
)
.then((responseeventsdetails: SPHttpClientResponse) => {
@@ -376,61 +422,11 @@ export default class Sidebar extends React.Component
.json()
.then((eventsdatauser) => {
if (!eventsdatauser.error) {
- let presentuser = eventsdatauser.value.filter(
- (x: { MemberId: any }) =>
- x.MemberId ===
- datada.value.find(
- (d: { Title: string }) =>
- d.Title.toLowerCase() ===
- datauser.Email.toLowerCase()
- ).ID
- );
let memberids: any = _.uniqBy(
eventsdatauser.value,
"MemberId"
);
- let counts = _.countBy(
- eventsdatauser.value,
- "MemberId"
- );
let memcount: Array = [];
- if (
- presentuser.length === 0 &&
- memberData !== 0
- ) {
- let eventItem: EventList = null;
- eventItem = this.state.edetailsIds[0];
- const listDefinition: any = {
- Title: eventItem.Title,
- EventId: eventItem.Id,
- MemberId: memberData,
- DateofEvent: new Date(),
- Count: 10,
- MemberName: datauser.DisplayName,
- EventName: eventItem.Title
- };
- const spHttpClientOptions: ISPHttpClientOptions = {
- body: JSON.stringify(listDefinition),
- };
- if (true) {
- const url: string =
- "/" +
- this.state.inclusionpath +
- "/" +
- this.state.sitename +
- "/_api/web/lists/GetByTitle('Event Track Details')/items";
- this.props.context.spHttpClient.post(
- url,
- SPHttpClient.configurations.v1,
- spHttpClientOptions
- );
- this.props.callBack();
- memcount.push({
- id: memberData,
- points: 10,
- });
- }
- }
for (let i = 0; i < memberids.length; i++) {
if (datada.value.findIndex((v: { ID: any }) => v.ID === memberids[i].MemberId) !== -1) {
let totalUserPoints = 0;
@@ -444,10 +440,37 @@ export default class Sidebar extends React.Component
}
}
+ //Assign zero points and get data of the approved members who hasn't participated in any event
+ let tempArray: any = [];
+ for (let i = 0; i < datada.value.length; i++) {
+ if (memcount.findIndex((member: { id: any }) => member.id === datada.value[i].ID) === -1 &&
+ datada.value[i].Status === stringsConstants.approvedStatus
+ ) {
+ tempArray.push({
+ id: datada.value[i].ID,
+ points: 0,
+ });
+ }
+ }
+ memcount = [...memcount, ...tempArray];
let pointsTotal = 0;
let rank: number;
+
+ //Sorting
+ //Intially sort approved champions in the descending order of points count
+ //if champion doesn't have any points sort them in ascending order of their ids
memcount
- .sort((x, y) => y.points - x.points)
+ .sort((a, b) => {
+
+ if (a.points < b.points) return 1;
+
+ if (a.points > b.points) return -1;
+
+ if (a.id > b.id) return 1;
+
+ if (a.id < b.id) return -1;
+
+ })
.map((x: any, ind: number) => {
if (
x.id ===
@@ -462,7 +485,6 @@ export default class Sidebar extends React.Component
}
});
this.setState({
- user: datauser,
isLoaded: true,
totalUserPointsfromList: pointsTotal,
totalUsers: totalchamps,
@@ -479,8 +501,68 @@ export default class Sidebar extends React.Component
});
}
- //getting extra symbol, so using default menthod
+ //Get settings from config list
+ private async getConfigListSettings() {
+ try {
+ const configListData: IConfigList[] = await commonServiceManager.getMemberListColumnConfigSettings();
+ if (configListData.length === 3) {
+ this.setState({ configListSettings: configListData });
+ }
+ else {
+ console.log(
+ stringsConstants.CMPErrorMessage +
+ ` while loading the page. There could be a problem with the ${stringsConstants.ConfigList} data.`
+ );
+ }
+ }
+ catch (error) {
+ console.error("CMP_Sidebar_getConfigListSettings \n", error);
+ console.log(
+ stringsConstants.CMPErrorMessage +
+ `while retrieving the ${stringsConstants.ConfigList} settings. Below are the details: \n` +
+ JSON.stringify(error),
+ );
+ }
+ }
+
+ //Get memberlist column names from member list
+ private async getMemberListColumnNames() {
+ try {
+ const columnsDisplayNames: any[] = await commonServiceManager.getMemberListColumnDisplayNames();
+ if (columnsDisplayNames.length > 0) {
+ this.setState({ memberListColumnNames: columnsDisplayNames });
+ }
+ }
+ catch (error) {
+ console.error("CMP_Sidebar_getMemberListColumnNames \n", error);
+ console.log(
+ stringsConstants.CMPErrorMessage +
+ ` while retrieving the ${stringsConstants.MemberList} column data. Below are the details: \n` +
+ JSON.stringify(error),
+ );
+ }
+ }
+ //populate member list column display names into the states
+ private populateColumnNames() {
+ const enabledSettingsArray = this.state.configListSettings.filter((setting) => setting.Value === stringsConstants.EnabledStatus);
+ for (let setting of enabledSettingsArray) {
+ const columnObject = this.state.memberListColumnNames.find((column) => column.InternalName === setting.Title);
+ if (columnObject.InternalName === stringsConstants.RegionColumn) {
+ this.setState({ regionColumnName: columnObject.Title });
+ continue;
+ }
+ if (columnObject.InternalName === stringsConstants.CountryColumn) {
+ this.setState({ countryColumnName: columnObject.Title });
+ continue;
+ }
+ if (columnObject.InternalName === stringsConstants.GroupColumn) {
+ this.setState({ groupColumnName: columnObject.Title });
+ }
+ }
+ }
+
+ //getting extra symbol, so using default menthod
public onRenderCaretDown = (): JSX.Element => {
return ;
}
@@ -738,33 +820,57 @@ export default class Sidebar extends React.Component
}
onChange={(evt) => this.handleInput(evt, "Title")}
/>
-
- this.filterUsers("region", event)}
- placeholder={LocaleStrings.RegionPlaceholder}
- options={this.options(this.state.regions)}
- styles={this.dropdownStyles}
- onRenderCaretDown={this.onRenderCaretDown}
- defaultValue={this.state.currentUser.Region}
- calloutProps={{ className: "nonMemberDdCallout" }}
- />
-
-
- this.filterUsers("country", event)
- }
- placeholder={LocaleStrings.CountryPlaceholder}
- options={this.options(this.state.coutries)}
- styles={this.dropdownStyles}
- onRenderCaretDown={this.onRenderCaretDown}
- defaultValue={this.state.currentUser.Country}
- calloutProps={{ className: "nonMemberDdCallout" }}
- />
-