1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1831],{33591:function(e,t,n){(window.__NEXT_P=window.__NEXT_P||[]).push(["/gift/redeem",function(){return n(83930)}])},83930:function(e,t,n){"use strict";n.r(t),n.d(t,{__N_SSG:function(){return h},default:function(){return f}});var a,i=n(85893),s=n(11163),r=n(79324),c=n(19452),o=n(47568),l=n(97582),u=n(67294),d={not_found:"We don't recognize this gift link. Please check that you copied all of it.",already_redeemed:"This gift link has already been used.",in_progress:"This gift link is being redeemed right now. Try again in a few minutes.",batch_closed:"All the subscriptions in this gift have been claimed.",batch_unpaid:"This gift isn\u2019t active yet. Please check back shortly.",expired:"This gift link has expired."},m=function(e){var t=e.code,n=(0,u.useState)({phase:"checking"}),s=n[0],r=n[1],c=(0,u.useState)(""),m=c[0],h=c[1],f=(0,u.useState)(""),b=f[0],p=f[1],g=(0,u.useState)(""),_=g[0],v=g[1],x=(0,u.useState)(!1),N=x[0],j=x[1],y=(0,u.useState)(null),G=y[0],R=y[1],w=(0,u.useState)(null),F=w[0],k=w[1],C=(0,u.useState)(null!==t&&void 0!==t?t:null),T=C[0],S=C[1],X=(0,u.useState)(""),E=X[0],P=X[1];(0,u.useEffect)((function(){t&&S(t)}),[t]),(0,u.useEffect)((function(){if(T){var e=!1;return r({phase:"checking"}),fetch("/api/gift/validate-code?code=".concat(encodeURIComponent(T))).then((function(e){return e.json()})).then((function(t){var n;e||r(t.valid?{phase:"usable",purchaseIdentifier:t.purchaseIdentifier}:{phase:"unusable",reason:null!==(n=t.reason)&&void 0!==n?n:"not_found"})})).catch((function(){e||r({phase:"unusable",reason:"unknown"})})),function(){e=!0}}r({phase:"entry"})}),[T]);var q,O=function(){var e=(0,o.Z)((function(e){var t,n,a,i,s;return(0,l.__generator)(this,(function(c){switch(c.label){case 0:e.preventDefault(),j(!0),R(null),c.label=1;case 1:return c.trys.push([1,4,5,6]),[4,fetch("/api/gift/redeem",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:T,firstName:m,lastName:b,email:_})})];case 2:return[4,(t=c.sent()).json()];case 3:if(n=c.sent(),!t.ok){if(n.reason)return r({phase:"unusable",reason:n.reason}),[2];throw new Error(null!==(a=n.error)&&void 0!==a?a:"Something went wrong. Please try again.")}return k({needsPassword:Boolean(n.needsPassword)}),[3,6];case 4:return i=c.sent(),R(null!==(s=i.message)&&void 0!==s?s:"An unexpected error occurred."),[3,6];case 5:return j(!1),[7];case 6:return[2]}}
1))}));return function(t){return e.apply(this,arguments)}}();return F?(0,i.jsxs)("div",{className:"GiftRedeemForm",children:[(0,i.jsx)("h1",{className:"GiftRedeemForm__title itc-cushing",children:"You\u2019re all set"}),(0,i.jsx)("p",{className:"GiftRedeemForm__lede graebenbach",children:F.needsPassword?"Your Tablet subscription is active. Check your email for a link to set your password \u2014 it should arrive within a few minutes.":"Your Tablet subscription is active. Sign in with your existing account to start reading."})]}):"checking"===s.phase?(0,i.jsx)("div",{className:"GiftRedeemForm",children:(0,i.jsx)("p",{className:"GiftRedeemForm__lede graebenbach",children:"Checking your gift code\u2026"})}):"entry"===s.phase?(0,i.jsxs)("form",{className:"GiftRedeemForm",onSubmit:function(e){e.preventDefault();var t=E.trim();t&&S(t)},children:[(0,i.jsx)("h1",{className:"GiftRedeemForm__title itc-cushing",children:"Claim your Tablet subscription"}),(0,i.jsx)("p",{className:"GiftRedeemForm__lede graebenbach",children:"Enter the gift code you were sent to get started."}),(0,i.jsx)("input",{className:"GiftRedeemForm__input GiftRedeemForm__input--code graebenbach",placeholder:"XXXX-XXXX-XXXX","aria-label":"Gift code",value:E,onChange:function(e){return P(e.target.value)},autoComplete:"off",autoCapitalize:"characters",spellCheck:!1,required:!0}),(0,i.jsx)("button",{type:"submit",className:"GiftRedeemForm__submit-btn graebenbach",children:"Continue"})]}):"unusable"===s.phase?(0,i.jsxs)("div",{className:"GiftRedeemForm",children:[(0,i.jsx)("h1",{className:"GiftRedeemForm__title itc-cushing",children:"Gift subscription"}),(0,i.jsx)("p",{className:"GiftRedeemForm__lede graebenbach",children:(q=s.reason,null!==(a=d[q])&&void 0!==a?a:"This gift link can\u2019t be used.")}),(0,i.jsx)("button",{type:"button",className:"GiftRedeemForm__link-btn graebenbach",onClick:function(){S(null),P("")},children:"Try a different code"})]}):(0,i.jsxs)("form",{className:"GiftRedeemForm",onSubmit:O,children:[(0,i.jsx)("h1",{className:"GiftRedeemForm__title itc-cushing",children:"Claim your Tablet subscription"}),(0,i.jsx)("p",{className:"GiftRedeemForm__lede graebenbach",children:"Someone has gifted you a year of Tablet. Tell us where to send it."}),(0,i.jsxs)("fieldset",{className:"GiftRedeemForm__fieldset",children:[(0,i.jsx)("legend",{className:"GiftRedeemForm__legend graebenbach",children:"Your details"}),(0,i.jsxs)("div",{className:"GiftRedeemForm__row",children:[(0,i.jsx)("input",{className:"GiftRedeemForm__input graebenbach",placeholder:"First name","aria-label":"First name",value:m,onChange:function(e){return h(e.target.value)},required:!0}),(0,i.jsx)("input",{className:"GiftRedeemForm__input graebenbach",placeholder:"Last name","aria-label":"Last name",value:b,onChange:function(e){return p(e.target.value)},required:!0})]}),(0,i.jsx)("input",{className:"GiftRedeemForm__input graebenbach",type:"email",placeholder:"Email address","aria-label":"Email address",value:_,onChange:function(e){return v(e.target.value)},required:!0})]}),G&&(0,i.jsx)("p",{className:"GiftRedeemForm__error graebenbach",children:G}),(0,i.jsx)("button",{type:"submit",className:"GiftRedeemForm__submit-btn graebenbach",disabled:N,children:N?"Claiming\u2026":"Claim my subscription"})]})},h=!0,f=function(){var e=(0,s.useRouter)().query,t="string"===typeof e.code?e.code:void 0;return(0,i.jsxs)("div",{className:"GiftRedeemView view content-with-nav",children:[(0,i.jsx)(c.T3,{title:"Claim your gift subscription",description:"Redeem your gifted Tablet Magazine subscription."}),(0,i.jsx)(r.Z,{}),(0,i.jsx)("div",{className:"content-padding-x content-height pt6 md:pt8 flex flex-col items-center",children:(0,i.jsx)("div",{className:"w100",style:{maxWidth:"640px",paddingBottom:"80px"},children:(0,i.jsx)(m,{code:t})})})]})}}},function(e){e.O(0,[1354,9452,3904,9774,2888,179],(function(){return t=33591,e(e.s=t);var t}));var t=e.O();_N_E=t}]); 2//# sourceMappingURL=redeem-d3ba3352e4ae2c43.js.map
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.