PageSourceSearch

https://holidaythai.com/assets/HotelOutlets-CWlGrEr5.js

js holidaythai.com collected 2026-10-02 13:52:56 UTC 5,958 bytes, 1 lines download raw bytes

1import{ce as I,K as q,r as t,s as x,j as e,B as l,ag as w,_ as C,a1 as _,h as k,ah as z,aj as v,I as F,a4 as V,a5 as Y,a6 as K,a7 as M,a8 as R}from"./index-LAef4FAh.js";import{H as U,f as D}from"./HotelAdminLayout-D45NwIyk.js";import{S as $}from"./switch-DU3zvDcN.js";import{D as G,a as J,b as Q,c as W,d as X,e as Z}from"./dialog-DMm6owy5.js";import{P as ee}from"./pen-BXBDyf1S.js";import"./use-mobile-Kd5aMTze.js";import"./sheet-Cyv-LVly.js";import"./index-JglnD_Uo.js";import"./ticket-Bcy--bUf.js";import"./log-in-D7fHSPdv.js";import"./ellipsis-D5DDpfqE.js";const E=[{value:"front_desk",label:"Front Desk"},{value:"cafe",label:"คาเฟ่"},{value:"restaurant",label:"ร้านอาหาร"},{value:"minimart",label:"มินิมาร์ท / ร้านค้า"},{value:"laundry",label:"ซักรีด"},{value:"transport",label:"รถรับส่ง / ทัวร์"},{value:"other",label:"อื่นๆ"}],se=Object.fromEntries(E.map(a=>[a.value,a.label]));function he(){const{hotelClient:a}=I(),{toast:i}=q(),[o,O]=t.useState([]),[T,g]=t.useState(!0),[L,r]=t.useState(!1),[n,N]=t.useState(null),[S,b]=t.useState(!1),[c,h]=t.useState(""),[u,j]=t.useState("other"),[f,p]=t.useState(!0),d=t.useCallback(async()=>{if(!a)return;g(!0);const{data:s}=await x.from("outlets").select("*").eq("hotel_client_id",a.id).order("sort_order").order("created_at");O(s||[]),g(!1)},[a]);t.useEffect(()=>{d()},[d]);const y=()=>{N(null),h(""),j("other"),p(!0),r(!0)},A=s=>{N(s),h(s.name),j(s.type),p(s.is_active),r(!0)},H=async()=>{if(!(!c.trim()||!a)){b(!0);try{if(n){const{error:s}=await x.from("outlets").update({name:c.trim(),type:u,is_active:f}).eq("id",n.id);if(s)throw s;i({title:"อัปเดตจุดขายสำเร็จ"})}else{const s=o.length>0?Math.max(...o.map(B=>B.sort_order))+1:0,{error:m}=await x.from("outlets").insert({hotel_client_id:a.id,name:c.trim(),type:u,is_active:f,sort_order:s});if(m)throw m;i({title:"เพิ่มจุดขายสำเร็จ"})}r(!1),d()}catch(s){i({title:"เกิดข้อผิดพลาด",description:s==null?void 0:s.message,variant:"destructive"})}finally{b(!1)}}},P=async s=>{if(s.is_default){i({title:"ไม่สามารถลบจุดขายเริ่มต้นได้",variant:"destructive"});return}if(!confirm(`ต้องการลบ "${s.name}" ?`))return;const{error:m}=await x.from("outlets").delete().eq("id",s.id);m?i({title:"ไม่สามารถลบได้",description:"อาจมีรายการขายที่เชื่อมอยู่",variant:"destructive"}):(i({title:"ลบสำเร็จ"}),d())};return e.jsx(U,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"จุดขาย (Outlets)"}),e.jsxs(l,{onClick:y,children:[e.jsx(w,{className:"h-4 w-4 mr-1"})," เพิ่มจุดขาย"]})]}),T?e.jsx("p",{className:"text-muted-foreground text-sm",children:"กำลังโหลด..."}):o.length===0?e.jsx(C,{children:e.jsxs(_,{className:"py-12 text-center",children:[e.jsx(D,{className:"h-12 w-12 mx-auto text-muted-foreground/40 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:"ยังไม่มีจุดขาย"}),e.jsxs(l,{variant:"outline",className:"mt-4",onClick:y,children:[e.jsx(w,{className:"h-4 w-4 mr-1"})," เพิ่มจุดขายแรก"]})]})}):e.jsx("div",{className:"grid gap-3",children:o.map(s=>e.jsx(C,{children:e.jsxs(_,{className:"flex items-center justify-between py-4 px-5",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(D,{className:"h-5 w-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-foreground",children:s.name}),s.is_default&&e.jsx(k,{variant:"secondary",className:"text-[10px]",children:"ค่าเริ่มต้น"}),!s.is_active&&e.jsx(k,{variant:"outline",className:"text-[10px] text-muted-foreground",children:"ปิดใช้งาน"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:se[s.type]||s.type})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>A(s),children:e.jsx(ee,{className:"h-4 w-4"})}),!s.is_default&&e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>P(s),children:e.jsx(z,{className:"h-4 w-4"})})]})]})},s.id))}),e.jsx(G,{open:L,onOpenChange:r,children:e.jsxs(J,{className:"max-w-sm",children:[e.jsxs(Q,{children:[e.jsx(W,{children:n?"แก้ไขจุดขาย":"เพิ่มจุดขาย"}),e.jsx(X,{children:n?"แก้ไขข้อมูลจุดขาย":"สร้างจุดขายใหม่ในโรงแรม"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs(v,{children:["ชื่อจุดขาย ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(F,{value:c,onChange:s=>h(s.target.value),placeholder:"เช่น คาเฟ่ริมสระ",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(v,{children:"ประเภท"}),e.jsxs(V,{value:u,onValueChange:j,children:[e.jsx(Y,{className:"mt-1",children:e.jsx(K,{})}),e.jsx(M,{children:E.map(s=>e.jsx(R,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(v,{children:"เปิดใช้งาน"}),e.jsx($,{checked:f,onCheckedChange:p})]})]}),e.jsxs(Z,{children:[e.jsx(l,{variant:"outline",onClick:()=>r(!1),children:"ยกเลิก"}),e.jsx(l,{onClick:H,disabled:S||!c.trim(),children:S?"กำลังบันทึก...":n?"บันทึก":"เพิ่ม"})]})]})})]})})}export{he 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.