1"use strict";(self.webpackChunkquickGrowth=self.webpackChunkquickGrowth||[]).push([[3359],{3359(e,t,r){r.r(t),r.d(t,{default:()=>p});var s=r(2555),a=r(5043),l=r(5475),n=r(3216),i=r(3976),d=r(5016),o=r(579);const c={submitted:{label:"Submitted",color:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30"},assigned:{label:"Assigned to Rep",color:"bg-yellow-400/15 text-yellow-400 border-yellow-400/25"},discovery:{label:"Discovery",color:"bg-orange-500/20 text-orange-400 border-orange-500/30"},pricing_review:{label:"Pricing Review",color:"bg-purple-500/20 text-purple-400 border-purple-500/30"},contract_sent:{label:"Contract Ready",color:"bg-cyan-500/20 text-cyan-400 border-cyan-500/30"},client_review:{label:"Under Review",color:"bg-sky-500/20 text-sky-400 border-sky-500/30"},approved:{label:"Approved",color:"bg-green-500/20 text-green-400 border-green-500/30"},converted_to_job:{label:"Project Started",color:"bg-emerald-500/20 text-emerald-400 border-emerald-500/30"},declined:{label:"Declined",color:"bg-red-500/20 text-red-400 border-red-500/30"}},x={urgent:"text-red-400",high:"text-orange-400",medium:"text-yellow-400",low:"text-secondary"};function m(e){if(!e)return"";const t=Date.now()-new Date(e).getTime(),r=Math.floor(t/6e4);if(r<1)return"just now";if(r<60)return"".concat(r,"m ago");const s=Math.floor(r/60);return s<24?"".concat(s,"h ago"):"".concat(Math.floor(s/24),"d ago")}const u={admin:"bg-purple-500/20 text-purple-400 border-purple-500/30",sales_rep:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",client:"bg-green-500/20 text-green-400 border-green-500/30"};function p(){var e;const{id:t}=(0,n.g)(),r=(0,n.Zp)(),p=(0,n.zy)(),{user:h}=(0,d.As)(),[b,f]=(0,a.useState)(null),[y,g]=(0,a.useState)(!0),[j,v]=(0,a.useState)(null),[w,N]=(0,a.useState)((null===(e=p.state)||void 0===e?void 0:e.activeTab)||"overview"),[_,k]=(0,a.useState)(null),[C,S]=(0,a.useState)([]),[q,D]=(0,a.useState)(!1),[L,M]=(0,a.useState)(""),[R,A]=(0,a.useState)(!1),z=(0,a.useRef)(null),[T,B]=(0,a.useState)(!1),[P,Y]=(0,a.useState)(!1),[E,W]=(0,a.useState)(""),[I,O]=(0,a.useState)(!1),U=(0,a.useCallback)((async()=>{g(!0);try{const{data:e,error:r}=await i.supabase.from("service_requests").select("\n *,\n assigned_rep:profiles!service_requests_assigned_sales_rep_id_fkey(id, full_name, email)\n ").eq("id",t).eq("client_id",h.id).single();if(r)throw r;f(e)}catch(e){v("Request not found or access denied")}finally{g(!1)}}),[t,h.id]),F=(0,a.useCallback)((async()=>{D(!0);try{const{data:e}=await i.supabase.from("job_threads").select("*").eq("service_request_id",t).eq("thread_type","external").single();if(e){k(e);const{data:t}=await i.supabase.from("messages").select("*, sender:profiles!messages_sender_id_fkey(id, full_name, role)").eq("thread_id",e.id).order("created_at",{ascending:!0});S(t||[]),setTimeout((()=>{var e;return null===(e=z.current)||void 0===e?void 0:e.scrollIntoView({behavior:"smooth"})}),100)}}catch(e){}finally{D(!1)}}),[t]);(0,a.useEffect)((()=>{U()}),[U]),(0,a.useEffect)((()=>{y||F()}),[y,F]);const V=async()=>{if(L.trim()){A(!0);try{let e=_;if(!e){const{data:r,error:s}=await i.supabase.from("job_threads").insert({service_request_id:t,thread_type:"external"}).select().single();if(s)throw s;e=r,k(r)}const{data:r,error:s}=await i.supabase.from("messages").insert({thread_id:e.id,sender_id:h.id,content:L.trim()}).select("*, sender:profiles!messages_sender_id_fkey(id, full_name, role)").single();if(s)throw s;S((e=>[...e,r])),M(""),setTimeout((()=>{var e;return null===(e=z.current)||void 0===e?void 0:e.scrollIntoView({behavior:"smooth"})}),100)}catch(e){console.error("Error sending message:",e)}finally{A(!1)}}},G=[{key:"overview",label:"Overview"},{key:"chat",label:"Chat",badge:C.length||null},...null!==b&&void 0!==b&&b.contract_sent_at?[{key:"contract",label:"Contract"}]:[]];if(y)return(0,o.jsx)("div",{className:"flex items-center justify-center py-20",children:(0,o.jsx)("div",{className:"w-10 h-10 border-2 border-yellow-500 border-t-transparent rounded-full animate-spin"})});if(j||!b)return(0,o.jsxs)("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[(0,o.jsx)("p",{className:"text-red-400 mb-4 text-sm",children:j}),(0,o.jsx)("button",{onClick:()=>r("/dashboard/client/services"),className:"text-yellow-500 hover:text-yellow-400 text-sm",children:"\u2190 Back to requests"})]});const H=c[b.workflow_status]||c.submitted,K=!!b.contract_sent_at,$=!!b.contract_accepted_at;return(0,o.jsxs)("div",{className:"space-y-6",children:[(0,o.jsxs)("div",{className:"flex items-center gap-3",children:[(0,o.jsxs)("button",{onClick:()=>r("/dashboard/client/services"),className:"flex items-center gap-1.5 text-sm text-secondary hover:text-primary transition-colors",children:[(0,o.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),"My Requests"]}),(0,o.jsx)("span",{className:"text-muted",children:"/"}),(0,o.jsx)("span",{className:"text-sm text-primary truncate",children:b.title})]}),(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-2xl p-5 sm:p-6",children:[(0,o.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start gap-4",children:[(0,o.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,o.jsxs)("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[(0,o.jsx)("h1",{className:"text-xl font-bold text-primary",children:b.title}),(0,o.jsx)("span",{className:"px-2.5 py-1 rounded-full text-xs font-medium border ".concat(H.color),children:H.label})]}),(0,o.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted",children:[(0,o.jsx)("span",{children:b.service_type}),b.priority&&(0,o.jsx)("span",{className:"capitalize font-medium ".concat(x[b.priority]),children:b.priority}),(0,o.jsxs)("span",{children:["Submitted ",new Date(b.created_at).toLocaleDateString()]})]})]}),b.job_id&&(0,o.jsx)(l.N_,{to:"/dashboard/client/jobs/".concat(b.job_id),className:"text-xs px-3 py-2 bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 rounded-lg hover:bg-emerald-500/30 transition-colors flex-shrink-0",children:"View Your Project \u2192"})]}),b.assigned_rep&&(0,o.jsxs)("div",{className:"mt-4 pt-4 border-t border-theme flex items-center gap-3",children:[(0,o.jsx)("div",{className:"w-8 h-8 rounded-full bg-yellow-500/10 border border-yellow-500/20 flex items-center justify-center",children:(0,o.jsx)("span",{className:"text-xs font-bold text-yellow-500",children:(b.assigned_rep.full_name||b.assigned_rep.email||"R")[0].toUpperCase()})}),(0,o.jsxs)("div",{children:[(0,o.jsx)("p",{className:"text-xs text-muted",children:"Your Account Manager"}),(0,o.jsx)("p",{className:"text-sm font-medium text-primary",children:b.assigned_rep.full_name||b.assigned_rep.email})]})]})]}),K&&!$&&(0,o.jsxs)("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-2xl p-5 flex flex-col sm:flex-row sm:items-center gap-4",children:[(0,o.jsxs)("div",{className:"flex-1",children:[(0,o.jsx)("p",{className:"text-sm font-semibold text-yellow-400 mb-1",children:"Your contract is ready for review"}),(0,o.jsx)("p",{className:"text-xs text-secondary",children:"Review the contract in the Contract tab and accept or request changes before your project begins."})]}),(0,o.jsx)("button",{onClick:()=>N("contract"),className:"px-4 py-2.5 bg-yellow-500 text-black font-medium rounded-xl hover:bg-yellow-400 transition-colors text-sm flex-shrink-0",children:"Review Contract"})]}),$&&!b.job_id&&(0,o.jsxs)("div",{className:"bg-green-500/10 border border-green-500/20 rounded-2xl p-4 flex items-center gap-3",children:[(0,o.jsx)("svg",{className:"w-5 h-5 text-green-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,o.jsx)("p",{className:"text-sm text-green-400",children:"Contract accepted \u2014 your project will be set up shortly."})]}),(0,o.jsx)("div",{className:"border-b border-theme",children:(0,o.jsx)("div",{className:"flex gap-1 overflow-x-auto scrollbar-hide",children:G.map((e=>(0,o.jsxs)("button",{onClick:()=>N(e.key),className:"flex items-center gap-1.5 px-4 py-2.5 text-sm font-medium whitespace-nowrap border-b-2 transition-colors ".concat(w===e.ke
1y?"border-yellow-500 text-yellow-500":"border-transparent text-secondary hover:text-primary"),children:[e.label,e.badge&&(0,o.jsx)("span",{className:"text-xs bg-card border border-theme px-1.5 py-0.5 rounded-full",children:e.badge})]},e.key)))})}),"overview"===w&&(0,o.jsxs)("div",{className:"space-y-4",children:[(0,o.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl p-5",children:[(0,o.jsx)("h3",{className:"text-xs font-semibold text-secondary uppercase tracking-wider mb-3",children:"Your Request"}),(0,o.jsxs)("dl",{className:"space-y-2.5 text-sm",children:[(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Service"}),(0,o.jsx)("dd",{className:"text-primary",children:b.service_type})]}),(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Budget"}),(0,o.jsx)("dd",{className:"text-primary",children:b.budget||"\u2014"})]}),(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Timeline"}),(0,o.jsx)("dd",{className:"text-primary",children:b.timeline_preference||"\u2014"})]}),(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Priority"}),(0,o.jsx)("dd",{className:"capitalize font-medium ".concat(x[b.priority]||"text-secondary"),children:b.priority||"\u2014"})]})]})]}),(b.final_agreed_price||b.proposed_price||b.scope_summary)&&(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl p-5",children:[(0,o.jsx)("h3",{className:"text-xs font-semibold text-secondary uppercase tracking-wider mb-3",children:"Proposed Terms"}),(0,o.jsxs)("dl",{className:"space-y-2.5 text-sm",children:[b.final_agreed_price&&(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Total Price"}),(0,o.jsxs)("dd",{className:"text-yellow-400 font-bold",children:["$",Number(b.final_agreed_price).toLocaleString("en-US",{minimumFractionDigits:2})]})]}),b.retainer_amount&&(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Deposit Due"}),(0,o.jsxs)("dd",{className:"text-primary",children:["$",Number(b.retainer_amount).toLocaleString("en-US",{minimumFractionDigits:2})]})]}),b.timeline&&(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Timeline"}),(0,o.jsx)("dd",{className:"text-primary",children:b.timeline})]}),null!=b.revision_limit&&(0,o.jsxs)("div",{className:"flex justify-between",children:[(0,o.jsx)("dt",{className:"text-muted",children:"Revisions"}),(0,o.jsx)("dd",{className:"text-primary",children:b.revision_limit})]})]})]})]}),b.description&&(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl p-5",children:[(0,o.jsx)("h3",{className:"text-xs font-semibold text-secondary uppercase tracking-wider mb-2",children:"Your Description"}),(0,o.jsx)("p",{className:"text-sm text-secondary whitespace-pre-wrap leading-relaxed",children:b.description})]}),b.scope_summary&&(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl p-5",children:[(0,o.jsx)("h3",{className:"text-xs font-semibold text-secondary uppercase tracking-wider mb-2",children:"Agreed Scope"}),(0,o.jsx)("p",{className:"text-sm text-secondary whitespace-pre-wrap leading-relaxed",children:b.scope_summary}),b.deliverables&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("h4",{className:"text-xs font-semibold text-secondary uppercase tracking-wider mt-4 mb-2",children:"Deliverables"}),(0,o.jsx)("p",{className:"text-sm text-secondary whitespace-pre-wrap",children:b.deliverables})]})]})]}),"chat"===w&&(0,o.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,o.jsx)("p",{className:"text-xs text-muted",children:"Chat directly with your account manager. All messages are saved."}),(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl flex flex-col",style:{height:"420px"},children:[(0,o.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[q?(0,o.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,o.jsx)("div",{className:"w-6 h-6 border-2 border-yellow-500 border-t-transparent roun
1ded-full animate-spin"})}):0===C.length?(0,o.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[(0,o.jsx)("svg",{className:"w-10 h-10 text-muted mb-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,o.jsx)("p",{className:"text-sm text-muted",children:"No messages yet. Ask your account manager a question."})]}):C.map((e=>{var t,r,s;const a=e.sender_id===h.id;return(0,o.jsxs)("div",{className:"flex gap-2.5 ".concat(a?"flex-row-reverse":""),children:[(0,o.jsx)("div",{className:"w-7 h-7 rounded-full flex items-center justify-center flex-shrink-0 text-xs font-bold border ".concat(u[null===(t=e.sender)||void 0===t?void 0:t.role]||u.client),children:((null===(r=e.sender)||void 0===r?void 0:r.full_name)||"?")[0].toUpperCase()}),(0,o.jsxs)("div",{className:"max-w-[75%] flex flex-col gap-1 ".concat(a?"items-end":"items-start"),children:[(0,o.jsxs)("div",{className:"flex items-center gap-2",children:[(0,o.jsx)("span",{className:"text-xs text-muted",children:a?"You":(null===(s=e.sender)||void 0===s?void 0:s.full_name)||"Team"}),(0,o.jsx)("span",{className:"text-xs text-muted",children:m(e.created_at)})]}),(0,o.jsx)("div",{className:"px-3.5 py-2.5 rounded-2xl text-sm leading-relaxed ".concat(a?"bg-yellow-500/20 text-primary rounded-tr-sm":"bg-surface text-primary rounded-tl-sm"),children:e.content})]})]},e.id)})),(0,o.jsx)("div",{ref:z})]}),(0,o.jsxs)("div",{className:"border-t border-theme p-3 flex gap-2",children:[(0,o.jsx)("textarea",{value:L,onChange:e=>M(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),V())},placeholder:"Send a message to your account manager\u2026",rows:1,className:"flex-1 bg-input border border-theme rounded-xl px-3 py-2 text-sm text-primary placeholder-muted focus:outline-none focus:border-yellow-500 resize-none"}),(0,o.jsx)("button",{onClick:V,disabled:R||!L.trim(),className:"px-4 py-2 bg-yellow-500 text-black font-medium rounded-xl hover:bg-yellow-400 disabled:opacity-50 transition-colors text-sm flex-shrink-0",children:R?"\u2026":"Send"})]})]})]}),"contract"===w&&(0,o.jsxs)("div",{className:"space-y-4",children:[$?(0,o.jsxs)("div",{className:"bg-green-500/10 border border-green-500/20 rounded-xl px-4 py-3 flex items-center gap-3",children:[(0,o.jsx)("svg",{className:"w-5 h-5 text-green-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,o.jsxs)("p",{className:"text-sm text-green-400 font-medium",children:["You accepted this contract on ",new Date(b.contract_accepted_at).toLocaleDateString()]})]}):(0,o.jsxs)("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-xl px-4 py-3 flex items-center gap-3",children:[(0,o.jsxs)("svg",{className:"w-5 h-5 text-yellow-400 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,o.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]}),(0,o.jsx)("p",{className:"text-sm text-yellow-400",children:"Please review the contract below and accept or request changes."})]}),(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-xl overflow-hidden",children:[(0,o.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-b border-theme",children:[(0,o.jsx)("h3",{className:"text-xs font-semibold text-secondary uppercase tracking-wider",children:"Contract"}),b.contract_version&&(0,o.jsxs)("span",{className:"text-xs text-muted",children:["v",b.contract_version]})]}),(0,o.jsx)("div",{className:"overflow-y-auto p-6 sm:p-8",style:{maxHeight:"70vh",minHeight:"320px"},children:(0,o.jsx)("pre",{className:"text-sm text-primary whitespace-pre-wrap leading-[1.75] font-sans",children:b.contract_content})})]}),!$&&(0,o.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,o.jsx)("button",{onClick:async()=>{B(!0);try{const e=(new Date).toISOString(),{error:r}=await i.supabase.from("service_requests").update({contract_accepted_at:e,workflow_status:"approved"}).eq("id",t).eq("client_id",h.id);if(r)throw r;f((t=>(0,s.A)((0,s.A)({},t),{},{contract_accepted_at:e,workflow_status:"approved"})))}catch(e){console.error("Error accepting contract:",e)}finally{B(!1)}},disabled:T,className:"px-6 py-2.5 bg-green-600 text-white font-medium rounded-xl hover:bg-green-500 disabled:opacity-50 transition-colors text-sm",children:T?"Accepting\u2026":"Accept Contract"}),(0,o.jsx)("button",{onClick:()=>O(!0),className:"px-6 py-2.5 border border-theme text-secondary hover:text-red-400 hover:border-red-500/30 rounded-xl transition-colors text-sm",children:"Request Changes"})]})]}),I&&(0,o.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50 p-4",children:(0,o.jsxs)("div",{className:"bg-card border border-theme rounded-2xl p-6 w-full max-w-sm",children:[(0,o.jsx)("h2",{className:"text-lg font-bold text-primary mb-2",children:"Request Changes"}),(0,o.jsx)("p",{className:"text-sm text-secondary mb-4",children:"Let us know what you'd like changed. Our team will review your feedback and revise the contract."}),(0,o.jsx)("textarea",{value:E,onChange:e=>W(e.target.value),placeholder:"Describe what you'd like changed\u2026",rows:4,className:"w-full bg-input border border-theme rounded-xl px-4 py-3 text-primary text-sm focus:outline-none focus:border-yellow-500 resize-none mb-4"}),(0,o.jsxs)("div",{className:"flex gap-3",children:[(0,o.jsx)("button",{onClick:async()=>{Y(!0);try{const{error:e}=await i.supabase.from("service_requests").update({contract_declined_at:(new Date).toISOString(),workflow_status:"client_review",declined_reason:E.trim()||null}).eq("id",t).eq("client_id",h.id);if(e)throw e;f((e=>(0,s.A)((0,s.A)({},e),{},{workflow_status:"client_review",contract_declined_at:(new Date).toISOString()}))),O(!1)}catch(e){console.error("Error declining contract:",e)}finally{Y(!1)}},disabled:P,className:"flex-1 px-4 py-2.5 bg-red-600 text-white font-medium rounded-xl hover:bg-red-500 disabled:opacity-50 transition-colors text-sm",children:P?"Sending\u2026":"Send Feedback"}),(0,o.jsx)("button",{onClick:()=>O(!1),className:"flex-1 px-4 py-2.5 border border-theme text-secondary rounded-xl hover:text-primary transition-colors text-sm",children:"Cancel"})]})]})}),(0,o.jsx)("style",{children:".scrollbar-hide::-webkit-scrollbar{display:none}.scrollbar-hide{-ms-overflow-style:none;scrollbar-width:none}"})]})}}}]); 2//# sourceMappingURL=3359.8a2dd0af.chunk.js.map
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.