PageSourceSearch

https://digitalbehandling.se/assets/OrgInvoiceRecipientsPage-Wu3dGEYl.js

js digitalbehandling.se collected 2026-09-30 08:27:33 UTC 4,369 bytes, 2 lines download raw bytes

1import{s as g,g as b,x as C,n as I,r as s,j as e,B as N,A,C as O,c as R,d as T,aO as z,a as D,aD as L,_ as B,aE as P,aF as U,L as u,T as H,I as S,aP as K}from"./index-CobRY8C4.js";const M={economyEmails:[],accountingFirmName:null,accountingFirmEmail:null,updatedAt:null,exists:!1};async function q(t){const{data:a,error:n}=await g.from("organization_invoice_recipients").select("economy_emails, accounting_firm_name, accounting_firm_email, updated_at").eq("organization_id",t).maybeSingle();if(n)throw n;return a?{economyEmails:a.economy_emails??[],accountingFirmName:a.accounting_firm_name??null,accountingFirmEmail:a.accounting_firm_email??null,updatedAt:a.updated_at??null,exists:!0}:{...M}}async function G(t){var l;const{data:a}=await g.auth.getUser(),{error:n}=await g.from("organization_invoice_recipients").upsert({organization_id:t.orgId,economy_emails:t.economyEmails,accounting_firm_name:t.accountingFirmName,accounting_firm_email:t.accountingFirmEmail,updated_by:((l=a==null?void 0:a.user)==null?void 0:l.id)??null,updated_at:new Date().toISOString()},{onConflict:"organization_id"});if(n)throw n}function Y(t){return[...new Set(t.split(/[\s,;]+/).map(a=>a.trim()).filter(a=>a.length>0))]}function $(t){return t.filter(a=>!/^[^@\s]+@[^@\s.]+\.[^@\s]+$/.test(a))}function Q(){const t=b(),{toast:a}=C(),n=I(),[l,f]=s.useState(""),[h,p]=s.useState(""),[m,x]=s.useState(""),[o,w]=s.useState(!0),[v,j]=s.useState(!1),[y,_]=s.useState(null);s.useEffect(()=>{if(!n)return;let i=!1;return(async()=>{try{const r=await q(n);if(i)return;f(r.economyEmails.join(`
2`)),p(r.accountingFirmName??""),x(r.accountingFirmEmail??""),_(r.updatedAt)}catch(r){a({title:"Kunde inte hämta mottagarna",description:r.message,variant:"destructive"})}finally{i||w(!1)}})(),()=>{i=!0}},[n,a]);const c=Y(l),E=m.trim()?[m.trim()]:[],d=$([...c,...E]),F=c.length===0&&E.length===0,k=async()=>{if(n){if(d.length>0){a({title:"Ogiltig e-postadress",description:d.join(", "),variant:"destructive"});return}j(!0);try{await G({orgId:n,economyEmails:c,accountingFirmName:h.trim()||null,accountingFirmEmail:m.trim()||null}),_(new Date().toISOString()),a({title:"Mottagarna sparade"})}catch(i){a({title:"Kunde inte spara",description:i.message,variant:"destructive"})}finally{j(!1)}}};return e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>t(-1),children:[e.jsx(A,{className:"mr-2 h-4 w-4"})," Tillbaka"]}),e.jsxs(O,{children:[e.jsxs(R,{children:[e.jsx(T,{children:"Fakturauppgifter – mottagare"}),e.jsx(z,{children:"Här anger ni vilka i er organisation som ska fÃ¥ fakturaunderlagen för utbildningarna. Underlagen gÃ¥r endast till er egen ekonomi och till er ekonomibyrÃ¥ – aldrig till kunden och aldrig till deltagaren."})]}),e.jsxs(D,{className:"space-y-6",children:[F&&!o&&e.jsxs(L,{variant:"destructive",children:[e.jsx(B,{className:"h-4 w-4"}),e.jsx(P,{children:"Inga mottagare satta"}),e.jsx(U,{children:"SÃ¥ länge fältet är tomt gÃ¥r inga fakturaunderlag ut för er organisation. Ange minst en adress."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"economy",children:"Ekonomi hos oss (en adress per rad)"}),e.jsx(H,{id:"economy",rows:4,value:l,onChange:i=>f(i.target.value),placeholder:"[email protected]",disabled:o}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[c.length," adress",c.length===1?"":"er"," angivna."]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"firmName",children:"EkonomibyrÃ¥ (namn, valfritt)"}),e.jsx(S,{id:"firmName",value:h,onChange:i=>p(i.target.value),placeholder:"ByrÃ¥n AB",disabled:o})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"firmEmail",children:"EkonomibyrÃ¥ns e-post (valfritt)"}),e.jsx(S,{id:"firmEmail",value:m,onChange:i=>x(i.target.value),placeholder:"[email protected]",disabled:o})]})]}),d.length>0&&e.jsxs("p",{className:"text-sm text-destructive",children:["Ogiltiga adresser: ",d.join(", ")]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(N,{onClick:k,disabled:v||o||!n,children:[e.jsx(K,{className:"mr-2 h-4 w-4"}),v?"Sparar…":"Spara mottagare"]}),y&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Senast ändrat ",new Date(y).toLocaleStr
2ing("sv-SE")]})]})]})]})]})}export{Q 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.