PageSourceSearch

https://www.pasjonat-taniec.pl/assets/IndividualLessons-IGX1ubki.js

js pasjonat-taniec.pl collected 2026-10-09 22:03:19 UTC 12,711 bytes, 1 lines download raw bytes

1import{h as ee,y as te,r as _,s as l,i as D,w as u,j as e,B as w,m as B,q as Z,ad as ae,x as z,C as se,v as ie,l as O,k as ne,t as re,M as oe,bN as le,N as ce,P as de,Q as me,R as pe,L as d,I as h,Y as Q,Z as R,_ as W,$ as A,a0 as L,T as ue,ah as j}from"./index-BLSTqzUa.js";import{u as P}from"./useMutation-DUusf-EJ.js";import{C as he}from"./calendar-CfxGVEG7.js";import{P as ye}from"./plus-BTxjxw_Y.js";import{C as xe}from"./car-Cw-PeYK8.js";import{C as _e}from"./circle-check-BpAz2lpj.js";import{P as je}from"./pencil-CzBjjYGV.js";import{T as ge}from"./trash-2-CeedNIdz.js";import{C as ve}from"./circle-alert-C9p63set.js";import{s as fe}from"./startOfMonth-qL9WjxZC.js";import{e as we}from"./endOfMonth-CkszCeXH.js";import{p as C}from"./parseISO-CNY7pvQe.js";import"./addWeeks-D5Ofar4z.js";import"./differenceInCalendarMonths-Cs_acXpk.js";import"./endOfWeek-C-PzNL7U.js";const Ie=()=>{const{user:b}=ee(),M=te(),[y,G]=_.useState(null),[K,N]=_.useState(!1),[g,S]=_.useState(null),[k,V]=_.useState(new Date),[a,o]=_.useState({lesson_date:"",start_time:"10:00",end_time:"11:00",lesson_type:"adult",travel_cost:"0",notes:"",participant_name:"",participant_email:"",room:"",city:""});_.useEffect(()=>{b&&l.from("instructors").select("id").eq("user_id",b.id).maybeSingle().then(({data:t})=>{t&&G(t.id)})},[b]);const{data:T=[]}=D({queryKey:["locations-active"],queryFn:async()=>{const{data:t,error:i}=await l.from("locations").select("city").eq("is_active",!0).order("sort_order");if(i)throw i;return t}}),{data:I=[]}=D({queryKey:["individual-lessons",y,u(k,"yyyy-MM")],enabled:!!y,queryFn:async()=>{const t=u(fe(k),"yyyy-MM-dd"),i=u(we(k),"yyyy-MM-dd"),{data:s,error:n}=await l.from("individual_lessons").select("*").eq("instructor_id",y).gte("lesson_date",t).lte("lesson_date",i).order("lesson_date").order("start_time");if(n)throw n;return s}}),{data:E=[]}=D({queryKey:["room-occupancy",a.lesson_date,a.city],enabled:!!a.lesson_date&&!!a.city&&K,queryFn:async()=>{const t=u(C(a.lesson_date),"EEEE",{locale:z}),i=t.charAt(0).toUpperCase()+t.slice(1),{data:s}=await l.from("group_schedules").select("start_time, end_time, room, groups!inner(city, name, is_active)").eq("day_of_week",i),n=(s||[]).filter(r=>{var c,m,f;return((m=(c=r.groups)==null?void 0:c.city)==null?void 0:m.toLowerCase())===a.city.toLowerCase()&&((f=r.groups)==null?void 0:f.is_active)}),{data:p}=await l.from("individual_lessons").select("start_time, end_time, room, city, participant_name, instructor_id").eq("lesson_date",a.lesson_date).eq("city",a.city),x=[];return n.forEach(r=>{var c,m,f;r.room&&x.push({start:(c=r.start_time)==null?void 0:c.slice(0,5),end:(m=r.end_time)==null?void 0:m.slice(0,5),room:r.room,label:((f=r.groups)==null?void 0:f.name)||"Grupa",type:"group"})}),(p||[]).forEach(r=>{var c,m;r.room&&x.push({start:(c=r.start_time)==null?void 0:c.slice(0,5),end:(m=r.end_time)==null?void 0:m.slice(0,5),room:r.room,label:r.instructor_id===y?"Twoja lekcja":"Lekcja indyw.",type:"individual"})}),x.sort((r,c)=>r.start.localeCompare(c.start))}}),q=P({mutationFn:async t=>{var s;const i={instructor_id:y,lesson_date:t.lesson_date,start_time:t.start_time,end_time:t.end_time,lesson_type:t.lesson_type,travel_cost:parseFloat(t.travel_cost)||0,notes:t.notes||null,participant_name:t.participant_name||null,participant_email:((s=t.participant_email)==null?void 0:s.trim())||null,room:t.room||null,city:t.city||null};if(t.id){const{error:n}=await l.from("individual_lessons").update(i).eq("id",t.id);if(n)throw n}else{const{error:n}=await l.from("individual_lessons").insert(i);if(n)throw n}},onSuccess:()=>{M.invalidateQueries({queryKey:["individual-lessons"]}),j.success(g?"Zaktualizowano lekcję":"Dodano lekcję"),H()},onError:t=>j.error(t.message)}),Y=P({mutationFn:async t=>{const{error:i}=await l.from("individual_lessons").delete().eq("id",t);if(i)throw i},onSuccess:()=>{M.invalidateQueries({queryKey:["individual-lessons"]}),j.success("Usunięto lekcję")}}),F=P({mutationFn:async t=>{if(!t.participant_email)throw new Error("Brak adresu e-mail uczestnika — uzupełnij go w edycji lekcji.");const{data:i}=await l.from("app_settings").select("key, value").in("key",["review_google_url","review_google_url_lowicz","review_google_url_sochaczew","review_facebook_url"]),s=Object.fromEntries((i||[]).map(x=>[x.key,x.value])),{error:n}=await l.functions.invoke("send-transactional-email",{body:{templateName:"thank-you-review",recipientEmail:t.participant_email,idempotencyKey:`thank-you-review-${t.id}`,templateData:{recipientName:t.participant_name||void 0,lessonDate:u(C(t.lesson_date),"d MMMM yyyy",{locale:z}),googleReviewUrl:s.review_google_url||void 0,googleReviewUrlLowicz:s.review_google_url_lowicz||void 0,googleReviewUrlSochaczew:s.review_google_url_sochaczew||void 0,facebookReviewUrl:s.review_facebook_url||void 0}}});if(n)throw n;const{error:p}=await l.from("individual_lessons").update({thank_you_sent_at:new Date().toISOString()}).eq("id",t.id);if(p)throw p},onSuccess:()=>{M.invalidateQueries({queryKey:["individual-lessons"]}),j.success("Wysłano podziękowanie z prośbą o opinię")},onError:t=>j.error(t.message||"Nie udało się wysłać wiadomości")}),U=t=>{var i;S(null),o({lesson_date:t?u(t,"yyyy-MM-dd"):"",start_time:"10:00",end_time:"11:00",lesson_type:"adult",travel_cost:"0",notes:"",participant_name:"",participant_email:"",room:"",city:((i=T[0])==null?void 0:i.city)||""}),N(!0)},$=t=>{var i,s;
1S(t),o({lesson_date:t.lesson_date,start_time:(i=t.start_time)==null?void 0:i.slice(0,5),end_time:(s=t.end_time)==null?void 0:s.slice(0,5),lesson_type:t.lesson_type,travel_cost:String(t.travel_cost||0),notes:t.notes||"",participant_name:t.participant_name||"",participant_email:t.participant_email||"",room:t.room||"",city:t.city||""}),N(!0)},H=()=>{N(!1),S(null)},J=()=>{if(!a.lesson_date||!a.start_time||!a.end_time){j.error("Wypełnij datę i godziny");return}q.mutate({...a,id:g==null?void 0:g.id})},X=I.map(t=>C(t.lesson_date)),v={};return I.forEach(t=>{v[t.lesson_date]||(v[t.lesson_date]=[]),v[t.lesson_date].push(t)}),y?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",style:{fontFamily:"var(--font-heading)"},children:"Lekcje indywidualne"}),e.jsxs(w,{onClick:()=>U(),children:[e.jsx(ye,{className:"h-4 w-4 mr-2"})," Dodaj lekcję"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[auto_1fr] gap-6",children:[e.jsx(B,{children:e.jsx(Z,{className:"p-4",children:e.jsx(he,{mode:"single",month:k,onMonthChange:V,onSelect:t=>t&&U(t),modifiers:{hasLesson:X},modifiersClassNames:{hasLesson:"bg-primary/20 text-primary font-bold"},className:ae("p-3 pointer-events-auto"),locale:z})})}),e.jsx("div",{className:"space-y-4",children:Object.keys(v).length===0?e.jsx("p",{className:"text-muted-foreground",children:"Brak lekcji w tym miesiącu. Kliknij dzień w kalendarzu, aby dodać."}):Object.entries(v).map(([t,i])=>e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-semibold text-muted-foreground mb-2 flex items-center gap-2",children:[e.jsx(se,{className:"h-4 w-4"}),u(C(t),"EEEE, d MMMM yyyy",{locale:z})]}),e.jsx("div",{className:"space-y-2",children:i.map(s=>{var n,p;return e.jsx(B,{children:e.jsxs(Z,{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm font-medium",children:[(n=s.start_time)==null?void 0:n.slice(0,5)," – ",(p=s.end_time)==null?void 0:p.slice(0,5)]}),e.jsx(O,{variant:s.lesson_type==="athlete"?"default":"secondary",children:s.lesson_type==="athlete"?"Zawodnik UKTS":"Dorosły"})]}),s.participant_email&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ne,{className:"h-4 w-4"}),s.participant_email]}),s.participant_name&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(re,{className:"h-4 w-4"}),s.participant_name]}),(s.room||s.city)&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(oe,{className:"h-4 w-4"}),[s.room,s.city].filter(Boolean).join(" • ")]}),s.travel_cost>0&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(xe,{className:"h-4 w-4"}),"Dojazd: ",s.travel_cost," zł"]}),s.notes&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.notes})]}),e.jsxs("div",{className:"flex gap-1 items-center",children:[s.thank_you_sent_at?e.jsxs(O,{variant:"outline",className:"gap-1 whitespace-nowrap",children:[e.jsx(_e,{className:"h-3 w-3"})," Podziękowanie wysłane"]}):e.jsx(w,{variant:"ghost",size:"sm",title:"Wyślij podziękowanie i prośbę o opinię",disabled:F.isPending,onClick:()=>F.mutate(s),children:e.jsx(le,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>$(s),children:e.jsx(je,{className:"h-4 w-4"})}),e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>Y.mutate(s.id),children:e.jsx(ge,{className:"h-4 w-4 text-destructive"})})]})]})},s.id)})})]},t))})]}),e.jsx(ce,{open:K,onOpenChange:N,children:e.jsxs(de,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(me,{children:e.jsx(pe,{children:g?"Edytuj lekcję":"Nowa lekcja indywidualna"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Data"}),e.jsx(h,{type:"date",value:a.lesson_date,onChange:t=>o({...a,lesson_date:t.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Godzina rozpoczęcia"}),e.jsx(h,{type:"time",value:a.start_time,onChange:t=>o({...a,start_time:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Godzina zakończenia"}),e.jsx(h,{type:"time",value:a.end_time,onChange:t=>o({...a,end_time:t.target.value})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Lokalizacja"}),e.jsxs(Q,{value:a.city,onValueChange:t=>o({...a,city:t}),children:[e.jsx(R,{children:e.jsx(W,{placeholder:"Wybierz miasto"})}),e.jsx(A,{children:T.map(t=>e.jsx(L,{value:t.city,children:t.city},t.city))})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Sala"}),e.jsx(h,{value:a.room,onChange:t=>o({...a,room:t.target.value}),placeholder:"np. Sala 1"})]})]}),a.lesson_date&&a.city&&E.length>0&&e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-primary"}),"Zajętość sal — ",a.city,", ",a.lesson_date]}),e.jsx("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:E.map((t,i)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsxs(O,{variant:t.type==="group"?"secondary":"outline",className:"text-xs min-w-[60px] justify-center",children:[t.start,"–",t.end]}),e.jsx("span",{className:"font-medium",children:t.room}),e.jsxs("span",{className:"text-muted-foreground",children:["— ",t.label]})]},i))})]}),a.lesson_date&&a.city&&E.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Brak zajętych sal w tym dniu i lokalizacji."}),e.jsxs("div",{children:[e.jsx(d,{children:"Typ lekcji"}),e.jsxs(Q,{value:a.lesson_type,onValueChange:t=>o({...a,lesson_type:t}),children:[e.jsx(R,{children:e.jsx(W,{})}),e.jsxs(A,{children:[e.jsx(L,{value:"adult",children:"Dorosły (np. pierwszy taniec)"}),e.jsx(L,{value:"athlete",children:"Zawodnik UKTS Pasjonat"})]})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Imię uczestnika / pary"}),e.jsx(h,{value:a.participant_name,onChange:t=>o({...a,participant_name:t.target.value}),placeholder:"np. Anna i Jan"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"E-mail uczestnika"}),e.jsx(h,{type:"email",value:a.participant_email,onChange:t=>o({...a,participant_email:t.target.value}),placeholder:"np. [email protected]"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Potrzebny, aby po zajęciach wysłać podziękowanie i prośbę o opinię."})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Koszt dojazdu (zł)"}),e.jsx(h,{type:"number",min:"0",step:"1",value:a.travel_cost,onChange:t=>o({...a,travel_cost:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Notatka"}),e.jsx(ue,{value:a.notes,onChange:t=>o({...a,notes:t.target.value}),rows:3,placeholder:"Opcjonalna notatka..."})]}),e.jsx(w,{onClick:J,disabled:q.isPending,className:"w-full",children:q.isPending?"Zapisywanie...":"Zapisz"})]})]})})]}):e.jsx("p",{className:"text-muted-foreground",children:"Ładowanie..."})};export{Ie 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.