SetupPage-hUHebIlA.js 5.4 KB

1
  1. import{i as e}from"./chunk-aKtaBQYM.js";import{C as t,D as n,a as r,w as i}from"./client-BdOyoZJz.js";import{t as a}from"./useMutation-qh3Iyscy.js";import{t as o}from"./info-DcT0QU8O.js";import{n as s}from"./ToastContext-VFOrCCoA.js";import{Vn as c,vt as l,yt as u}from"./index-BoVbGTav.js";var d=e(n(),1),f=t();function p(){let e=c(),{t}=i(),{showToast:n}=s(),{mode:p}=l(),{refreshAuth:m}=u(),[h,g]=(0,d.useState)(!1),[_,v]=(0,d.useState)(``),[y,b]=(0,d.useState)(``),[x,S]=(0,d.useState)(``),C=a({mutationFn:()=>r.setupAuth({auth_enabled:h,admin_username:h?_:void 0,admin_password:h?y:void 0}),onSuccess:async r=>{await m(),r.auth_enabled?r.admin_created?(n(t(`setup.toast.authEnabledAdminCreated`)),e(`/login`)):(n(t(`setup.toast.authEnabledExistingAdmins`)),e(`/login`)):(n(t(`setup.toast.setupCompleted`)),e(`/`))},onError:e=>{n(e.message,`error`)}});return(0,f.jsx)(`div`,{className:`min-h-screen flex items-center justify-center bg-bambu-dark p-4`,children:(0,f.jsxs)(`div`,{className:`max-w-md w-full space-y-8 p-8 bg-gradient-to-br from-bambu-card to-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary shadow-lg`,children:[(0,f.jsxs)(`div`,{className:`text-center`,children:[(0,f.jsx)(`div`,{className:`flex items-center justify-center mb-6`,children:(0,f.jsx)(`img`,{src:p===`dark`?`/img/bambuddy_logo_dark_transparent.png`:`/img/bambuddy_logo_light.png`,alt:`Bambuddy`,className:`h-16`})}),(0,f.jsx)(`h2`,{className:`text-3xl font-bold text-white`,children:t(`setup.title`)}),(0,f.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray`,children:t(`setup.subtitle`)})]}),(0,f.jsxs)(`form`,{className:`mt-8 space-y-6`,onSubmit:e=>{if(e.preventDefault(),h&&(_||y)){if(!_||!y){n(t(`setup.toast.enterBothCredentials`),`error`);return}if(y!==x){n(t(`setup.toast.passwordsDoNotMatch`),`error`);return}if(y.length<6){n(t(`setup.toast.passwordTooShort`),`error`);return}}C.mutate()},children:[(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsxs)(`div`,{className:`flex items-center p-4 bg-bambu-dark-secondary/50 rounded-lg border border-bambu-dark-tertiary`,children:[(0,f.jsx)(`input`,{id:`auth-enabled`,type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`h-4 w-4 text-bambu-green focus:ring-bambu-green border-bambu-dark-tertiary rounded bg-bambu-dark-secondary`}),(0,f.jsx)(`label`,{htmlFor:`auth-enabled`,className:`ml-3 block text-sm font-medium text-white`,children:t(`setup.enableAuth`)})]}),h&&(0,f.jsxs)(`div`,{className:`space-y-4 mt-4`,children:[(0,f.jsx)(`div`,{className:`p-3 bg-bambu-dark-secondary/50 border border-bambu-dark-tertiary rounded-lg`,children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(o,{className:`w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0`}),(0,f.jsxs)(`div`,{className:`text-sm text-bambu-gray`,children:[(0,f.jsx)(`p`,{className:`text-white font-medium mb-1`,children:t(`setup.adminAccount`)}),(0,f.jsx)(`p`,{children:t(`setup.adminAccountDesc`)})]})]})}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-username`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminUsername`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-username`,type:`text`,value:_,onChange:e=>v(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminUsernamePlaceholder`),autoComplete:`username`})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsxs)(`label`,{htmlFor:`admin-password`,className:`block text-sm font-medium text-white mb-2`,children:[t(`setup.adminPassword`),` `,(0,f.jsx)(`span`,{className:`text-bambu-gray text-xs`,children:t(`setup.optionalIfAdminExists`)})]}),(0,f.jsx)(`input`,{id:`admin-password`,type:`password`,value:y,onChange:e=>b(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.adminPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]}),y&&(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`confirm-password`,className:`block text-sm font-medium text-white mb-2`,children:t(`setup.confirmPassword`)}),(0,f.jsx)(`input`,{id:`confirm-password`,type:`password`,value:x,onChange:e=>S(e.target.value),className:`block w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors`,placeholder:t(`setup.confirmPasswordPlaceholder`),minLength:6,autoComplete:`new-password`})]})]})]}),(0,f.jsx)(`div`,{children:(0,f.jsx)(`button`,{type:`submit`,disabled:C.isPending,className:`w-full flex justify-center py-3 px-4 bg-bambu-green hover:bg-bambu-green-light text-white font-medium rounded-lg shadow-lg shadow-bambu-green/20 hover:shadow-bambu-green/30 focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:ring-offset-2 focus:ring-offset-bambu-dark-secondary transition-all disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-bambu-green`,children:C.isPending?t(`setup.settingUp`):t(`setup.completeSetup`)})})]})]})})}export{p as SetupPage};