Wizzas commited on
Commit
4738f34
·
verified ·
1 Parent(s): a0a6f3d

Update verified React dashboard

Browse files
frontend/dist/assets/TeamWorkspace-DDUIOnAd.js ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import{c as ie,r,l as ze,a as Fe,b as Me,d as We,e as je,s as Oe,f as qe,g as z,R as e,h as xe,n as Re,i as Ie,j as Ue,w as ge,k as Le,m as He,o as Be,p as Ge,q as Ke,t as Qe,v as $e,u as Ye,x as Ze,y as Je,z as Ae,L as Xe,S as Ve,A as et,B as Te,C as tt,D as at,E as Pe,F as rt}from"./index-DW2D9BlT.js";/**
2
+ * @license lucide-react v0.468.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const nt=ie("ArchiveRestore",[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h2",key:"tvwodi"}],["path",{d:"M20 8v11a2 2 0 0 1-2 2h-2",key:"1gkqxj"}],["path",{d:"m9 15 3-3 3 3",key:"1pd0qc"}],["path",{d:"M12 12v9",key:"192myk"}]]);/**
7
+ * @license lucide-react v0.468.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const De=ie("Cloud",[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]]);/**
12
+ * @license lucide-react v0.468.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const st=ie("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
17
+ * @license lucide-react v0.468.0 - ISC
18
+ *
19
+ * This source code is licensed under the ISC license.
20
+ * See the LICENSE file in the root directory of this source tree.
21
+ */const lt=ie("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
22
+ * @license lucide-react v0.468.0 - ISC
23
+ *
24
+ * This source code is licensed under the ISC license.
25
+ * See the LICENSE file in the root directory of this source tree.
26
+ */const ct=ie("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
27
+ * @license lucide-react v0.468.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const it=ie("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
32
+ * @license lucide-react v0.468.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const ot=ie("Send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);/**
37
+ * @license lucide-react v0.468.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const dt=ie("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function ut({user:E,inspection:i,notes:Y=[],inspections:o=[],inspectionLoading:W=!1,onSelectInspection:v,onEvidence:te}){const _=r.useRef(0),B=r.useRef(!1),w=r.useRef(i==null?void 0:i.id),Z=r.useRef(null),se=r.useRef(null),[q,J]=r.useState("checking"),[G,A]=r.useState([]),[x,X]=r.useState([]),[m,T]=r.useState(""),[h,P]=r.useState([]),[D,b]=r.useState([]),[K,j]=r.useState(""),[p,me]=r.useState(!1),[Q,ae]=r.useState(""),[g,L]=r.useState(""),[le,H]=r.useState(""),[n,y]=r.useState("Normal"),[u,C]=r.useState(""),[S,N]=r.useState(!1),[V,re]=r.useState(""),[pe,oe]=r.useState(""),[ye,be]=r.useState(null),[Se,Ne]=r.useState(0),[ke,fe]=r.useState(""),[we,_e]=r.useState(""),[ee,ne]=r.useState(""),s=G.find(t=>t.id===m),R=ze(Y),$=Fe(G),O=Me(i,Y,G,W),Ce=We({description:Q,owner:g,supervisor:le,priority:n,due:u},x),he=O.ready?Ce||(S?"":"Confirm that the saved Staff review identifies a defect before creating the case."):O.reason,Ee=je(s,E.id,x.some(t=>t.user_id===E.id&&t.role==="developer")),a=!!s&&ye!==null&&ye!==s.version;async function l(){const t=++_.current,d=await z(),f=await d.rpc("defectrag_ca_staff");if(t!==_.current)return;if(f.error||f.data!==!0)throw J("denied"),A([]),X([]),T(""),P([]),b([]),new Error("Sign in with an approved Staff account and verify the security code before opening corrective actions.");const M=await Promise.all([d.from("corrective_actions").select("*").order("created_at",{ascending:!1}).limit(500),d.from("staff_members").select("user_id,display_name,role,revoked_at").is("revoked_at",null)]);if(t===_.current){if(M.some(I=>I.error))throw J("unavailable"),A([]),X([]),T(""),P([]),b([]),M.find(I=>I.error).error;J("authorized"),A(M[0].data||[]),X(M[1].data||[]),j(""),Ne(I=>I+1)}}r.useEffect(()=>{const t=Oe(l,{onState:d=>{d.error&&(J("unavailable"),j(d.error),A([]),X([]),T(""),P([]),b([]))}});return()=>{t.stop(),_.current++}},[E.id]),r.useEffect(()=>{const t=()=>{_.current++,J("checking"),A([]),X([]),T(""),P([]),b([]),l().catch(d=>j(d.message))};return window.addEventListener("defectrag-auth-change",t),()=>window.removeEventListener("defectrag-auth-change",t)},[E.id]),r.useEffect(()=>{w.current&&w.current!==(i==null?void 0:i.id)&&(ae(""),L(""),H(""),C(""),y("Normal")),w.current=i==null?void 0:i.id,N(!1)},[i==null?void 0:i.id]),r.useEffect(()=>{N(!1)},[R==null?void 0:R.id]),r.useEffect(()=>{q==="authorized"&&qe(se.current)},[q,i==null?void 0:i.id,R==null?void 0:R.id]);function c(){oe(""),re((s==null?void 0:s.state)||""),fe((s==null?void 0:s.owner_id)||""),_e((s==null?void 0:s.supervisor_id)||""),ne(""),be((s==null?void 0:s.version)??null)}r.useEffect(c,[s==null?void 0:s.id]),r.useEffect(()=>{s&&qe(Z.current)},[s==null?void 0:s.id]),r.useEffect(()=>{let t=!0;const d=_.current;if(P([]),b([]),!(!s||q!=="authorized"))return z().then(f=>Promise.all([f.from("corrective_action_history").select("*").eq("case_id",s.id).order("version"),f.from("corrective_action_events").select("id,case_id,version,kind,status,attempts,last_error,created_at").eq("case_id",s.id).order("created_at",{ascending:!1})])).then(f=>{if(!(!t||d!==_.current)){if(f.some(M=>M.error))throw f.find(M=>M.error).error;P(f[0].data||[]),b(f[1].data||[])}}).catch(f=>{t&&d===_.current&&j(f.message)}),()=>{t=!1}},[s==null?void 0:s.id,s==null?void 0:s.version,Se,E.id,q]);async function k(t){if(!B.current){B.current=!0,me(!0),j("");try{await t(),await l(),ge()}catch(d){j(d.message||"Corrective action request failed.")}finally{B.current=!1,me(!1)}}}const F=t=>{var d;return((d=x.find(f=>f.user_id===t))==null?void 0:d.display_name)||"Former / unavailable staff"};return e.createElement("section",{className:"card case-workspace",ref:se,tabIndex:-1,"aria-label":"Corrective Actions workspace"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,"Corrective Actions"),e.createElement("p",null,"Track work needed after a Staff review confirms a defect. Assign someone to fix it, set a due date, and keep a record of progress.")),e.createElement("button",{className:"secondary",disabled:p,onClick:()=>k(l)},"Refresh cases")),K&&e.createElement("div",{className:"error",role:"alert"},xe(K)),q==="checking"&&e.createElement("p",{role:"status"},"Checking Staff access and the security code…"),q!=="checking"&&q!=="authorized"&&e.createElement("p",{className:"note"},"Open Staff workspace to check account approval and enter the security code. Then return here and try again."),q==="authorized"&&e.createElement(e.Fragment,null,e.createElement("p",{className:"caption"},"Showing up to 500 cases available to this account. Open: ",$.open," · Resolved / closed: ",$.resolved," · Overdue: ",$.overdue," · Average resolution: ",$.averageResolutionHours===null?"No resolved cases":$.averageResolutionHours.toFixed(1)+" hours",". Email delivery is separate from whether the case has been saved."),e.createElement("h3",null,"Create and assign a case"),e.createElement("p",{className:"caption"},"1. Choose a Team inspection. 2. Save its defect review. 3. Assign the work and deadline."),v&&e.createElement("label",{className:"field"},"Team inspection",e.createElement("select",{value:(i==null?void 0:i.id)||"",disabled:p||W,onChange:t=>v(t.target.value)},e.createElement("option",{value:""},"Choose a shared product inspection"),o.filter(t=>!t.archived_at).map(t=>{var d;return e.createElement("option",{key:t.id,value:t.id},((d=t.payload)==null?void 0:d.category)||"Product"," · ",t.id.slice(0,8)," · ",new Date(t.created_at).toLocaleString())}))),v&&!o.some(t=>!t.archived_at)&&e.createElement("p",{className:"note"},"No active Team inspections are available. Open a saved Personal inspection and choose Share with team before creating a case."),e.createElement("p",{className:"note",id:"case-creation-guidance",role:"status"},O.reason),e.createElement("p",{className:"caption"},"Assignment fields can be filled in as a draft. Nothing is saved or emailed until Create corrective action succeeds. Unsaved drafts stay on this page. Reloading, signing out or losing verified access can discard them."),!x.length&&e.createElement("p",{className:"note"},"No active Staff are available for assignment. Refresh cases or contact the workspace administrator. No account permissions will be changed here."),i&&!i.archived_at&&!W&&e.createElement("button",{className:"secondary",disabled:p,onClick:()=>te==null?void 0:te(i.id)},"Open photo and Staff review"),O.existingCaseId&&e.createElement("button",{className:"secondary",onClick:()=>T(O.existingCaseId)},"Open existing case"),e.createElement("form",{className:"login-form","aria-label":"Assign corrective action","aria-describedby":"case-creation-guidance case-submit-guidance",onSubmit:t=>{if(t.preventDefault(),!(he||p||B.current))return k(async()=>{const d=await z(),f=await Le(d,"defectrag_create_corrective_action",{p_inspection:i.id,p_review:O.review.id,p_confirmed:S,p_owner:g,p_supervisor:le,p_priority:n,p_description:Q,p_due:new Date(u).toISOString()});T(f),ae(""),N(!1)})}},e.createElement("label",{className:"field"},"What needs fixing?",e.createElement("textarea",{disabled:p,required:!0,minLength:10,maxLength:2e3,value:Q,onInput:t=>ae(t.target.value),onChange:t=>ae(t.target.value)})),e.createElement("label",{className:"field"},"Person responsible",e.createElement("select",{disabled:p,required:!0,value:g,onChange:t=>L(t.target.value)},e.createElement("option",{value:""},"Choose active staff"),x.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Supervisor",e.createElement("select",{disabled:p,required:!0,value:le,onChange:t=>H(t.target.value)},e.createElement("option",{value:""},"Choose active staff"),x.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Priority",e.createElement("select",{disabled:p,value:n,onChange:t=>y(t.target.value)},["Low","Normal","High","Critical"].map(t=>e.createElement("option",{key:t},t)))),e.createElement("label",{className:"field"},"Due date and time",e.createElement("input",{disabled:p,type:"datetime-local",required:!0,value:u,onInput:t=>C(t.target.value),onChange:t=>C(t.target.value)})),e.createElement("p",{className:"caption"},"Times use this device’s time zone. Choose a future deadline within the next year. The deadline is saved with the case."),e.createElement("p",{className:"note"},"Email reminders require administrator activation. Saving this case does not send an email by itself. The current n8n workflow targets the supervisor; it does not yet email the person responsible automatically. Confirm delivery with the supervisor separately."),e.createElement("label",null,e.createElement("input",{type:"checkbox",disabled:p||!O.ready,checked:S,onChange:t=>N(t.target.checked)})," A Staff review has confirmed a defect that needs fixing. An unusual inspection result alone is not enough."),e.createElement("p",{className:"note",id:"case-submit-guidance",role:"status"},he?"Cannot create yet: "+he:"Ready to save the assignment. No email is sent by this button."),e.createElement("button",{className:"primary",disabled:p||!!he},"Create corrective action")),e.createElement("h3",{className:"section-gap"},"Saved cases"),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Case"),e.createElement("th",null,"Status"),e.createElement("th",null,"Owner"),e.createElement("th",null,"Priority"),e.createElement("th",null,"Due"),e.createElement("th",null))),e.createElement("tbody",null,G.map(t=>e.createElement("tr",{key:t.id},e.createElement("td",null,t.id.slice(0,8)),e.createElement("td",null,t.state,!["Resolved","Closed","Cancelled"].includes(t.state)&&Date.parse(t.due_at)<Date.now()?" · Overdue":""),e.createElement("td",null,F(t.owner_id)),e.createElement("td",null,t.priority),e.createElement("td",null,new Date(t.due_at).toLocaleString()),e.createElement("td",null,e.createElement("button",{className:"text-button",onClick:()=>T(t.id)},"Details")))))),!G.length&&e.createElement("p",{className:"caption"},"No cases are available to this account yet.")),s&&e.createElement("div",{className:"cloud-message",ref:Z,tabIndex:-1,"aria-label":"Corrective action case details"},e.createElement("div",{className:"section-title"},e.createElement("h3",null,"Case ",s.id.slice(0,8)," · ",s.state),e.createElement("button",{className:"text-button",onClick:()=>T("")},"Close details")),e.createElement("p",null,s.description),e.createElement("p",null,"Person responsible: ",F(s.owner_id)," · Supervisor: ",F(s.supervisor_id)," · Due: ",new Date(s.due_at).toLocaleString()),e.createElement("p",null,"Confirmed by: ",F(s.confirmed_by)),e.createElement("button",{className:"secondary",onClick:()=>te(s.inspection_id)},"Open the linked photo and review"),Re(s.state).length>0&&!Ee&&e.createElement("p",{className:"note"},"Only the person responsible, the supervisor or a Developer can change this case after verifying their security code. Other Staff can read it."),!Re(s.state).length&&e.createElement("p",{className:"note"},"This case is ",s.state.toLowerCase(),". Its saved assignment and history are available to read; further updates are not permitted."),a&&Ee&&e.createElement("p",{className:"note",role:"status"},"This case changed while the update was being drafted. The draft has been kept; it has not been saved. Copy any text needed before loading the latest case. ",e.createElement("button",{className:"secondary",disabled:p,onClick:()=>{c(),j("")}},"Load latest case and replace draft")),Re(s.state).length>0&&Ee&&e.createElement("form",{className:"login-form",onSubmit:t=>{t.preventDefault(),k(async()=>{if(a)throw new Error("The case changed. Load the latest case before saving.");const d=await z(),f=await Le(d,"defectrag_update_corrective_action",{p_id:s.id,p_version:ye,p_state:V,p_note:pe,p_owner:ke,p_supervisor:we,p_due:ee?new Date(ee).toISOString():null});be(f),oe(""),ne("")})}},e.createElement("label",{className:"field"},"Case status",e.createElement("select",{disabled:p||a,value:V,onChange:t=>re(t.target.value)},Re(s.state).map(t=>e.createElement("option",{key:t},t)))),e.createElement("label",{className:"field"},"Owner",e.createElement("select",{disabled:p||a,required:!0,value:ke,onChange:t=>fe(t.target.value)},e.createElement("option",{value:""},"Choose active staff"),x.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Supervisor",e.createElement("select",{disabled:p||a,required:!0,value:we,onChange:t=>_e(t.target.value)},e.createElement("option",{value:""},"Choose active staff"),x.map(t=>e.createElement("option",{key:t.user_id,value:t.user_id},t.display_name)))),e.createElement("label",{className:"field"},"Change due date and time (optional)",e.createElement("input",{disabled:p||a,type:"datetime-local",value:ee,onInput:t=>ne(t.target.value),onChange:t=>ne(t.target.value)})),e.createElement("label",{className:"field"},"What changed or was fixed?",e.createElement("textarea",{disabled:p,required:!0,minLength:3,maxLength:2e3,value:pe,onInput:t=>oe(t.target.value),onChange:t=>oe(t.target.value)})),e.createElement("button",{className:"primary",disabled:p||!V||a},"Save case update")),e.createElement("h3",null,"Status history"),h.map(t=>e.createElement("p",{key:t.id},e.createElement("strong",null,t.state)," · ",F(t.actor_id)," · ",new Date(t.created_at).toLocaleString(),e.createElement("br",null),t.note,t.snapshot&&e.createElement("small",null,e.createElement("br",null),"Owner: ",F(t.snapshot.owner_id)," · Supervisor: ",F(t.snapshot.supervisor_id)," · Due: ",new Date(t.snapshot.due_at).toLocaleString()))),e.createElement("h3",null,"Email delivery"),e.createElement("p",{className:"caption"},"Waiting emails have not been sent. If delivery fails or is uncertain, contact the workspace administrator. The case stays saved even when the email service is unavailable."),D.map(t=>e.createElement("p",{key:t.id},Ie(t.kind)," · ",Ue(t.status)," · attempts ",t.attempts,t.last_error?" · "+xe(t.last_error):"")))))}function mt({client:E,user:i,onChange:Y}){var H;const[o,W]=r.useState(null),[v,te]=r.useState([]),[_,B]=r.useState([]),[w,Z]=r.useState(null),[se,q]=r.useState(""),[J,G]=r.useState(""),[A,x]=r.useState(""),[X,m]=r.useState(""),[T,h]=r.useState(""),[P,D]=r.useState(""),[b,K]=r.useState(!1),[j,p]=r.useState([]),[me,Q]=r.useState([]),ae=((H=window.DEFECTRAG_PUBLIC_CONFIG)==null?void 0:H.registrationEnabled)===!0;async function g(){if(!i){W(null),p([]),Q([]);return}const n=await He(E);W(n);const{data:y,error:u}=await E.auth.mfa.listFactors();if(u)throw u;const C=(y.totp||[]).filter(S=>S.status==="verified");if(te(C),B((y.all||[]).filter(S=>S.factor_type==="totp"&&S.status==="unverified")),G(S=>{var N;return C.some(V=>V.id===S)?S:((N=C[0])==null?void 0:N.id)||""}),n.role==="developer"&&n.approved&&n.aal2){const[S,N]=await Promise.all([E.rpc("defectrag_access_directory"),E.rpc("defectrag_notification_status")]);if(S.error)throw S.error;if(N.error)throw N.error;p(S.data||[]),Q(N.data||[])}else p([]),Q([])}async function L(n){K(!0),D("");try{await n()}catch(y){D(y.message||"Security request failed.")}finally{K(!1)}}r.useEffect(()=>{let n=!0;return Z(null),q(""),p([]),Q([]),E&&i?g().catch(y=>{n&&D(y.message)}):W(null),()=>{n=!1}},[E,i==null?void 0:i.id]);async function le(){await $e(E,(w==null?void 0:w.id)||J,se),q(""),Z(null),await g(),Y(),D("Security code verified. Staff access is available only after the account is approved.")}return e.createElement("div",{className:"section-gap"},e.createElement("h3",null,"Sign-in and account security"),P&&e.createElement("p",{className:"note",role:"status"},xe(P)),i?e.createElement(e.Fragment,null,e.createElement("p",null,"Access: ",e.createElement("strong",null,o!=null&&o.revoked?"revoked":o!=null&&o.approved?"approved":(o==null?void 0:o.request_status)||"not requested")," · Authenticator: ",e.createElement("strong",null,o!=null&&o.aal2?"security code verified":"enter security code")),e.createElement("button",{className:"secondary",disabled:b,onClick:()=>L(g)},"Refresh account status"),o&&!o.approved&&!o.revoked&&!o.request_status&&e.createElement("form",{className:"login-form",onSubmit:n=>{n.preventDefault(),L(async()=>{await Ge(E,A),await g(),D("Request sent. Check back here for Developer approval. Team and private Staff work are not available while the request is waiting."),Y()})}},e.createElement("label",{className:"field"},"Display name",e.createElement("input",{value:A,maxLength:80,onChange:n=>x(n.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:b||!o.registration_enabled||!o.email_verified},"Request staff access")),e.createElement("p",{className:"caption"},"Use an authenticator app for the extra six-digit sign-in code. Keep access to that app. If it is lost, contact the workspace administrator; resetting the password does not remove this security check."),!w&&!v.length&&!_.length&&e.createElement("button",{className:"secondary",disabled:b,onClick:()=>L(async()=>Z(await Ke(E)))},"Set up a security code app"),!w&&_.map(n=>e.createElement("p",{key:n.id,className:"caption"},"Authenticator setup was not finished. ",e.createElement("button",{className:"text-button",disabled:b,onClick:()=>L(async()=>{const{error:y}=await E.auth.mfa.unenroll({factorId:n.id});if(y)throw y;await g()})},"Cancel incomplete setup"))),w&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("p",null,"Open an authenticator app, scan this private QR code, then enter the six-digit code below to finish. Do not share the QR code or security codes."),e.createElement("img",{src:w.totp.qr_code,width:"200",height:"200",alt:"Private authenticator enrollment QR code"}),e.createElement("button",{className:"text-button",disabled:b,onClick:()=>L(async()=>{const{error:n}=await E.auth.mfa.unenroll({factorId:w.id});if(n)throw n;Z(null),q("")})},"Cancel incomplete setup"))),(w||v.length>0)&&e.createElement("form",{className:"login-form",onSubmit:n=>{n.preventDefault(),L(le)}},!w&&e.createElement("label",{className:"field"},"Security code app",e.createElement("select",{value:J,onChange:n=>G(n.target.value)},v.map(n=>e.createElement("option",{key:n.id,value:n.id},n.friendly_name||"Authenticator")))),e.createElement("label",{className:"field"},"Six-digit security code",e.createElement("input",{inputMode:"numeric",autoComplete:"one-time-code",pattern:"[0-9]{6}",maxLength:6,value:se,onChange:n=>q(n.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:b},"Verify security code")),(o==null?void 0:o.role)==="developer"&&o.approved&&o.aal2&&e.createElement(e.Fragment,null,e.createElement("h3",{className:"section-gap"},"Staff access management"),e.createElement("p",null,"Approve or reject requests that are still waiting. Removing access stops new Staff actions but keeps inspection history."),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Account"),e.createElement("th",null,"Status"),e.createElement("th",null,"Role"),e.createElement("th",null,"Action"))),e.createElement("tbody",null,j.map(n=>e.createElement("tr",{key:n.user_id},e.createElement("td",null,n.display_name,e.createElement("br",null),e.createElement("small",null,n.email)),e.createElement("td",null,n.status),e.createElement("td",null,n.role||"applicant"),e.createElement("td",null,n.user_id!==i.id&&(n.status==="pending"?["approve","reject"]:n.status==="approved"?["revoke"]:[]).map(y=>e.createElement("button",{key:y,className:"text-button",disabled:b,onClick:()=>{window.confirm(`${y[0].toUpperCase()+y.slice(1)} access for ${n.display_name}?`)&&L(async()=>{await Qe(E,n,y),await g(),Y(),D("Account access updated. Check Email delivery below separately; saving this change does not confirm an email was sent.")})}},{approve:"Approve",reject:"Reject",revoke:"Remove access"}[y])))))))),e.createElement("h3",{className:"section-gap"},"Email delivery"),e.createElement("p",{className:"caption"},"Waiting emails have not been sent. Delivery depends on administrator settings and the email service being available. Sent means the email service accepted the message; it may still reach Spam or fail to arrive."),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Event"),e.createElement("th",null,"Delivery"),e.createElement("th",null,"Attempts"),e.createElement("th",null))),e.createElement("tbody",null,me.map(n=>e.createElement("tr",{key:n.id},e.createElement("td",null,Ie(n.kind)),e.createElement("td",null,Ue(n.status)),e.createElement("td",null,n.attempts),e.createElement("td",null,n.status==="dead"&&e.createElement("button",{className:"text-button",disabled:b,onClick:()=>L(async()=>{const{error:y}=await E.rpc("defectrag_retry_notification",{p_id:n.id});if(y)throw y;await g()})},"Retry delivery"))))))))):ae?e.createElement("form",{className:"login-form",onSubmit:n=>{n.preventDefault(),L(async()=>{await Be(E,{email:X,password:T,displayName:A,redirectTo:location.origin+location.pathname}),h(""),D("Check the inbox and Spam folder for a confirmation email. Open its link, sign in, then choose Request staff access. A Developer must approve the request before Staff work is available.")})}},e.createElement("p",null,"New to Staff work? Create an account, confirm the email, then request access. The public demo can be used without an account."),e.createElement("label",{className:"field"},"Display name",e.createElement("input",{value:A,onChange:n=>x(n.target.value),maxLength:80,autoComplete:"name",required:!0})),e.createElement("label",{className:"field"},"Email",e.createElement("input",{type:"email",value:X,onChange:n=>m(n.target.value),autoComplete:"email",required:!0})),e.createElement("label",{className:"field"},"New password",e.createElement("input",{type:"password",minLength:12,value:T,onChange:n=>h(n.target.value),autoComplete:"new-password",required:!0})),e.createElement("button",{className:"secondary",disabled:b||!E},"Register account")):e.createElement("p",{className:"caption"},"New account registration is currently closed. Existing Staff can sign in below. The public demo is still available."))}function ft({onOpenInspection:E,onOpenCorrectiveActions:i,onChooseInspection:Y,casesView:o=!1,initialInspectionId:W=null}){var Ee;const v=r.useRef(0),te=r.useRef(null),_=r.useRef(0),B=r.useRef(null),w=r.useRef(0),Z=r.useRef(null),se=r.useRef(null),[q,J]=r.useState(0),[G,A]=r.useState(!1),[x,X]=r.useState({state:"refreshing"}),[m,T]=r.useState(null),[h,P]=r.useState(null),[D,b]=r.useState([]),[K,j]=r.useState({}),[p,me]=r.useState(""),[Q,ae]=r.useState(""),[g,L]=r.useState(!1),[le,H]=r.useState(""),[n,y]=r.useState(!1),[u,C]=r.useState(null),[S,N]=r.useState([]),[V,re]=r.useState([]),[pe,oe]=r.useState(""),[ye,be]=r.useState(!1),[Se,Ne]=r.useState(""),[ke,fe]=r.useState(!1),[we,_e]=r.useState(null),ee=Ye(),ne=Ze(window.DEFECTRAG_PUBLIC_CONFIG);r.useEffect(()=>()=>{S.filter(a=>a.startsWith("blob:")).forEach(a=>URL.revokeObjectURL(a))},[S]),r.useEffect(()=>{B.current=u},[u]),r.useEffect(()=>{u&&qe(Z.current)},[q]),r.useEffect(()=>{if(!m||!h||!W)return;const a=m.id+":"+W;se.current!==a&&(se.current=a,O({id:W},{focus:!o}))},[m==null?void 0:m.id,h==null?void 0:h.user_id,W]);const s=Je();async function R(a){L(!0),H("");try{await a()}catch(l){H(l.message||"Team request failed.")}finally{L(!1)}}async function $(){var U;const a=++_.current,l=v.current,c=(U=B.current)==null?void 0:U.id,{client:k,staff:F}=await rt();let t=k.from("shared_inspections").select("*").order("created_at",{ascending:!1}).limit(200);t=n?t.not("archived_at","is",null):t.is("archived_at",null);const[{data:d,error:f},{data:M,error:I},ve]=await Promise.all([t,k.from("staff_members").select("*"),c?k.from("staff_notes").select("*").eq("inspection_id",c).order("created_at"):{data:[]}]);if(f)throw f;if(I)throw I;if(ve.error)throw ve.error;if(a===_.current&&(P(F),H(""),b(d||[]),j(Object.fromEntries((M||[]).map(ce=>[ce.user_id,ce.display_name]))),c&&l===v.current)){const ce=(d||[]).find(de=>de.id===c);if(!ce)v.current++,C(null),N([]),re([]);else if(C(ce),re(ve.data||[]),Date.now()-w.current>480*1e3)if(ee){const de=await Ae(k,ce);a===_.current&&l===v.current?(N(de),w.current=Date.now()):de.forEach(ue=>URL.revokeObjectURL(ue))}else{const de=await Promise.all([ce.image_path,ce.heatmap_path].map(ue=>k.storage.from("team-inspections").createSignedUrl(ue,900)));if(a===_.current&&l===v.current){if(de.some(ue=>ue.error))throw new Error("Shared image links could not refresh.");N(de.map(ue=>ue.data.signedUrl)),w.current=Date.now()}}}}r.useEffect(()=>{if(!s)return;let a=!1,l;return z().then(async c=>{!a&&ee&&_e(c),l=c.auth.onAuthStateChange((F,t)=>{var d;if(!a){const f=((d=t==null?void 0:t.user)==null?void 0:d.id)||null;te.current!==f&&(v.current++,_.current++,C(null),b([]),N([]),re([]),P(null),te.current=f),T((t==null?void 0:t.user)||null),F==="PASSWORD_RECOVERY"&&be(!0)}}).data.subscription;const{data:k}=await c.auth.getUser();a||T(k.user)}).catch(c=>{a||H(c.message)}),()=>{a=!0,v.current++,l==null||l.unsubscribe()}},[s]),r.useEffect(()=>{if(!m)return;const a=Oe($,{onState:l=>{X(l),l.error&&(H(l.error),ee&&(v.current++,b([]),j({}),C(null),N([]),re([]),P(null)))}});return()=>{a.stop(),_.current++}},[m==null?void 0:m.id,n]);async function O(a,{focus:l=!0}={}){const c=++v.current;A(!0);try{await R(async()=>{if(c!==v.current)return;const k=await z(),F=k.storage.from("team-inspections"),[{data:t,error:d},{data:f,error:M}]=await Promise.all([k.from("shared_inspections").select("*").eq("id",a.id).single(),k.from("staff_notes").select("*").eq("inspection_id",a.id).order("created_at")]);if(c!==v.current)return;if(d)throw d;if(M)throw M;const I=ee?await Ae(k,t):null,ve=I?I.map(U=>({data:{signedUrl:U}})):await Promise.all([t.image_path,t.heatmap_path].map(U=>F.createSignedUrl(U,900)));if(ve.some(U=>U.error))throw new Error("Private images could not be loaded. Check staff/storage policies.");if(c!==v.current){I==null||I.forEach(U=>URL.revokeObjectURL(U));return}B.current=t,w.current=Date.now(),C(t),N(ve.map(U=>U.data.signedUrl)),re(f||[]),l&&J(U=>U+1)})}finally{c===v.current&&A(!1)}}function Ce(){v.current++,B.current=null,A(!1),C(null),N([]),re([])}async function he(){await R(async()=>{const a=await z(),l=D.filter(c=>c.owner_id===m.id).map(c=>c.id);if(l.length){const{error:c}=await a.rpc("archive_team_inspections",{p_ids:l});if(c)throw c}v.current++,C(null),fe(!1),await $(),ge()})}return s?e.createElement(e.Fragment,null,e.createElement("section",{className:"card"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",null,e.createElement(dt,{size:21})," ",o?"Corrective Actions access":"Staff workspace"),e.createElement("p",null,"Sign in to review inspections shared with the team. New inspections start in Personal Workspace and are shared only when chosen.")),e.createElement("span",{className:"subtle-tag"},e.createElement(De,{size:13})," STAFF ACCESS")),le&&e.createElement("div",{className:"error",role:"alert"},xe(le)),G&&e.createElement("p",{role:"status"},"Opening the shared photo and review…"),o&&!ne&&e.createElement("p",{className:"note"},"Corrective Actions has been turned off for this app. Inspections and reviews are still available. Contact the workspace administrator if needed."),ee&&we&&(!o||!h)&&e.createElement(mt,{key:(m==null?void 0:m.id)||"anonymous",client:we,user:m,onChange:()=>{ge(),m&&R($)}}),m?e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("div",null,e.createElement(Ve,{size:18}),e.createElement("strong",null,(h==null?void 0:h.display_name)||m.email),e.createElement("span",{className:"subtle-tag"},(h==null?void 0:h.role)||"CHECKING ACCESS")),e.createElement("button",{className:"secondary",disabled:g,onClick:()=>R($)},e.createElement(it,{size:16})," Refresh"),!o&&h&&ne&&e.createElement("button",{className:"secondary",onClick:()=>i==null?void 0:i()},"Open Corrective Actions"),o&&h&&e.createElement("button",{className:"secondary",onClick:()=>Y==null?void 0:Y()},"Choose a Team inspection"),e.createElement("button",{className:"secondary",onClick:()=>R(async()=>{await(await z()).auth.signOut(),b([]),C(null),P(null)})},e.createElement(ct,{size:16})," Sign out")),ye&&e.createElement("form",{className:"login-form",onSubmit:a=>{a.preventDefault(),R(async()=>{const l=await z(),{error:c}=await l.auth.updateUser({password:Se});if(c)throw c;Ne(""),be(!1)})}},e.createElement("label",{className:"field"},"Set a new password",e.createElement("input",{type:"password",minLength:12,autoComplete:"new-password",value:Se,onChange:a=>Ne(a.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:g},"Save password")),!o&&e.createElement(e.Fragment,null,e.createElement("div",{className:"team-toolbar"},e.createElement("span",{role:"status"},"Team Workspace · latest ",D.length," shared inspections · ",x.state==="synced"?"updated at "+new Date(x.at).toLocaleTimeString():x.state==="offline"?"offline; shown results may be out of date":x.state==="stale"?"update failed; shown results may be out of date":"refreshing…"," · checks for changes every 15 seconds"),(h==null?void 0:h.role)==="developer"&&e.createElement("button",{className:"secondary",onClick:()=>{y(!n),C(null)}},e.createElement(nt,{size:16}),n?"Active history":"Restore archived team work"),!n&&e.createElement("button",{className:"secondary danger",disabled:g||!D.some(a=>a.owner_id===m.id),onClick:()=>fe(!0)},e.createElement(et,{size:16})," Archive my shared inspections")),ke&&e.createElement("div",{className:"note"},e.createElement("div",null,e.createElement("strong",null,"Archive your visible records?"),e.createElement("p",null,"They will leave the shared active history. Original files and conversations remain recoverable by a developer. Other staff members’ records will stay active."),e.createElement("div",{className:"button-row"},e.createElement("button",{className:"primary",disabled:g,onClick:he},"Archive my records"),e.createElement("button",{className:"secondary",onClick:()=>fe(!1)},"Cancel")))),e.createElement("div",{className:"table-wrap"},e.createElement("table",null,e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null,"Inspection"),e.createElement("th",null,"Product"),e.createElement("th",null,"Result"),e.createElement("th",null,"Shared by"),e.createElement("th",null,"Saved"),e.createElement("th",null))),e.createElement("tbody",null,D.map(a=>{var l;return e.createElement("tr",{key:a.id},e.createElement("td",null,e.createElement("strong",null,a.id.slice(0,8))),e.createElement("td",null,a.payload.category),e.createElement("td",null,e.createElement("span",{className:"badge "+((l=a.payload.verdict)==null?void 0:l.toLowerCase())},Te(a.payload.verdict))),e.createElement("td",null,K[a.owner_id]||"Staff member"),e.createElement("td",null,new Date(a.created_at).toLocaleString()),e.createElement("td",null,e.createElement("button",{className:"text-button",disabled:g,onClick:()=>O(a)},"Review"),n&&(h==null?void 0:h.role)==="developer"&&e.createElement("button",{className:"text-button",disabled:g,onClick:()=>R(async()=>{const c=await z(),{error:k}=await c.rpc("restore_team_inspections",{p_ids:[a.id]});if(k)throw k;await $(),ge()})},"Restore")))}))),!D.length&&e.createElement("div",{className:"empty"},e.createElement(De,{size:30}),e.createElement("p",null,n?"No archived records to recover.":"No shared inspections yet. Open an inspection result and select Share with team."))))):e.createElement("form",{className:"login-form",onSubmit:a=>{a.preventDefault(),R(async()=>{const l=await z(),{error:c}=await l.auth.signInWithPassword({email:p,password:Q});if(c)throw c;ae("")})}},e.createElement("label",{className:"field"},"Work email",e.createElement("input",{type:"email",autoComplete:"username",value:p,onChange:a=>me(a.target.value),required:!0})),e.createElement("label",{className:"field"},"Password",e.createElement("input",{type:"password",autoComplete:"current-password",value:Q,onChange:a=>ae(a.target.value),required:!0})),e.createElement("button",{className:"primary",disabled:g},g?e.createElement(Xe,{className:"spin",size:17}):e.createElement(lt,{size:17})," Sign in"),e.createElement("button",{type:"button",className:"text-button",disabled:!p||g,onClick:()=>R(async()=>{const a=await z(),{error:l}=await a.auth.resetPasswordForEmail(p,{redirectTo:location.origin+location.pathname});if(l)throw l;H("Password reset requested. Check the inbox and Spam folder.")})},"Reset password"),e.createElement("p",{className:"caption"},ee?"A new account needs Developer approval before Staff work is available. Approved Staff must also enter their security code when asked.":"The workspace administrator must approve an account before it can access Staff work."))),o&&m&&h&&ne&&e.createElement(ut,{key:m.id,user:m,inspection:u,notes:V,inspections:D,inspectionLoading:G,onSelectInspection:a=>a?O({id:a},{focus:!1}):Ce(),onEvidence:a=>O({id:a})}),m&&u&&e.createElement("section",{className:"card",ref:Z,tabIndex:-1,"aria-labelledby":"shared-inspection-title"},e.createElement("div",{className:"section-title"},e.createElement("div",null,e.createElement("h2",{id:"shared-inspection-title"},"Shared inspection · ",u.id.slice(0,8)),e.createElement("p",null,"Shared copy from ",K[u.owner_id]||"a colleague",". These are saved results. Opening them does not run another inspection.")),e.createElement("div",{className:"button-row"},E&&!u.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>E(u)},"Open full result and assistant"),!o&&ne&&!u.archived_at&&e.createElement("button",{className:"secondary",onClick:()=>i==null?void 0:i(u)},"Create or view corrective actions"),e.createElement("button",{className:"text-button",onClick:Ce},"Close"))),e.createElement("div",{className:"shared-images"},S.map((a,l)=>e.createElement("img",{key:a,src:a,alt:l?"Saved highlighted areas":"Saved inspected product"}))),e.createElement("div",{className:"observation"},e.createElement("strong",null,"SAVED RESULT"),e.createElement("span",null,Te(u.payload.verdict)," · score ",Number(u.payload.score).toFixed(5)," · review limit ",Number(u.payload.threshold).toFixed(5))),e.createElement("h3",{className:"section-gap"},"Saved assistant conversation"),(Ee=u.conversation)!=null&&Ee.length?u.conversation.map((a,l)=>e.createElement("p",{className:"cloud-message",key:l},e.createElement("strong",null,a.role==="user"?"Inspector":"Evidence Assistant",": "),a.question||a.answer)):e.createElement("p",{className:"caption"},"No assistant conversation was shared with this inspection."),!u.archived_at&&e.createElement(tt,{key:u.id+String(V.length),current:V.map(a=>Pe(a,K)).filter(Boolean).at(-1),disabled:g,onSave:async a=>{const l=await z(),{error:c}=await l.from("staff_notes").insert({inspection_id:u.id,author_id:m.id,body:at(a.status,a.decision,a.note)});if(c)throw c;await O(u,{focus:!o}),ge()}}),e.createElement("h3",{className:"section-gap"},"Team notes"),V.filter(a=>!Pe(a,K)).map(a=>e.createElement("div",{className:"cloud-message",key:a.id},e.createElement("strong",null,K[a.author_id]||"Staff member"),e.createElement("p",null,a.body),e.createElement("small",null,new Date(a.created_at).toLocaleString()))),!u.archived_at&&e.createElement("form",{className:"question-form",onSubmit:a=>{a.preventDefault(),R(async()=>{const l=await z(),{error:c}=await l.from("staff_notes").insert({inspection_id:u.id,author_id:m.id,body:pe.trim()});if(c)throw c;oe(""),await O(u),ge()})}},e.createElement("input",{"aria-label":"Staff review note",maxLength:2e3,placeholder:"Add a note for the team…",value:pe,onChange:a=>oe(a.target.value)}),e.createElement("button",{className:"primary",disabled:g||!pe.trim()},e.createElement(ot,{size:16})," Add note")))):e.createElement("section",{className:"card cloud-setup"},e.createElement("div",{className:"setup-icon"},e.createElement(De,{size:32})),e.createElement("span",{className:"eyebrow"},"TEAM WORKSPACE"),e.createElement("h2",null,"Team workspace is not available yet."),e.createElement("p",null,"The workspace administrator needs to connect shared storage before Staff can sign in here."),e.createElement("div",{className:"setup-grid"},[["01","Connect shared storage","The workspace administrator completes this setup."],["02","Set up staff access","The administrator sets up approval and account security."],["03","Connect this dashboard","The administrator connects the app, then Staff can sign in."]].map(([a,l,c])=>e.createElement("div",{key:a},e.createElement("b",null,a),e.createElement("h3",null,l),e.createElement("p",null,c)))),e.createElement("a",{className:"primary",href:"https://supabase.com/dashboard",target:"_blank",rel:"noreferrer"},"Administrator setup ",e.createElement(st,{size:16})),e.createElement("p",{className:"caption"},"Contact the workspace administrator for help. The public demo can be used without Staff access."))}export{ft as default};
frontend/dist/assets/index-DW2D9BlT.js ADDED
The diff for this file is too large to render. See raw diff
 
frontend/dist/index.html CHANGED
@@ -1,3 +1,3 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="theme-color" content="#132e32"/><meta name="description" content="Local visual anomaly inspection with traceable evidence."/><title>DefectRAG · Inspection intelligence</title><link rel="icon" type="image/svg+xml" href="./logo.svg"><script src="./config.js"></script> <script type="module" crossorigin src="./assets/index-DvSS0xmr.js"></script>
2
  <link rel="stylesheet" crossorigin href="./assets/index-CxVCcQhp.css">
3
  </head><body><div id="root"></div></body></html>
 
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><meta name="theme-color" content="#132e32"/><meta name="description" content="Local visual anomaly inspection with traceable evidence."/><title>DefectRAG · Inspection intelligence</title><link rel="icon" type="image/svg+xml" href="./logo.svg"><script src="./config.js"></script> <script type="module" crossorigin src="./assets/index-DW2D9BlT.js"></script>
2
  <link rel="stylesheet" crossorigin href="./assets/index-CxVCcQhp.css">
3
  </head><body><div id="root"></div></body></html>