Skip to content

fix(store): minor-fixes-after-storeEventsWrapper #390

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

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions packages/contact-center/station-login/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@ export const useStationLogin = (props: UseStationLoginProps) => {
const loginCb = props.onLogin;
const logoutCb = props.onLogout;
const logger = props.logger;
const [isAgentLoggedIn, setIsAgentLoggedIn] = useState(props.isAgentLoggedIn);
Copy link
Author

@Shreyas281299 Shreyas281299 Feb 19, 2025

Choose a reason for hiding this comment

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

original comment- See if we can remove the isAgentLogged in props as we already have this in the store

Removed the local state

const [dialNumber, setDialNumber] = useState('');
const [deviceType, setDeviceType] = useState(props.deviceType || '');
const [team, setTeam] = useState('');
const [loginSuccess, setLoginSuccess] = useState<StationLoginSuccess>();
const [loginFailure, setLoginFailure] = useState<Error>();
const [logoutSuccess, setLogoutSuccess] = useState<StationLogoutSuccess>();

useEffect(() => {
setIsAgentLoggedIn(props.isAgentLoggedIn);
}, [props.isAgentLoggedIn]);

const handleContinue = async () => {
try {
store.setShowMultipleLoginAlert(false);
Expand Down Expand Up @@ -47,7 +42,6 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogin({teamId: team, loginOption: deviceType, dialNumber: dialNumber})
.then((res: StationLoginSuccess) => {
setLoginSuccess(res);
setIsAgentLoggedIn(true);
store.setDeviceType(deviceType);
store.setIsAgentLoggedIn(true);
if (res.data.auxCodeId) {
Expand All @@ -73,7 +67,6 @@ export const useStationLogin = (props: UseStationLoginProps) => {
cc.stationLogout({logoutReason: 'User requested logout'})
.then((res: StationLogoutSuccess) => {
setLogoutSuccess(res);
setIsAgentLoggedIn(false);
store.setIsAgentLoggedIn(false);
store.setDeviceType('');
if (logoutCb) {
Expand Down Expand Up @@ -106,7 +99,6 @@ export const useStationLogin = (props: UseStationLoginProps) => {
loginSuccess,
loginFailure,
logoutSuccess,
isAgentLoggedIn,
handleContinue,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const StationLoginComponent: React.FunctionComponent<StationLoginProps> = ({onLo
onLogin,
onLogout,
logger,
isAgentLoggedIn,
deviceType,
});

Expand All @@ -22,8 +21,10 @@ const StationLoginComponent: React.FunctionComponent<StationLoginProps> = ({onLo
teams,
loginOptions,
deviceType,
isAgentLoggedIn,
showMultipleLoginAlert,
Copy link
Author

Choose a reason for hiding this comment

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

Original comment- we can move showMultipleLoginAlert to results as we already have it rather than putting it directly in the presentation component

Moved

};
return <StationLoginPresentational {...props} showMultipleLoginAlert={showMultipleLoginAlert} />;
return <StationLoginPresentational {...props} />;
};

const StationLogin = observer(StationLoginComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ export type StationLoginPresentationalProps = Pick<
showMultipleLoginAlert: boolean;
};

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

export type StationLoginProps = Pick<IStationLoginProps, 'onLogin' | 'onLogout'>;
19 changes: 0 additions & 19 deletions packages/contact-center/station-login/tests/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const logger = {
log: jest.fn(),
error: jest.fn(),
};
const isAgentLoggedIn = false;

describe('useStationLogin Hook', () => {
afterEach(() => {
Expand Down Expand Up @@ -87,7 +86,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'BROWSER',
})
);
Expand All @@ -112,7 +110,6 @@ describe('useStationLogin Hook', () => {

expect(result.current).toEqual({
name: 'StationLogin',
isAgentLoggedIn: true,
setDeviceType: expect.any(Function),
setDialNumber: expect.any(Function),
setTeam: expect.any(Function),
Expand Down Expand Up @@ -152,7 +149,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: '',
})
);
Expand Down Expand Up @@ -190,7 +186,6 @@ describe('useStationLogin Hook', () => {
cc: ccMock,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand Down Expand Up @@ -222,7 +217,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -247,7 +241,6 @@ describe('useStationLogin Hook', () => {

expect(result.current).toEqual({
name: 'StationLogin',
isAgentLoggedIn: false,
setDeviceType: expect.any(Function),
setDialNumber: expect.any(Function),
setTeam: expect.any(Function),
Expand All @@ -272,7 +265,6 @@ describe('useStationLogin Hook', () => {
cc: ccMock,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -297,7 +289,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -323,7 +314,6 @@ describe('useStationLogin Hook', () => {

expect(result.current).toEqual({
name: 'StationLogin',
isAgentLoggedIn: true,
setDeviceType: expect.any(Function),
setDialNumber: expect.any(Function),
setTeam: expect.any(Function),
Expand Down Expand Up @@ -362,7 +352,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'BROWSER',
})
);
Expand All @@ -377,7 +366,6 @@ describe('useStationLogin Hook', () => {

expect(result.current).toEqual({
name: 'StationLogin',
isAgentLoggedIn: false,
setDeviceType: expect.any(Function),
setDialNumber: expect.any(Function),
setTeam: expect.any(Function),
Expand All @@ -401,7 +389,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -426,7 +413,6 @@ describe('useStationLogin Hook', () => {
cc: ccMock,
onLogin: loginCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -449,7 +435,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -472,7 +457,6 @@ describe('useStationLogin Hook', () => {
cc: ccMock,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand All @@ -498,7 +482,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand Down Expand Up @@ -528,7 +511,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand Down Expand Up @@ -559,7 +541,6 @@ describe('useStationLogin Hook', () => {
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn,
deviceType: 'EXTENSION',
})
);
Expand Down
45 changes: 22 additions & 23 deletions packages/contact-center/station-login/tests/station-login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import React from 'react';
import {render, screen} from '@testing-library/react';
import {StationLogin} from '../../src';
import * as helper from '../../src/helper';
import * as presentational from '../../src/station-login/station-login.presentational';
import '@testing-library/jest-dom';

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

const loginOptions = ['EXTENSION', 'AGENT_DN', 'BROWSER'];
const deviceType = 'BROWSER';
const logger = {};
const teamsMock = ['team123', 'team456'];
const ccMock = {
on: () => {},
off: () => {},
};
const loginOptionsMock = ['EXTENSION', 'AGENT_DN', 'BROWSER'];
const deviceTypeMock = 'BROWSER';
const loggerMock = {};
const isAgentLoggedInMock = false;

// Mock the store import
jest.mock('@webex/cc-store', () => {
return {
cc: {
on: jest.fn(),
off: jest.fn(),
},
teams,
loginOptions,
deviceType,
logger,
isAgentLoggedIn: false,
cc: ccMock,
teams: teamsMock,
loginOptions: loginOptionsMock,
deviceType: deviceTypeMock,
logger: loggerMock,
isAgentLoggedIn: isAgentLoggedInMock,
};
});

Expand All @@ -31,21 +33,18 @@ const logoutCb = jest.fn();
describe('StationLogin Component', () => {
it('renders StationLoginPresentational with correct props', () => {
const useStationLoginSpy = jest.spyOn(helper, 'useStationLogin');
const StationLoginPresentationalSpy = jest
.spyOn(presentational, 'default')
.mockReturnValue(<div>StationLoginPresentational</div>);

render(<StationLogin onLogin={loginCb} onLogout={logoutCb} />);

expect(useStationLoginSpy).toHaveBeenCalledWith({
cc: {
on: expect.any(Function),
off: expect.any(Function),
},
cc: ccMock,
onLogin: loginCb,
onLogout: logoutCb,
logger,
isAgentLoggedIn: false,
deviceType: 'BROWSER',
logger: loggerMock,
deviceType: deviceTypeMock,
});
const heading = screen.getByTestId('station-login-heading');
expect(heading).toHaveTextContent('StationLogin');
});
});
5 changes: 0 additions & 5 deletions packages/contact-center/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class Store implements IStore {
constructor() {
makeAutoObservable(this, {
cc: observable.ref,
currentTask: observable, // Make currentTask observable
incomingTask: observable,
taskList: observable,
wrapupRequired: observable,
currentState: observable,
Copy link
Author

Choose a reason for hiding this comment

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

Store is already updating these values and the latest values are reaching the components, so we dont need them as observable here, makeAutoObservable method is doing this for us.

});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/contact-center/store/src/store.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ enum CC_EVENTS{

export type {
IContactCenter,
ITask,
Copy link
Author

Choose a reason for hiding this comment

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

Importing ITask from cc-sdk and exporting it from store, all the types from cc-sdk wll be imported and exported from the store, this will ensure cc-store is the only place where we use cc-sdk as a dependency

Profile,
Team,
AgentLogin,
Expand All @@ -106,7 +107,7 @@ export type {
IStore,
ILogger,
IWrapupCode,
IStoreWrapper
IStoreWrapper,
}

export {
Expand Down
16 changes: 13 additions & 3 deletions packages/contact-center/store/src/storeEventsWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import {IStoreWrapper, IStore, InitParams, TASK_EVENTS, CC_EVENTS, IWrapupCode, WithWebex} from './store.types';
import {ITask} from '@webex/plugin-cc';
import {
IStoreWrapper,
IStore,
InitParams,
TASK_EVENTS,
CC_EVENTS,
IWrapupCode,
WithWebex,
IContactCenter,
ITask,
Copy link
Author

Choose a reason for hiding this comment

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

ITask imported from store/types

} from './store.types';
import Store from './store';
import {runInAction} from 'mobx';

Expand Down Expand Up @@ -235,14 +244,15 @@ class StoreWrapper implements IStoreWrapper {
}
};

setupIncomingTaskHandler = (ccSDK: any) => {
setupIncomingTaskHandler = (ccSDK: IContactCenter) => {
Copy link
Author

Choose a reason for hiding this comment

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

Removed any type

ccSDK.on(TASK_EVENTS.TASK_INCOMING, this.handleIncomingTask);

ccSDK.on(CC_EVENTS.AGENT_STATE_CHANGE, this.handleStateChange);
ccSDK.on(CC_EVENTS.AGENT_MULTI_LOGIN, this.handleMultiLoginCloseSession);
ccSDK.on(TASK_EVENTS.TASK_HYDRATE, this.handleTaskHydrate);

return () => {
// TODO: https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-617635, remove event listeners after logout
ccSDK.off(TASK_EVENTS.TASK_INCOMING, this.handleIncomingTask);
ccSDK.off(CC_EVENTS.AGENT_STATE_CHANGE, this.handleStateChange);
ccSDK.off(CC_EVENTS.AGENT_MULTI_LOGIN, this.handleMultiLoginCloseSession);
Expand Down
5 changes: 0 additions & 5 deletions packages/contact-center/store/tests/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ describe('Store', () => {

expect(makeAutoObservable).toHaveBeenCalledWith(storeInstance, {
cc: expect.any(Function),
currentState: expect.any(Object),
currentTask: expect.any(Object),
incomingTask: expect.any(Object),
taskList: expect.any(Object),
wrapupRequired: expect.any(Object),
});
});

Expand Down
Loading