PageSourceSearch

https://lhkgo.com/assets/AdminHKRates-8DtBhwnZ.js

js lhkgo.com collected 2026-10-07 16:10:27 UTC 17,224 bytes, 2 lines download raw bytes

1import{r as o,k as te,v as ie,s as g,j as e,L as k,B as x,a3 as W,ad as ne,aE as le,aj as de,aC as q,at as ce,au as oe,av as me,aw as xe,ab as M,aD as he}from"./index-XV4mQklL.js";import{u as C,w as ue,r as pe}from"./xlsx-uoQkVabA.js";import{R as $}from"./RemarkTemplatesPicker-CLYKc2wC.js";import{S as B}from"./save-BdZ2ii_f.js";const E=[{value:"included",label_en:"All Taxes and Custom Clearance Included",label_zh:"已含所有稅項及清關費用"},{value:"excluded",label_en:"Excluded Taxes",label_zh:"不含稅項"},{value:"limited",label_en:"Excluded Taxes and Limited Custom Clearance Included",label_zh:"不含稅項,包含有限清關服務"}],ge=["United Kingdom","United States","Australia","Canada","Japan","Singapore","South Korea","Taiwan","Malaysia","Thailand","Germany","France"],ye=()=>{const j=o.useRef(null),{toast:m}=te(),[K,L]=o.useState([]),[X,G]=o.useState(!0),[f,y]=o.useState(null),[v,S]=o.useState(!1),[b,N]=o.useState(!1),[c,D]=o.useState(new Set),[U,z]=o.useState(!1),[F,J]=o.useState("all"),[A,Q]=o.useState("all"),{data:h=[]}=ie({queryKey:["carriers"],queryFn:async()=>{const{data:s,error:i}=await g.from("carriers").select("*").eq("is_active",!0).order("display_order",{ascending:!0});if(i)throw i;return s}});h.length>0&&h[0].carrier_code;const[a,n]=o.useState({origin:"Hong Kong",destination:"United Kingdom",carrier:"",weight_min:0,weight_max:.5,drop_off_price:0,pick_up_price:0,min_days:1,max_days:4,tax_status:"included",remarks:""});o.useEffect(()=>{_()},[]),o.useEffect(()=>{h.length>0&&!a.carrier&&n(s=>({...s,carrier:h[0].carrier_code}))},[h]);const _=async()=>{try{const{data:s,error:i}=await g.from("hk_outbound_rates").select("*").order("destination").order("carrier").order("weight_min");if(i)throw i;L(s||[])}catch(s){m({title:"Error loading rates",description:s.message,variant:"destructive"})}finally{G(!1)}},V=s=>{y(s.id),n({origin:s.origin,destination:s.destination,carrier:s.carrier,weight_min:s.weight_min,weight_max:s.weight_max,drop_off_price:s.drop_off_price,pick_up_price:s.pick_up_price,min_days:s.min_days,max_days:s.max_days,tax_status:s.tax_status||"included",remarks:s.remarks||""})},R=async()=>{N(!0);try{if(f){const{error:s}=await g.from("hk_outbound_rates").update({weight_min:a.weight_min,weight_max:a.weight_max,drop_off_price:a.drop_off_price,pick_up_price:a.pick_up_price,min_days:a.min_days,max_days:a.max_days,tax_status:a.tax_status,remarks:a.remarks||null}).eq("id",f);if(s)throw s;m({title:"Rate updated successfully"})}else{const{error:s}=await g.from("hk_outbound_rates").insert(a);if(s)throw s;m({title:"Rate added successfully"})}y(null),S(!1),_()}catch(s){m({title:"Error saving rate",description:s.message,variant:"destructive"})}finally{N(!1)}},Y=async s=>{if(confirm("Are you sure you want to delete this rate?"))try{const{error:i}=await g.from("hk_outbound_rates").delete().eq("id",s);if(i)throw i;m({title:"Rate deleted successfully"}),_()}catch(i){m({title:"Error deleting rate",description:i.message,variant:"destructive"})}},Z=async()=>{if(c.size!==0&&confirm(`Are you sure you want to delete ${c.size} rate(s)?`)){z(!0);try{const{error:s}=await g.from("hk_outbound_rates").delete().in("id",Array.from(c));if(s)throw s;m({title:`${c.size} rate(s) deleted successfully`}),D(new Set),_()}catch(s){m({title:"Error deleting rates",description:s.message,variant:"destructive"})}finally{z(!1)}}},I=s=>s.replace(/\u00A0/g," ").replace(/\s+/g," ").trim(),H=K.filter(s=>!(F!=="all"&&s.carrier!==F||A!=="all"&&I(s.destination)!==A)),ee=[...new Set(K.map(s=>I(s.destination)))].sort(),O=s=>{const i=new Set(c);i.has(s)?i.delete(s):i.add(s),D(i)},P=()=>{y(null),S(!1),n({origin:"Hong Kong",destination:"United Kingdom",carrier:"UPS",weight_min:0,weight_max:.5,drop_off_price:0,pick_up_price:0,min_days:1,max_days:4,tax_status:"included",remarks:""})},se=()=>{S(!0),y(null),n({origin:"Hong Kong",destination:"United Kingdom",carrier:"UPS",weight_min:0,weight_max:.5,drop_off_price:0,pick_up_price:0,min_days:1,max_days:4,tax_status:"included",remarks:""})},ae=()=>{const s=[{Origin:"Hong Kong",Destination:"United Kingdom",Carrier:"UPS","Weight Min":0,"Weight Max":.5,"Drop Off":150,"Pick Up":180,"Min Days":3,"Max Days":5},{Origin:"Hong Kong",Destination:"United States",Carrier:"FedEx","Weight Min":.5,"Weight Max":1,"Drop Off":180,"Pick Up":210,"Min Days":4,"Ma
1x Days":7}],i=C.json_to_sheet(s),d=C.book_new();C.book_append_sheet(d,i,"HK Rates"),i["!cols"]=[{wch:12},{wch:18},{wch:10},{wch:12},{wch:12},{wch:10},{wch:10},{wch:10},{wch:10}],ue(d,"hk_outbound_rates_template.xlsx"),m({title:"Template downloaded"})};if(X)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"w-8 h-8 animate-spin text-primary"})});const re=async s=>{var d;const i=(d=s.target.files)==null?void 0:d[0];if(i){N(!0);try{const r=await i.arrayBuffer(),u=pe(r),p=u.Sheets[u.SheetNames[0]],t=C.sheet_to_json(p).map(l=>({origin:l.Origin||l.origin||"Hong Kong",destination:l.Destination||l.destination,carrier:l.Carrier||l.carrier,weight_min:parseFloat(l["Weight Min"]||l.weight_min||0),weight_max:parseFloat(l["Weight Max"]||l.weight_max||0),drop_off_price:parseFloat(l["Drop Off"]||l.drop_off_price||0),pick_up_price:parseFloat(l["Pick Up"]||l.pick_up_price||0),min_days:parseInt(l["Min Days"]||l.min_days||1),max_days:parseInt(l["Max Days"]||l.max_days||4)})).filter(l=>l.destination&&l.carrier);if(t.length===0)throw new Error("No valid rates found in file");const{error:w}=await g.from("hk_outbound_rates").insert(t);if(w)throw w;m({title:`Imported ${t.length} rates successfully`}),_()}catch(r){m({title:"Import failed",description:r.message,variant:"destructive"})}finally{N(!1),j.current&&(j.current.value="")}}};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-heading text-2xl font-bold",children:"From Hong Kong Rates"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Manage shipping rates from Hong Kong with weight tiers"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{ref:j,type:"file",accept:".xlsx,.xls,.csv",onChange:re,className:"hidden"}),c.size>0&&e.jsxs(x,{variant:"destructive",onClick:Z,disabled:U,children:[U?e.jsx(k,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(W,{className:"w-4 h-4 mr-2"}),"Delete (",c.size,")"]}),e.jsxs(x,{variant:"outline",onClick:ae,children:[e.jsx(ne,{className:"w-4 h-4 mr-2"}),"Template"]}),e.jsxs(x,{variant:"outline",onClick:()=>{var s;return(s=j.current)==null?void 0:s.click()},disabled:b,children:[e.jsx(le,{className:"w-4 h-4 mr-2"}),"Import"]}),e.jsxs(x,{onClick:se,disabled:v||!!f,children:[e.jsx(de,{className:"w-4 h-4 mr-2"}),"Add Rate"]})]})]}),e.jsxs("div",{className:"flex gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Filter Carrier"}),e.jsxs("select",{value:F,onChange:s=>J(s.target.value),className:"h-10 px-3 rounded-lg bg-secondary border border-border text-sm",children:[e.jsx("option",{value:"all",children:"All Carriers"}),h.map(s=>e.jsx("option",{value:s.carrier_code,children:s.name_en},s.carrier_code))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Filter Destination"}),e.jsxs("select",{value:A,onChange:s=>Q(s.target.value),className:"h-10 px-3 rounded-lg bg-secondary border border-border text-sm",children:[e.jsx("option",{value:"all",children:"All Destinations"}),ee.map(s=>e.jsx("option",{value:s,children:s},s))]})]})]}),v&&e.jsxs("div",{className:"bg-card rounded-xl border border-primary/50 p-6 mb-6",children:[e.jsx("h3",{className:"font-heading font-semibold mb-4",children:"Add New Rate"}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4 mb-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Destination"}),e.jsx("select",{value:a.destination,onChange:s=>n({...a,destination:s.target.value}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border",children:ge.map(s=>e.jsx("option",{value:s,children:s},s))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Carrier"}),e.jsx("select",{value:a.carrier,onChange:s=>n({...a,carrier:s.target.value}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border",children:h.map(s=>e.jsx("option",{value:s.carrier_code,children:s.name_en},s.carrier_code))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Weight Min (kg)"}),e.jsx("input",{type:"number",step:"0.001",value:a.weight_min,onChange:s=>n({...a,weight_min:parseFloat(s.target.value)||0}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Weight Max (kg)"}),e.jsx("input",{type:"number",step:"0.001",value:a.weight_max,onChange:s=>n({...a,weight_max:parseFloat(s.target.value)||0}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Drop Off 
1(HKD)"}),e.jsx("input",{type:"number",step:"1",value:a.drop_off_price,onChange:s=>n({...a,drop_off_price:parseFloat(s.target.value)||0}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Pick Up (HKD)"}),e.jsx("input",{type:"number",step:"1",value:a.pick_up_price,onChange:s=>n({...a,pick_up_price:parseFloat(s.target.value)||0}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Min Days"}),e.jsx("input",{type:"number",value:a.min_days,onChange:s=>n({...a,min_days:parseInt(s.target.value)||1}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Max Days"}),e.jsx("input",{type:"number",value:a.max_days,onChange:s=>n({...a,max_days:parseInt(s.target.value)||4}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border"})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:"Tax & Customs Status"}),e.jsx("select",{value:a.tax_status,onChange:s=>n({...a,tax_status:s.target.value}),className:"w-full h-10 px-3 rounded-lg bg-secondary border border-border",children:E.map(s=>e.jsx("option",{value:s.value,children:s.label_en},s.value))})]}),e.jsx("div",{className:"col-span-2 md:col-span-5",children:e.jsx($,{value:a.remarks,onChange:s=>n({...a,remarks:s})})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(x,{onClick:R,disabled:b,children:[b?e.jsx(k,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(B,{className:"w-4 h-4 mr-2"}),"Save"]}),e.jsxs(x,{variant:"outline",onClick:P,children:[e.jsx(q,{className:"w-4 h-4 mr-2"}),"Cancel"]})]})]}),H.length===0?e.jsx("div",{className:"bg-card rounded-xl border border-border/50 p-8 text-center text-muted-foreground",children:"No rates configured. Add your first rate above."}):e.jsx(ce,{type:"multiple",className:"space-y-2",children:(()=>{const s={};return H.forEach(i=>{const d=I(i.destination);s[d]||(s[d]=[]),s[d].push(i)}),Object.entries(s).sort(([i],[d])=>i.localeCompare(d)).map(([i,d])=>e.jsxs(oe,{value:i,className:"bg-card rounded-xl border border-border/50 overflow-hidden",children:[e.jsx(me,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-heading font-semibold",children:i}),e.jsxs("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded-full",children:[d.length," rates"]})]})}),e.jsx(xe,{className:"px-0 pb-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{className:"bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3 w-10",children:e.jsx(M,{checked:d.every(r=>c.has(r.id)),onCheckedChange:()=>{const r=d.every(p=>c.has(p.id)),u=new Set(c);d.forEach(p=>r?u.delete(p.id):u.add(p.id)),D(u)}})}),e.jsx("th",{className:"text-left p-3 font-medium text-xs",children:"Carrier"}),e.jsx("th",{className:"text-right p-3 font-medium text-xs",children:"Weight Min"}),e.jsx("th",{className:"text-right p-3 font-medium text-xs",children:"Weight Max"}),e.jsx("th",{className:"text-right p-3 font-medium text-xs",children:"Drop Off"}),e.jsx("th",{className:"text-right p-3 font-medium text-xs",children:"Pick Up"}),e.jsx("th",{className:"text-center p-3 font-medium text-xs",children:"Days"}),e.jsx("th",{className:"text-left p-3 font-medium text-xs",children:"Tax Status"}),e.jsx("th",{className:"text-left p-3 font-medium text-xs",children:"Remarks"}),e.jsx("th",{className:"text-right p-3 font-medium text-xs",children:"Actions"})]})}),e.jsx("tbody",{children:d.map(r=>{var u,p,T;return e.jsx("tr",{className:`border-t border-border/50 ${c.has(r.id)?"bg-primary/5":""}`,children:f===r.id?e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"p-3",children:e.jsx(M,{checked:c.has(r.id),onCheckedChange:()=>O(r.id)})}),e.jsx("td",{className:"p-3",children:((u=h.find(t=>t.carrier_code===r.carrier))==null?void 0:u.name_en)||r.carrier}),e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"number",step:"0.001",value:a.weight_min,onChange:t=>n({...a,weight_min:parseFloat(t.target.value)||0}),className:"w-20 h-8 px-2 rounded bg-secondary border border-border text-right"})}),e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"number",step:"0.001",value:a.weight_max,onChange:t=>n({...a,weight_max:parseFloat(t.target.value)||0}),className:"w-20 h-8 px-2 rounded bg-secondary border border-border text-right"})}),e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"number",step:"1",value:a.drop_off_price,onChange:t=>n({...a,drop_off_price:parseFloat(t.target.value)||0}),className:"w-20 h-8 px-2 rounded bg-secondary border border-border text-right"})}),e.jsx("td",{className:"p-3",children:e.jsx("input",{type:"number",step:"1",value:a.pick_up_price,onChange:t=>n({...a,pick_up_price:parseFloat(t.target.value)||0}),className:"w-20 h-8 px-2 rounded bg-secondary border border-border text-right"})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex gap-1 justify-center",children:[e.jsx("input",{type:"number",value:a.min_days,onChange:t=>n({...a,min_days:parseInt(t.target.value)||1}),className:"w-12 h-8 px-2 rounded bg-secondary border border-border text-center"}),e.jsx("span",{children:"-"}),e.jsx("input",{type:"number",value:a.max_days,onChange:t=>n({...a,max_days:parseInt(t.target.value)||4}),className:"w-12 h-8 px-2 rounded bg-secondary border border-border text-center"})]})}),e.jsx("td",{className:"p-3",children:e.jsx("select",{value:a.tax_status,onChange:t=>n({...a,tax_status:t.target.value}),className:"w-32 h-8 px-2 rounded bg-secondary border border-border text-xs",children:E.map(t=>e.jsx("option",{value:t.value,children:t.label_en},t.value))})}),e.jsx("td",{className:"p-3",children:e.jsx($,{value:a.remarks,onChange:t=>n({...a,remarks:t})})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex gap-1 justify-end",children:[e.jsx(x,{size:"sm",onClick:R,disabled:b,children:b?e.jsx(k,{className:"w-4 h-4 animate-spin"}):e.jsx(B,{className:"w-4 h-4"})}),e.jsx(x,{size:"sm",variant:"outline",onClick:P,children:e.jsx(q,{className:"w-4 h-4"})})]})})]}):e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"p-3",children:e.jsx(M,{checked:c.has(r.id),onCheckedChange:()=>O(r.id)})}),e.jsx("td",{className:"p-3 font-medium",children:((p=h.find(t=>t.carrier_code===r.carrier))==null?void 0:p.name_en)||r.carrier}),e.jsx("td",{className:"p-3 text-right",children:r.weight_min}),e.jsx("td",{className:"p-3 text-right",children:r.weight_max}),e.jsxs("td",{className:"p-3 text-right font-semibold",children:["$",r.drop_off_price]}),e.jsxs("td",{className:"p-3 text-right font-semibold",children:["$",r.pick_up_price]}),e.jsxs("td",{className:"p-3 text-center",children:[r.min_days,"-",r.max_days]}),e.jsx("td",{className:"p-3 text-xs max-w-[180px]",children:((T=E.find(t=>t.value===r.tax_status))==null?void 0:T.label_en)||r.tax_status||"Included"}),e.jsx("td",{className:"p-3 max-w-[200px]",children:r.remarks?e.jsx("div",{className:"flex flex-wrap gap-1",children:r.remarks.split(`
2`).filter(Boolean).map((t,w)=>e.jsx("span",{className:"inline-block text-xs px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium",children:t},w))}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"—"})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex gap-1 justify-end",children:[e.jsx(x,{size:"sm",variant:"outline",onClick:()=>V(r),disabled:!!f||v,children:e.jsx(he,{className:"w-4 h-4"})}),e.jsx(x,{size:"sm",variant:"outline",onClick:()=>Y(r.id),disabled:!!f||v,children:e.jsx(W,{className:"w-4 h-4 text-destructive"})})]})})]})},r.id)})})]})})})]},i))})()})]})};export{ye 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.