PageSourceSearch

https://vidapeps.com/assets/VidaGrants-DYBAz2tH.js

js vidapeps.com collected 2026-10-04 08:10:04 UTC 10,275 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-query-CniT1WJL.js";import{u as ae,r,L as _}from"./vendor-react-69GsFwrV.js";import{f as O,u as se,F as re,G as j,I as L,e1 as ne,cZ as ie,t as Y,V as oe,bQ as de,m as le,e2 as ce,e3 as me}from"./index-KjAD5lCC.js";import{a as ue,b as xe}from"./api-BP6hRV2j.js";import{S as he,a5 as pe,ac as ge,h as fe}from"./vendor-ui-Ad3ANzF6.js";import"./vendor-forms-q6h4WU-p.js";const W=[2500,5e3,1e4,25e3,5e4],be=2500,ye=5e4;function Ne(a){return`$${(a/100).toFixed(0)}`}function ve({valueCents:a,onChange:n,customText:u,onCustomTextChange:l}){const h=a!=null&&W.includes(a)&&u==="";return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:grid-cols-5",children:W.map(i=>{const o=h&&a===i;return e.jsx("button",{type:"button","aria-pressed":o,onClick:()=>{l(""),n(i)},"data-testid":`grant-amount-${i}`,className:O("rounded-card border px-3 py-2.5 text-base font-semibold tabular-nums transition-colors",o?"border-vida-gold-500 bg-vida-gold-soft text-vida-gold-700 ring-1 ring-vida-gold-500":"border-card-border bg-card text-ink hover:border-vida-gold-500/50"),children:Ne(i)},i)})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"grant-custom-amount",className:"text-sm font-medium text-ink",children:"Or enter a custom amount"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-base text-ink-3","aria-hidden":"true",children:"$"}),e.jsx("input",{id:"grant-custom-amount",type:"text",inputMode:"numeric",placeholder:"25 to 500",value:u,onChange:i=>{const o=i.target.value.replace(/[^\d]/g,"");if(l(o),o===""){n(null);return}n(Number(o)*100)},"data-testid":"grant-amount-custom",className:O("w-full rounded-card border bg-card py-2.5 pl-7 pr-3 text-base text-ink tabular-nums","placeholder:text-ink-3 focus:border-vida-gold-500 focus:outline-none focus:ring-1 focus:ring-vida-gold-500",u!==""&&!G(a)?"border-amber/50":"border-card-border")})]}),u!==""&&!G(a)&&e.jsx("p",{className:"text-xs text-amber",children:"Enter a whole dollar amount between $25 and $500."})]})]})}function G(a){return a!=null&&Number.isInteger(a)&&a>=be&&a<=ye&&a%100===0}const R=280;function Ee(){const[,a]=ae(),{user:n,isAuthenticated:u}=se(),{toast:l}=le(),[h,i]=r.useState(1e4),[o,B]=r.useState(""),[k,D]=r.useState("purchaser"),[C,K]=r.useState(""),[w,U]=r.useState(""),[p,X]=r.useState(""),[c,V]=r.useState(null),T=r.useRef(null),[M,g]=r.useState(null),[q,$]=r.useState(!1),[A,z]=r.useState(!1),{data:F}=ue(u),S=xe(),x=r.useMemo(()=>(F??[]).slice().sort((t,s)=>t.sortOrder-s.sortOrder),[F]);r.useEffect(()=>{c===null&&x.length>0&&V(x[0].key)},[c,x]),r.useEffect(()=>{$(!1),g(null)},[c]);const f=x.find(t=>t.key===c)??null,v=!!f&&f.checkoutMode==="embedded_card"&&!!f.clientConfig,b=k==="recipient",y=G(h),I=!b||/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(w.trim())&&p.length<=R,H=y&&I&&!!c&&!S.isPending&&!A,N=h??0,J=(t,s)=>({valueCents:N,deliverTo:k,railKey:c,...b?{recipientEmail:w.trim(),...C.trim()?{recipientName:C.trim()}:{},...p.trim()?{giftMessage:p.trim()}:{}}:{},...t?{paymentToken:t}:{},...s?{verificationToken:s}:{}}),P=(t,s)=>{S.mutate(J(t,s),{onSuccess:m=>Q(m),onError:m=>{const d=m;if(v&&d.status===402){g(d.data?.error??"Your card was declined. Please try another card.");return}l({title:"Couldn't complete purchase",description:d.data?.error??d.message??"Please try again.",variant:"destructive"})}})},Q=async t=>{const s=t.payment,m=()=>a(`/order-confirmation/${t.id}`);if(s?.status==="confirming"){m();return}const d=s?.razorpay;if(d?.orderId&&d?.keyId){try{const E=await ce({handle:d,document:{id:t.id,orderNumber:t.orderNumber},prefill:{email:n?.email??"",name:`${n?.firstName??""} ${n?.lastName??""}`.trim()}});await fetch("/api/payments/razorpay/verify",{method:"POST",headers:{"content-type":"application/json"},credentials:"include",body:JSON.stringify(E)})}catch(E){E instanceof me||l({title:"Payment not completed",description:"You can finish paying from your order page.",variant:"destructive"})}m();return}if(s?.paymentUrl){window.location.assign(s.paymentUrl);return}m()},Z=async()=>
1{if(!y){l({title:"Choose an amount between $25 and $500",variant:"destructive"});return}if(!I){l({title:"Add a valid recipient email",variant:"destructive"});return}if(v){g(null),z(!0);const t=await T.current?.tokenize();if(z(!1),!t)return;P(t.paymentToken,t.verificationToken);return}P()},ee=t=>{g(null),P(t.paymentToken,t.verificationToken)},te=x;return e.jsxs(re,{width:"narrow",padY:!0,className:"space-y-5",children:[e.jsxs("header",{className:"text-center",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-pill bg-vida-gold-soft px-3 py-1 text-caption font-semibold text-vida-gold-700",children:[e.jsx(he,{className:"size-3.5","aria-hidden":"true"})," VidaGrants"]}),e.jsx("h1",{className:"mt-3 font-display text-t1 text-ink",children:"VidaGrants"}),e.jsx("p",{className:"mt-1 text-ink-2",children:"Prepaid VidaPeps credit for future research orders."}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-sm text-ink-3",children:"Give flexible VidaPeps credit without guessing what they need. Choose an amount, send a unique VidaCode, and let them apply it to a future order."})]}),e.jsxs(j,{children:[e.jsxs("h2",{className:"mb-3 flex items-center gap-1.5 text-sm font-semibold text-ink",children:[e.jsx(pe,{className:"size-4 text-vida-gold-700","aria-hidden":"true"})," Choose an amount"]}),e.jsx(ve,{valueCents:h,onChange:i,customText:o,onCustomTextChange:B})]}),e.jsxs(j,{children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold text-ink",children:"Who is this for?"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[{key:"purchaser",label:"For myself",sub:"Added to your VidaCredit"},{key:"recipient",label:"A gift",sub:"Send a VidaCode by email"}].map(t=>{const s=k===t.key;return e.jsxs("button",{type:"button","aria-pressed":s,onClick:()=>D(t.key),"data-testid":`grant-deliver-${t.key}`,className:`rounded-card border p-3 text-left transition-colors ${s?"border-vida-gold-500 bg-vida-gold-soft ring-1 ring-vida-gold-500":"border-card-border bg-card hover:border-vida-gold-500/50"}`,children:[e.jsx("span",{className:"block text-sm font-semibold text-ink",children:t.label}),e.jsx("span",{className:"block text-xs text-ink-3",children:t.sub})]},t.key)})}),b&&e.jsxs("div",{className:"mt-4 space-y-3","data-testid":"grant-gift-fields",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"grant-recipient-name",className:"text-sm font-medium text-ink",children:"Recipient name (optional)"}),e.jsx(L,{id:"grant-recipient-name",value:C,onChange:t=>K(t.target.value),placeholder:"Their name","data-testid":"grant-recipient-name"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"grant-recipient-email",className:"text-sm font-medium text-ink",children:"Recipient email"}),e.jsx(L,{id:"grant-recipient-email",type:"email",inputMode:"email",value:w,onChange:t=>U(t.target.value),placeholder:"[email protected]","data-testid":"grant-recipient-email"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{htmlFor:"grant-gift-message",className:"text-sm font-medium text-ink",children:"Message (optional)"}),e.jsx("textarea",{id:"grant-gift-message",value:p,maxLength:R,onChange:t=>X(t.target.value),rows:3,placeholder:"Add a short note","data-testid":"grant-gift-message",className:"w-full rounded-card border border-card-border bg-card px-3 py-2.5 text-base text-ink placeholder:text-ink-3 focus:border-vida-gold-500 focus:outline-none focus:ring-1 focus:ring-vida-gold-500"}),e.jsxs("p",{className:"text-right text-xs text-ink-3 tabular-nums",children:[p.length,"/",R]})]})]})]}),e.jsxs(j,{children:[e.jsx("h2",{className:"mb-1 text-sm font-semibold text-ink",children:"Payment"}),e.jsx("p",{className:"mb-3 text-caption text-ink-3",children:"Grants are sold at full face value. Choose how you'd like to pay."}),x.length>0?e.jsx(ne,{methods:te,listPriceCents:N,value:c,onChange:V}):e.jsx("p",{className:"text-sm text-ink-3",children:"No payment methods are available right now."}),v&&f?.clientConfig&&e.jsxs("div",{className:"mt-4",children:[e.jsx(ie,{ref:T,config:f.clientConfig,amountCents:Math.max(N,1),contact:{firstName:n?.firstName??"",lastName:n?.lastName??"",email:n?.email??""},onError:g,onReady:$,onWalletToken:ee}),M&&e.jsx("p",{className:"mt-2 text-xs text-danger","data-testid":"grant-card-error",children:M}),e.jsx("p",{className:"mt-2 text-xs text-ink-3",children:"Your card 
1is entered securely on this page; we never see or store your card number."})]})]}),e.jsxs(j,{children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-ink-2",children:[b?"Gift value":"Grant value",y?"":" (choose $25 to $500)"]}),e.jsx("span",{className:"font-mono text-base font-bold text-ink tabular-nums",children:Y(y?N:0)})]}),e.jsx(oe,{block:!0,className:"mt-4",onClick:Z,disabled:!H||v&&!q,"data-testid":"grant-place-order",children:S.isPending||A?"Processing...":`Buy VidaGrant ${y?Y(N):""}`.trim()}),e.jsxs("p",{className:"mt-3 flex items-start gap-1.5 text-xs text-ink-3",children:[e.jsx(ge,{className:"mt-0.5 size-3.5 shrink-0 text-vida-green-700","aria-hidden":"true"}),"VidaCredit is VidaPeps store credit for research supplies. It has no cash value and applies at checkout once redeemed."]}),e.jsxs("p",{className:"mt-1.5 flex items-start gap-1.5 text-xs text-ink-3",children:[e.jsx(fe,{className:"mt-0.5 size-3.5 shrink-0 text-ink-3","aria-hidden":"true"}),b?"We'll email the VidaCode to your recipient once payment clears.":"Your VidaCode appears on your order page and is emailed to you once payment clears."]}),e.jsx("p",{className:"mt-3 text-center text-caption text-ink-3",children:de(typeof window>"u"?"":window.location.hostname).surfaceId==="store"?e.jsxs(e.Fragment,{children:["Manage grants you've bought in your"," ",e.jsx(_,{href:"/account/orders",className:"font-medium text-primary hover:underline",children:"account"}),"."]}):e.jsxs(e.Fragment,{children:["Track credit from grants in your"," ",e.jsx(_,{href:"/wallet",className:"font-medium text-primary hover:underline",children:"wallet"}),"."]})})]})]})}export{Ee 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.