Files
doormile_crm_build/dist/assets/ClientFormDialog-4iTaiNea.js
2026-07-08 18:53:29 +05:30

2 lines
13 KiB
JavaScript

import{o as be,r as t,j as e,p as fe,q as je,n as Q,s as Ce,t as Se,v as Te,L as we,B as H,l as ke,D as $,w as Ne,x as Le}from"./index-TNj5auBr.js";import{D as Pe,L as ze,F as f,a as Ie}from"./plus-CZCr3OEY.js";import{B as Re}from"./Banner-DVJsik2E.js";import{u as Ae,a as De,g as Be,i as Me,b as qe,c as Ee,d as X,F as Ve,T as x}from"./TextInput-DL-5979h.js";import{S as B}from"./Selector-D-0RMSQ0.js";import{M as Ke}from"./map-pin-BQjktuvD.js";import{T as ee}from"./TextArea-B4wLAlyG.js";const Fe={wrapper:{kY2c9j:"x1vjfegm",$$css:!0}},Ge={sm:{kZKoxP:"x6k0iem",$$css:!0},md:{kZKoxP:"x1ueg155",$$css:!0},lg:{kZKoxP:"xssyfek",$$css:!0}};function M(i,o){const c=i.trim();if(c===""||c==="-")return null;const h=Number(c);return!Number.isFinite(h)||o.isIntegerOnly&&!Number.isInteger(h)||o.min!=null&&h<o.min||o.max!=null&&h>o.max?null:h}function I({label:i,isLabelHidden:o=!1,description:c,isOptional:h=!1,isRequired:R=!1,isDisabled:m=!1,startIcon:a,labelIcon:T,status:r,size:A,onChange:g,value:u,placeholder:L,labelTooltip:P,hasAutoFocus:n=!1,htmlName:E,autoComplete:V,min:s,max:l,step:j,units:C,isIntegerOnly:d=!1,onFocus:v,onBlur:w,hasClear:z,onEnter:k,onKeyDown:N,width:S,xstyle:se,className:re,style:ne,ref:ie,...te}){const J=be(A,"md"),O=t.useId(),W=t.useId(),Z=t.useId(),K=t.useRef(null),_=t.useRef(null),D=Ae(),[p,F]=t.useState(null),le={warning:"warning",error:"error",success:"success"},oe={warning:"warning",error:"error",success:"success"},ue=[c?W:null,r!=null&&r.message?Z:null].filter(Boolean).join(" ")||void 0,ce=t.useMemo(()=>p!==null?p:u==null?"":String(u),[p,u]),de=t.useMemo(()=>p===null||!p.trim()?!0:M(p,{min:s,max:l,isIntegerOnly:d})!==null,[p,s,l,d]),pe=t.useCallback(y=>{const b=y.target.value;F(b);const G=M(b,{min:s,max:l,isIntegerOnly:d});G!==null&&G!==u&&g(G)},[u,g,s,l,d]),xe=t.useCallback(y=>{v==null||v(y)},[v]),he=t.useCallback(y=>{if(p!==null){const b=M(p,{min:s,max:l,isIntegerOnly:d});b!==null&&b!==u&&g(b)}F(null),w==null||w(y)},[p,u,g,s,l,d,w]),me=t.useCallback(y=>{if(y.key==="Enter"){if(p!==null){const b=M(p,{min:s,max:l,isIntegerOnly:d});b!==null&&b!==u&&g(b)}k==null||k()}N==null||N(y)},[p,u,g,s,l,d,k,N]),ge=t.useCallback(()=>{var y;z&&g(null),F(null),(y=K.current)==null||y.focus()},[z,g]),{onClick:ve,onMouseUp:ye}=De({containerRef:_,inputRef:K,disabled:m}),Y=e.jsxs("div",{ref:_,onClick:ve,onMouseUp:ye,...Ce(Te("number-input",{size:J,status:(r==null?void 0:r.type)??null}),Se(X.base,Fe.wrapper,Ge[J],m&&X.disabled,r&&Ee[r.type],r&&qe[r.type],r&&Me[r.type],D&&Be.inGroup,se),re,ne),children:[a&&fe(a,{size:"sm",color:"secondary"}),e.jsx("input",{...te,ref:je(ie,K),id:O,name:E,type:"number",autoComplete:V,value:ce,onChange:pe,onFocus:xe,onBlur:he,onKeyDown:me,placeholder:L,disabled:m,autoFocus:n,"data-autofocus":n||void 0,min:s??void 0,max:l??void 0,step:j??void 0,"aria-describedby":ue,"aria-required":R===!0?"true":void 0,"aria-invalid":(r==null?void 0:r.type)==="error"?"true":void 0,"aria-label":D?i:void 0,...{0:{className:"x1lliihq x98rzlu xeuugli xc342km xng3xce x1717udv x9ynric xjm74w1 x6pjikd xw6l6zx x1tgivj0 xjbqb8w x1a2a7pz xeyghm5"},2:{className:"x1lliihq x98rzlu xeuugli xc342km xng3xce x1717udv x9ynric xjm74w1 x6pjikd xw6l6zx x1tgivj0 xjbqb8w x1a2a7pz xeyghm5 x1h6gzvc"},1:{className:"x1lliihq x98rzlu xeuugli xc342km xng3xce x1717udv x9ynric xjm74w1 x6pjikd xw6l6zx xjbqb8w x1a2a7pz xeyghm5 xv1l7n4"},3:{className:"x1lliihq x98rzlu xeuugli xc342km xng3xce x1717udv x9ynric xjm74w1 x6pjikd xw6l6zx xjbqb8w x1a2a7pz xeyghm5 x1h6gzvc xv1l7n4"}}[!!m<<1|!de<<0]}),C&&e.jsx("span",{className:"x9ynric xjm74w1 xw6l6zx xv1l7n4 x2lah0s",children:C}),z&&u!=null&&!m&&e.jsx("button",{type:"button",onClick:ge,"aria-label":`Clear ${i}`,className:"x78zum5 x6s0dn4 xl56j7k x1717udv x1ghz6dp xc342km xng3xce xjbqb8w x1ypdohk xh6dtrn x1a2a7pz x1p25gnr x1y3gkto",children:e.jsx(Q,{icon:"close",size:"sm",color:"secondary"})}),r&&!D&&e.jsx(Q,{icon:le[r.type],size:"md",color:oe[r.type]})]});return D?Y:e.jsx(Ve,{label:i,isLabelHidden:o,description:c,inputID:O,descriptionID:c?W:void 0,isOptional:h,isRequired:R,isDisabled:m,labelIcon:T,status:r?{type:r.type,message:r.message,messageID:r.message?Z:void 0}:void 0,labelTooltip:P,width:S,children:Y})}I.displayName="NumberInput";const He=["retail","wholesale","manufacturer","distributor","services","ecommerce","other"],$e=["newClient","contacted","onboarded","lost"],Ue=["Daily","Weekly","Bi-weekly","Monthly","On-demand"],Je=["basicOnly","full","none"],Oe=["Blue Dart","Delhivery","DTDC","India Post / Speed Post","The Professional Couriers","XpressBees","Ecom Express","Shadowfax","Safexpress","VRL Logistics","TCI (Transport Corporation of India)","Om Logistics","Best Roadways","MSS (Mettur Super Services)","ABT Travels & Logistics","Navata Road Transport","KRS (Kerala Roadways)","Parveen Travels / Parveen Express","SRM Transports","KPN Travels & KPN Speed Parcel","SRS Travels","Hindusthan Travels","City Travels","Essaar Travels","No. 1 Air Travels","A1 Travels","Krish Travels","Hebron Transports","Horma Travels","Vivegam Travels","PSS Transport","SRT (Renugambal Travels)","Thamarai Bus Transports","Rathimeena Travels","Ganesh Travels","John Kennedy Bus Service","Arun Travel","Saaji Meera Roadways","ARC Parcel Service","Chakra Travels & Parcel Service","MVA Parcel And Bus Service","Shrinath Travels & Cargo","Hans Travels","Zingbus","Kalpana Travels / City Land Travels","Trackon Couriers","North India Transways","RSRTC Cargo","UPSRTC Cargo"],U=["Chennai","Coimbatore","Madurai","Tiruchirappalli","Salem","Tuticorin","Tirupur","Erode","Vellore","Tirunelveli","Thanjavur","Dindigul","Hosur","Nagercoil","Karur","Namakkal","Kanchipuram","Cuddalore","Thoothukudi","Bengaluru","Mysuru","Mangaluru","Hubli","Belagavi","Kalaburagi","Davangere","Ballari","Kochi","Thiruvananthapuram","Kozhikode","Kannur","Thrissur","Kollam","Hyderabad","Warangal","Visakhapatnam","Vijayawada","Tirupati","Guntur","Rajahmundry","Nellore","Mumbai","Pune","Nagpur","Nashik","Aurangabad","Kolhapur","Solapur","New Delhi","Gurugram","Noida","Faridabad","Chandigarh","Amritsar","Ludhiana","Jalandhar","Ahmedabad","Surat","Vadodara","Rajkot","Bhavnagar","Jamnagar","Jaipur","Jodhpur","Udaipur","Kota","Bikaner","Lucknow","Kanpur","Varanasi","Agra","Prayagraj","Gorakhpur","Bhopal","Indore","Gwalior","Jabalpur","Raipur","Kolkata","Siliguri","Durgapur","Patna","Gaya","Ranchi","Jamshedpur","Bhubaneswar","Cuttack","Guwahati","Dibrugarh","Agartala","Imphal","Shillong","Aizawl","Dimapur","Dehradun","Haridwar","Shimla","Srinagar","Jammu","Leh","Panaji","Puducherry","Port Blair"],ae={name:"",email:"",password:"",phone:"",city:"",businessState:"",businessType:"retail",status:"newClient",frequency:"Daily",parcelVolume:0,activeContracts:0,provider:"",efficiency:"",logisticsSegment:"",transitFrom:"",transitTo:"",neighbourhood:"",surveyAddress:"",surveyLat:"",surveyLng:"",dataConsent:"full",notes:"",pincode:""},We=i=>typeof i=="string"?i.charAt(0).toUpperCase()+i.slice(1).replace(/([A-Z])/g," $1").trim():i,Ze=(i,o)=>o&&!i.includes(o)?[o,...i]:i,q=(i,o)=>Ze(i,o).map(c=>({value:c,label:We(c)}));function ra({open:i,mode:o,initial:c,onClose:h,onSaved:R}){const m=o==="edit",[a,T]=t.useState(ae),[r,A]=t.useState(!1),[g,u]=t.useState(null),[L,P]=t.useState(!1),n=s=>l=>T(j=>({...j,[s]:l})),E=()=>{if(!navigator.geolocation){alert("Geolocation is not supported by your browser");return}P(!0),navigator.geolocation.getCurrentPosition(async s=>{const l=s.coords.latitude,j=s.coords.longitude;T(C=>({...C,surveyLat:l,surveyLng:j}));try{const d=await(await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${l}&lon=${j}`)).json();if(d&&d.address){const v=d.address,w=v.city||v.town||v.village||v.county||"",z=v.state||"",k=v.postcode||"",N=d.display_name||"";T(S=>({...S,city:w||S.city,businessState:z||S.businessState,pincode:k||S.pincode,surveyAddress:N||S.surveyAddress}))}}catch(C){console.error("Reverse geocoding failed",C)}finally{P(!1)}},s=>{alert("Unable to retrieve your location"),P(!1)})};t.useEffect(()=>{i&&(T({...ae,...c||{}}),u(null))},[i,c]);const V=async()=>{if(!a.name.trim()){u("Client name is required.");return}A(!0),u(null);const s=a.surveyLat===""?void 0:Number(a.surveyLat),l=a.surveyLng===""?void 0:Number(a.surveyLng),j={first_name:a.name.trim(),phone:a.phone,city:a.city,businessState:a.businessState,businessType:a.businessType,status:a.status,frequency:a.frequency,parcelVolume:Number(a.parcelVolume)||0,activeContracts:Number(a.activeContracts)||0,provider:a.provider,efficiency:a.efficiency,logisticsSegment:a.logisticsSegment,transitFrom:a.transitFrom,transitTo:a.transitTo,neighbourhood:a.neighbourhood,pincode:a.pincode,surveyAddress:a.surveyAddress,dataConsent:a.dataConsent,notes:a.notes,lastUpdated:new Date().toISOString().slice(0,10),registration_source:"web",...a.email.trim()?{email:a.email.trim()}:{},...s!=null?{survey_lat:s}:{},...l!=null?{survey_long:l}:{}};try{m?await Ne(c.id,j):await Le({...j,...a.password?{password:a.password}:{}}),R()}catch(C){u(C.message||"Failed to save client")}finally{A(!1)}};return e.jsx(Pe,{isOpen:i,onOpenChange:s=>{s||h()},width:800,maxHeight:"90dvh",purpose:"form",children:e.jsx(we,{header:e.jsx(Ie,{title:m?"Edit Client":"Add Client",onOpenChange:s=>{s||h()}}),content:e.jsx(ke,{children:e.jsxs(f,{children:[g&&e.jsx(Re,{status:"error",title:g}),e.jsx($,{label:"Business"}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(x,{label:"Client Name",isRequired:!0,value:a.name,onChange:n("name")}),e.jsx(x,{label:"Phone",value:a.phone,onChange:n("phone")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(x,{label:"Email",type:"email",value:a.email,onChange:n("email")}),!m&&e.jsx(x,{label:"Password",type:"password",value:a.password,onChange:n("password")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(B,{label:"Business Type",options:q(He,a.businessType),value:a.businessType,onChange:n("businessType")}),e.jsx(B,{label:"Status",options:q($e,a.status),value:a.status,onChange:n("status")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(B,{label:"Order Frequency",options:q(Ue,a.frequency),value:a.frequency,onChange:n("frequency")}),e.jsx(I,{label:"Parcel Volume",value:Number(a.parcelVolume)||0,onChange:n("parcelVolume")}),e.jsx(I,{label:"Contracts",value:Number(a.activeContracts)||0,onChange:n("activeContracts")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsxs("div",{children:[e.jsx(x,{label:"Current Provider",list:"providers-list",value:a.provider||"",onChange:n("provider")}),e.jsx("datalist",{id:"providers-list",children:Oe.map(s=>e.jsx("option",{value:s},s))})]}),e.jsx(x,{label:"Efficiency",value:a.efficiency,onChange:n("efficiency")})]}),e.jsx(x,{label:"Logistics Segment",placeholder:"First Mile, Last Mile",value:a.logisticsSegment,onChange:n("logisticsSegment")}),e.jsx($,{label:"Location & Transit"}),e.jsxs(f,{direction:"horizontal",children:[e.jsxs("div",{children:[e.jsx(x,{label:"City",list:"cities-list",value:a.city||"",onChange:n("city")}),e.jsx("datalist",{id:"cities-list",children:U.map(s=>e.jsx("option",{value:s},s))})]}),e.jsx(x,{label:"State",value:a.businessState,onChange:n("businessState")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(x,{label:"Pincode",value:a.pincode,onChange:n("pincode")}),e.jsx(x,{label:"Neighbourhood / Zone",value:a.neighbourhood,onChange:n("neighbourhood")})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsxs("div",{children:[e.jsx(x,{label:"Transit From",list:"cities-list-from",value:a.transitFrom||"",onChange:n("transitFrom")}),e.jsx("datalist",{id:"cities-list-from",children:U.map(s=>e.jsx("option",{value:s},s))})]}),e.jsxs("div",{children:[e.jsx(x,{label:"Transit To",list:"cities-list-to",value:a.transitTo||"",onChange:n("transitTo")}),e.jsx("datalist",{id:"cities-list-to",children:U.map(s=>e.jsx("option",{value:s},s))})]})]}),e.jsxs(f,{direction:"horizontal",children:[e.jsx(I,{label:"Latitude",value:a.surveyLat===""?void 0:Number(a.surveyLat),onChange:n("surveyLat")}),e.jsx(I,{label:"Longitude",value:a.surveyLng===""?void 0:Number(a.surveyLng),onChange:n("surveyLng")}),e.jsx("div",{style:{display:"flex",alignItems:"flex-end"},children:e.jsx(H,{label:L?"Getting GPS...":"Get GPS Location",variant:"secondary",icon:L?void 0:e.jsx(Ke,{size:16}),onClick:E,isDisabled:L,style:{width:"100%",height:"40px"}})})]}),e.jsx(ee,{label:"Survey Address",rows:2,value:a.surveyAddress,onChange:n("surveyAddress")}),e.jsx($,{label:"Other"}),e.jsx(B,{label:"Data Consent",options:q(Je,a.dataConsent),value:a.dataConsent,onChange:n("dataConsent")}),e.jsx(ee,{label:"Notes",rows:2,value:a.notes,onChange:n("notes")})]})}),footer:e.jsx(ze,{hasDivider:!0,children:e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:"12px"},children:[e.jsx(H,{label:"Cancel",variant:"ghost",onClick:h,isDisabled:r}),e.jsx(H,{label:m?"Save Changes":"Create Client",variant:"primary",onClick:V,isDisabled:r,isLoading:r})]})})})})}export{ra as C,I as N};