veza/apps/web/dist_verification/assets/SettingsPage-CSSzd1W-.js

4 lines
36 KiB
JavaScript
Raw Normal View History

import{a as n,j as e}from"./vendor-react-yWUy5XPk.js";import{c as ue,h as Se,p as J,n as ke,g as V,i as W,C as z,b as K,d as $,e as X,f as Y,B as N,D as _e,u as me,l as Ae,o as re,v as Ee,L as Te,S as b,w as ne}from"./index-CYK_b1Uz.js";import{u as oe}from"./users-CZ92MzeH.js";import{T as Fe,a as De,b as O,c as G}from"./Tabs-jry2MOtG.js";import{L as h,I as E}from"./input-CGdBHtsQ.js";import{S as ee}from"./Select-DA2I33Xz.js";import{ah as Re,a2 as Pe,e as he,aa as se,i as le,A as Le,aS as qe,at as xe,g as ae,d as pe,b as Ve,a3 as Ie,W as fe,am as Ue,as as ze,u as Me,aT as Oe}from"./vendor-icons-DJFb1Tiw.js";import{C as w}from"./checkbox-DgTIon8S.js";import{A as ge,a as je}from"./alert-FT0GWKW4.js";import{r as Q}from"./features-DItyhINc.js";import{o as H,e as ie,s as Ge,b as v}from"./vendor-utils-DtoSyhX2.js";import"./vendor-CveO81sn.js";import"./vendor-security-DsrNJhpn.js";import"./vendor-router-BNNHboN9.js";import"./vendor-tanstack-kPY9uK0s.js";import"./vendor-http-Cz8wfb0q.js";import"./vendor-motion-B3XPS3Jc.js";import"./vendor-i18n-CMcqpBLz.js";import"./dropdown-CA3EXRNb.js";const ve=n.forwardRef(({className:s,value:a,onValueChange:t,disabled:r,children:l,...i},d)=>{const o=[];n.Children.forEach(l,c=>{n.isValidElement(c)&&c.type===U&&!c.props.disabled&&o.push(c.props.value)});const x=c=>{if(o.length===0)return;const m=a?o.indexOf(a):-1;let u;switch(c.key){case"ArrowDown":case"ArrowRight":u=m===-1?0:(m+1)%o.length;break;case"ArrowUp":case"ArrowLeft":u=m===-1?o.length-1:(m-1+o.length)%o.length;break;default:return}c.preventDefault();const f=o[u];f!==void 0&&t?.(f),c.currentTarget.querySelectorAll('input[type="radio"]')[u]?.focus()};return e.jsx("div",{ref:d,className:ue("grid gap-2",s),role:"radiogroup",onKeyDown:x,...i,children:n.Children.map(l,c=>{if(n.isValidElement(c)&&c.type===U){const m=c.props.value===a,u=c.props.value===o[0];return n.cloneElement(c,{checked:m,onCheckedChange:()=>t?.(c.props.value),disabled:r||c.props.disabled,tabIndex:m||a===void 0&&u?0:-1})}return c})})});ve.displayName="RadioGroup";const U=n.forwardRef(({className:s,value:a,checked:t,onCheckedChange:r,disabled:l,tabIndex:i,...d},o)=>e.jsxs("label",{role:"radio","aria-checked":!!t,className:ue("aspect-square h-4 w-4 rounded-full border border-border text-muted-foreground","ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","cursor-pointer relative inline-flex items-center justify-center",t&&"border-primary text-primary",s),children:[e.jsx("input",{ref:o,type:"radio",value:a,checked:t,onChange:r,disabled:l,tabIndex:i,className:"sr-only",...d}),t&&e.jsx(Re,{className:"h-2.5 w-2.5 fill-current text-current"})]}));U.displayName="RadioGroupItem";const He=[{value:"en",label:"English"},{value:"fr",label:"Français"},{value:"es",label:"Español"},{value:"de",label:"Deutsch"},{value:"it",label:"Italiano"},{value:"pt",label:"Português"},{value:"ru",label:"Русский"},{value:"ja",label:"日本語"},{value:"zh",label:"中文"},{value:"ko",label:"한국어"}],Ye=[{value:"UTC",label:"UTC"},{value:"Europe/Paris",label:"Europe/Paris"},{value:"America/New_York",label:"America/New_York"},{value:"America/Los_Angeles",label:"America/Los_Angeles"},{value:"Asia/Tokyo",label:"Asia/Tokyo"},{value:"Asia/Shanghai",label:"Asia/Shanghai"}];function Be({preferences:s,onChange:a}){const t=i=>{a({...s,language:Array.isArray(i)?i[0]??"":i})},r=i=>{a({...s,timezone:Array.isArray(i)?i[0]??"":i})},l=i=>{a({...s,theme:i})};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"language",children:"Langue"}),e.jsx(ee,{options:He,value:s.language,onChange:t,placeholder:"Sélectionner une langue",name:"language"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{htmlFor:"timezone",children:"Fuseau horaire"}),e.jsx(ee,{options:Ye,value:s.timezone,onChange:r,placeholder:"Sélectionner un fuseau horaire",name:"timezone"})]}),e.jsxs("div",{className:"
`)),t("Backup codes copied to clipboard"))},[u,t]),C=n.useCallback(()=>{if(!u?.recovery_codes)return;const p=document.createElement("a"),T=new Blob([u.recovery_codes.join(`
`)],{type:"text/plain"});p.href=URL.createObjectURL(T),p.download="veza-backup-codes.txt",document.body.appendChild(p),p.click(),t("Backup codes downloaded")},[u,t]),L=n.useCallback(()=>{d("totp"),l(2)},[]),S=n.useCallback(()=>{t("SMS method not yet available in this region","info")},[t]);return{step:r,setStep:l,method:i,verificationCode:o,setVerificationCode:x,loading:c,setupData:u,error:g,fetchSetupData:j,handleVerify:_,copyCodes:P,downloadCodes:C,goToStep2Totp:L,handleSmsUnavailable:S}}function os({onBack:s,onComplete:a}){const{addToast:t}=me(),{step:r,method:l,verificationCode:i,setVerificationCode:d,loading:o,setupData:x,handleVerify:c,copyCodes:m,downloadCodes:u,goToStep2Totp:f,handleSmsUnavailable:g}=ns(s),y=()=>{x&&(navigator.clipboard.writeText(x.secret),t("Secret Key copied"))};return e.jsxs("div",{className:"animate-fadeIn max-w-2xl mx-auto",children:[e.jsx(ss,{onBack:s}),r===1&&e.jsx(as,{onChooseTotp:f,onChooseSms:g}),r===2&&e.jsx(ts,{method:l,loading:o,setupData:x,verificationCode:i,onVerificationCodeChange:d,onVerify:c,onCopySecret:y,onSendSmsPlaceholder:()=>t("Code sent to your phone","info")}),r===3&&e.jsx(rs,{setupData:x,onCopy:m,onDownload:u,onComplete:a})]})}const ls=()=>{const[s,a]=n.useState(null),[t,r]=n.useState(!0),[l,i]=n.useState(!1),d=async()=>{r(!0);try{const o=await te.getStatus();a(o.enabled)}catch(o){Ae.error("Failed to fetch 2FA status",{error:o})}finally{r(!1)}};return n.useEffect(()=>{d()},[]),l?e.jsx(z,{className:"border-primary/20 bg-primary/5",children:e.jsx(Y,{className:"pt-6",children:e.jsx(os,{onBack:()=>i(!1),onComplete:()=>{i(!1),d()}})})}):e.jsxs(z,{children:[e.jsxs(K,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"h-5 w-5"}),"Two-Factor Authentication (2FA)"]}),e.jsx(X,{children:"Add an extra layer of security to your account"})]}),e.jsx(Y,{children:t?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ae,{className:"h-4 w-4 animate-spin"})," Checking 2FA status..."]}):s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-success/10 border border-success/20 rounded-lg",children:[e.jsx(Ue,{className:"h-8 w-8 text-success"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-foreground",children:"2FA is enabled"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Your account is protected by an additional security layer."})]})]}),e.jsx(N,{variant:"outline",className:"text-destructive hover:bg-destructive/10 hover:text-destructive border-destructive/20",onClick:()=>{confirm("Are you sure you want to disable 2FA? This will make your account less secure.")&&a(!1)},children:"Disable 2FA"})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-orange-500/5 border border-orange-500/10 rounded-lg",children:[e.jsx(ze,{className:"h-8 w-8 text-orange-500"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-foreground",children:"2FA is not enabled"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"We highly recommend enabling 2FA to protect your music and assets."})]})]}),e.jsx(N,{onClick:()=>i(!0),children:"Setup 2FA"})]})})]})};function is(){const{mutationError:s,retryCount:a,maxRetry:t,handleRetry:r,dismissError:l,isChangingPassword:i,currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:c,confirmPassword:m,setConfirmPassword:u,passwordError:f,handleChangePassword:g,isDeleteDialogOpen:y,setIsDeleteDialogOpen:j,isDeletingAccount:_,deletePassword:P,setDeletePassword:C,deleteReason:L,setDeleteReason:S,deleteConfirmText:p,setDeleteConfirmText:T,deleteValidationError:k,setDeleteValidationError:Z,handleDeleteAccount:A,handleExportData:M}=Ke();return e.jsxs("div",{className:"space-y-6",children:[s&&e.jsx($e,{error:s,retryCount:a,maxRetry:t,onRetry:r,onDismiss:l}),e.jsx(Xe,{currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:c,confirmPassword:m,setConfirmPassword:u,passwordError:f,isChangingPassword:i,onSubmit:g}),e.jsx(ls,{}),e.jsx(