2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{_ as C}from"./BaseTable.vue_vue_type_style_index_0_lang-f9e383e0.js";import{_ as D}from"./button.vue_vue_type_style_index_0_lang-5b65d3cd.js";import{I as q}from"./Icon-ff3adddf.js";import{_ as M}from"./Modal.vue_vue_type_style_index_0_lang-743b5887.js";import{_ as P}from"./BasicInput.vue_vue_type_style_index_0_lang-75f50aa0.js";import{a3 as R,a4 as _,d as T,t as F,h as A,a0 as p,o as $,K as S,w as c,a as y,b as u,L as v,r as E,c as V,a2 as z}from"./index-c822befc.js";import{b as O,F as x}from"./index-1491d479.js";import{u as L}from"./useBaseTable-3aeb2499.js";import{M as N}from"./index-71609388.js";import{T as B}from"./index-81ddbbad.js";import"./usePrefix-93de78a0.js";import"./index-69ae13da.js";import"./raf-e9e40ecb.js";import"./index-d11abaf6.js";import"./colors-b3e52159.js";import"./styleChecker-cf4483ca.js";import"./useState-3b1f4886.js";import"./index-976673f9.js";import"./debounce-89f3cd70.js";import"./SearchOutlined-8e71a0af.js";import"./pickAttrs-6fdf7ff0.js";import"./CheckOutlined-af96a0f7.js";import"./objectDestructuringEmpty-24e23e90.js";import"./eagerComputed-7892359b.js";import"./index-16f734d6.js";import"./BasicModal.vue_vue_type_style_index_0_lang-fa4544ee.js";import"./index-1f56a36b.js";import"./index-b00d1c6a.js";import"./EyeOutlined-b57fa33c.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./usePrice-7afab779.js";import"./Col-25b75183.js";const j=async a=>{const{TableEngineRequest:s}=await R(()=>import("./buildSupabaseQuery-623c69c8.js"),["assets/buildSupabaseQuery-623c69c8.js","assets/index-c822befc.js","assets/index-158f9d8b.css"]),t=await s(a,"users");try{if(Array.isArray(t==null?void 0:t.rows)){const e=t.rows.map(r=>({id:r.id??null,first_name:r.first_name||"",last_name:r.last_name||"",phone:r.phone||"",fname:r.first_name||"",lname:r.last_name||"",mobile:r.phone||"",...r}));return{...t,rows:e}}}catch(e){console.log("[getMembersTable] normalize error:",e)}return t},I=async a=>{const{data:s,error:t}=await _.from("users").select("*").eq("id",a).single();if(t)throw t;return{id:s.id??null,first_name:s.first_name||"",last_name:s.last_name||"",phone:s.phone||"",fname:s.first_name||"",lname:s.last_name||"",mobile:s.phone||"",...s}},G=async a=>{const s={};a.first_name&&a.first_name.trim()!==""&&(s.first_name=a.first_name.trim()),a.last_name&&a.last_name.trim()!==""&&(s.last_name=a.last_name.trim()),a.phone&&a.phone.trim()!==""&&(s.phone=a.phone.trim());const{data:t,error:e}=await _.from("users").select("id, user_id").order("created_at",{ascending:!1}).limit(100);if(e||!t||t.length===0)throw new Error("برای ایجاد کاربر جدید، حداقل یک کاربر باید در سیستم وجود داشته باشد");let r=null;const w=t.find(d=>d.id===d.user_id);w?r=w.id:r=t[0].id,s.user_id=r;let l=null,f=null,i=0;const o=10,m=new Set;for(m.add(r);i<o;){const d=await _.from("users").insert([s]).select().single();if(f=d.error,l=d.data,!f)break;if(f.code==="23505"&&f.message.includes("user_id")){if(i++,i>=o)throw new Error("خطا در ایجاد کاربر: user_id باید منحصر به فرد باشد. لطفاً چند لحظه صبر کنید و دوباره تلاش کنید.");await new Promise(b=>setTimeout(b,300*i));const{data:n,error:U}=await _.from("users").select("id, user_id").order("created_at",{ascending:!1}).limit(100);if(!U&&n&&n.length>0){const b=n.find(h=>!m.has(h.id));if(b){r=b.id,m.add(r),s.user_id=r;continue}const g=n.find(h=>h.id===h.user_id&&!m.has(h.id));if(g){r=g.id,m.add(r),s.user_id=r;continue}const k=n.find(h=>h.id!==r);if(k){r=k.id,s.user_id=r;continue}}throw new Error("خطا در ایجاد کاربر: لطفاً چند لحظه صبر کنید و دوباره تلاش کنید.")}else throw f}if(f)throw f;if(l&&l.id&&l.user_id!==l.id){const{data:d,error:n}=await _.from("users").update({user_id:l.id}).eq("id",l.id).select().single();if(!n&&d)return d;if(n)throw n}return l},H=async(a,s)=>{const t={};s.first_name!==void 0&&(t.first_name=s.first_name.trim()||null),s.last_name!==void 0&&(t.last_name=s.last_name.trim()||null),s.phone!==void 0&&(t.phone=s.p
|