import { removePhonePlus } from '../utils/removePhonePlus'; import { API_BASE_URI } from './apiBaseUrl'; import { type ResponseStatus } from './handlers/verifiedFormHandler'; import { LeadServiceFetch } from './LeadServiceAPI'; export type PhoneOnly = { phone?: string; }; export type SendCodeProps = PhoneOnly & { captchaToken?: string; }; const SEND_CODE_URL = 'initCorporateLead'; type errorCode = 'SMS_COOLDOWN' | 'CAPTCHA_REQUIRED'; type SendCodeResponse = | (ResponseStatus & { errorCode?: errorCode; verificationId?: string; attemptsLeft?: number; }) | null; export const sendCode = async ({ phone = '', captchaToken = '', }: SendCodeProps): Promise => { const submitBody = { phone: removePhonePlus(phone), captchaToken, }; try { const response = await LeadServiceFetch(`${API_BASE_URI}/${SEND_CODE_URL}`, submitBody); if (!response?.status) { return null; } return response.json(); } catch (e) { return null; } };