Files
doormile_crm_build/dist/assets/Survey-q3ahIjIS.js
2026-06-16 16:28:00 +05:30

2 lines
16 KiB
JavaScript

import{r as F,j as e,i as H,a as m,S as u,B as d,T as n,H as le,C as oe,I as w,K as V,L as ce}from"./index-DdJWTZFy.js";import{d as de,D as xe,a as he,b as ue,c as pe,e as G,f as ge}from"./DeleteOutline-DetaO5yn.js";import{d as me,a as je,b as D,c as fe}from"./StorefrontOutlined-DupKwNFq.js";import{T as ye,d as be}from"./PhoneOutlined-CBkctqNs.js";import{d as ve}from"./LocalShippingOutlined-DRozEKne.js";import{P as _e,G as c,C}from"./PageHeader-CdP5B6Qy.js";import{E as Ce}from"./EmptyState-CQsHTCg9.js";import{B as $}from"./Button-Bcwcjqrt.js";import{C as Se}from"./Link-Dp34e72e.js";import{T as h}from"./TextField-Btd7UbKs.js";import{I as ke}from"./InputAdornment-Bnl7vvhj.js";import{T as $e,a as ze,b as Pe,c as z,d as l,e as We}from"./TableRow-CEoQ4SIZ.js";var L={},Re=H;Object.defineProperty(L,"__esModule",{value:!0});var A=L.default=void 0,Te=Re(F()),Ie=e;A=L.default=(0,Te.default)((0,Ie.jsx)("path",{d:"M7 15h7v2H7zm0-4h10v2H7zm0-4h10v2H7zm12-4h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-.14 0-.27.01-.4.04-.39.08-.74.28-1.01.55-.18.18-.33.4-.43.64-.1.23-.16.49-.16.77v14c0 .27.06.54.16.78s.25.45.43.64c.27.27.62.47 1.01.55.13.02.26.03.4.03h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m-7-.25c.41 0 .75.34.75.75s-.34.75-.75.75-.75-.34-.75-.75.34-.75.75-.75M19 19H5V5h14z"}),"AssignmentOutlined");var M={},we=H;Object.defineProperty(M,"__esModule",{value:!0});var K=M.default=void 0,De=we(F()),Ee=e;K=M.default=(0,De.default)((0,Ee.jsx)("path",{d:"M23 8c0 1.1-.9 2-2 2-.18 0-.35-.02-.51-.07l-3.56 3.55c.05.16.07.34.07.52 0 1.1-.9 2-2 2s-2-.9-2-2c0-.18.02-.36.07-.52l-2.55-2.55c-.16.05-.34.07-.52.07s-.36-.02-.52-.07l-4.55 4.56c.05.16.07.33.07.51 0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2c.18 0 .35.02.51.07l4.56-4.55C8.02 9.36 8 9.18 8 9c0-1.1.9-2 2-2s2 .9 2 2c0 .18-.02.36-.07.52l2.55 2.55c.16-.05.34-.07.52-.07s.36.02.52.07l3.55-3.56C19.02 8.35 19 8.18 19 8c0-1.1.9-2 2-2s2 .9 2 2"}),"TimelineOutlined");var N={},Be=H;Object.defineProperty(N,"__esModule",{value:!0});var X=N.default=void 0,Oe=Be(F()),Ae=e;X=N.default=(0,Oe.default)((0,Ae.jsx)("path",{d:"M22 8.98V18c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2l.01-12c0-1.1.89-2 1.99-2h10.1c-.06.32-.1.66-.1 1s.04.68.1 1H4l8 5 3.67-2.29c.47.43 1.02.76 1.63.98L12 13 4 8v10h16V9.9c.74-.15 1.42-.48 2-.92M16 5c0 1.66 1.34 3 3 3s3-1.34 3-3-1.34-3-3-3-3 1.34-3 3"}),"MarkEmailUnreadOutlined");const P="https://api.doormile.com/api/v1",q=()=>{const r=localStorage.getItem("auth_token");return{"Content-Type":"application/json",...r?{Authorization:`Bearer ${r}`}:{}}};async function J(r=1){const s=await fetch(`${P}/admin/competitor-branches?limit=200&page=${r}`,{headers:q()});if(!s.ok)throw new Error("Failed to fetch branches");return s.json()}async function Fe(r){const{id:s,created_at:j,updated_at:o,...f}=r,x=s?`${P}/admin/competitor-branches/${s}`:`${P}/admin/competitor-branches`,b=await fetch(x,{method:s?"PUT":"POST",headers:q(),body:JSON.stringify(f)});if(!b.ok)throw new Error("Failed to save branch");return b.json()}async function He(r){const s=await fetch(`${P}/admin/competitor-branches/${r}`,{method:"DELETE",headers:q()});if(!s.ok)throw new Error("Failed to delete branch");return s.json()}const Le={id:null,company:"",area:"",phone:"",rate_per_kg:"",offers_pickup:"",offers_drop:"",time_in_days:"",packing_charge:"",plus_code:"",address:""},Me={textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700,color:"grey.700"};function _({label:r,color:s="default"}){return r==null||r===""?e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.500"},children:"—"}):e.jsx(C,{size:"small",label:r,sx:{fontWeight:600,...s==="default"?{bgcolor:"grey.100",color:"grey.700"}:{bgcolor:`${s}.lighter`,color:`${s}.dark`}}})}function y({label:r,children:s}){return e.jsxs(d,{children:[e.jsx(n,{variant:"caption",color:"text.secondary",sx:Me,children:r}),e.jsx(d,{sx:{mt:.5},children:s})]})}function E({label:r,value:s}){return e.jsx(y,{label:r,children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:s?"grey.800":"grey.500",wordBreak:"break-word"},children:s||"—"})})}function B({icon:r,title:s,accent:j="primary",children:o}){return e.jsxs(d,{sx:{height:"100%",borderRadius:2,border:1,borderColor:"divider",bgcolor:"background.paper",overflow:"hidden",boxShadow:"0 2px 8px rgba(0,0,0,0.03)"},children:[e.jsxs(u,{direction:"row",spacing:1,alignItems:"center",sx:{px:2,py:1.5,borderBottom:1,borderColor:"divider",bgcolor:`${j}.lighter`,opacity:.999},children:[e.jsx(r,{sx:{fontSize:18,color:`${j}.main`}}),e.jsx(n,{variant:"overline",sx:{fontWeight:700,color:"grey.800",letterSpacing:.6,lineHeight:1},children:s})]}),e.jsx(u,{spacing:2,sx:{p:2},children:o})]})}function O({label:r,value:s,icon:j,color:o="primary"}){return e.jsx(d,{sx:{flex:1,p:2.5,borderRadius:2,border:1,borderColor:"divider",bgcolor:"background.paper",boxShadow:"0 4px 20px rgba(0,0,0,0.03)"},children:e.jsxs(u,{direction:"row",spacing:2,alignItems:"center",children:[e.jsx(d,{sx:{width:48,height:48,borderRadius:2,bgcolor:`${o}.lighter`,color:`${o}.main`,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(j,{sx:{fontSize:24}})}),e.jsxs(d,{children:[e.jsx(n,{variant:"h4",sx:{fontWeight:800,color:"grey.800",lineHeight:1.1},children:s}),e.jsx(n,{variant:"body2",sx:{fontWeight:600,mt:.5},color:"text.secondary",children:r})]})]})})}function Ne({row:r,onEdit:s,onDelete:j}){const[o,f]=m.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs(z,{hover:!0,sx:{"& > *":{borderBottom:"unset"}},children:[e.jsx(l,{sx:{pl:1,width:48},children:e.jsx(w,{size:"small",onClick:()=>f(!o),sx:{color:"grey.500",bgcolor:o?"grey.100":"transparent","&:hover":{bgcolor:"grey.200"}},children:o?e.jsx(me,{}):e.jsx(je,{})})}),e.jsxs(l,{children:[e.jsx(n,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:r.area||"—"}),r.company&&e.jsx(n,{variant:"caption",color:"text.secondary",children:r.company})]}),e.jsx(l,{children:e.jsxs(u,{direction:"row",spacing:.75,alignItems:"center",children:[e.jsx(be,{sx:{fontSize:15,color:"grey.400"}}),e.jsx(n,{variant:"body2",children:r.phone||"—"})]})}),e.jsx(l,{children:e.jsxs(u,{direction:"row",spacing:.75,alignItems:"flex-start",children:[e.jsx(D,{sx:{fontSize:16,color:"grey.400",mt:.2}}),e.jsx(n,{variant:"body2",sx:{maxWidth:250,display:"-webkit-box",WebkitLineClamp:1,WebkitBoxOrient:"vertical",overflow:"hidden"},children:r.address||"—"})]})}),e.jsx(l,{children:e.jsx(n,{variant:"body2",sx:{fontWeight:600},children:r.rate_per_kg||"—"})}),e.jsx(l,{children:e.jsxs(u,{direction:"row",spacing:1,flexWrap:"wrap",children:[r.offers_pickup&&e.jsx(C,{size:"small",label:`Pickup: ${r.offers_pickup}`}),r.offers_drop&&e.jsx(C,{size:"small",label:`Drop: ${r.offers_drop}`}),r.time_in_days&&e.jsx(C,{size:"small",label:`Days: ${r.time_in_days}`}),r.packing_charge&&e.jsx(C,{size:"small",label:`Packing: ${r.packing_charge}`}),!r.offers_pickup&&!r.offers_drop&&!r.time_in_days&&!r.packing_charge&&e.jsx(n,{variant:"body2",color:"text.secondary",children:"—"})]})}),e.jsxs(l,{align:"right",children:[e.jsx(V,{title:"Edit",children:e.jsx(w,{size:"small",onClick:x=>{x.stopPropagation(),s(r)},children:e.jsx(G,{fontSize:"small"})})}),e.jsx(V,{title:"Delete",children:e.jsx(w,{size:"small",onClick:x=>{x.stopPropagation(),j(r)},children:e.jsx(ge,{fontSize:"small"})})})]})]}),e.jsx(z,{children:e.jsx(l,{colSpan:7,sx:{py:0,borderBottom:o?void 0:"none"},children:e.jsx(ce,{in:o,timeout:"auto",unmountOnExit:!0,children:e.jsxs(d,{sx:{m:2,borderRadius:2.5,border:1,borderColor:"divider",overflow:"hidden",boxShadow:"0 4px 16px rgba(0,0,0,0.06)"},children:[e.jsxs(u,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},spacing:1.5,sx:{px:2.5,py:1.75,borderBottom:1,borderColor:"divider",background:x=>`linear-gradient(90deg, ${x.palette.primary.lighter}88 0%, ${x.palette.background.paper} 75%)`},children:[e.jsxs(u,{direction:"row",spacing:1.5,alignItems:"center",children:[e.jsx(d,{sx:{width:40,height:40,borderRadius:"50%",bgcolor:"primary.main",color:"primary.contrastText",display:"flex",alignItems:"center",justifyContent:"center",fontWeight:700,fontSize:"1.2rem"},children:(r.company||r.area||"S")[0].toUpperCase()}),e.jsxs(d,{children:[e.jsx(n,{variant:"subtitle1",sx:{fontWeight:700,lineHeight:1.2},children:r.company||"Survey Record"}),e.jsx(n,{variant:"caption",color:"text.secondary",children:r.area||"Unknown Area"})]})]}),e.jsx($,{size:"small",variant:"contained",startIcon:e.jsx(G,{}),onClick:()=>s(r),children:"Edit Survey"})]}),e.jsx(d,{sx:{p:2.5,bgcolor:"grey.50"},children:e.jsxs(c,{container:!0,spacing:2.5,alignItems:"stretch",children:[e.jsx(c,{item:!0,xs:12,md:4,children:e.jsxs(B,{icon:fe,title:"Enquiry Details",accent:"primary",children:[e.jsx(y,{label:"Rate per kg",children:e.jsx(_,{label:r.rate_per_kg,color:r.rate_per_kg&&r.rate_per_kg!=="Not answered"?"success":"default"})}),e.jsx(y,{label:"Pickup",children:e.jsx(_,{label:r.offers_pickup,color:"info"})}),e.jsx(y,{label:"Drop",children:e.jsx(_,{label:r.offers_drop,color:"info"})}),e.jsx(y,{label:"Packing",children:e.jsx(_,{label:r.packing_charge,color:"info"})})]})}),e.jsx(c,{item:!0,xs:12,md:4,children:e.jsxs(B,{icon:ve,title:"Logistics & Ops",accent:"primary",children:[e.jsx(y,{label:"Time in Days",children:e.jsx(_,{label:r.time_in_days,color:"primary"})}),e.jsx(E,{label:"Company",value:r.company}),e.jsx(E,{label:"Contact Number",value:r.phone})]})}),e.jsx(c,{item:!0,xs:12,md:4,children:e.jsxs(B,{icon:D,title:"Location & Pincode",accent:"primary",children:[e.jsx(y,{label:"Area / Zone",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:r.area||"—"})}),e.jsx(E,{label:"Plus Code",value:r.plus_code}),e.jsx(y,{label:"Full Address",children:e.jsxs(u,{direction:"row",spacing:1,sx:{p:1.25,borderRadius:1.5,bgcolor:"grey.50",border:1,borderColor:"divider"},children:[e.jsx(D,{sx:{fontSize:16,color:"grey.400",mt:"2px"}}),e.jsx(n,{variant:"body2",sx:{color:"grey.800",lineHeight:1.5},children:r.address||"—"})]})})]})})]})})]})})})})]})}function tr(){const[r,s]=m.useState([]),[j,o]=m.useState(0),[f,x]=m.useState(!0),[b,Y]=m.useState(""),[W,R]=m.useState(0),[S,Z]=m.useState(5),[Q,v]=m.useState(!1),[a,T]=m.useState(null);m.useEffect(()=>{let t=!1;async function i(){x(!0);try{const g=await J(1),I=[...g.data||[]];if((g.total||0)>200){const ne=await J(2);I.push(...ne.data||[])}t||(s(I),o(g.total||I.length))}catch{t||s([])}finally{t||x(!1)}}return i(),()=>{t=!0}},[]);const k=r.filter(t=>{if(!b)return!0;const i=b.toLowerCase();return t.company&&t.company.toLowerCase().includes(i)||t.area&&t.area.toLowerCase().includes(i)||t.phone&&t.phone.includes(i)||t.address&&t.address.toLowerCase().includes(i)}),U=k.slice(W*S,W*S+S),ee=t=>{T({...t}),v(!0)},re=()=>{T({...Le}),v(!0)},te=async()=>{try{const t=await Fe(a);a.id?s(i=>i.map(g=>g.id===a.id?t:g)):(s(i=>[t,...i]),o(i=>i+1)),v(!1)}catch{alert("Failed to save. Please try again.")}},ae=async t=>{if(window.confirm("Delete this branch record?"))try{await He(t.id),s(i=>i.filter(g=>g.id!==t.id)),o(i=>i-1)}catch{alert("Failed to delete. Please try again.")}},p=t=>i=>T(g=>({...g,[t]:i.target.value})),se=new Set(r.map(t=>t.company).filter(Boolean)).size,ie=r.filter(t=>t.rate_per_kg&&t.rate_per_kg!=="Not answered"&&t.rate_per_kg!=="").length;return e.jsxs(e.Fragment,{children:[e.jsx(_e,{title:"Field Surveys",breadcrumbs:[{label:"Surveys"}],action:e.jsx($,{variant:"contained",startIcon:e.jsx(de,{}),onClick:re,sx:{borderRadius:2,px:3,boxShadow:"0 4px 12px rgba(0,0,0,0.1)"},children:"New Survey"})}),e.jsxs(u,{direction:{xs:"column",md:"row"},spacing:2,sx:{mt:3,mb:1},children:[e.jsx(O,{label:"Total Surveys",value:f?"…":j,icon:A,color:"primary"}),e.jsx(O,{label:"Companies Surveyed",value:f?"…":se,icon:K,color:"success"}),e.jsx(O,{label:"With Rate Info",value:f?"…":ie,icon:X,color:"warning"})]}),e.jsxs(Se,{sx:{overflow:"hidden",mt:3,borderRadius:2.5,boxShadow:"0 8px 24px rgba(0,0,0,0.04)",border:1,borderColor:"grey.200"},children:[e.jsxs(d,{sx:{px:2.5,py:2,borderBottom:1,borderColor:"divider",display:"flex",alignItems:"center",gap:1.5,background:t=>`linear-gradient(90deg, ${t.palette.primary.lighter}66 0%, ${t.palette.background.paper} 70%)`},children:[e.jsx(d,{sx:{width:40,height:40,borderRadius:2,bgcolor:"primary.lighter",color:"primary.main",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(A,{fontSize:"small"})}),e.jsxs(d,{children:[e.jsx(n,{variant:"subtitle1",sx:{fontWeight:700,color:"grey.800",lineHeight:1.2},children:"Survey Records"}),e.jsx(n,{variant:"caption",color:"text.secondary",children:"Manage business enquiry and survey data from the field"})]})]}),e.jsxs(u,{direction:{xs:"column",md:"row"},spacing:1.5,sx:{p:2},alignItems:{md:"center"},children:[e.jsx(h,{size:"small",placeholder:"Search by company, area, phone, or address…",value:b,onChange:t=>{Y(t.target.value),R(0)},sx:{minWidth:300},InputProps:{startAdornment:e.jsx(ke,{position:"start",children:e.jsx(le,{fontSize:"small"})})}}),e.jsx(d,{sx:{flexGrow:1}}),e.jsxs(n,{variant:"body2",color:"text.secondary",children:[k.length," ",k.length===1?"record":"records"]})]}),f?e.jsx(d,{sx:{display:"flex",justifyContent:"center",py:6},children:e.jsx(oe,{size:36})}):e.jsxs(e.Fragment,{children:[e.jsx($e,{children:e.jsxs(ze,{sx:{minWidth:1e3},children:[e.jsx(Pe,{children:e.jsxs(z,{sx:{"& th":{bgcolor:"grey.50",fontWeight:700,color:"grey.700",textTransform:"uppercase",fontSize:"0.72rem",letterSpacing:.4}},children:[e.jsx(l,{sx:{width:48}}),e.jsx(l,{children:"Area / Company"}),e.jsx(l,{children:"Contact"}),e.jsx(l,{children:"Location"}),e.jsx(l,{children:"Rate / Pricing"}),e.jsx(l,{children:"Logistics"}),e.jsx(l,{align:"right",children:"Actions"})]})}),e.jsx(We,{children:U.length===0?e.jsx(z,{children:e.jsx(l,{colSpan:7,sx:{border:"none"},children:e.jsx(Ce,{title:"No records found",caption:"Try a different search term or add a new survey."})})}):U.map(t=>e.jsx(Ne,{row:t,onEdit:ee,onDelete:ae},t.id))})]})}),e.jsx(ye,{component:"div",count:k.length,page:W,onPageChange:(t,i)=>R(i),rowsPerPage:S,onRowsPerPageChange:t=>{Z(+t.target.value),R(0)},rowsPerPageOptions:[5,10,25]})]})]}),e.jsxs(xe,{open:Q,onClose:()=>v(!1),maxWidth:"md",fullWidth:!0,children:[e.jsx(he,{children:a!=null&&a.id?"Edit Survey":"New Survey"}),e.jsx(ue,{dividers:!0,children:e.jsxs(c,{container:!0,spacing:2,children:[e.jsx(c,{item:!0,xs:12,sm:6,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Company",value:(a==null?void 0:a.company)||"",onChange:p("company")})}),e.jsx(c,{item:!0,xs:12,sm:6,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Area",value:(a==null?void 0:a.area)||"",onChange:p("area")})}),e.jsx(c,{item:!0,xs:12,sm:6,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Phone Number",value:(a==null?void 0:a.phone)||"",onChange:p("phone")})}),e.jsx(c,{item:!0,xs:12,sm:6,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Rate per kg",value:(a==null?void 0:a.rate_per_kg)||"",onChange:p("rate_per_kg")})}),e.jsx(c,{item:!0,xs:12,sm:3,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Pickup",value:(a==null?void 0:a.offers_pickup)||"",onChange:p("offers_pickup")})}),e.jsx(c,{item:!0,xs:12,sm:3,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Drop",value:(a==null?void 0:a.offers_drop)||"",onChange:p("offers_drop")})}),e.jsx(c,{item:!0,xs:12,sm:3,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Time in days",value:(a==null?void 0:a.time_in_days)||"",onChange:p("time_in_days")})}),e.jsx(c,{item:!0,xs:12,sm:3,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Packing charge",value:(a==null?void 0:a.packing_charge)||"",onChange:p("packing_charge")})}),e.jsx(c,{item:!0,xs:12,sm:6,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Plus code",value:(a==null?void 0:a.plus_code)||"",onChange:p("plus_code")})}),e.jsx(c,{item:!0,xs:12,children:e.jsx(h,{fullWidth:!0,size:"small",label:"Address",value:(a==null?void 0:a.address)||"",onChange:p("address"),multiline:!0,minRows:2})})]})}),e.jsxs(pe,{sx:{p:2},children:[e.jsx($,{onClick:()=>v(!1),children:"Cancel"}),e.jsx($,{variant:"contained",onClick:te,children:"Save Survey"})]})]})]})}export{tr as default};