PageSourceSearch

https://vault22.com/_next/static/chunks/pages/admin/merchants-c7d276d0ec242698.js

js vault22.com collected 2026-09-24 13:41:06 UTC 11,484 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8507],{37347:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>c});var a=s(37876),r=s(14232),d=s(37497),l=s(53403);function n(e){if(!e)return"—";try{return new Date(e).toLocaleDateString()}catch(t){return e}}function i(e){let{id:t,name:s}=e,[d,l]=(0,r.useState)(!1);return d?(0,a.jsx)("div",{className:"w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center text-xs font-medium text-gray-500",title:"No logo for ".concat(s||"merchant"),children:(s||"?").slice(0,2).toUpperCase()}):(0,a.jsx)("img",{src:"".concat("https://d178lv7sexce98.cloudfront.net/merchants","/").concat(t,".png"),alt:s||"merchant",className:"w-8 h-8 rounded-full object-cover bg-white border border-gray-200",onError:()=>l(!0),loading:"lazy"})}function c(){let[e,t]=(0,r.useState)([]),[s,c]=(0,r.useState)(!0),[m,o]=(0,r.useState)(null),[x,u]=(0,r.useState)(""),[h,p]=(0,r.useState)("all"),[g,y]=(0,r.useState)(null),[b,f]=(0,r.useState)(!1),[j,N]=(0,r.useState)(""),[v,w]=(0,r.useState)(!1),[C,k]=(0,r.useState)(!1),[S,A]=(0,r.useState)(null),[_,D]=(0,r.useState)(null),[M,E]=(0,r.useState)(!1),[F,L]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(!F)return;let e=setTimeout(()=>L(null),4e3);return()=>clearTimeout(e)},[F]);let T=async()=>{try{c(!0),o(null);let e=await l.KD.listMerchantsAdmin();e.success&&Array.isArray(e.data)?t(e.data):(t([]),o(e.error||"Failed to load merchants"))}catch(e){o((null==e?void 0:e.message)||"Failed to load merchants"),t([])}finally{c(!1)}};(0,r.useEffect)(()=>{T()},[]);let z=(0,r.useMemo)(()=>{let t=e;if("all"!==h&&(t=t.filter(e=>"custom"===h?e.isCustom:!e.isCustom)),x.trim()){let e=x.trim().toLowerCase();t=t.filter(t=>(t.name||"").toLowerCase().includes(e))}return t},[e,x,h]),K=()=>{y(null),f(!1),A(null)},U=async()=>{try{let e;if(k(!0),A(null),!j.trim()){A("Name is required"),k(!1);return}if(b)e=await l.KD.createMerchantAdmin({name:j.trim(),isCustom:v});else{if(!g)return void k(!1);e=await l.KD.updateMerchantAdmin(g.id,{name:j.trim(),isCustom:v})}e.success?(L({type:"success",text:b?"Merchant '".concat(j,"' created"):"Merchant '".concat(j,"' updated")}),K(),await T()):A(e.error||"Failed to save")}catch(e){A((null==e?void 0:e.message)||"Failed to save")}finally{k(!1)}},B=async()=>{if(_)try{E(!0);let e=await l.KD.deleteMerchantAdmin(_.id);e.success?(L({type:"success",text:"Merchant '".concat(_.name,"' deleted")}),D(null),await T()):L({type:"error",text:e.error||"Failed to delete"})}catch(e){L({type:"error",text:(null==e?void 0:e.message)||"Failed to delete"})}finally{E(!1)}};return(0,a.jsxs)(d.A,{children:[(0,a.jsxs)("div",{className:"space-y-6",children:[(0,a.jsxs)("div",{className:"flex flex-wrap justify-between items-start gap-2",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h2",{className:"text-2xl font-bold text-gray-900","data-testid":"merchants-title",children:"Merchants"}),(0,a.jsx)("p",{className:"mt-1 text-sm text-gray-500",children:"Merchant catalog used by transaction enrichment. Add new merchants here so they appear with canonical names in the customer app."})]}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("button",{onClick:()=>{f(!0),y(null),N(""),w(!1),A(null)},className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700","data-testid":"merchants-add",children:"+ Add Merchant"}),(0,a.jsx)("button",{onClick:T,disabled:s,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50","data-testid":"merchants-refresh",children:s?"Loading…":"Refresh"})]})]}),(0,a.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,a.jsx)("input",{value:x,onChange:e=>u(e.target.value),placeholder:"Filter by name…",className:"form-input flex-1 max-w-sm px-3 py-2 border border-gray-300 rounded-md text-sm focus:ring-2 focus:ring-blue-500","data-testid":"merchants-search"}),(0,a.jsx)("div",{className:"flex items-center gap-1 bg-gray-100 p-1 rounded-lg",children:["all","custom","system"].map(e=>(0,a.jsx)("button",{onClick:()=>p(e),className:"px-3 py-1.5 text-xs font-medium rounded-md transition-colors ".concat(h===e?"bg-white text-gray-900 shadow-sm":"text-gray-600 hover:text-gray-900"),"data-testid":"merchants-filter-".concat(e),children:"all"===e?"All":"custom"===e?"Custom"
1:"System"},e))}),(0,a.jsxs)("span",{className:"text-xs text-gray-500","data-testid":"merchants-count",children:[z.length," of ",e.length]})]}),m&&(0,a.jsx)("div",{className:"bg-red-50 border border-red-200 text-red-700 rounded-md px-4 py-3 text-sm","data-testid":"merchants-error",children:m}),s&&(0,a.jsx)("div",{className:"flex justify-center py-12",children:(0,a.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500"})}),!s&&(0,a.jsxs)("div",{className:"bg-white shadow rounded-lg overflow-hidden","data-testid":"merchants-table",children:[(0,a.jsxs)("table",{className:"min-w-full divide-y divide-gray-200",children:[(0,a.jsx)("thead",{className:"bg-gray-50",children:(0,a.jsxs)("tr",{children:[(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase w-12",children:"Logo"}),(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Name"}),(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Type"}),(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Created"}),(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Updated"}),(0,a.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase",children:"Last edited by"}),(0,a.jsx)("th",{className:"px-4 py-2 text-right text-xs font-medium text-gray-500 uppercase",children:"Actions"})]})}),(0,a.jsxs)("tbody",{className:"bg-white divide-y divide-gray-100",children:[0===z.length&&(0,a.jsx)("tr",{children:(0,a.jsx)("td",{colSpan:7,className:"px-4 py-6 text-center text-sm text-gray-500",children:"No merchants match your filter"})}),z.slice(0,500).map(e=>(0,a.jsxs)("tr",{className:"hover:bg-gray-50","data-testid":"merchants-row-".concat(e.name),children:[(0,a.jsx)("td",{className:"px-4 py-2",children:(0,a.jsx)(i,{id:e.id,name:e.name})}),(0,a.jsx)("td",{className:"px-4 py-2 text-sm font-medium text-gray-900",children:e.name||"—"}),(0,a.jsx)("td",{className:"px-4 py-2 text-xs",children:(0,a.jsx)("span",{className:"px-2 py-0.5 rounded-full ".concat(e.isCustom?"bg-purple-100 text-purple-700":"bg-gray-100 text-gray-600"),children:e.isCustom?"Custom":"System"})}),(0,a.jsx)("td",{className:"px-4 py-2 text-xs text-gray-500",children:n(e.createdAt)}),(0,a.jsx)("td",{className:"px-4 py-2 text-xs text-gray-500",children:n(e.lastUpdatedDate)}),(0,a.jsx)("td",{className:"px-4 py-2 text-xs text-gray-500",children:e.updatedBy||e.createdBy||"—"}),(0,a.jsxs)("td",{className:"px-4 py-2 text-right space-x-2",children:[(0,a.jsx)("button",{onClick:()=>{y(e),f(!1),N(e.name||""),w(e.isCustom),A(null)},className:"px-2 py-1 text-xs font-medium text-blue-700 bg-blue-50 rounded-md hover:bg-blue-100","data-testid":"merchants-edit-".concat(e.name),children:"Edit"}),(0,a.jsx)("button",{onClick:()=>D(e),className:"px-2 py-1 text-xs font-medium text-red-700 bg-red-50 rounded-md hover:bg-red-100","data-testid":"merchants-delete-".concat(e.name),children:"Delete"})]})]},e.id))]})]}),z.length>500&&(0,a.jsxs)("p",{className:"px-4 py-2 text-xs text-gray-500 bg-gray-50",children:["Showing first 500 of ",z.length," matches — refine the filter to see more."]})]})]}),(b||g)&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 overflow-y-auto","data-testid":"merchants-edit-modal",children:(0,a.jsxs)("div",{className:"flex min-h-full items-start justify-center p-4",children:[(0,a.jsx)("div",{className:"fixed inset-0 bg-gray-900/60 backdrop-blur-sm",onClick:C?void 0:K}),(0,a.jsxs)("div",{className:"relative bg-white rounded-lg shadow-xl max-w-md w-full mt-16 p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-3",children:b?"Add merchant":"Edit ".concat(null==g?void 0:g.name)}),S&&(0,a.jsx)("div",{className:"bg-red-50 border border-red-200 text-red-700 rounded-md px-4 py-2 text-sm mb-3",children:S}),(0,a.jsxs)("div",{className:"space-y-3",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:["Name ",(0,a.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,a.jsx)("input",{value:j,onChange:e=>N(e.target.value),className:"form-input w-full px-3 py-2 border border-gray-300 rounded-md text-sm","data-testid":"merchants-edit-name",autoFocus:!0})]}),(0,a.jsxs)("label",{className:"inline-flex items-center gap-2 cursor-pointer",children:[(0,a.jsx)("input",{type:"checkbox",checked:v,onChange:e=>w(e.target.checked),className:"form-checkbox h-4 w-4 text-blue-600 rounded","data-testid":"merchants-edit-is-custom"}),(0,a.jsx)("span",{className:"text-sm text-gray-800",children:"Custom merchant (added by customer, not in system catalog)"})]})]}),(0,a.jsxs)("div",{className:"mt-5 flex justify-end gap-3 border-t pt-4",children:[(0,a.jsx)("button",{onClick:K,disabled:C,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:"Cancel"}),(0,a.jsx)("button",{onClick:U,disabled:C||!j.trim(),className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed","data-testid":"merchants-edit-save",children:C?"Saving…":b?"Create merchant":"Save changes"})]})]})]})}),_&&(0,a.jsx)("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:(0,a.jsxs)("div",{className:"flex min-h-full items-start justify-center p-4",children:[(0,a.jsx)("div",{className:"fixed inset-0 bg-gray-900/60 backdrop-blur-sm",onClick:M?void 0:()=>D(null)}),(0,a.jsxs)("div",{className:"relative bg-white rounded-lg shadow-xl max-w-md w-full mt-32 p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-gray-900",children:"Delete merchant?"}),(0,a.jsxs)("p",{className:"text-sm text-gray-500 mt-2",children:[(0,a.jsx)("span",{className:"font-medium",children:_.name})," will be soft-deleted (preserved as historical record). Transactions linked to this merchant will keep working but no new auto-categorisation will surface it."]}),(0,a.jsxs)("div",{className:"mt-5 flex justify-end gap-3",children:[(0,a.jsx)("button",{onClick:()=>D(null),disabled:M,className:"px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50",children:"Cancel"}),(0,a.jsx)("button",{onClick:B,disabled:M,className:"px-4 py-2 text-sm font-medium text-white bg-red-600 rounded-md hover:bg-red-700 disabled:opacity-50","data-testid":"merchants-delete-confirm",children:M?"Deleting…":"Delete"})]})]})]})}),F&&(0,a.jsx)("div",{className:"fixed top-4 right-4 z-[60] flex items-center gap-3 rounded-md px-4 py-3 shadow-lg border ".concat("success"===F.type?"bg-green-50 border-green-200 text-green-800":"bg-red-50 border-red-200 text-red-800"),children:(0,a.jsx)("span",{className:"text-sm font-medium",children:F.text})})]})}},67856:(e,t,s)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/merchants",function(){return s(37347)}])}},e=>{e.O(0,[7497,636,6593,8792],()=>e(e.s=67856)),_N_E=e.O()}]);

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.