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

4 lines
36 KiB
JavaScript
Raw Normal View History

import{a as n,j as e}from"./vendor-react-Dkpvlwai.js";import{d as ue,h as ke,g as Se,p as J,a as I,E as Q,C as z,b as W,c as $,f as X,e as H,B as N,D as _e,n as me,o as re,u as Ae,L as Ee,S as b,t as ne}from"./index-jE2AGx2y.js";import{u as oe}from"./users-_nyTUiUz.js";import{T as Te,a as De,b as O,c as B}from"./Tabs-DcqFJUlH.js";import{L as h,I as E}from"./input-CpxrTzwP.js";import{S as ee}from"./Select-Zbef75Fw.js";import{am as Fe,au as Re,a as he,an as se,T as le,av as Pe,aw as Le,ax as xe,L as ae,C as fe,A as qe,e as Ie,P as pe,ay as Ve,az as Ue,aA as ze,aB as Me}from"./vendor-icons-CbmLcMl-.js";import{C as w}from"./checkbox-zOPO199O.js";import{A as ge,a as je}from"./alert-DvTTzGyG.js";import{r as Y}from"./features-DIZYat5y.js";import{o as G,e as ie,s as Oe,b as v}from"./vendor-utils-CDFfoeXY.js";import"./vendor-CAoAb3tF.js";import"./vendor-router-4bycex72.js";import"./vendor-tanstack-BoI3DtL9.js";import"./dropdown-WuZUrg5z.js";const ve=n.forwardRef(({className:s,value:a,onValueChange:t,disabled:r,children:i,...c},d)=>{const o=[];n.Children.forEach(i,l=>{n.isValidElement(l)&&l.type===U&&!l.props.disabled&&o.push(l.props.value)});const x=l=>{if(o.length===0)return;const m=a?o.indexOf(a):-1;let u;switch(l.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}l.preventDefault(),t?.(o[u]),l.currentTarget.querySelectorAll('input[type="radio"]')[u]?.focus()};return e.jsx("div",{ref:d,className:ue("grid gap-2",s),role:"radiogroup",onKeyDown:x,...c,children:n.Children.map(i,l=>{if(n.isValidElement(l)&&l.type===U){const m=l.props.value===a,u=l.props.value===o[0];return n.cloneElement(l,{checked:m,onCheckedChange:()=>t?.(l.props.value),disabled:r||l.props.disabled,tabIndex:m||a===void 0&&u?0:-1})}return l})})});ve.displayName="RadioGroup";const U=n.forwardRef(({className:s,value:a,checked:t,onCheckedChange:r,disabled:i,tabIndex:c,...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:i,tabIndex:c,className:"sr-only",...d}),t&&e.jsx(Fe,{className:"h-2.5 w-2.5 fill-current text-current"})]}));U.displayName="RadioGroupItem";const Be=[{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:"한국어"}],Ge=[{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 He({preferences:s,onChange:a}){const t=c=>{a({...s,language:Array.isArray(c)?c[0]:c})},r=c=>{a({...s,timezone:Array.isArray(c)?c[0]:c})},i=c=>{a({...s,theme:c})};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:Be,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:Ge,value:s.timezone,onChange:r,placeholder:"Sélectionner un fuseau horaire",name:"timezone"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{children:"Thème"}),e.jsxs(ve,{value:s.theme,onValueChange:i,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(U,{value
`)),t("Backup codes copied to clipboard"))},[u,t]),C=n.useCallback(()=>{if(!u?.recovery_codes)return;const f=document.createElement("a"),T=new Blob([u.recovery_codes.join(`
`)],{type:"text/plain"});f.href=URL.createObjectURL(T),f.download="veza-backup-codes.txt",document.body.appendChild(f),f.click(),t("Backup codes downloaded")},[u,t]),L=n.useCallback(()=>{d("totp"),i(2)},[]),k=n.useCallback(()=>{t("SMS method not yet available in this region","info")},[t]);return{step:r,setStep:i,method:c,verificationCode:o,setVerificationCode:x,loading:l,setupData:u,error:g,fetchSetupData:j,handleVerify:_,copyCodes:P,downloadCodes:C,goToStep2Totp:L,handleSmsUnavailable:k}}function ns({onBack:s,onComplete:a}){const{addToast:t}=me(),{step:r,method:i,verificationCode:c,setVerificationCode:d,loading:o,setupData:x,handleVerify:l,copyCodes:m,downloadCodes:u,goToStep2Totp:p,handleSmsUnavailable:g}=rs(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(es,{onBack:s}),r===1&&e.jsx(ss,{onChooseTotp:p,onChooseSms:g}),r===2&&e.jsx(as,{method:i,loading:o,setupData:x,verificationCode:c,onVerificationCodeChange:d,onVerify:l,onCopySecret:y,onSendSmsPlaceholder:()=>t("Code sent to your phone","info")}),r===3&&e.jsx(ts,{setupData:x,onCopy:m,onDownload:u,onComplete:a})]})}const os=()=>{const[s,a]=n.useState(null),[t,r]=n.useState(!0),[i,c]=n.useState(!1),d=async()=>{r(!0);try{const o=await te.getStatus();a(o.enabled)}catch(o){console.error("Failed to fetch 2FA status",o)}finally{r(!1)}};return n.useEffect(()=>{d()},[]),i?e.jsx(z,{className:"border-primary/20 bg-primary/5",children:e.jsx(H,{className:"pt-6",children:e.jsx(ns,{onBack:()=>c(!1),onComplete:()=>{c(!1),d()}})})}):e.jsxs(z,{children:[e.jsxs(W,{children:[e.jsxs($,{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5"}),"Two-Factor Authentication (2FA)"]}),e.jsx(X,{children:"Add an extra layer of security to your account"})]}),e.jsx(H,{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(Ve,{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(Ue,{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:()=>c(!0),children:"Setup 2FA"})]})})]})};function ls(){const{mutationError:s,retryCount:a,maxRetry:t,handleRetry:r,dismissError:i,isChangingPassword:c,currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:l,confirmPassword:m,setConfirmPassword:u,passwordError:p,handleChangePassword:g,isDeleteDialogOpen:y,setIsDeleteDialogOpen:j,isDeletingAccount:_,deletePassword:P,setDeletePassword:C,deleteReason:L,setDeleteReason:k,deleteConfirmText:f,setDeleteConfirmText:T,deleteValidationError:S,setDeleteValidationError:Z,handleDeleteAccount:A,handleExportData:M}=Qe();return e.jsxs("div",{className:"space-y-6",children:[s&&e.jsx(We,{error:s,retryCount:a,maxRetry:t,onRetry:r,onDismiss:i}),e.jsx($e,{currentPassword:d,setCurrentPassword:o,newPassword:x,setNewPassword:l,confirmPassword:m,setConfirmPassword:u,passwordError:p,isChangingPassword:c,onSubmit:g}),e.jsx(os,{}),e.jsx(Xe,