PageSourceSearch

https://frimurer.no/assets/MembershipSettings-CPCgyRDS.js

js frimurer.no collected 2026-10-02 12:14:00 UTC 7,068 bytes, 1 lines download raw bytes

1import{u as J,r as p,j as e}from"./vendor-react-GnwsTJfO.js";import{u as O,b as d,a as z}from"./vendor-query-Dp4tHR6-.js";import{u as W,f as x,B as o,Z,C as S,G as k,J as C,g as E,T as X,t as Y,v as M,w as q,x as $,I as g,U as F,y as T,V as t}from"./index-Bk3sb3g_.js";import{e as ee}from"./AdminNavigation-DVMee0wC.js";import{T as K}from"./trash-2-DOLSXo7O.js";import{S as se}from"./save-DqX4_s7f.js";import"./vendor-cjs-BcELrC9x.js";import"./vendor-supabase-BWPZKnGU.js";import"./vendor-ui-C1xCQL2z.js";import"./vendor-utils-B2rm_Apj.js";import"./MasonicCross-CB_Vslf8.js";import"./image-CJtwgLmH.js";import"./users-Cq75-41X.js";const je=()=>{const r=J(),m=O(),{getSetting:b,updateSetting:n}=W(),[j,u]=p.useState(""),[f,N]=p.useState("#3B82F6"),[i,L]=p.useState(""),[v,A]=p.useState(""),w=b("membership_notification_emails")||[],H=d({mutationFn:async s=>{const a=s.trim().toLowerCase();if(!a.includes("@"))throw new Error("Ugyldig e-postadresse");if(w.includes(a))throw new Error("Adressen er allerede lagt til");await n.mutateAsync({key:"membership_notification_emails",value:[...w,a]})},onSuccess:()=>{A(""),t("Varslingsadresse lagt til")},onError:s=>{t.error(s.message||"Kunne ikke legge til adresse")}}),V=d({mutationFn:async s=>{await n.mutateAsync({key:"membership_notification_emails",value:w.filter(a=>a!==s)})},onSuccess:()=>{t("Varslingsadresse fjernet")}}),{data:c,isLoading:te}=z({queryKey:["membership-statuses"],queryFn:async()=>{const{data:s,error:a}=await x.from("membership_inquiry_statuses").select("*").order("sort_order");if(a)throw a;return s}}),Q=d({mutationFn:async()=>
1{const s=c!=null&&c.length?Math.max(...c.map(l=>l.sort_order))+1:0,{error:a}=await x.from("membership_inquiry_statuses").insert({label:j.trim(),color:f,sort_order:s});if(a)throw a},onSuccess:()=>{m.invalidateQueries({queryKey:["membership-statuses"]}),u(""),t("Status lagt til")}}),P=d({mutationFn:async s=>{const{error:a}=await x.from("membership_inquiry_statuses").delete().eq("id",s);if(a)throw a},onSuccess:()=>{m.invalidateQueries({queryKey:["membership-statuses"]}),t("Status slettet")},onError:()=>{t.error("Kan ikke slette status som er i bruk")}}),R=d({mutationFn:async({id:s,label:a,color:l})=>{const{error:y}=await x.from("membership_inquiry_statuses").update({label:a,color:l}).eq("id",s);if(y)throw y},onSuccess:()=>{m.invalidateQueries({queryKey:["membership-statuses"]}),t("Status oppdatert")}}),h=b("membership_handler_user_ids")||[],{data:_}=z({queryKey:["membership-handler-profiles",h],queryFn:async()=>{if(!h.length)return[];const{data:s}=await x.from("profiles").select("user_id, first_name, last_name, display_name").in("user_id",h);return s||[]},enabled:h.length>0}),I=d({mutationFn:async s=>{var B;const{data:a,error:l}=await x.functions.invoke("get-users",{body:{search:s}});if(l)throw l;const y=(B=a==null?void 0:a.users)==null?void 0:B.find(G=>G.email===s);if(!y)throw new Error("Bruker ikke funnet");const D=[...h,y.id];await n.mutateAsync({key:"membership_handler_user_ids",value:D})},onSuccess:()=>{L(""),m.invalidateQueries({queryKey:["membership-handler-profiles"]}),t("Saksbehandler lagt til")},onError:s=>{t.error(s.message||"Kunne ikke legge til saksbehandler")}}),U=d({mutationFn:async s=>{const a=h.filter(l=>l!==s);await n.mutateAsync({key:"membership_handler_user_ids",value:a})},onSuccess:()=>{m.invalidateQueries({queryKey:["membership-handler-profiles"]}),t("Saksbehandler fjernet")}});return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(ee,{}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-3xl",children:[e.jsxs(o,{variant:"ghost",onClick:()=>r("/admin/membership"),className:"mb-4",children:[e.jsx(Z,{className:"h-4 w-4 mr-2"}),"Tilbake"]}),e.jsx("h1",{className:"text-2xl font-bold mb-6",children:"Innstillinger for medlemshenvendelser"}),e.jsxs(S,{className:"mb-6",children:[e.jsx(k,{children:e.jsx(C,{children:"Statuser"})}),e.jsxs(E,{className:"space-y-4",children:[e.jsxs(X,{children:[e.jsx(Y,{children:e.jsxs(M,{children:[e.jsx(q,{children:"Farge"}),e.jsx(q,{children:"Navn"}),e.jsx(q,{})]})}),e.jsx($,{children:c==null?void 0:c.map(s=>e.jsx(ae,{status:s,onUpdate:R.mutate,onDelete:P.mutate},s.id))})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{type:"color",value:f,onChange:s=>N(s.target.value),className:"w-12 p-1 h-10"}),e.jsx(g,{placeholder:"Ny status...",value:j,onChange:s=>u(s.target.value),className:"flex-1"}),e.jsxs(o,{onClick:()=>Q.mutate(),disabled:!j.trim()||Q.isPending,children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Legg til"]})]})]})]}),e.jsxs(S,{className:"mb-6",children:[e.jsx(k,{children:e.jsx(C,{children:"Varsling på e-post"})}),e.jsxs(E,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Disse e-postadressene får en varsling hver gang noen sender inn en henvendelse om medlemskap."}),w.map(s=>e.jsxs("div",{className:"flex items-center justify-between border rounded-md p-3",children:[e.jsx("span",{className:"text-sm",children:s}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>V.mutate(s),children:e.jsx(K,{className:"h-4 w-4 text-destructive"})})]},s)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{placeholder:"E-postadresse for varsling...",value:v,onChange:s=>A(s.target.value),type:"email",className:"flex-1"}),e.jsxs(o,{onClick:()=>v.trim()&&H.mutate(v),disabled:!v.trim()||H.isPending,children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Legg til"]})]})]})]}),e.jsxs(S,{children:[e.jsx(k,{children:e.jsx(C,{children:"Saksbehandlere"})}),e.jsxs(E,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Webmaster har alltid tilgang. Legg til andre brukere som skal ha tilgang til henvendelser."}),_==null?void 0:_.map(s=>e.jsxs("div",{className:"flex items-center justify-between border rounded-md p-3",children:[e.jsxs("span",{className:"text-sm",children:[s.first_name," ",s.last_name||s.display_name]}),e.jsx(o,{variant:"ghost",size:"sm",onClick:()=>
1U.mutate(s.user_id),children:e.jsx(K,{className:"h-4 w-4 text-destructive"})})]},s.user_id)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(g,{placeholder:"E-postadresse til bruker...",value:i,onChange:s=>L(s.target.value),type:"email",className:"flex-1"}),e.jsxs(o,{onClick:()=>i.trim()&&I.mutate(i.trim()),disabled:!i.trim()||I.isPending,children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Legg til"]})]})]})]})]})]})},ae=({status:r,onUpdate:m,onDelete:b})=>{const[n,j]=p.useState(r.label),[u,f]=p.useState(r.color),N=n!==r.label||u!==r.color;return e.jsxs(M,{children:[e.jsx(T,{children:e.jsx(g,{type:"color",value:u,onChange:i=>f(i.target.value),className:"w-10 h-8 p-1"})}),e.jsx(T,{children:e.jsx(g,{value:n,onChange:i=>j(i.target.value),className:"max-w-[200px]"})}),e.jsxs(T,{className:"text-right space-x-1",children:[N&&e.jsx(o,{size:"sm",variant:"outline",onClick:()=>m({id:r.id,label:n,color:u}),children:e.jsx(se,{className:"h-3 w-3"})}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>b(r.id),children:e.jsx(K,{className:"h-3 w-3 text-destructive"})})]})]})};export{je 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.