chore: more fixes

This commit is contained in:
Muhsin Keloth
2025-06-11 15:01:53 +05:30
parent 48293001ed
commit 2f8214eb87
4 changed files with 161 additions and 123 deletions
@@ -0,0 +1,100 @@
import { useWhatsappSignupValidation } from './useWhatsappSignupValidation';
import { useWhatsappSignupState } from './useWhatsappSignupState';
import { useWhatsappSignupHandlers } from './useWhatsappSignupHandlers';
import { useWhatsappSignupApi } from './useWhatsappSignupApi';
import { useWhatsappFacebookSDK } from './useWhatsappFacebookSDK';
import { useWhatsappMessageHandler } from './useWhatsappMessageHandler';
export function useWhatsappComposableOrchestrator({ store, router, t }) {
// Validation composable
const { isValidBusinessData, normalizeBusinessData } =
useWhatsappSignupValidation();
// State composable
const {
fbSdkLoaded,
isProcessing,
processingMessage,
authCodeReceived,
currentStep,
authCode,
businessData,
isAuthenticating,
hasSignupStarted,
resetState,
} = useWhatsappSignupState();
// Handlers composable
const { handleSignupError, handleSignupCancellation, handleSignupSuccess } =
useWhatsappSignupHandlers({
currentStep,
isProcessing,
isAuthenticating,
resetState,
store,
router,
t,
});
// API composable
const { completeSignupFlow } = useWhatsappSignupApi({
authCodeReceived,
authCode,
currentStep,
isProcessing,
processingMessage,
store,
t,
handleSignupError,
handleSignupSuccess,
});
// Facebook SDK composable
const { loadFacebookSdk, launchEmbeddedSignup } = useWhatsappFacebookSDK({
fbSdkLoaded,
hasSignupStarted,
processingMessage,
isProcessing,
isAuthenticating,
currentStep,
authCode,
authCodeReceived,
businessData,
completeSignupFlow,
handleSignupError,
t,
});
// Message handler composable
const { handleSignupMessage } = useWhatsappMessageHandler({
isValidBusinessData,
normalizeBusinessData,
businessData,
authCodeReceived,
authCode,
completeSignupFlow,
currentStep,
processingMessage,
handleSignupError,
handleSignupCancellation,
t,
});
return {
// State
fbSdkLoaded,
isProcessing,
processingMessage,
authCodeReceived,
currentStep,
authCode,
businessData,
isAuthenticating,
hasSignupStarted,
// Methods
loadFacebookSdk,
launchEmbeddedSignup,
handleSignupMessage,
};
}
@@ -0,0 +1,27 @@
import { computed } from 'vue';
export function useWhatsappComputed({ t, hasSignupStarted, isProcessing }) {
const benefits = computed(() => [
{
key: 'EASY_SETUP',
text: t('INBOX_MGMT.ADD.WHATSAPP.EMBEDDED_SIGNUP.BENEFITS.EASY_SETUP'),
},
{
key: 'SECURE_AUTH',
text: t('INBOX_MGMT.ADD.WHATSAPP.EMBEDDED_SIGNUP.BENEFITS.SECURE_AUTH'),
},
{
key: 'AUTO_CONFIG',
text: t('INBOX_MGMT.ADD.WHATSAPP.EMBEDDED_SIGNUP.BENEFITS.AUTO_CONFIG'),
},
]);
const showLoader = computed(
() => hasSignupStarted.value || isProcessing.value
);
return {
benefits,
showLoader,
};
}
@@ -0,0 +1,19 @@
export function useWhatsappLifecycle({ loadFacebookSdk, handleSignupMessage }) {
const setupMessageListener = () => {
window.addEventListener('message', handleSignupMessage);
};
const cleanupMessageListener = () => {
window.removeEventListener('message', handleSignupMessage);
};
const initialize = () => {
loadFacebookSdk();
setupMessageListener();
};
return {
initialize,
cleanupMessageListener,
};
}