PageSourceSearch

https://console.quidkey.com/assets/default-rates-D0dVg9RD.js

js quidkey.com collected 2026-09-24 13:41:17 UTC 5,885 bytes, 1 lines download raw bytes

1import{K as _,b as O,r as o,k as h,j as e,B as p,aK as b,aL as C,cr as Q,aC as M,aD as S,aE as F,aF as H,aG as L,aH as P,aI as k,aJ as K,U as c}from"./main-To_L_1y0.js";import{u as N}from"./useMutation-B7FocJ-g.js";import{C as T,a as q,b as z,c as I,d as B}from"./card-C3vrXP0B.js";import{b as G}from"./responsive-dialog-DmvfOf_v.js";import{d as $,a as J,H as U,R as V,b as W,f as X,c as Y,s as Z,m as ee,e as x,g as se,h as ae}from"./rates-history-dialog-BECRB8TR.js";import{U as te}from"./users-D4X-iSzw.js";import{P as re}from"./plus-Dmm6tEsW.js";import"./input-DYzx90jl.js";import"./label-DhPWvjid.js";import"./trash-2-ts-U4SRs.js";function ye(){const s=_(),{can:r}=O(),R=r("default-rates:create"),w=r("default-rates:sync"),[A,d]=o.useState(!1),[f,y]=o.useState(!1),[g,u]=o.useState(!1),t=h(ae()),l=h({...$(),enabled:f}),i=h({...J(),enabled:g}),v=N({mutationFn:a=>se(a),onSuccess:async()=>{await s.invalidateQueries({queryKey:x.active}),await s.invalidateQueries({queryKey:x.history}),c.success("Default rates updated"),d(!1)},onError:a=>{c.error("Failed to update default rates",{description:a.message})}}),n=N({mutationFn:Z,onSuccess:async a=>{u(!1),c.success(a===0?"Every merchant already has all default rates":`Applied missing default rates to ${a} merchant${a===1?"":"s"}`),await s.invalidateQueries({queryKey:ee.all}),await s.invalidateQueries({queryKey:x.missingOnMerchants})},onError:a=>{c.error("Failed to apply default rates to merchants",{description:a.message})}}),j=o.useMemo(()=>D(t.data),[t.data]),m=i.data?.merchants??[],E=!i.isPending&&!i.isError&&m.length>0&&!n.isPending;return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight truncate sm:text-3xl",children:"Default Rates"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Global pricing templates applied to new merchants."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>y(!0),children:[e.jsx(U,{className:"mr-1.5 h-4 w-4"}),"History"]}),w?e.jsxs(p,{variant:"outline",size:"sm",onClick:()=>u(!0),disabled:t.isLoading||!t.data,children:[e.jsx(te,{className:"mr-1.5 h-4 w-4"}),"Apply to merchants"]}):null,R?e.jsxs(p,{size:"sm",onClick:()=>d(!0),disabled:t.isLoading,children:[e.jsx(re,{className:"mr-1.5 h-4 w-4"}),"New version"]}):null]})]})}),e.jsxs(T,{children:[e.jsxs(q,{children:[e.jsx(z,{children:"Active default rates"}),e.jsx(I,{children:"Only one default rates version is active at a time."})]}),e.jsx(B,{children:t.isLoading?e.jsx(b,{title:"Loading default rates…"}):t.isError?e.jsx(C,{title:"Failed to load default rates",error:t.error,onRetry:()=>t.refetch()}):t.data?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-sm text-muted-foreground",children:[e.jsx("span",{children:"Active version"}),e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-xs text-foreground",children:t.data.version}),t.data.created_by?e.jsxs("span",{children:["created by ",t.data.created_by]}):null,e.jsx("span",{children:Q(t.data.created_at)})]}),e.jsx(V,{rates:j})]}):e.jsx("div",{className:"text-sm text-muted-foreground",children:"No default rates configured."})})]}),e.jsx(W,{open:A,onOpenChange:d,title:"Create default rates version",description:"This creates a new active version of default rates.",initialRates:j,onSave:async a=>{await v.mutateAsync(a.map(ie))},isSaving:v.isPending}),e.jsx(M,{open:g,onOpenChange:a=>{!a&&!n.isPending&&u(!1)},children:e.jsxs(S,{children:[e.jsxs(F,{children:[e.jsx(H,{children:"Apply default rates to merchants"}),e.jsx(L,{children:"Merchants missing any of the active default rates get a new rate version that adds them."})]}),e.jsx("div",{className:"mt-2 space-y-3 text-sm text-muted-foreground",children:i.isPending?e.jsx(b,{title:"Loading merchants…"}):i.isError?e.jsx(C,{title:"Failed to load the merchants missing default rates",error:i.error,onRetry:()=>i.refetch()}):m.length===0?e.jsx("p",{children:"Every merchant already has all active default rates."}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:["Each merchant below gets a new rate version adding the default rates it lacks,"," ",e.jsx("strong",{className:"text-foreground",children:"including defaults removed from that merchant on purpose"}),". Rates it already has, including custom values, are copied unchanged."]}),e.jsx("div",{role:"region",tabIndex:0,"aria-label":"Merchants that will receive new rates",className:"max-h-56 overflow-y-auto rounded-md border",children:e.jsx("ul",{className:"divide-y",children:m.map(a=>e.jsxs("li",{className:"px-3 py-2",children:[e.jsx("div",{className:"font-medium text-foreground",children:a.brand_name}),e.jsx("div",{className:"mt-0.5 text-xs",children:a.rates_to_add.map(X).join(", ")})]},a.merchant_id))})})]})}),e.jsxs(P,{className:G,children:[e.jsx(k,{disabled:n.isPending,children:"Cancel"}),e.jsx(K,{disabled:!E,onClick:a=>{a.preventDefault(),n.mutate()},children:n.isPending?"Applying…":"Apply"})]})]})}),e.jsx(Y,{open:f,onOpenChange:y,title:"Default rates history",description:"All versions for default rates.",history:(l.data??[]).map(ne),isLoading:l.isLoading,error:l.isError?l.error?.message:null})]})}function D(s){return s?.rates?s.rates.map(r=>({id:r.id,type:r.type,value:r.value,unit:r.unit,base:r.base,conversion_currencies:r.conversion_currencies,notes:r.notes??void 0})):[]}function ie(s){return{type:s.type,value:s.value,unit:s.unit,base:s.base,conversion_currencies:s.
1conversion_currencies,notes:s.notes}}function ne(s){return{id:s.id,version:s.version,is_active:s.is_active,created_by:s.created_by,created_at:s.created_at,rates:D(s)}}export{ye as component};

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.