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

Regression: Prevent button from losing state when rerendering #24648

Merged
merged 1 commit into from
Feb 28, 2022
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
4 changes: 4 additions & 0 deletions client/lib/voip/VoIPUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,8 @@ export class VoIPUser extends Emitter<VoipEvents> implements OutgoingRequestDele
getAggregator(): QueueAggregator | undefined {
return this.queueInfo;
}

getRegistrarState(): string | undefined {
return this.registerer?.state.toString().toLocaleLowerCase();
}
}
19 changes: 13 additions & 6 deletions client/sidebar/sections/components/OmnichannelCallToggleReady.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const OmnichannelCallToggleReady = (): ReactElement => {
} as const;
const voipClient = useCallClient();

useEffect(() => {
let agentEnabled = false;
const state = voipClient.getRegistrarState();
if (state === 'registered') {
agentEnabled = true;
}
setAgentEnabled(agentEnabled);
setRegistered(agentEnabled);
}, [voipClient]);
// TODO: move registration flow to context provider
const handleVoipCallStatusChange = useMutableCallback((): void => {
// TODO: backend set voip call status
Expand All @@ -31,23 +40,21 @@ export const OmnichannelCallToggleReady = (): ReactElement => {
});

const onUnregistrationError = useMutableCallback((): void => {
voipClient.off('unregistrationerror', onUnregistrationError);
setRegistered(false);
setAgentEnabled(false);
});

const onUnregistered = useMutableCallback((): void => {
setRegistered(!registered);
voipClient.off('unregistered', onUnregistered);
voipClient.off('registrationerror', onUnregistrationError);
});

const onRegistrationError = useMutableCallback((): void => {
voipClient.off('registrationerror', onRegistrationError);
setRegistered(false);
setAgentEnabled(false);
});

const onRegistered = useMutableCallback((): void => {
setRegistered(!registered);
voipClient.off('registered', onRegistered);
voipClient.off('registrationerror', onRegistrationError);
});

useEffect(() => {
Expand Down