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

feat: taskList and IncomingTask widgets added #348

Open
wants to merge 15 commits into
base: ccwidgets
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions docs/react-samples/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import React, { useState } from 'react';
import {StationLogin, UserState, store} from '@webex/cc-widgets'
import React, {useState} from 'react';
import {StationLogin, UserState, IncomingTask, TaskList, store} from '@webex/cc-widgets';

function App() {
const [isSdkReady, setIsSdkReady] = useState(false);
const [accessToken, setAccessToken] = useState("");
const [accessToken, setAccessToken] = useState('');
const [isLoggedIn, setIsLoggedIn] = useState(false);

const webexConfig = {
fedramp: false,
logger: {
level: 'log'
}
}
fedramp: false,
logger: {
level: 'log',
},
};

const onLogin = () => {
console.log('Agent login has been succesful');
setIsLoggedIn(true);
}
};

const onLogout = () => {
console.log('Agent logout has been succesful');
setIsLoggedIn(false);
}
};

return (
<>
Expand All @@ -33,25 +33,26 @@ function App() {
onChange={(e) => setAccessToken(e.target.value)}
/>
<button
disabled={accessToken.trim() === ""}
disabled={accessToken.trim() === ''}
onClick={() => {
store.init({webexConfig, access_token: accessToken}).then(() => {
setIsSdkReady(true);
});
}}
>Init Widgets</button>
{
isSdkReady && (
<>
<StationLogin onLogin={onLogin} onLogout={onLogout} />
{
isLoggedIn && <UserState />
}
</>
)
}
>
sreenara marked this conversation as resolved.
Show resolved Hide resolved
Init Widgets
</button>
{isSdkReady && (
<>
<StationLogin onLogin={onLogin} onLogout={onLogout} />
{isLoggedIn && <UserState />}
{isLoggedIn && <IncomingTask />}
{isLoggedIn && <TaskList />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have this one-line

Suggested change
{isLoggedIn && <UserState />}
{isLoggedIn && <IncomingTask />}
{isLoggedIn && <TaskList />}
{
isLoggedIn && (
<UserState />
<IncomingTask />
<TaskList />
)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also have callbacks assigned for onAccepted and onDeclined to ensure they're called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added them with prints

</>
)}
</>
);
}

// @ts-ignore
window.store = store;
sreenara marked this conversation as resolved.
Show resolved Hide resolved
rsarika marked this conversation as resolved.
Show resolved Hide resolved
export default App;
1 change: 1 addition & 0 deletions packages/contact-center/cc-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@r2wc/react-to-web-component": "2.0.3",
"@webex/cc-station-login": "workspace:*",
"@webex/cc-store": "workspace:*",
"@webex/cc-task": "workspace:*",
"@webex/cc-user-state": "workspace:*"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/contact-center/cc-widgets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {StationLogin} from '@webex/cc-station-login';
import {UserState} from '@webex/cc-user-state';
import {IncomingTask, TaskList} from '@webex/cc-task';
import store from '@webex/cc-store';

export {StationLogin, UserState, store};
export {StationLogin, UserState, IncomingTask, TaskList, store};
17 changes: 17 additions & 0 deletions packages/contact-center/cc-widgets/src/wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import r2wc from '@r2wc/react-to-web-component';
import {StationLogin} from '@webex/cc-station-login';
import {UserState} from '@webex/cc-user-state';
import store from '@webex/cc-store';
import {TaskList, IncomingTask} from '@webex/cc-task';

const WebUserState = r2wc(UserState);
const WebIncomingTask = r2wc(IncomingTask, {
props: {
onAccepted: 'function',
onDeclined: 'function',
},
});

const WebTaskList = r2wc(TaskList);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the task list have any props? What if the user refreshes, and when we re-login, we want to show the existing task list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added the props with accepted and declined


const WebStationLogin = r2wc(StationLogin, {
props: {
Expand All @@ -20,4 +29,12 @@ if (!customElements.get('widget-cc-station-login')) {
customElements.define('widget-cc-station-login', WebStationLogin);
}

if (!customElements.get('widget-cc-incoming-task')) {
customElements.define('widget-cc-incoming-task', WebIncomingTask);
}

if (!customElements.get('widget-cc-task-list')) {
customElements.define('widget-cc-task-list', WebTaskList);
}

export {store};
sreenara marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 22 additions & 9 deletions packages/contact-center/station-login/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useState} from "react";
import {useState} from 'react';
import {StationLoginSuccess, StationLogoutSuccess} from '@webex/plugin-cc';
import {UseStationLoginProps} from "./station-login/station-login.types";
import {UseStationLoginProps} from './station-login/station-login.types';
sreenara marked this conversation as resolved.
Show resolved Hide resolved
import store from '@webex/cc-store'; // we need to import as we are losing the context of this in store
sreenara marked this conversation as resolved.
Show resolved Hide resolved

export const useStationLogin = (props: UseStationLoginProps) => {
const cc = props.cc;
Expand All @@ -17,10 +18,12 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogin({teamId: team, loginOption: deviceType, dialNumber: dialNumber})
.then((res: StationLoginSuccess) => {
setLoginSuccess(res);
if(loginCb){
store.setSelectedLoginOption(deviceType);
if (loginCb) {
loginCb();
}
}).catch((error: Error) => {
})
.catch((error: Error) => {
console.error(error);
setLoginFailure(error);
});
Expand All @@ -30,14 +33,24 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogout({logoutReason: 'User requested logout'})
.then((res: StationLogoutSuccess) => {
setLogoutSuccess(res);
if(logoutCb){
if (logoutCb) {
logoutCb();
}
}).catch((error: Error) => {
})
.catch((error: Error) => {
console.error(error);
});
};

return {name: 'StationLogin', setDeviceType, setDialNumber, setTeam, login, logout, loginSuccess, loginFailure, logoutSuccess};
}

return {
name: 'StationLogin',
setDeviceType,
setDialNumber,
setTeam,
login,
logout,
loginSuccess,
loginFailure,
logoutSuccess,
};
};
sreenara marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface IStationLoginProps {
*/
teams: Team[];

/**
/**
* Station login options available for the agent
*/
loginOptions: string[];
Expand All @@ -43,7 +43,7 @@ export interface IStationLoginProps {
*/
loginFailure?: Error;

/**
/**
* Response data received on agent login success
*/
logoutSuccess?: StationLogoutSuccess;
Expand Down Expand Up @@ -74,8 +74,21 @@ export interface IStationLoginProps {
setTeam: (team: string) => void;
}

export type StationLoginPresentationalProps = Pick<IStationLoginProps, 'name' | 'teams' | 'loginOptions' | 'login' | 'logout' | 'loginSuccess' | 'loginFailure' | 'logoutSuccess' | 'setDeviceType' | 'setDialNumber' | 'setTeam'>;
export type StationLoginPresentationalProps = Pick<
IStationLoginProps,
| 'name'
| 'teams'
| 'loginOptions'
| 'login'
| 'logout'
| 'loginSuccess'
| 'loginFailure'
| 'logoutSuccess'
| 'setDeviceType'
| 'setDialNumber'
| 'setTeam'
>;

export type UseStationLoginProps = Pick<IStationLoginProps, 'cc' | 'onLogin' | 'onLogout'>;

export type StationLoginProps = Pick<IStationLoginProps, 'onLogin' | 'onLogout'>;
export type StationLoginProps = Pick<IStationLoginProps, 'onLogin' | 'onLogout'>;
11 changes: 11 additions & 0 deletions packages/contact-center/station-login/tests/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import {renderHook, act, waitFor} from '@testing-library/react';
import {useStationLogin} from '../src/helper';

const teams = ['team123', 'team456'];

const loginOptions = ['EXTENSION', 'AGENT_DN', 'BROWSER'];
jest.mock('@webex/cc-store', () => {
return {
cc: {},
teams,
loginOptions,
};
});
Comment on lines +7 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are mocking the store here, shouldn't we add a test to check if the setSelectedLoginOption method was called?


// Mock webex instance
const ccMock = {
stationLogin: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion packages/contact-center/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"react": "18.3.1",
"react-dom": "18.3.1",
"typescript": "5.6.3",
"webex": "3.7.0-wxcc.3"
"webex": "3.7.0-wxcc.4"
},
"devDependencies": {
"@babel/core": "7.25.2",
Expand Down
62 changes: 31 additions & 31 deletions packages/contact-center/store/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import {makeAutoObservable, observable} from 'mobx';
import Webex from 'webex';
import {
IContactCenter,
Profile,
Team,
WithWebex,
IdleCode,
InitParams,
IStore
} from './store.types';
import {IContactCenter, Profile, Team, WithWebex, IdleCode, InitParams, IStore} from './store.types';

class Store implements IStore {
teams: Team[] = [];
loginOptions: string[] = [];
cc: IContactCenter;
idleCodes: IdleCode[] = [];
agentId: string = '';
selectedLoginOption: string = '';
rsarika marked this conversation as resolved.
Show resolved Hide resolved

constructor() {
makeAutoObservable(this, {cc: observable.ref});
}

setSelectedLoginOption(option: string): void {
this.selectedLoginOption = option;
}

registerCC(webex: WithWebex['webex']): Promise<void> {
this.cc = webex.cc;
return this.cc.register().then((response: Profile) => {
this.teams = response.teams;
this.loginOptions = response.loginVoiceOptions;
this.idleCodes = response.idleCodes;
this.agentId = response.agentId;
}).catch((error) => {
console.error('Error registering contact center', error);
return Promise.reject(error);
});
return this.cc
.register()
.then((response: Profile) => {
this.teams = response.teams;
this.loginOptions = response.loginVoiceOptions;
this.idleCodes = response.idleCodes;
this.agentId = response.agentId;
})
.catch((error) => {
console.error('Error registering contact center', error);
return Promise.reject(error);
});
}

init(options: InitParams): Promise<void> {
if('webex' in options) {
if ('webex' in options) {
sreenara marked this conversation as resolved.
Show resolved Hide resolved
// If devs decide to go with webex, they will have to listen to the ready event before calling init
// This has to be documented
// This has to be documented
return this.registerCC(options.webex);
}
return new Promise((resolve, reject) => {

const timer = setTimeout(() => {
reject(new Error('Webex SDK failed to initialize'));
}, 6000);

const webex = Webex.init({
config: options.webexConfig,
credentials: {
access_token: options.access_token
}
access_token: options.access_token,
},
});

webex.once('ready', () => {
clearTimeout(timer);
this.registerCC(webex).then(() => {
resolve();
})
.catch((error) => {
reject(error);
})
})
this.registerCC(webex)
.then(() => {
resolve();
})
.catch((error) => {
reject(error);
});
});
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/contact-center/task/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('../../../.babelrc');

module.exports = baseConfig;
Loading