PageSourceSearch

https://ruminants.ai/assets/SocialOnboardingPage-Cu8FMPyk.js

js ruminants.ai collected 2026-10-05 14:51:58 UTC 14,051 bytes, 1 lines download raw bytes

1import{u as Q,j as e,a as oe,k as ne,t as le,l as ie,c as ce,E as M,I as K,a2 as ue,L as W,a3 as de,N as me,Q as fe,O as ge,cE as he,cF as xe}from"./index-DPoJI_wR.js";import{a as s}from"./lucide-BOxB89cY.js";import{g as pe,u as be,P as ye,B as ve,i as je}from"./useRegistrationAgeRequirement-DZWfntGu.js";import{s as Ne,c as _e}from"./icons-DJ_uuSz7.js";import{c as Ce}from"./claimAnonymousChat-B8kOaddZ.js";import{L as we}from"./Logo-BYZ4AgCX.js";import"./index-DvMljiKo.js";function ke(r){if(!r)return null;try{return`+${pe(r)}`}catch{return null}}function Z(r){return r.normalize("NFD").replace(/[\u0300-\u036f]/g,"").toLowerCase()}function Se({value:r,onChange:P,options:w,iconComponent:u,disabled:q,readOnly:O,name:R}){const{t:b}=Q(),[n,y]=s.useState(!1),[g,d]=s.useState(""),j=s.useRef(null),h=s.useRef(null),x=s.useMemo(()=>w.map(a=>({...a,code:ke(a.value)})),[w]),N=s.useMemo(()=>{const a=Z(g.trim());if(!a)return x;const m=a.replace(/\D/g,"");return x.filter(l=>m&&l.code&&l.code.replace(/\D/g,"").startsWith(m)?!0:Z(l.label).includes(a))},[x,g]);s.useEffect(()=>{if(!n)return;const a=l=>{j.current&&!j.current.contains(l.target)&&(y(!1),d(""))},m=l=>{l.key==="Escape"&&(y(!1),d(""))};return document.addEventListener("mousedown",a),document.addEventListener("keydown",m),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("keydown",m)}},[n]),s.useEffect(()=>{n&&h.current?.focus()},[n]);const _=x.find(a=>a.value===r),k=q||O,C=a=>{P(a),y(!1),d("")};return e.jsxs("div",{ref:j,className:"relative",children:[e.jsxs("button",{type:"button",name:R,disabled:k,onClick:()=>!k&&y(a=>!a),"aria-haspopup":"listbox","aria-expanded":n,"aria-label":b("common.label.country_code",{defaultValue:"Country calling code"}),className:"flex items-center gap-1 rounded px-1 py-0.5 text-sm text-foreground hover:bg-surface-hover focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-sage disabled:opacity-60",children:[u?e.jsx(u,{country:r,label:_?.label}):null,e.jsx("span",{className:"tabular-nums text-muted-foreground",children:_?.code||"+"})]}),n&&e.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-72 rounded-md border border-outline-default bg-surface-elevated shadow-lg",children:[e.jsx("div",{className:"border-b border-outline-default p-2",children:e.jsx("input",{ref:h,type:"text",value:g,onChange:a=>d(a.target.value),placeholder:b("common.placeholder.country_search",{defaultValue:"Country or code (e.g. Brazil or 55)"}),className:"w-full rounded border border-input bg-background px-2 py-1.5 text-sm text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-brand-sage"})}),e.jsxs("ul",{role:"listbox",className:"max-h-60 overflow-auto py-1",children:[N.length===0&&e.jsx("li",{className:"px-3 py-2 text-sm text-muted-foreground",children:b("common.text.no_results",{defaultValue:"No results"})}),N.map(a=>e.jsx("li",{children:e.jsxs("button",{type:"button",role:"option","aria-selected":a.value===r,onClick:()=>C(a.value),className:`flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-surface-hover ${a.value===r?"bg-surface-hover font-semibold":""}`,children:[u?e.jsx(u,{country:a.value,label:a.label}):null,e.jsx("span",{className:"flex-1 truncate text-foreground",children:a.label}),a.code&&e.jsx("span",{className:"tabular-nums text-xs text-muted-foreground",children:a.code})]})},a.value||"ZZ"))]})]})]})}const{loading:Ve,error:Ee}=Ne,{beef:Le,dairy:Pe}=_e;function Ie(){const{t:r,currentLanguage:P}=Q(),{isLanguageExplicit:w}=oe(),u=ne(),q=le(),{login:O}=ie(),{setCategory:R}=ce(),b=q.state||{},[n,y]=s.useState(b.onboardingToken),g=b.profile||{},[d,j]=s.useState(""),[h,x]=s.useState(""),[N,_]=s.useState(""),[k,C]=s.useState(""),[a,m]=s.useState(!1),[l,J]=s.useState([]),[f,B]=s.useState(""),[T,I]=s.useState(""),[S,Y]=s.useState(!1),[F,G]=s.useState(""),[i,v]=s.useState({}),[U,V]=s.useState(!1),[E,H]=s.useState(void 0),{requirement:p,isLoading:X,hasError:ee}=be(h),D=s.useMemo(()=>{const t=new URLSearchParams(window.location.search);return{utm_source:t.get("utm_source")||void 0,utm_medium:t.get("utm_medium")||void 0,utm_campaign:t.get("utm_campaign")||void 0}},[]);s.useEffect(()=>{n||u("/login",{replace:!0})},[n,u]),s.useEffect(()=>{M.get("/api/countries").then(t=>J(t.data)).catch(t=>console.error("Error fetching countries:",t))},[]),s.useEffect(()=>{M.get("/api/app-config").then(t=>{const o=t.data?.countryCode;
1typeof o=="string"&&/^[A-Za-z]{2}$/.test(o)&&H(o.toUpperCase())}).catch(()=>{})},[]),s.useEffect(()=>{if(!E||h||l.length===0)return;const t=l.find(o=>o.code.toUpperCase()===E);t&&(x(t.code),C(t.name))},[E,h,l]),s.useEffect(()=>{p?.requires_date_of_birth===!1&&(I(""),v(t=>{if(!t.dateOfBirth)return t;const o={...t};return delete o.dateOfBirth,o}))},[p?.requires_date_of_birth]);const $=l.filter(t=>{const o=N.toLowerCase();return t.name.toLowerCase().includes(o)||t.nameEn.toLowerCase().includes(o)}),te=()=>{const t={};return d?je(d)||(t.phone=r("register.error.phone.invalid",{defaultValue:"Invalid phone number format."})):t.phone=r("register.error.phone.required",{defaultValue:"Phone number is required"}),f||(t.category=r("login.error.category_required",{defaultValue:"Select your preferred knowledge base to continue."})),h||(t.country=r("register.error.country.required",{defaultValue:"Country is required"})),ee||!p?t.country=r("register.error.age_requirement_unavailable",{defaultValue:"We could not verify the registration requirements for this country. Please try again."}):p.requires_date_of_birth&&!T&&(t.dateOfBirth=r("privacy.age.invalid_dob",{defaultValue:"Invalid date of birth"})),S||(t.terms=r("register.error.terms.required",{defaultValue:"You must accept the Terms of Use and Privacy Policy"})),v(t),Object.keys(t).length===0},re=async t=>{if(t.preventDefault(),!n||!te())return;V(!0),v({});const o="",se=await de();try{const L=await fetch(`${o}/api/auth/social/onboarding`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({onboardingToken:n,phone:d,country:h,language_code:P,language_is_explicit:w,category:f,date_of_birth:p?.requires_date_of_birth?T:void 0,acceptTerms:S,acceptPrivacy:S,referral_code:F||void 0,utm_source:D.utm_source,utm_medium:D.utm_medium,utm_campaign:D.utm_campaign,meta_fbc:ge()||void 0,meta_fbp:fe()||void 0,client_ip_address:se||void 0,marketing_consent:me()})}),c=await L.json().catch(()=>({}));if(!L.ok){if(typeof c.onboardingToken=="string"&&c.onboardingToken&&y(c.onboardingToken),c.code==="USER_NOT_APPROVED"){u("/pending-approval",{replace:!0});return}const A=c.field,z=c.errorKey?r(c.errorKey,{defaultValue:c.error||"Registration failed."}):c.error||r("register.error.internal",{defaultValue:"Internal error creating user."});v(A?{[A==="date_of_birth"?"dateOfBirth":A]:z}:{form:z}),V(!1);return}if(c.user){O(c.user),f&&await R(f).catch(()=>{}),await Ce(),u(he(),{replace:!0});return}v({form:r("register.error.internal",{defaultValue:"Internal error creating user."})}),V(!1)}catch(L){console.error("[SocialOnboarding] submit failed:",L),v({form:r("register.error.internal",{defaultValue:"Internal error creating user."})}),V(!1)}},ae=async()=>{await xe(),u("/login",{replace:!0})};return n?e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-background py-12 px-4 sm:px-6 lg:px-8",children:[e.jsx("div",{className:"fixed top-4 right-4 z-50",children:e.jsx(K,{})}),e.jsxs("div",{className:"max-w-md w-full space-y-8",children:[e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx(we,{priority:!0,alt:r("login.logo_alt",{defaultValue:"Ruminants.AI logo"}),className:"h-16 w-auto"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-heading text-lg font-semibold text-foreground",children:r("auth.social.onboarding_title",{defaultValue:"Almost there"})}),e.jsx("p",{className:"mt-1 font-body text-sm text-muted-foreground",children:r("auth.social.onboarding_subtitle_generic",{defaultValue:"We just need a few details your provider does not share."})})]})]}),e.jsx("div",{className:"rounded-md border border-outline-default bg-surface-elevated p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[g.picture?e.jsx("img",{src:g.picture,alt:"",className:"h-10 w-10 rounded-full object-cover",referrerPolicy:"no-referrer"}):null,e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate font-body text-sm font-semibold text-foreground",children:g.name||"—"}),e.jsx("p",{className:"truncate font-body text-xs text-muted-foreground",children:g.email||"—"})]})]})}),i.form&&e.jsx("div",{className:"bg-surface-tint-red border-l-4 border-destructive text-destructive p-4 rounded-md",role:"alert",children:e.jsxs("div",{className:"flex",children:[e.jsx(Ee,{className:"h-5 w-5 mr-3 shrink-0"}),e.jsx("p",{className:"text-sm",children:i.form})]})}),e.jsxs("form",{className:"font-body space-y-6",onSubmit:re,children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex w-full items-center gap-[3px] rounded-full border border-outline-default bg-surface-elevated p-[5px] shadow-sm",role:"tablist","aria-label":r("category_selector.aria",{defaultValue:"Cattle category"}),children:[e.jsxs("button",{type:"button",onClick:()=>B("dairy"),role:"tab","aria-selected":f==="dairy",className:`flex-1 inline-flex h-9 items-center justify-center gap-2 rounded-full px-4 font-heading text-sm font-semibold transition-all ${f==="dairy"?"bg-brand-gradient-dairy text-white shadow-sm":"text-text-muted hover:text-brand-midnight"}`,children:[e.jsx(Pe,{className:"h-4 w-4"}),e.jsx("span",{children:r("category_selector.dairy",{defaultValue:"Dairy"})})]}),e.jsxs("button",{type:"button",onClick:()=>B("beef"),role:"tab","aria-selected":f==="beef",className:`flex-1 inline-flex h-9 items-center justify-center gap-2 rounded-full px-4 font-heading text-sm font-semibold transition-all ${f==="beef"?"bg-brand-gradient-beef text-white shadow-sm":"text-text-muted hover:text-brand-midnight"}`,children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{children:r("category_selector.beef",{defaultValue:"Beef"})})]})]}),i.category&&e.jsx("p",{className:"mt-2 text-sm text-destructive",children:i.category})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"social-phone",className:"block text-sm font-medium text-foreground mb-1.5",children:r("common.label.phone",{defaultValue:"Phone Number"})}),e.jsx(ye,{id:"social-phone",international:!0,defaultCountry:E||void 0,countrySelectComponent:Se,value:d,onChange:t=>j(t||""),className:"w-full"}),i.phone&&e.jsx("p",{className:"mt-2 text-sm text-destructive",children:i.phone})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1.5",children:r("register.label.language",{defaultValue:"Language"})}),e.jsx(K,{})]}),e.jsxs("div",{className:"relative",children:[e.jsx("label",{htmlFor:"social-country",className:"block text-sm font-medium text-foreground mb-1.5",children:r("common.label.country",{defaultValue:"Country"})}),e.jsx("input",{id:"social-country",type:"text",value:k||N,onChange:t=>{_(t.target.value),C(""),x(""),m(!0)},onFocus:()=>m(!0),className:"appearance-none block w-full p-3 border border-input rounded-md shadow-sm bg-background text-base text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-brand-sage",placeholder:r("common.placeholder.country",{defaultValue:"Select your country"}),autoComplete:"off"}),a&&$.length>0&&e.jsx("ul",{className:"absolute z-20 mt-1 max-h-60 w-full overflow-auto rounded-md border border-outline-default bg-surface-elevated shadow-lg",children:$.slice(0,50).map(t=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>{x(t.code),C(t.name),_(""),m(!1)},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-surface-hover",children:[e.jsx(ue,{code:t.code}),e.jsx("span",{children:t.name})]})},t.code))}),i.country&&e.jsx("p",{className:"mt-2 text-sm text-destructive",children:i.country})]}),p?.requires_date_of_birth&&e.jsx(ve,{id:"social-dob",value:T,onChange:I,error:i.dateOfBirth,minimumAge:p.minimum_age}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"social-referral",className:"block text-sm font-medium text-foreground mb-1.5",children:r("register.label.referral_code",{defaultValue:"Referral code (optional)"})}),e.jsx("input",{id:"social-referral",type:"text",value:F,onChange:t=>G(t.target.value),className:"appearance-none block w-full p-3 border border-input rounded-md shadow-sm bg-background text-base text-foreground focus:outline-none focus:ring-2 focus:ring-brand-sage"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"flex items-start gap-3 text-sm text-foreground",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:t=>
1Y(t.target.checked),className:"mt-1 h-4 w-4 rounded border-input"}),e.jsxs("span",{children:[r("register.label.accept_terms",{defaultValue:"I accept the"})," ",e.jsx(W,{to:"/terms",target:"_blank",className:"font-medium text-primary hover:text-primary/90",children:r("register.link.terms",{defaultValue:"Terms of Use"})})," ",r("common.and",{defaultValue:"and"})," ",e.jsx(W,{to:"/privacy",target:"_blank",className:"font-medium text-primary hover:text-primary/90",children:r("register.link.privacy",{defaultValue:"Privacy Policy"})})]})]}),i.terms&&e.jsx("p",{className:"mt-2 text-sm text-destructive",children:i.terms})]}),e.jsx("button",{type:"submit",disabled:U||X,className:`w-full flex justify-center rounded-md px-4 py-3 font-body text-sm font-semibold text-white hover:opacity-90 disabled:opacity-50 min-h-[44px] ${f==="beef"?"bg-brand-gradient-beef":"bg-brand-gradient-dairy"}`,children:U?e.jsx(Ve,{className:"h-5 w-5 animate-spin"}):r("auth.social.onboarding_submit",{defaultValue:"Create my account"})}),e.jsx("button",{type:"button",onClick:ae,className:"w-full text-center text-sm font-medium text-muted-foreground hover:text-foreground",children:r("common.action.cancel",{defaultValue:"Cancel"})})]})]})]}):null}export{Ie as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.