PageSourceSearch

https://www.elite.se/dist/client/assets/RewardRedeemModal.component-DTcxaBqb.js

js elite.se collected 2026-10-02 03:46:11 UTC 5,251 bytes, 1 lines download raw bytes

1import{r as e}from"./chunk-BtN6Uazr.js";import{t}from"./react-B5sKNx7D.js";import{n}from"./redux-toolkit.modern-DxeNC2Ic.js";import{G as r,In as i,J as a,X as o,Y as s,vn as c}from"./entry-client-DrEVLKbw.js";import{t as l}from"./useAppDispatch-j4Ju7O7A.js";import{t as u}from"./useAppSelector-tBVwsT2U.js";import{t as d}from"./ApiBase-JGqbe2rI.js";import{t as f}from"./modal.component-BrwWPyAC.js";import{t as p}from"./useMemberPoints-BvE9AY6q.js";var m=e(t()),h=class extends d{constructor(e,t=``,n=``,r=()=>{}){super(e,t,n,r)}async postRedemption(e,t){let n=this.endpoints.reward.redeemReward.replace(this.endpoints.placeholders.rewardCode,encodeURIComponent(e));await this.fetchWithAntiforgery(n,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({points:t})},`Rewards postRedemption`,!0)}},g=n(`rewards/redeemReward`,async({rewardCode:e,points:t},{getState:n,dispatch:i})=>{let{shared:l}=n();if(!l.endpoints)throw Error(`API endpoints not configured`);if(!l.jwtToken)throw Error(`JWT token is required for reward redemption`);if(!l.antiforgeryToken)throw Error(`Antiforgery token is required`);i(o(c.Loading)),i(a(null));let u=new h(l.endpoints,l.jwtToken,l.antiforgeryToken,e=>i(r(e)));try{return await u.postRedemption(e,t),i(o(c.Idle)),i(s(!0)),{success:!0}}catch(e){throw i(o(c.Failed)),i(a(e instanceof Error?e.message:`Failed to redeem reward`)),e}}),_=i();function v(e,t,n){let r=typeof e==`string`?parseInt(e,10):e;if(Number.isNaN(r))return`${e} ${n}`;let i=t||`sv-SE`;return`${r.toLocaleString(i)} ${n}`}var y=({item:e,redeemPointsText:t,addRewardConfirmationText:n,addRewardErrorText:r,loadingRewardApiText:i,showRedeemButton:a,isOpen:o,onClose:s,modalTrigger:d})=>{let{currentUser:h,sharedI18n:y,culture:b}=u(e=>e.shared),{status:x,error:S,redemptionSuccess:C}=u(e=>e.rewards),w=l(),T=p(o),[E,D]=(0,m.useState)(null),[O,k]=(0,m.useState)(null),A=(0,m.useId)().replace(/:/g,``),j=E?e.rewardCategories.find(e=>e.code===E):null,M=j?parseInt(j.points??``,10):null,N=!(a&&h?.loggedIn),P=!N&&j!==null&&!Number.isNaN(M??NaN)&&(M??0)<=T;(0,m.useEffect)(()=>{x===c.Loading&&k(null)},[x]);let F=(0,m.useCallback)(e=>{e.preventDefault(),!(!P||!j||Number.isNaN(M??NaN))&&k({code:j.code??``,points:M})},[P,j,M]),I=(0,m.useCallback)(()=>{O&&w(g({rewardCode:O.code,points:O.points}))},[O,w]),L=(0,m.useCallback)(()=>{k(null)},[]),R=x!==c.Loading&&x!==c.Failed&&!(C&&x===c.Idle&&!S)&&!O;return(0,_.jsx)(f,{className:`reward-redeem-modal`,isVisible:o,onHandleClose:s,modalTrigger:d,usePortal:!0,aside:!0,modalOverlayCloses:!0,closeButtonVisible:!1,closeButtonText:y?.sharedResource?.closeButton??``,content:(0,_.jsxs)(_.Fragment,{children:[e.imageMarkup?(0,_.jsx)(`div`,{className:`reward-redeem-modal__image`,dangerouslySetInnerHTML:{__html:e.imageMarkup}}):null,(0,_.jsxs)(`div`,{className:`reward-redeem-modal__content`,children:[(0,_.jsx)(`h4`,{className:`reward-redeem-modal__title`,children:e.header}),e.text?(0,_.jsx)(`div`,{className:`reward-redeem-modal__text`,dangerouslySetInnerHTML:{__html:e.text}}):null,x===c.Loading&&(0,_.jsxs)(`div`,{className:`reward-redeem-modal__loader`,"data-loading":`true`,children:[(0,_.jsx)(`svg`,{width:`24`,height:`24`,"aria-hidden":`true`,children:(0,_.jsx)(`use`,{href:`#icon-loader`})}),(0,_.jsx)(`p`,{children:i})]}),C&&x===c.Idle&&!S&&(0,_.jsx)(`p`,{className:`reward-redeem-modal__success`,children:n}),x===c.Failed&&(0,_.jsx)(`p`,{className:`reward-redeem-modal__error`,children:S??r}),O&&t&&(0,_.jsxs)(`div`,{className:`reward-redeem-modal__confirm`,children:[(0,_.jsx)(`p`,{className:`reward-redeem-modal__confirm-message`,children:t}),(0,_.jsxs)(`div`,{className:`reward-redeem-modal__button-wrapper reward-redeem-modal__confirm-actions`,children:[(0,_.jsx)(`button`,{type:`button`,className:`cta-button cta-button__secondary`,onClick:L,children:y?.sharedResource?.cancel??``}),(0,_.jsx)(`button`,{type:`button`,className:`cta-button cta-button__member-primary`,onClick:I,children:y?.sharedResource?.order??``})]})]}),R&&(0,_.jsxs)(`form`,{id:A,className:`reward-redeem-modal__form`,onSubmit:F,noValidate:!0,children:[(0,_.jsxs)(`fieldset`,{className:`reward-redeem-modal__fieldset`,children:[(0,_.jsx)(`legend`,{className:`reward-redeem-modal__legend`,children:e.title}),(0,_.jsx)(`ul`,{className:`reward-redeem-modal__options`,"aria-label":e.title,children:e.rewardCategories.map(e=>{let t=parseInt(e.points??``,10),n=!Number.isNaN(t)&&t>T||N,r=`${A}-${e.code}`;return(0,_.jsxs)(`li`,{className:`reward-redeem-modal__option`,children:[(0,_.jsx)(`input`,{type:`radio`,id:r,name:`rewardOption`,value:e.code,className:`reward-redeem-modal__option-radio`,disabled:n,checked:E===e.code,onChange:()=>D(e.code??null),"aria-describedby":`${r}-points`}),(0,_.jsx)(`label`,{htmlFor:r,className:`reward-redeem-modal__option-label`,children:e.name}),(0,_.jsx)(`span`,{id:`${r}
1-points`,className:`reward-redeem-modal__option-points`,children:v(e.points??``,b,y?.currencyResource?.points??``)})]},e.code)})})]}),(0,_.jsx)(`div`,{className:`reward-redeem-modal__button-wrapper`,children:(0,_.jsx)(`button`,{type:`submit`,className:`cta-button__small cta-button__member-primary`,disabled:!P,"aria-disabled":!P,children:y?.sharedResource?.order??``})})]})]})]})})};export{y 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.