PageSourceSearch

https://practicepad.realbraveaudio.com/assets/ManageProfiles-D8T2zkQM.js

js realbraveaudio.com collected 2026-10-05 05:26:41 UTC 6,231 bytes, 1 lines download raw bytes

1import{r as t,t as v,y as l,j as e,D as k,E as L,F as I,G as B,f as E,Y as F,ab as O,e as u,q,u as M,b3 as T,P as H,x as R,K as _,aq as U,aB as z,ar as $,ad as G}from"./index-CyxPczMw.js";import{P as Y}from"./PageHeader-DRlI33kR.js";import{C as K,a as J,b as Q,d as V,c as W}from"./card-BTzI-rMQ.js";import{L as A}from"./label-C-kv2OvQ.js";import{A as X,a as Z,b as ee,c as se,d as ae,e as te,f as re,g as ie}from"./alert-dialog-BmMImwsH.js";import{P}from"./plus-GWLvnhUo.js";import{P as le}from"./pencil-CYF0GGXl.js";function ne({open:i,onOpenChange:n,studentId:r,onSuccess:c}){const[N,y]=t.useState(!1),[f,h]=t.useState(!1),[x,m]=t.useState(""),[o,j]=t.useState(""),[g,b]=t.useState(""),[p,D]=t.useState(null);t.useEffect(()=>{i&&r&&S()},[i,r]);const S=async()=>{if(r){y(!0);try{const{data:a,error:s}=await v.from("students").select("user_id, date_of_birth").eq("id",r).single();if(s||!a){l.error("Failed to load student data"),n(!1);return}D(a.user_id),b(a.date_of_birth||"");const{data:d,error:w}=await v.from("profiles").select("first_name, last_name").eq("user_id",a.user_id).single();if(w||!d){l.error("Failed to load profile data"),n(!1);return}m(d.first_name||""),j(d.last_name||"")}catch(a){console.error("Error fetching student data:",a),l.error("Failed to load student data")}finally{y(!1)}}},C=async()=>{if(!x||!o){l.error("Please enter first and last name");return}if(!r||!p){l.error("Student data not loaded");return}h(!0);try{const{error:a}=await v.from("profiles").update({first_name:x,last_name:o,updated_at:new Date().toISOString()}).eq("user_id",p);if(a)throw a;const{error:s}=await v.from("students").update({date_of_birth:g||null}).eq("id",r);if(s)throw s;l.success("Profile updated successfully"),c==null||c(),n(!1)}catch(a){console.error("Error updating profile:",a),l.error("Failed to update profile")}finally{h(!1)}};return e.jsx(k,{open:i,onOpenChange:n,children:e.jsxs(L,{className:"max-w-md",children:[e.jsx(I,{children:e.jsx(B,{children:"Edit Family Member"})}),N?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(E,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{htmlFor:"firstName",children:"First Name"}),e.jsx(F,{id:"firstName",value:x,onChange:a=>m(a.target.value),placeholder:"First name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{htmlFor:"lastName",children:"Last Name"}),e.jsx(F,{id:"lastName",value:o,onChange:a=>j(a.target.value),placeholder:"Last name"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(A,{htmlFor:"dateOfBirth",children:"Date of Birth"}),e.jsx(F,{id:"dateOfBirth",type:"date",value:g,onChange:a=>b(a.target.value)})]})]}),e.jsxs(O,{children:[e.jsx(u,{variant:"outline",onClick:()=>n(!1),disabled:f,children:"Cancel"}),e.jsxs(u,{onClick:C,disabled:N||f,children:[f&&e.jsx(E,{className:"h-4 w-4 mr-2 animate-spin"}),"Save Changes"]})]})]})})}function xe(){const i=q(),{user:n,loading:r,userRole:c}=M(),{profiles:N,loading:y}=T(),[f,h]=t.useState(!1),[x,m]=t.useState(!1),[o,j]=t.useState(null),[g,b]=t.useState("");if(t.useState(0),t.useEffect(()=>{!r&&!n&&i("/auth"),!r&&c!=="parent"&&i("/")},[n,r,c,i]),r||y)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(H,{size:"lg"})});const p=N.filter(s=>s.type==="student"),D=s=>{j(s),h(!0)},S=(s,d)=>{j(s),b(d),m(!0)},C=async()=>{if(o)try{const{data:s,error:d}=await v.functions.invoke("terminate-student",{body:{studentId:o}});if(d)throw d;const w=s==null?void 0:s.error;if(w)throw new Error(w);l.success(`${g} has been removed from your family`),m(!1),window.location.reload()}catch(s){console.error("Error removing family member:",s),l.error("Failed to remove family member")}},a=()=>{window.location.reload()};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Y,{title:"Manage Profiles",subtitle:"Add or remove family members"}),e.jsxs(K,{children:[e.jsxs(J,{className:"flex flex-row items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(Q,{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),"Family Members"]}),e.jsx(V,{children:"Students linked to your parent account"})]}),e.jsxs(u,{onClick:()=>i("/parent/add-family-member"),children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),"Add Student"]})]}),e.jsx(W,{children:p.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(_,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"No students linked to your account"}),e.jsxs(u,{onClick:()=>i("/parent/add-family-member"),children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),"Add Your First Student"]})]}):e.jsx("div",{className:"space-y-4",children:p.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(U,{className:"h-12 w-12",children:[e.jsx(z,{src:s.avatarUrl}),e.jsx($,{children:e.jsx(_,{className:"h-6 w-6"})})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[s.firstName," ",s.lastName]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Student"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{variant:"outline",size:"sm",onClick:()=>s.studentId&&D(s.studentId),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(u,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>s.studentId&&S(s.studentId,`${s.firstName} ${s.lastName}`),children:e.jsx(G,{className:"h-4 w-4"})})]})]},s.id))})})]}),e.jsx(ne,{open:f,onOpenChange:h,studentId:o,onSuccess:a}),e.jsx(X,{open:x,onOpenChange:m,children:e.jsxs(Z,{children:[e.jsxs(ee,{children:[e.jsx(se,{children:"Remove Family Member"}),e.jsxs(ae,{children:["Are you sure you want to remove ",g," from your family? This will terminate their student account."]})]}),e.jsxs(te,{children:[e.jsx(re,{children:"Cancel"}),e.jsx(ie,{onClick:C,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]})})]})}export{xe 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.