From 8e015e686ae7456725a976dd597ee16bd1200858 Mon Sep 17 00:00:00 2001 From: Alex Kwan Date: Wed, 5 Mar 2025 14:18:40 -0800 Subject: [PATCH] draft of modality specific usePropsFor functions --- .../communication-react/src/mergedHooks.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/communication-react/src/mergedHooks.ts b/packages/communication-react/src/mergedHooks.ts index 269573d5b4d..171cfa41eb3 100644 --- a/packages/communication-react/src/mergedHooks.ts +++ b/packages/communication-react/src/mergedHooks.ts @@ -143,3 +143,45 @@ export const usePropsFor = JSX.Element>( throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.'; } }; + +export const useChatPropsFor = JSX.Element>( + component: Component +): ComponentProps => { + const chatSelector = getChatSelector(component); + const chatProps = useChatSelector(chatSelector); + const chatHandlers = useChatHandlers[0]>(component); + + if (chatProps) { + if (!chatHandlers) { + throw 'Please initialize chatClient and chatThreadClient first!'; + } + return { ...chatProps, ...chatHandlers } as any; + } + + if (!chatSelector) { + throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List."; + } else { + throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.'; + } +}; + +export const useCallingPropsFor = JSX.Element>( + component: Component +): ComponentProps => { + const callingSelector = getCallingSelector(component); + const callProps = useCallingSelector(callingSelector); + const callingHandlers = useCallingHandlers[0]>(component); + + if (callProps) { + if (!callingHandlers) { + throw 'Please initialize callClient first!'; + } + return { ...callProps, ...callingHandlers } as any; + } + + if (!callingSelector) { + throw "Can't find corresponding selector for this component. Please check the supported components from Azure Communication UI Feature Component List."; + } else { + throw 'Could not find props for this component, ensure the component is wrapped by appropriate providers.'; + } +};