PageSourceSearch

https://aidealer360.com/assets/ClientOffboarding-Bt_63xTj.js

js aidealer360.com collected 2026-09-24 12:39:19 UTC 12,386 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-vendor-B12AOeKi.js";import{e as pe,r as d}from"./react-vendor-DZt7wVAJ.js";import{u as I,w as ue}from"./xlsx-BQptaUDQ.js";import{u as ge,P as N,B as f,ar as fe,q as v,v as O,w as E,aP as je,x as F,y as _,L as J,g as Q,a8 as X,bm as be,ap as ee,I as Ne,s as h,i as p,l as ve,r as se,f as ae}from"./index-CUOC2qQu.js";import{S as _e,a as we,b as Ce,c as ye,d as De}from"./select-B8RrBf7t.js";import{A as ze,a as Se,b as Ae,c as Ie,d as Oe,e as Ee,g as Fe,f as Te}from"./alert-dialog-Dj2y0brn.js";import{a as ke,B as T,s as Be}from"./excelDataSanitizer-CynNAh0h.js";import{F as qe}from"./file-spreadsheet-BXdlMI0T.js";import{C as Pe}from"./circle-check-CwVqBPQR.js";import{B as k}from"./ban-Bwhze7-o.js";import"./charts-vendor-B6q1L48j.js";import"./supabase-vendor-dOy44Gxq.js";import"./animation-vendor-BAVy02gd.js";function Qe(){const j=pe(),{isPlatformAdmin:w,loading:C,registrationUser:x}=ge(),[y,B]=d.useState([]),[c,q]=d.useState(""),[t,P]=d.useState(null),[o,L]=d.useState(null),[u,g]=d.useState([]),[D,te]=d.useState(""),[ie,z]=d.useState(!1),[S,M]=d.useState(!1),[R,$]=d.useState(!0),[G,H]=d.useState(!1);d.useEffect(()=>{!C&&!w&&j("/")},[C,w,j]),d.useEffect(()=>{async function s(){$(!0);const{data:a,error:i}=await h.from("organizations").select("id, name, code, is_active, is_internal").eq("is_internal",!1).order("name");i?(p.error("Failed to load organizations"),console.error(i)):B(a||[]),$(!1)}s()},[]),d.useEffect(()=>{if(!c){P(null),L(null),g([]);return}const s=y.find(i=>i.id===c);P(s||null);async function a(){H(!0);const{data:i}=await h.from("dealerships").select("id").eq("organization_id",c),n=(i||[]).map(r=>r.id),{count:m}=await h.from("registration_users").select("id",{count:"exact",head:!0}).eq("organization_id",c);L({userCount:m||0,dealershipCount:n.length,dealershipIds:n});const A=Object.values(T).map(r=>({appName:r.appName,displayName:r.displayName,exported:!1,exportedAt:null,recordCount:0,isExporting:!1}));g(A),H(!1)}a()},[c,y]);const U=async s=>{if(!t||!o)return;const a=T[s];if(!a){p.error(`No backup configuration found for ${s}`);return}g(i=>i.map(n=>n.appName===s?{...n,isExporting:!0}:n));try{const i=I.book_new();let n=0;for(const r of a.tables){let l=h.from(r.tableName).select("*");const de=["organizations","registration_users","organization_branding","organization_settings","job_roles","job_role_default_apps"],ce=["vehicles","vehicle_notes","special_order_parts","sop_notes","registrations","registration_notes","prewrite_records","quotes","scoreboard_deals","chat_sessions","dealership_branding","application_settings","default_disclaimers","dealership_inventory_config"];de.includes(r.tableName)?r.tableName==="organizations"?l=l.eq("id",c):l=l.eq("organization_id",c):ce.includes(r.tableName)&&o.dealershipIds.length>0?l=l.in("dealership_id",o.dealershipIds):r.tableName==="dealerships"?l=l.eq("organization_id",c):r.tableName==="user_dealership_access"&&o.dealershipIds.length>0&&(l=l.in("dealership_id",o.dealershipIds)),r.orderBy&&(l=l.order(r.orderBy));const{data:me,error:Y}=await l;if(Y){console.warn(`Error fetching ${r.tableName}:`,Y);continue}const W=me||[];n+=W.length;const{sanitizedData:Z}=Be(W),xe=r.formatter?r.formatter(Z):Z,he=I.json_to_sheet(xe);I.book_append_sheet(i,he,r.sheetName.substring(0,31))}const m=ve(new Date,"yyyy-MM-dd_HHmm"),A=`${a.appId}_${t.code}_${m}.xlsx`;ue(i,A),g(r=>r.map(l=>l.appName===s?{...l,exported:!0,exportedAt:new Date,recordCount:n,isExporting:!1}:l)),await se({userId:(x==null?void 0:x.id)||"",module:ae.ADMIN,action:"Export Organization Data",details:{organization_id:c,organization_name:t.name,app_name:s,record_count:n}}),p.success(`Exported ${n} records from ${a.displayName}`)}catch(i){console.error("Export error:",i),p.error(`Failed to export ${s}`),g(n=>n.map(m=>m.appName===s?{...m,isExporting:!1}:m))}},re=async()=>{for(const s of u)s.exported||await U(s.appName)},ne=async()=>{if(!(!t||!o)){M(!0);try{const{error:s}=await h.from("organizations").update({is_active:!1}).eq("id",c);if(s)throw s;await se({userId:(x==null?void 0:x.id)||"",module:ae.ADMIN,action:"Disable Organization",details:{organization_id:c,organization_name:t.name,organization_code:t.code,user_count:o.userCount,dealership_count:o.dealershipCount,exports_completed:u.filter(i=>i.exported).map(i=>i.appName)}}),p.success(`${t.name} has been disabled`),z(!1);const{data:a}=await h.from("organizations").select("id, name, code, is_active, is_internal").eq("is_internal",!1).order("name");B(a||[]),q("")}catch(s){console.error("Disable error:",s),p.error("Failed to disable organization")}finally{M(!1)}}}
1,le=Object.entries(ke).sort(([,s],[,a])=>s.order-a.order).map(([s,a])=>({category:s,label:a.label,exports:u.filter(i=>{const n=T[i.appName];return(n==null?void 0:n.category)===s})})).filter(s=>s.exports.length>0),V=u.filter(s=>s.exported).length,b=u.length,K=b>0?V/b*100:0,oe=D==="CONFIRM"&&(t==null?void 0:t.is_active);return C?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-primary"})}):w?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b bg-card",children:e.jsx("div",{className:"container mx-auto px-4 py-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(f,{variant:"ghost",onClick:()=>j("/system-admin"),children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Back to System Admin"]}),e.jsx("div",{className:"h-6 w-px bg-border"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Client Off-Boarding"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Export data and disable organizations"})]})]})})}),e.jsxs("main",{className:"container mx-auto px-4 py-8 space-y-8",children:[e.jsxs(v,{children:[e.jsxs(O,{children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(je,{className:"h-5 w-5"}),"Step 1: Select Organization"]}),e.jsx(F,{children:"Choose the organization to off-board"})]}),e.jsxs(_,{children:[e.jsxs("div",{className:"max-w-md",children:[e.jsx(J,{htmlFor:"organization",children:"Organization"}),e.jsxs(_e,{value:c,onValueChange:q,disabled:R,children:[e.jsx(we,{id:"organization",className:"mt-1.5",children:e.jsx(Ce,{placeholder:R?"Loading...":"Select an organization"})}),e.jsx(ye,{children:y.map(s=>e.jsx(De,{value:s.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:s.name}),e.jsx(Q,{variant:s.is_active?"default":"destructive",className:"text-xs",children:s.is_active?"Active":"Disabled"})]})},s.id))})]})]}),t&&o&&e.jsx("div",{className:"mt-6 p-4 bg-muted/50 rounded-lg",children:e.jsxs("div",{className:"grid grid-cols-3 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.userCount}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Users"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:o.dealershipCount}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Dealerships"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:e.jsx(Q,{variant:t.is_active?"default":"destructive",children:t.is_active?"Active":"Disabled"})}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Status"})]})]})})]})]}),t&&o&&e.jsxs(v,{children:[e.jsxs(O,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(E,{className:"flex items-center gap-2",children:[e.jsx(qe,{className:"h-5 w-5"}),"Step 2: Export Data"]}),e.jsx(F,{children:"Download all organization data as Excel files"})]}),e.jsxs(f,{onClick:re,disabled:G,children:[e.jsx(X,{className:"h-4 w-4 mr-2"}),"Download All"]})]}),b>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm mb-2",children:[e.jsxs("span",{children:[V," of ",b," applications exported"]}),e.jsxs("span",{children:[Math.round(K),"%"]})]}),e.jsx(be,{value:K,className:"h-2"})]})]}),e.jsx(_,{children:G?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(N,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-6",children:le.map(s=>e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground mb-3",children:s.label}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-3",children:s.exports.map(a=>e.jsxs("div",{className:`p-3 border rounded-lg transition-colors ${a.exported?"border-green-500/50 bg-green-500/5":"border-border"}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:a.displayName}),a.exported&&e.jsx(Pe,{className:"h-4 w-4 text-green-500 shrink-0"})]}),a.exported?e.jsxs("div",{className:"text-xs text-muted-foreground",children:[a.recordCount," records"]}):e.jsxs(f,{size:"sm",variant:"outline",className:"w-full h-7 text-xs",onClick:()=>U(a.appName),disabled:a.isExporting,children:[a.isExporting?e.jsx(N,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(X,{className:"h-3 w-3 mr-1"}),"Export"]})]},a.appName))})]},s.category))})})]}),t&&o&&t.is_active&&e.jsxs(v,{className:"border-destructive/50",children:[e.jsxs(O,{children:[e.jsxs(E,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(k,{className:"h-5 w-5"}),"Step 3: Confirm & Disable"]}),e.jsx(F,{children:"Permanently disable access to this organization"})]}),e.jsxs(_,{className:"space-y-6",children:[e.jsx("div",{className:"p-4 bg-destructive/10 border border-destructive/30 rounded-lg",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ee,{className:"h-5 w-5 text-destructive shrink-0 mt-0.5"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsx("p",{className:"font-medium text-destructive",children:"Warning: Disabling this organization will:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-muted-foreground",children:[e.jsxs("li",{children:["Block all ",o.userCount," users from logging in"]}),e.jsxs("li",{children:["Affect ",o.dealershipCount," dealerships"]}),e.jsx("li",{children:"Data will be preserved but inaccessible"}),e.jsx("li",{children:"This action can be reversed by a Platform Administrator"})]})]})]})}
1),e.jsxs("div",{className:"max-w-md space-y-2",children:[e.jsxs(J,{htmlFor:"confirm",children:["Type ",e.jsx("span",{className:"font-mono font-bold",children:"CONFIRM"})," to proceed:"]}),e.jsx(Ne,{id:"confirm",value:D,onChange:s=>te(s.target.value),placeholder:"Type CONFIRM",className:D==="CONFIRM"?"border-green-500":""})]}),e.jsxs(f,{variant:"destructive",size:"lg",disabled:!oe,onClick:()=>z(!0),className:"w-full sm:w-auto",children:[e.jsx(k,{className:"h-4 w-4 mr-2"}),"DISABLE ORGANIZATION"]})]})]}),t&&!t.is_active&&e.jsx(v,{className:"border-muted",children:e.jsxs(_,{className:"py-8 text-center",children:[e.jsx(k,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"This organization is already disabled"}),e.jsxs("p",{className:"text-muted-foreground mb-4",children:["Users from ",t.name," cannot log in."]}),e.jsx(f,{variant:"outline",onClick:()=>j("/admin-control?tab=organization&subtab=org-list"),children:"Go to Organizations to Re-activate"})]})})]}),e.jsx(ze,{open:ie,onOpenChange:z,children:e.jsxs(Se,{children:[e.jsxs(Ae,{children:[e.jsxs(Ie,{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-5 w-5 text-destructive"}),"Disable ",t==null?void 0:t.name,"?"]}),e.jsxs(Oe,{className:"space-y-3",children:[e.jsx("p",{children:"This action will:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1",children:[e.jsx("li",{children:"Immediately log out all active users"}),e.jsx("li",{children:"Prevent all future logins"}),e.jsx("li",{children:"Set organization status to INACTIVE"})]}),e.jsx("p",{className:"font-medium mt-4",children:"This can be reversed by a Platform Administrator."})]})]}),e.jsxs(Ee,{children:[e.jsx(Fe,{disabled:S,children:"Cancel"}),e.jsx(Te,{onClick:ne,disabled:S,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:S?e.jsxs(e.Fragment,{children:[e.jsx(N,{className:"h-4 w-4 animate-spin mr-2"}),"Disabling..."]}):"Yes, Disable"})]})]})})]}):null}export{Qe 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.