PageSourceSearch

https://snapshot9.ai/assets/InvitationAccept-DSwQnd6A.js

js snapshot9.ai collected 2026-10-05 14:41:37 UTC 11,218 bytes, 1 lines download raw bytes

1import{u as e,e as s,q as a,j as t,Y as r}from"./index-BzykBEZi.js";import{h as l,b as i,u as n,r as o}from"./react-vendor-MSAyDDoi.js";import{f as d}from"./phoneValidation-CiHCDO_9.js";import{a as c,A as m,l as x,o as u,E as p,m as h,C as g}from"./icons-vendor-DZcQ4_Wo.js";import"./auth-vendor-p9lNoiyd.js";import"./stripe-vendor-D4jxSIHn.js";function b(){var b,f;const{token:y}=l(),j=i();n();const{isAuthenticated:N,dbUser:v}=e(),w=s(),[P,C]=o.useState(null),[k,S]=o.useState(null),[A,q]=o.useState(!0),[E,F]=o.useState(!1),[D,I]=o.useState(null),[L,U]=o.useState(!1),[Y,z]=o.useState(!1),[T,J]=o.useState({password:"",confirmPassword:"",firstName:"",lastName:"",title:"",phone:""}),[M,G]=o.useState({});o.useEffect(()=>{y&&O()},[y]);const O=async()=>{q(!0),I(null);try{const e=await a.get(`/invitations/${y}/validate`);if(e.data.success){if(C(e.data.invitation),S(e.data.organization),e.data.invitation.email){const s=e.data.invitation.email.split("@")[0].split(".");s.length>=2&&J(e=>({...e,firstName:s[0].charAt(0).toUpperCase()+s[0].slice(1),lastName:s[1].charAt(0).toUpperCase()+s[1].slice(1)}))}}else I(e.data.error||"Invalid invitation token")}catch(e){I(e.message||"Failed to validate invitation")}finally{q(!1)}},R=e=>{const{name:s,value:a}=e.target;let t=a;"phone"===s&&(t=d(a)),J(e=>({...e,[s]:t})),M[s]&&G(e=>{const a={...e};return delete a[s],a})};if(A)return t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-primary-600 mx-auto mb-4"}),t.jsx("p",{className:"text-gray-600",children:"Validating invitation..."})]})});if(D&&!P)return t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center p-4",children:t.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-8 max-w-md w-full text-center",children:[t.jsx(c,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),t.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Invalid Invitation"}),t.jsx("p",{className:"text-gray-600 mb-6",children:D}),t.jsx("button",{onClick:()=>j("/"),className:"px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition",children:"Go to Home"})]})});if(N&&v){const e=()=>"superadmin"===v.role?"/admin/organizations":"admin"===v.role?"/admin/dashboard":"manager"===v.role?"/manager-dashboard":"/input";return t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center p-4",children:t.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-8 max-w-md w-full text-center",children:[t.jsx(m,{className:"w-16 h-16 text-yellow-500 mx-auto mb-4"}),t.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Already Logged In"}),t.jsxs("p",{className:"text-gray-600 mb-6",children:["You are currently logged in as ",v.email,". To accept this invitation, please log out first."]}),t.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[t.jsx("button",{onClick:()=>j(e()),className:"flex-1 px-6 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 transition",children:"Go to Dashboard"}),t.jsx("button",{onClick:()=>{window.location.href="/login"},className:"flex-1 px-6 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition",children:"Logout"})]})]})})}return t.jsx("div",{className:"min-h-screen bg-gray-50 flex items-center justify-center p-4",children:t.jsxs("div",{className:"bg-white rounded-lg shadow-lg p-8 max-w-2xl w-full",children:[t.jsxs("div",{className:"text-center mb-8",children:[t.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 bg-primary-100 rounded-full mb-4",children:t.jsx(x,{className:"w-8 h-8 text-primary-600"})}),t.jsxs("h1",{className:"text-3xl font-bold text-gray-900 mb-2",children:["Join ",null==k?void 0:k.name]}),t.jsx("p",{className:"text-gray-600",children:"You've been invited to join the team"})]}),D&&P&&t.jsxs("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-lg flex items-start space-x-3",children:[t.jsx(m,{className:"w-5 h-5 text-red-600 mt-0.5"}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-medium text-red-900",children:"Error"}),t.jsx("p",{className:"text-sm text-red-700 mt-1",children:D})]})]}),t.jsx("div",{className:"bg-gray-50 rounded-lg p-6 mb-6",children:t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Email"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:null==P?void 0:P.email})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Role"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:(null==(b=null==P?void 0:P.role)?void 0:b.charAt(0).toUpperCase())+(null==(f=null==P?void 0:P.role)?void 0:f.slice(1))||"User"})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Organization"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:null==k?void 0:k.name})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Expires"}),t.jsxs("p",{className:"text-lg font-semibold text-gray-900 flex items-center",children:[t.jsx(u,{className:"w-4 h-4 inline mr-1"}),new Date(null==P?void 0:P.expiresAt).toLocaleDateString()]})]})]})}),t.jsxs("form",{onSubmit:async e=>{if(e.preventDefault(),(()=>{const e={};return T.password?T.password.length<8&&(e.password="Password must be at least 8 characters"):e.password="Password is required",T.confirmPassword?T.password!==T.confirmPassword&&(e.confirmPassword="Passwords do not match"):e.confirmPassword="Please confirm your password",T.firstName&&T.firstName.trim()||(e.firstName="First name is required"),T.lastName&&T.lastName.trim()||(e.lastName="Last name is required"),G(e),0===Object.keys(e).length})()){F(!0),I(null);try{const e=await r(y,T.password,{firstName:T.firstName.trim(),lastName:T.lastName.trim(),title:T.title.trim()||null,phone:T.phone.trim()||null});if(e.success){window.dispatchEvent(new CustomEvent("snapshot9-auth-change")),w.success("Welcome! Your account has been created successfully");const s=e.user;let a="/input";"superadmin"===(null==s?void 0:s.role)?a="/admin/organizations":"admin"===(null==s?void 0:s.role)?a="/admin/dashboard":"manager"===(null==s?void 0:s.role)&&(a="/manager-dashboard"),setTimeout(()=>{j(a,{replace:!0})},1500)}else I(e.error||"Failed to accept invitation"),w.error(e.error||"Failed to accept invitation")}catch(s){const e=s.message||"Failed to accept invitation. Please try again.";I(e),w.error(e)}finally{F(!1)}}else w.error("Please fix the errors in the form")},children:[t.jsxs("div",{className:"space-y-4 mb-6",children:[t.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Create Your Account"}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["First Name ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{type:"text",name:"firstName",value:T.firstName,onChange:R,required:!0,className:"w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent "+(M.firstName?"border-red-300 bg-red-50":"border-gray-300"),placeholder:"John"}),M.firstName&&t.jsx("p",{className:"mt-1 text-sm text-red-600",children:M.firstName})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Last Name ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsx("input",{type:"text",name:"lastName",value:T.lastName,onChange:R,required:!0,className:"w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent "+(M.lastName?"border-red-300 bg-red-50":"border-gray-300"),placeholder:"Doe"}),M.lastName&&t.jsx("p",{className:"mt-1 text-sm text-red-600",children:M.lastName})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Job Title"}),t.jsx("input",{type:"text",name:"title",value:T.title,onChange:R,className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent",placeholder:"e.g., Marketing Manager"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Phone Number"}),t.jsx("input",{type:"tel",name:"phone",value:T.phone,onChange:R,className:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent",placeholder:"+1 (555) 123-4567"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Password ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:L?"text":"password",name:"password",value:T.password,onChange:R,required:!0,className:"w-full px-4 py-2 pr-10 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent "+(M.password?"border-red-300 bg-red-50":"border-gray-300"),placeholder:"Create a strong password"}),t.jsx("button",{type:"button",onClick:()=>U(!L),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700",children:L?t.jsx(p,{className:"w-5 h-5"}):t.jsx(h,{className:"w-5 h-5"})})]}),M.password&&t.jsx("p",{className:"mt-1 text-sm text-red-600",children:M.password}),t.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"Must be at least 8 characters"})]}),t.jsxs("div",{children:[t.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Confirm Password ",t.jsx("span",{className:"text-red-500",children:"*"})]}),t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:Y?"text":"password",name:"confirmPassword",value:T.confirmPassword,onChange:R,required:!0,className:"w-full px-4 py-2 pr-10 border rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent "+(M.c
1onfirmPassword?"border-red-300 bg-red-50":"border-gray-300"),placeholder:"Re-enter your password"}),t.jsx("button",{type:"button",onClick:()=>z(!Y),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-500 hover:text-gray-700",children:Y?t.jsx(p,{className:"w-5 h-5"}):t.jsx(h,{className:"w-5 h-5"})})]}),M.confirmPassword&&t.jsx("p",{className:"mt-1 text-sm text-red-600",children:M.confirmPassword})]})]}),t.jsxs("button",{type:"submit",disabled:E,className:"w-full flex items-center justify-center space-x-2 px-6 py-3 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition disabled:opacity-50 disabled:cursor-not-allowed",children:[t.jsx(g,{className:"w-5 h-5"}),t.jsx("span",{children:E?"Creating Account...":"Accept Invitation & Create Account"})]})]}),t.jsxs("p",{className:"mt-4 text-xs text-center text-gray-600",children:["By accepting this invitation, you agree to our"," ",t.jsx("a",{href:"/terms",className:"text-primary-600 hover:text-primary-700",children:"Terms of Service"})," ","and"," ",t.jsx("a",{href:"/privacy",className:"text-primary-600 hover:text-primary-700",children:"Privacy Policy"})]})]})})}export{b 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.