diff --git a/client/src/components/owner-detail-form/owner-detail-form.container.jsx b/client/src/components/owner-detail-form/owner-detail-form.container.jsx index a92913d30..d78a11f04 100644 --- a/client/src/components/owner-detail-form/owner-detail-form.container.jsx +++ b/client/src/components/owner-detail-form/owner-detail-form.container.jsx @@ -32,15 +32,17 @@ function OwnerDetailFormContainer({ owner, refetch, bodyshop }) { // Fetch opt-out status on mount useEffect(() => { const fetchOptOutStatus = async () => { - if (bodyshop?.id && (owner?.ownr_ph1 || owner?.ownr_ph2)) { + if (bodyshop?.id && bodyshop?.messagingservicesid && (owner?.ownr_ph1 || owner?.ownr_ph2)) { const phoneNumbers = [owner.ownr_ph1, owner.ownr_ph2].filter(Boolean); const optOutSet = await phoneNumberOptOutService(apolloClient, bodyshop.id, phoneNumbers); setOptedOutPhones(optOutSet); + } else { + setOptedOutPhones(new Set()); } }; fetchOptOutStatus(); - }, [apolloClient, bodyshop?.id, owner?.ownr_ph1, owner?.ownr_ph2]); + }, [apolloClient, bodyshop?.id, bodyshop?.messagingservicesid, owner?.ownr_ph1, owner?.ownr_ph2]); // Reset form fields when owner changes useEffect(() => { @@ -136,10 +138,14 @@ function OwnerDetailFormContainer({ owner, refetch, bodyshop }) { loading={loading} form={form} isPhone1OptedOut={ - owner?.ownr_ph1 && optedOutPhones.has(phone(owner.ownr_ph1, "CA").phoneNumber?.replace(/^\+1/, "")) + bodyshop?.messagingservicesid && + owner?.ownr_ph1 && + optedOutPhones.has(phone(owner.ownr_ph1, "CA").phoneNumber?.replace(/^\+1/, "")) } isPhone2OptedOut={ - owner?.ownr_ph2 && optedOutPhones.has(phone(owner.ownr_ph2, "CA").phoneNumber?.replace(/^\+1/, "")) + bodyshop?.messagingservicesid && + owner?.ownr_ph2 && + optedOutPhones.has(phone(owner.ownr_ph2, "CA").phoneNumber?.replace(/^\+1/, "")) } />