Skip to content

Commit

Permalink
regression: voip toggle success/error toasts being displayed in quick…
Browse files Browse the repository at this point in the history
… succession (#33574)
  • Loading branch information
aleksandernsilva authored Oct 16, 2024
1 parent 3abc1e5 commit 2b8ac8a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undef
const dispatchToastMessage = useToastMessageDispatch();

const { clientError, isEnabled, isReady, isRegistered } = useVoipState();
const { register, unregister } = useVoipAPI();
const { register, unregister, onRegisteredOnce, onUnregisteredOnce } = useVoipAPI();

const toggleVoip = useMutation({
mutationFn: async () => {
Expand All @@ -24,10 +24,14 @@ export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undef
return false;
},
onSuccess: (isEnabled: boolean) => {
dispatchToastMessage({
type: 'success',
message: isEnabled ? t('Voice_calling_enabled') : t('Voice_calling_disabled'),
});
if (isEnabled) {
onRegisteredOnce(() => dispatchToastMessage({ type: 'success', message: t('Voice_calling_enabled') }));
} else {
onUnregisteredOnce(() => dispatchToastMessage({ type: 'success', message: t('Voice_calling_disabled') }));
}
},
onError: () => {
dispatchToastMessage({ type: 'error', message: t('Voice_calling_registration_failed') });
},
});

Expand Down
14 changes: 9 additions & 5 deletions apps/meteor/client/sidebar/header/hooks/useVoipItemsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undef
const dispatchToastMessage = useToastMessageDispatch();

const { clientError, isEnabled, isReady, isRegistered } = useVoipState();
const { register, unregister } = useVoipAPI();
const { register, unregister, onRegisteredOnce, onUnregisteredOnce } = useVoipAPI();

const toggleVoip = useMutation({
mutationFn: async () => {
Expand All @@ -24,10 +24,14 @@ export const useVoipItemsSection = (): { items: GenericMenuItemProps[] } | undef
return false;
},
onSuccess: (isEnabled: boolean) => {
dispatchToastMessage({
type: 'success',
message: isEnabled ? t('Voice_calling_enabled') : t('Voice_calling_disabled'),
});
if (isEnabled) {
onRegisteredOnce(() => dispatchToastMessage({ type: 'success', message: t('Voice_calling_enabled') }));
} else {
onUnregisteredOnce(() => dispatchToastMessage({ type: 'success', message: t('Voice_calling_disabled') }));
}
},
onError: () => {
dispatchToastMessage({ type: 'error', message: t('Voice_calling_registration_failed') });
},
});

Expand Down
6 changes: 6 additions & 0 deletions packages/ui-voip/src/hooks/useVoipAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type VoipAPI = {
unregister(): Promise<void>;
openDialer(): void;
closeDialer(): void;
onRegisteredOnce(cb: () => void): () => void;
onUnregisteredOnce(cb: () => void): () => void;
transferCall(calleeURL: string): Promise<void>;
changeAudioOutputDevice: VoipContextReady['changeAudioOutputDevice'];
changeAudioInputDevice: VoipContextReady['changeAudioInputDevice'];
Expand All @@ -32,6 +34,8 @@ export const useVoipAPI = (): VoipAPI => {
transferCall: NOOP,
changeAudioInputDevice: NOOP,
changeAudioOutputDevice: NOOP,
onRegisteredOnce: NOOP,
onUnregisteredOnce: NOOP,
} as VoipAPI;
}

Expand All @@ -47,6 +51,8 @@ export const useVoipAPI = (): VoipAPI => {
closeDialer: () => voipClient.notifyDialer({ open: false }),
changeAudioInputDevice,
changeAudioOutputDevice,
onRegisteredOnce: (cb: () => void) => voipClient.once('registered', cb),
onUnregisteredOnce: (cb: () => void) => voipClient.once('unregistered', cb),
};
}, [context]);
};

0 comments on commit 2b8ac8a

Please sign in to comment.