PageSourceSearch

https://laiglesiafiel.com/assets/FamilyEditPage-d42e1d66.js

js laiglesiafiel.com collected 2026-10-02 01:35:34 UTC 10,304 bytes, 1 lines download raw bytes

1import{u as n,j as e,O as I,s as se,bi as te,d0 as oe,cv as ie}from"./vendor-ui-fc56ca80.js";import{i as le,e as ne,r as u}from"./vendor-react-f9ccc48d.js";import{u as de}from"./index.esm-08da3b2e.js";import{t as me}from"./zod-182dcd03.js";import{h as ce,B as N,t as P,v as S,w as O,x as H,y as L,F as ue,K as fe,aI as be,M as xe,N as ge,O as he,a1 as pe,a2 as ye,a3 as je,a4 as ve,a5 as Ne,a6 as De,a7 as we,a8 as Ae}from"./index-90016d22.js";import{h as Ce,i as T,u as Ee,r as Fe,j as Me}from"./familyService-10e68e34.js";import{c as Re}from"./memberService-60ce7187.js";import{F as ke,M as Ie}from"./MemberMultiPicker-535631b8.js";import{a as Pe}from"./address-333af221.js";import{F as Se}from"./FamilyVisualizer-2126adc4.js";import{o as Oe,s as z,u as He,a5 as Le,a3 as Te}from"./vendor-utils-323b9898.js";import"./vendor-firebase-a557f106.js";import"./vendor-charts-9af8b7c0.js";import"./civil-5f5e63de.js";import"./coerce-b1c83b65.js";import"./AddressSubForm-0c1c692e.js";import"./avatar-4e73900d.js";import"./use-toast-1e8cd746.js";const V=s=>s?/^\d{4}-\d{2}-\d{2}$/.test(s)?Le(Te(s)):!1:!0,ze=Oe({familyName:z().min(2,"El nombre de la familia debe tener al menos 2 caracteres").max(100,"El nombre de la familia no puede exceder los 100 caracteres"),marriageAnniversaryDate:z().optional().refine(s=>s===""||s===void 0||V(s),{message:"Fecha de aniversario inválida. Use el formato YYYY-MM-DD o deje vacío."}),address:Pe}),ta=()=>{const{familyId:s}=le(),{userData:p}=ce(),g=p==null?void 0:p.churchId,$=ne(),{t:o}=He(["admin","members","common"]),[a,d]=u.useState(null),[x,h]=u.useState([]),[B,D]=u.useState(!0),[A,y]=u.useState(null),[U,j]=u.useState(!1),[c,w]=u.useState(null),{control:Y,handleSubmit:q,reset:C,formState:{errors:G,isSubmitting:E},setValue:K}=de({resolver:me(ze),defaultValues:{familyName:"",marriageAnniversaryDate:"",address:{countryCode:"CL",addressLine1:"",addressLine2:"",city:"",administrativeArea:"",subAdministrativeArea:"",postalCode:"",additionalInfo:""}}}),b=u.useCallback(async(r=!1)=>{var i,l,m,f,F,M,R,k;if(!s||!g){y("ID de familia o iglesia no disponible."),D(!1);return}r||D(!0),y(null);try{const t=await Ce(s);if(t){d(t);const v={familyName:t.name||"",marriageAnniversaryDate:t.marriageAnniversaryDate||"",address:{countryCode:((i=t.address)==null?void 0:i.countryCode)||"CL",addressLine1:((l=t.address)==null?void 0:l.addressLine1)||"",addressLine2:((m=t.address)==null?void 0:m.addressLine2)||"",city:((f=t.address)==null?void 0:f.city)||"",administrativeArea:((F=t.address)==null?void 0:F.administrativeArea)||"",subAdministrativeArea:((M=t.address)==null?void 0:M.subAdministrativeArea)||"",postalCode:((R=t.address)==null?void 0:R.postalCode)||"",additionalInfo:((k=t.address)==null?void 0:k.additionalInfo)||""}};if(C(v),t.memberRefs&&t.memberRefs.length>0){const ee=t.memberRefs.map(re=>re.personId),ae=await Re(g,ee);h(ae)}else h([])}else y("Familia no encontrada."),d(null),h([])}catch(t){console.error("Error fetching family details:",t);const v=t instanceof Error?t.message:"Ocurrió un error al cargar los datos.";y(v),n.error(`Error al cargar datos: ${v}`)}finally{r||D(!1)}},[s,g,C]);u.useEffect(()=>{b()},[b]),u.useEffect(()=>{a!=null&&a.name&&(document.title=o("admin:familyEditPage.titleNamed",{familyName:a.name}))},[a==null?void 0:a.name,o]);const J=async r=>{if(!s||!g||!a)return;const i={...a};d({...a,name:r.familyName,marriageAnniversaryDate:r.marriageAnniversaryDate,address:r.address});try{const l={name:r.familyName,marriageAnniversaryDate:r.marriageAnniversaryDate&&V(r.marriageAnniversaryDate)?r.marriageAnniversaryDate:null,address:r.address};await T(s,l),n.success("Detalles de la familia actualizados con éxito."),b(!0)}catch(l){console.error("Error updating family details:",l),n.error("No se pudieron actualizar los detalles."),d(i)}},Q=async(r,i)=>{if(!s||!a)return;const l=[...a.memberRefs],m=a.memberRefs.map(f=>f.personId===r?{...f,familyRole:i}:f);d({...a,memberRefs:m});try{await Ee(s,r,i),n.success("Rol actualizado."),b(!0)}catch(f){console.error("Error updating role:",f),n.error("Error al actualizar el rol."),d({...a,memberRefs:l})}},W=async r=>{if(!s||!a)return;const i=a.headOfHouseholdPersonId;d({...a,headOfHouseholdPersonId:r});try{await T(s,{headOfHouseholdPersonId:r}),n.success("Cabeza de familia actualizado.",{icon:e.jsx(ie,{className:"h-4 w-4 text-yellow-500"})}),b(!0)}catch(l){console.error("Error setting head:",l),n.error("Error al establecer cabeza de familia."),d({...a,headOfHouseholdPersonId:i})}},X=async r=>{if(!s||!a)return;const i=[...a.memberRefs],l=[...x];d({...a,memberRefs:a.memberRefs.filter(m=>m.personId!==r)}),h(x.filter(m=>m.id!==r)),w(null);try{await Fe(s,r),n.success("Miembro eliminado."),b(!0)}catch(m){console.error("Error removing member:",m),n.error("Error al eliminar miembro."),d({...a,memberRefs:i}
1),h(l)}},Z=r=>{const i=x.find(l=>l.id===r);i&&w(i)},_=async r=>{if(s)try{await Me(s,r.map(i=>({personId:i.id,role:"Other"}))),n.success(`${r.length} miembros agregados.`),await b(),j(!1)}catch(i){console.error("Error adding members:",i),n.error("Error al agregar miembros.")}};return B?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(I,{className:"h-8 w-8 animate-pulse text-muted-foreground/50"})}):A&&!a?e.jsx("div",{className:"p-10 text-center text-destructive",children:A}):e.jsxs("div",{className:"max-w-5xl mx-auto p-4 md:p-8 space-y-10 pb-24",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs(N,{variant:"ghost",className:"rounded-full gap-2 -ml-2 h-9 md:h-10 hover:bg-accent hover:text-accent-foreground",onClick:()=>$(-1),children:[e.jsx(se,{className:"h-4 w-4"}),o("common:buttons.back")]}),e.jsx("h1",{className:"text-xl md:text-2xl font-black text-foreground tracking-tight",children:a!=null&&a.name?o("admin:familyEditPage.titleNamed",{familyName:a.name}):o("admin:familyEditPage.title","Editar Familia")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8",children:[e.jsx("div",{className:"lg:col-span-1 space-y-6",children:e.jsxs(P,{className:"border-none shadow-xl shadow-black/5 dark:shadow-black/40 overflow-hidden bg-card",children:[e.jsxs(S,{className:"bg-muted/30 text-foreground p-6 border-b border-border",children:[e.jsx(O,{className:"text-xl font-bold",children:o("admin:familyRegistration.sections.basicInfo","Detalles Básicos")}),e.jsx(H,{className:"text-muted-foreground",children:"Información general y ubicación."})]}),e.jsxs("form",{onSubmit:q(J),children:[e.jsx(L,{className:"p-6 space-y-6",children:e.jsx(ke,{control:Y,errors:G,setValue:K})}),e.jsx(ue,{className:"bg-muted/10 border-t border-border p-6",children:e.jsxs(N,{type:"submit",disabled:E,className:"w-full rounded-xl bg-primary hover:bg-primary/90 text-primary-foreground h-12 font-bold shadow-lg shadow-primary/20",children:[e.jsx(te,{className:"w-4 h-4 mr-2"}),o(E?"common:buttons.saving":"common:buttons.saveChanges")]})})]})]})}),e.jsx("div",{className:"lg:col-span-2 space-y-6",children:e.jsxs(P,{className:"border-none shadow-xl shadow-black/5 dark:shadow-black/40 min-h-[500px] flex flex-col bg-card",children:[e.jsxs(S,{className:"flex flex-row items-center justify-between space-y-0 p-6 border-b border-border bg-muted/30",children:[e.jsxs("div",{children:[e.jsx(O,{className:"text-xl font-extrabold text-foreground",children:o("members:familyDetail.headers.members")}),e.jsx(H,{children:"Gestiona roles y jerarquía de forma visual."})]}),e.jsxs(fe,{open:U,onOpenChange:j,children:[e.jsx(be,{asChild:!0,children:e.jsxs(N,{className:"rounded-full bg-blue-600 hover:bg-blue-700 text-white shadow-lg shadow-blue-500/20 gap-2 px-4 md:px-6 h-10 md:h-11 border-none",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx("span",{className:"font-bold text-xs md:text-sm hidden md:inline",children:o("admin:familyEditPage.addMembers","Agregar Miembros")}),e.jsx("span",{className:"font-bold text-xs md:hidden",children:o("common:buttons.add","Agregar")})]})}),e.jsxs(xe,{className:"max-w-2xl rounded-3xl p-6 bg-card border-border",children:[e.jsx(ge,{children:e.jsx(he,{className:"text-2xl font-black text-foreground",children:o("admin:familyEditPage.searchMembersTitle","Añadir a la Familia")})}),e.jsx(Ie,{churchId:g,excludePersonIds:x.map(r=>r.id),onSelect:_,onClose:()=>j(!1)})]})]})]}),e.jsx(L,{className:"p-6 flex-1",children:x.length>0?e.jsx(Se,{familyDetails:a,allFamilyPersons:x,onUpdateRole:Q,onSetHead:W,onRemoveMember:Z,hideHeader:!0}):e.jsxs("div",{className:"h-full flex flex-col items-center justify-center text-center py-20 bg-muted/30 rounded-3xl border-2 border-dashed border-border",children:[e.jsx("div",{className:"bg-background p-6 rounded-full shadow-lg mb-6 shadow-black/5 dark:shadow-black/40",children:e.jsx(I,{className:"h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"text-lg font-bold text-foreground mb-2",children:o("members:familyDetail.messages.noMembers")}),e.jsx("p",{className:"text-muted-foreground max-w-xs mb-8",children:"Esta familia aún no tiene miembros asociados. Comienza agregando personas."}),e.jsx(N,{variant:"outline",className:"rounded-full px-8 font-bold border-border hover:bg-accent hover:text-accent-foreground",onClick:()=>j(!0),children:o("admin:familyEditPage.addFirstMember","Agregar el Primer Miembro")})]})})]})})]}),e.jsx(pe,{open:!!c,onOpenChange:r=>!r&&w(null),children:e.jsxs(ye,{className:"rounded-3xl p-8 bg-card border-border",children:[e.jsxs(je,{children:[e.jsx(ve,{className:"text-2xl font-black text-foreground",children:o("admin:familyEditPage.removeMemberConfirmTitle","Confirmar Eliminación")}),e.jsx(Ne,{className:"text-muted-foreground text-lg py-2",children:o("admin:familyEditPage.removeMemberConfirmText",{memberName:`${c==null?void 0:c.firstName} ${c==null?void 0:c.lastName}`})})]}),e.jsxs(De,{className:"gap-2 mt-4",children:[e.jsx(we,{className:"rounded-xl h-12 px-6 font-bold border-border hover:bg-accent hover:text-accent-foreground text-foreground",children:o("common:buttons.cancel")}),e.jsx(Ae,{onClick:()=>c&&X(c.id),className:"rounded-xl h-12 px-6 font-bold bg-destructive hover:bg-destructive/90 text-destructive-foreground border-none shadow-lg shadow-destructive/20",children:o("common:buttons.remove")})]})]})})]})};export{ta 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.