PageSourceSearch

https://greenlight-gcm.lovable.app/assets/MyBookings.7T_r-vGS.js

js greenlight-gcm.lovable.app collected 2026-10-03 03:27:47 UTC 13,452 bytes, 1 lines download raw bytes

1import{v as O,o as V,j as e,r as g}from"./vendor-react.BsJ9eaQA.js";import{L as I}from"./Layout.LSptpHsM.js";import{a as Q,C as q,e as R,f as H,j as W,m as P,h as te,o as se,B as A,t as $,s as X,u as Z,p as z,q as k,r as ae,c as re,v as ie}from"./index.B_dQ8nW1.js";import{u as b}from"./useBookingContext.CqC1mA1a.js";import{T as ne,a as le,b as J,c as f,d as ce,e as j}from"./table.BwkXE4Ao.js";import{B as m}from"./badge.DxTJnYb5.js";import{T as oe,a as me,b as G,c as K}from"./tabs.6svc970t.js";import{A as de}from"./archive.CKC2HqC1.js";import{C as ue}from"./circle-alert.DKjKy8G3.js";import{C as he}from"./clock.DeBDLW-m.js";import{C as pe}from"./circle-check-big.C5xN3HWq.js";import{C as xe}from"./credit-card.D8QFYmgp.js";import{D as fe}from"./dollar-sign.BwHYCqJM.js";import{C as je}from"./circle-dollar-sign.QXrkZkl6.js";import{W as ge}from"./WeeklyDateSelector.CZg6BOuz.js";import{C as ye}from"./calendar.bz7_5Gxc.js";import{P as ve,a as Se,b as Ne}from"./popover.D1I4nc8R.js";import{C as ee}from"./calendar.lCyBhcQk.js";import"./Navbar.BATNM7oQ.js";import"./usePermissions.qSohKOto.js";import"./logo.4xM8Td36.js";import"./avatar-menu.V8eumD9O.js";import"./avatar.Cuu9EkKG.js";import"./vendor-ui.BMOhr5L7.js";import"./dropdown-menu.eVZBZ5NT.js";import"./chevron-right.C7hG-Qsm.js";import"./check.BuxoXE3q.js";import"./circle.DzNGuoPf.js";import"./flag.CI3ashsS.js";import"./user-plus.BlYARK9H.js";import"./users.BRv1QrID.js";import"./car.COnuEjVj.js";import"./settings.DAmJ3cj7.js";import"./file-text.Cez4E4bv.js";import"./theme-toggle.CHBN20zq.js";import"./sun.DHOMFVke.js";import"./moon.CEEtVhNf.js";import"./layout-grid.M2cG0vof.js";import"./instagram.CCKidHQI.js";import"./facebook.D6D-DCWH.js";import"./use-mobile.BNy4pbSk.js";import"./x.CUXQnO5s.js";import"./menu.BpZ476fU.js";import"./PreviewModeBanner.DklaQfoB.js";import"./eye.C8NtFiKv.js";import"./building-2.3etmwd6P.js";import"./layout-dashboard.BAM553ne.js";import"./network.BThFjOPw.js";import"./useFacilityBySlug.Ds7jp9CD.js";import"./FacilityFooter.Dpbbc5nd.js";import"./useFacilityFooterSettings.BnGOZ_1e.js";import"./useMutation.D7pCHyR6.js";import"./footerLinks.DDUD3pYz.js";import"./external-link.BMMNQG6m.js";import"./message-circle.DwNBzTI1.js";import"./vendor-supabase.rDbyZezT.js";import"./chevron-left.Bjo4oOme.js";import"./index.CbCqSXsE.js";import"./index.CY7HSK1t.js";import"./index.BoFrevac.js";import"./index.CVarg4Ch.js";import"./index.CyCwpJJO.js";import"./index.BAEtXzHo.js";import"./index.BQUSLU58.js";import"./index.D0--w1QO.js";import"./index.Dn7-1XD-.js";import"./index.C9slIPSy.js";import"./index.DrSdt8qc.js";const Ce=({bookings:i,setBookings:y,showArchived:c=!1})=>{const{currentUser:N}=Q(),{cancelBooking:n}=b(),d=O(),{facilitySlug:D}=V();if(!N)return null;if(i.length===0)return e.jsx(q,{children:e.jsxs(R,{children:[e.jsx(H,{children:"My Bookings"}),e.jsx(W,{children:"You don't have any bookings yet."})]})});const l=i.filter(s=>s.status!=="cancelled"&&(!s.archived||c)),u=l.filter(s=>
1s.teeTimeSlot&&P(s.teeTimeSlot.date,s.teeTimeSlot.time)),h=l.filter(s=>s.teeTimeSlot&&!P(s.teeTimeSlot.date,s.teeTimeSlot.time));console.log("[MyBookings] Categorization:",{total:l.length,upcoming:h.length,past:u.length,sample:l.slice(0,3).map(s=>({id:s.id,status:s.status,archived:s.archived,teeTimeSlot:s.teeTimeSlot,hasTeeTimeSlot:!!s.teeTimeSlot})),bookingsWithoutSlot:l.filter(s=>!s.teeTimeSlot).length});const r=async s=>{try{await n(s),y(o=>o.map(t=>t.id===s?{...t,status:"cancelled"}:t)),$.success("Booking cancelled successfully")}catch(o){console.error("Error cancelling booking:",o),$.error("Failed to cancel booking")}},v=async s=>{if((s.teeTimeSlot?P(s.teeTimeSlot.date,s.teeTimeSlot.time):!1)||s.status==="cancelled"||s.archived){d(`/booking/${s.id}`);return}try{const{data:t,error:w}=await X.functions.invoke("booking-checkin-gateway",{body:{action:"issue_my_token",booking_id:s.id}});if(w||!(t!=null&&t.ok)||!(t!=null&&t.token))throw w||new Error("No token");if(t.grant)try{window.sessionStorage.setItem(`booking-grant:${t.token}`,JSON.stringify({grant:t.grant,exp:t.exp}))}catch{}const C=D||t.facility_slug;d(C?`/f/${C}/b/${t.token}`:`/booking/${s.id}`)}catch(t){console.error("Failed to open booking management:",t),d(`/booking/${s.id}`)}},_=s=>{switch(s==null?void 0:s.toLowerCase()){case"regular":return"Regular";case"senior":return"Senior";case"junior":return"Junior";case"complimentary":return"Comp";default:return s||"Regular"}},T=s=>{const o=s.paymentStatus||"pending",t=s.paymentMethod;switch(o){case"paid":return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs(m,{variant:"outline",className:"bg-green-50 text-green-700",children:[e.jsx(pe,{className:"w-3 h-3 mr-1"}),"Paid"]}),t&&e.jsx(m,{variant:"outline",className:"text-xs",children:t==="CC"?e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"w-3 h-3 mr-1"}),"Credit Card"]}):t==="Cash"?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-3 h-3 mr-1"}),"Cash"]}):e.jsxs(e.Fragment,{children:[e.jsx(je,{className:"w-3 h-3 mr-1"}),t]})})]});case"pending":return e.jsxs(m,{variant:"outline",className:"bg-yellow-50 text-yellow-700",children:[e.jsx(he,{className:"w-3 h-3 mr-1"}),"Pending"]});case"failed":return e.jsxs(m,{variant:"outline",className:"bg-red-50 text-red-700",children:[e.jsx(ue,{className:"w-3 h-3 mr-1"}),"Failed"]});default:return e.jsx(m,{variant:"outline",className:"bg-gray-50 text-gray-700",children:o})}},S=(s,o)=>e.jsxs(ne,{children:[e.jsx(le,{children:e.jsxs(J,{children:[e.jsx(f,{children:"Date"}),e.jsx(f,{children:"Time"}),e.jsx(f,{children:"Players"}),e.jsx(f,{children:"Types"}),e.jsx(f,{children:"Cart"}),e.jsx(f,{children:"Price"}),e.jsx(f,{children:"Payment"}),c&&e.jsx(f,{children:"Status"}),!o&&e.jsx(f,{className:"text-right",children:"Actions"})]})}),e.jsx(ce,{children:s.map(t=>{var C,B;const w=t.teeTimeSlot?P(t.teeTimeSlot.date,t.teeTimeSlot.time):!1;return e.jsxs(J,{className:`${t.status==="cancelled"||t.archived?"opacity-60":""} hover:bg-gray-50 cursor-pointer`,onClick:()=>v(t),children:[e.jsx(j,{children:t.teeTimeSlot?t.teeTimeSlot.date:"N/A"}),e.jsx(j,{children:(C=t.teeTimeSlot)!=null&&C.time?se(t.teeTimeSlot.time):"N/A"}),e.jsx(j,{children:e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:((B=t.players)==null?void 0:B[0])||"Unknown"}),t.players&&t.players.length>1&&e.jsx("div",{className:"text-xs text-muted-foreground mt-1 space-y-0.5",children:t.players.slice(1).map((p,x)=>{const E=t.playerEmails&&t.playerEmails[x+1];return e.jsxs("div",{children:[p,E&&e.jsxs("span",{className:"text-gray-500 ml-1",children:["(",E,")"]})]},x+1)})})]})}),e.jsx(j,{children:t.playerTypes?e.jsx("div",{className:"flex flex-col gap-0.5",children:t.playerTypes.map((p,x)=>e.jsx("div",{className:"text-xs",children:e.jsx(m,{variant:"outline",className:"font-normal bg-blue-50",children:_(p)})},x))}):e.jsx("span",{className:"text-gray-500 text-xs",children:"-"})}),e.jsx(j,{children:t.cartRequested?e.jsxs("div",{children:[e.jsxs(m,{variant:"outline",className:"bg-green-50",children:["Yes ",t.cartCount&&t.cartCount>0?`(${t.cartCount})`:""]}),t.cartNumbers&&t.cartNumbers.length>0&&e.jsxs("div",{className:"text-xs mt-1 text-gray-600",children:["Cart #: ",t.cartNumbers.join(", ")
1]})]}):e.jsx(m,{variant:"outline",className:"bg-gray-50",children:"No"})}),e.jsxs(j,{children:["$",t.price]}),e.jsx(j,{children:T(t)}),c&&e.jsx(j,{children:t.archived?e.jsxs(m,{variant:"outline",className:"bg-amber-50 text-amber-700",children:[e.jsx(de,{className:"w-3 h-3 mr-1"}),"Archived"]}):t.status==="cancelled"?e.jsx(m,{variant:"outline",className:"bg-red-50 text-red-700",children:"Cancelled"}):e.jsx(m,{variant:"outline",className:"bg-green-50 text-green-700",children:"Active"})}),!o&&e.jsx(j,{className:"text-right",onClick:p=>p.stopPropagation(),children:e.jsx(A,{variant:"outline",size:"sm",onClick:p=>{p.stopPropagation(),r(t.id)},disabled:w||t.status==="cancelled"||t.archived,children:t.status==="cancelled"?"Cancelled":"Cancel"})})]},t.id)})})]});return e.jsxs(q,{children:[e.jsxs(R,{children:[e.jsx(H,{children:"My Bookings"}),e.jsxs(W,{children:["Your tee times ",c?"(including archived)":""]})]}),e.jsx(te,{children:e.jsxs(oe,{defaultValue:"future",className:"w-full",children:[e.jsxs(me,{className:"mb-4",children:[e.jsxs(G,{value:"future",children:["Upcoming Bookings (",h.length,")"]}),e.jsxs(G,{value:"past",children:["Past Bookings (",u.length,")"]})]}),e.jsx(K,{value:"future",children:h.length>0?S(h,!1):e.jsx("p",{className:"text-muted-foreground py-4",children:"You don't have any upcoming bookings."})}),e.jsx(K,{value:"past",children:u.length>0?S(u,!0):e.jsx("p",{className:"text-muted-foreground py-4",children:"You don't have any past bookings."})})]})})]})},De=()=>{const{selectedDate:i,setSelectedDate:y,getAvailableTeeTimeSlots:c,fetchTeeTimeSlots:N}=b(),{settings:n}=Z();g.useEffect(()=>{N(i)},[i]);const d=n.seasonStartDate?new Date(n.seasonStartDate):new Date(2025,4,3),D=n.seasonEndDate?new Date(n.seasonEndDate):new Date(2025,10,30),l=r=>{r&&y(r)},u=r=>{const v=ae(r);return c(v).filter(T=>T.availableSpots>0).length},h=i?u(i):0;return e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold text-lg mb-2",children:"Select Date"}),e.jsxs(ve,{children:[e.jsx(Se,{asChild:!0,children:e.jsxs(A,{variant:"outline",className:z("w-full md:w-64 justify-start text-left font-normal border border-input","focus:outline-none focus:ring-2 focus:ring-golf-green focus:ring-opacity-50"),children:[e.jsx(ee,{className:"mr-2 h-4 w-4"}),e.jsx("span",{className:"flex-1",children:k(i)}),h>0&&e.jsxs("span",{className:"bg-golf-green-light text-golf-green-dark text-xs px-2 py-0.5 rounded-full ml-2",children:[h," slots"]})]})}),e.jsxs(Ne,{className:"w-auto p-0",align:"start",children:[e.jsx(ye,{mode:"single",selected:i,onSelect:l,disabled:r=>!r||r<d||r>D,initialFocus:!0,className:z("p-3 pointer-events-auto"),components:{DayContent:({date:r,...v})=>e.jsxs("div",{...v,className:"relative",children:[e.jsx("div",{children:r.getDate()}),r&&u(r)>0&&e.jsxs("div",{className:"text-[10px] mt-1 text-green-600",children:[u(r)," slots"]})]})}}),e.jsxs("div",{className:"text-xs text-center p-2 text-gray-500 border-t",children:["Golf season: ",n.seasonStartDate?new Date(n.seasonStartDate).toLocaleDateString("en-US",{month:"short",day:"numeric"}):"May 3"," - ",n.seasonEndDate?new Date(n.seasonEndDate).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}):"November 30, 2025"]})]})]})]})},qt=()=>{const{isAuthenticated:i,loading:y,currentUser:c,isSuperAdmin:N}=Q(),{settings:n}=Z(),d=O(),{facilitySlug:D}=V(),{defaultFacility:l}=re(),[u,h]=g.useState([]),[r,v]=g.useState(new Date),[_,T]=g.useState(!0),[S,s]=g.useState(!1),[o,t]=g.useState({});g.useEffect(()=>{!y&&!i&&d("/login")},[i,y,d]),g.useEffect(()=>{!D&&(l!=null&&l.slug)&&d(`/f/${l.slug}/my-bookings`,{replace:!0})},[D,l==null?void 0:l.slug,d]),g.useEffect(()=>{i&&c&&(async()=>{if(c){T(!0);try{let x=X.from("bookings").select("*, tee_time_slots(*)").or(`user_id.eq.${c.id},player_user_ids.cs.{${c.id}}`);(!S||!N)&&(x=x.eq("archived",!1));const{data:E,error:L}=await x.order("created_at",{ascending:!1});if(L)throw L;const F=E.map(a=>({id:a.id,userId:a.user_id,teeTimeSlotId:a.tee_time_slot_id,teeTimeId:a.tee_time_slot_id,roundPassId:a.round_pass_id,playerCount:a.player_count,players:a.players||[],playerEmails:a.player_emails||[],cartRequested:a.cart_requested,cartCount:a.cart_count||0,createdAt:new Date(a.created_at),price:a.price,checkedIn:a.checked_in,checkedInAt:a.checked_in_at?new Date(a.checked_in_at):void 0,checkedInBy:a.checked_in_by,status:a.status||"active",archived:a.archived||!1,paymentMethod:a.payment_method,paymentStatus:a.payment_status||"pending",teeTimeSlot:a.tee_time_slots?{id:a.tee_time_slots.id,date:a.tee_time_slots.date,time:a.tee_time_slots.time,availableSpots:a.tee_time_slots.available_spots}:void 0}));h(F);const M={};F.forEach(a=>{var U;
1if((U=a.teeTimeSlot)!=null&&U.date&&a.status!=="cancelled"){const Y=a.teeTimeSlot.date;M[Y]=(M[Y]||0)+1}}),t(M)}catch(x){console.error("Error fetching bookings:",x),$.error("Failed to load your bookings")}finally{T(!1)}}})()},[i,c,S,N]);const w=n.seasonStartDate?new Date(n.seasonStartDate):new Date(2025,4,3),C=n.seasonEndDate?new Date(n.seasonEndDate):new Date(2025,10,30),B=()=>v(new Date);return y||_&&i?e.jsx(I,{children:e.jsx("div",{className:"container mx-auto px-4 py-8 flex justify-center items-center min-h-[60vh]",children:e.jsx("p",{children:"Loading..."})})}):!y&&!i?null:e.jsx(I,{children:e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsx("h1",{className:"text-3xl font-bold mb-8",children:"My Bookings"}),e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-4",children:[e.jsx(De,{}),e.jsxs("div",{className:"flex items-center gap-2",children:[ie(r)&&e.jsx("div",{className:"flex items-center text-sm text-muted-foreground mr-3",children:e.jsxs("span",{children:["Current date: ",k(r)]})}),e.jsxs(A,{onClick:B,variant:"outline",className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),"Today"]}),N&&e.jsx(A,{onClick:()=>s(p=>!p),variant:S?"default":"outline",children:S?"Hide Archived":"Show Archived"})]})]}),e.jsx(ge,{selectedDate:r,onDateSelect:v,seasonStartDate:w,seasonEndDate:C,bookingCounts:o,isDateAllowedForBooking:()=>!0})]}),e.jsx(Ce,{bookings:u,setBookings:h,showArchived:S})]})})};export{qt 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.