PageSourceSearch

https://tailormyjob.com/_next/static/chunks/pages/admin/promo-da57301a8319cece.js

js tailormyjob.com collected 2026-10-02 01:46:57 UTC 17,524 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7997],{26259:(e,a,t)=>{"use strict";t.d(a,{A:()=>c});var r=t(37876),s=t(14232),l=t(48230),n=t.n(l),i=t(89099),o=t(89335),d=t(41957);let c=({children:e})=>{let a=(0,i.useRouter)(),{isAuthenticated:t,isLoading:l,getAccessToken:c}=(0,o.A)(),[m,u]=(0,s.useState)(!0),[x,h]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!0);if((0,s.useEffect)(()=>{(async()=>{if(!l){if(!t)return a.replace(`/login?redirect=${encodeURIComponent(a.asPath)}`);try{let e=await c();if(!e)return void a.replace(`/login?redirect=${encodeURIComponent(a.asPath)}`);try{await (0,d.AT)("/admin/stats",{token:e}),h(!0)}catch(e){if(403===e.statusCode)a.replace("/");else if(e.statusCode)a.replace(`/login?redirect=${encodeURIComponent(a.asPath)}`);else throw e}}catch(e){console.error("[AdminLayout] Admin verification failed:",e.message,e),a.replace("/")}finally{g(!1)}}})()},[l,t,a,c]),l||p||!x)return(0,r.jsx)("div",{className:"min-h-screen bg-gray-100 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"}),(0,r.jsx)("p",{className:"text-gray-600",children:"Verifying access..."})]})});let b=[{href:"/admin",label:"Dashboard",icon:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"},{href:"/admin/users",label:"Users",icon:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13-6a4 4 0 11-8 0 4 4 0 018 0z"},{href:"/admin/analytics",label:"Analytics",icon:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"},{href:"/admin/revenue",label:"Revenue",icon:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"},{href:"/admin/ai-monitor",label:"AI Monitor",icon:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"},{href:"/admin/promo",label:"Promo Codes",icon:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"},{href:"/admin/email-marketing",label:"Email Marketing",icon:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"},{href:"/admin/social-queue",label:"Social Queue",icon:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"},{href:"/admin/feedback",label:"Feedback",icon:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"},{href:"/admin/system",label:"System Health",icon:"M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01"},{href:"/admin/content",label:"Content",icon:"M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z"},{href:"/admin/waitlist",label:"Waitlist",icon:"M18 9v3m0 0v3m0-3h3m-3 0h-3m-2-5a4 4 0 11-8 0 4 4 0 018 0zM3 20a6 6 0 0112 0v1H3v-1z"}],f=e=>"/admin"===e?"/admin"===a.pathname:a.pathname.startsWith(e);return(0,r.jsxs)("div",{className:"min-h-screen bg-gray-100",children:[(0,r.jsxs)("aside",{className:`fixed inset-y-0 left-0 z-50 w-64 bg-gray-900 transform ${m?"translate-x-0":"-translate-x-full"} transition-transform duration-300 ease-in-out lg:translate-x-0`,children:[(0,r.jsxs)("div",{className:"flex items-center justify-between h-16 px-4 bg-gray-800",children:[(0,r.jsx)(n(),{href:"/admin",className:"text-xl font-bold text-white",children:"Admin Dashboard"}),(0,r.jsx)("button",{onClick:()=>u(!1),className:"lg:hidden text-gray-400 hover:text-white",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,r.jsx)("nav",{className:"mt-8 px-4",children:b.map(e=>(0,r.jsxs)(n(),{href:e.href,className:`flex items-center px-4 py-3 mb-2 rounded-lg transition-colors ${f(e.href)?"bg-blue-600 text-white":"text-gray-400 hover:bg-gray-800 hover:text-white"}`,children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:e.icon})}),e.label]},e.href))}),(0,r.jsx)("div",{className:"absolute bottom-0 left-0 right-0 p-4",children:(0,r.jsxs)(n(),{href:"/",className:"flex items-center px-4 py-3 text-gray-400 hover:bg-gray-800 hover:text-white rounded-lg transition-colors",children:[(0,r.jsx)("svg",{className:"w-5 h-5 mr-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 17l-5-5m0 0l5-5m-5 5h12"})}),"Back to App"]})})]}),(0,r.jsxs)("div",{className:"lg:ml-64 min-h-screen",children:[(0,r.jsxs)("header",{className:"bg-white shadow-sm h-16 flex items-center px-4 lg:px-8",children:[(0,r.jsx)("button",{onClick:()=>u(!0),className:"lg:hidden text-gray-600 hover:text-gray-900",children:(0,r.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}),(0,r.jsx)("h1",{className:"ml-4 lg:ml-0 text-xl font-semibold text-gray-800",children:b.find(e=>f(e.href))?.label||"Admin"})]}),(0,r.jsx)("main",{className:"p-4 lg:p-8",children:e})]}),m&&(0,r.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-40 lg:hidden",onClick:()=>u(!1)})]})}},52655:(e,a,t)=>{"use strict";t.r(a),t.d(a,{default:()=>d});var r=t(37876),s=t(14232),l=t(26259),n=t(79966);let i=[{value:"free",label:"100% Free"},{value:"percentage",label:"Percentage Off"},{value:"fixed_amount",label:"Fixed Amount Off"}],o=({isOpen:e,onClose:a,onSubmit:t,initialData:l,isLoading:n})=>
1{let[o,d]=(0,s.useState)({code:"",discount_type:"percentage",discount_value:0,currency:"USD",applicable_plans:["all"],max_redemptions:0,valid_from:"",valid_until:""});(0,s.useEffect)(()=>{l?d({code:l.code||"",discount_type:l.discount_type||"percentage",discount_value:l.discount_value||0,currency:l.currency||"USD",applicable_plans:l.applicable_plans||["all"],max_redemptions:l.max_redemptions||0,valid_from:l.valid_from?l.valid_from.slice(0,16):"",valid_until:l.valid_until?l.valid_until.slice(0,16):""}):d({code:"",discount_type:"percentage",discount_value:0,currency:"USD",applicable_plans:["all"],max_redemptions:0,valid_from:"",valid_until:""})},[l,e]);let c=e=>{let{name:a,value:t,type:r}=e.target;d(e=>({...e,[a]:"number"===r?Number(t):t}))};return e?(0,r.jsxs)("div",{className:"fixed inset-0 z-50 overflow-y-auto",children:[(0,r.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50",onClick:a}),(0,r.jsx)("div",{className:"flex min-h-full items-center justify-center p-4",children:(0,r.jsxs)("div",{className:"relative bg-white rounded-lg shadow-xl max-w-lg w-full p-6",children:[(0,r.jsx)("h2",{className:"text-xl font-bold text-gray-900 mb-4",children:l?"Edit Promo Code":"Create Promo Code"}),(0,r.jsxs)("form",{onSubmit:e=>{e.preventDefault();let a={...o};a.valid_from&&(a.valid_from=new Date(a.valid_from).toISOString()),a.valid_until&&(a.valid_until=new Date(a.valid_until).toISOString()),t(a)},className:"space-y-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Promo Code"}),(0,r.jsx)("input",{type:"text",name:"code",value:o.code,onChange:c,disabled:!!l,placeholder:"e.g., WELCOME20",className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100",required:!0})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Discount Type"}),(0,r.jsx)("select",{name:"discount_type",value:o.discount_type,onChange:c,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:i.map(e=>(0,r.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"percentage"===o.discount_type?"Percentage (%)":"fixed_amount"===o.discount_type?"Amount":"Value"}),(0,r.jsx)("input",{type:"number",name:"discount_value",value:o.discount_value,onChange:c,disabled:"free"===o.discount_type,min:"0",max:"percentage"===o.discount_type?100:void 0,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:bg-gray-100"})]})]}),"fixed_amount"===o.discount_type&&(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Currency"}),(0,r.jsxs)("select",{name:"currency",value:o.currency,onChange:c,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",children:[(0,r.jsx)("option",{value:"USD",children:"USD"}),(0,r.jsx)("option",{value:"TWD",children:"TWD"})]})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Applicable Plans"}),(0,r.jsx)("input",{type:"text",value:o.applicable_plans.join(", "),onChange:e=>{let a=e.target.value;if("all"===a)d(e=>({...e,applicable_plans:["all"]}));else{let e=a.split(",").map(e=>e.trim()).filter(Boolean);d(a=>({...a,applicable_plans:e}))}},placeholder:"all, or: pro, career_turbo",className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"}),(0,r.jsx)("p",{className:"text-xs text-gray-500 mt-1",children:'Enter "all" or comma-separated plan names'})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Max Redemptions (0 = unlimited)"}),(0,r.jsx)("input",{type:"number",name:"max_redemptions",value:o.max_redemptions,onChange:c,min:"0",className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),(0,r.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Valid From"}),(0,r.jsx)("input",{type:"datetime-local",name:"valid_from",value:o.valid_from,onChange:c,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]}),(0,r.jsxs)("div",{children:[(0,r.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Valid Until"}),(0,r.jsx)("input",{type:"datetime-local",name:"valid_until",value:o.valid_until,onCh
1ange:c,className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"})]})]}),(0,r.jsxs)("div",{className:"flex justify-end gap-3 pt-4",children:[(0,r.jsx)("button",{type:"button",onClick:a,className:"px-4 py-2 text-gray-700 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors",children:"Cancel"}),(0,r.jsx)("button",{type:"submit",disabled:n,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",children:n?"Saving...":l?"Update":"Create"})]})]})]})})]}):null},d=()=>{let[e,a]=(0,s.useState)([]),[t,i]=(0,s.useState)(!0),[d,c]=(0,s.useState)(null),[m,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),{get:b,post:f,put:y,del:v}=(0,n.A)(),j=async()=>{try{i(!0);let e=await b("/admin/promo");a(e.data?.promo_codes||[])}catch(e){c(e.message)}finally{i(!1)}};(0,s.useEffect)(()=>{j()},[]);let N=async e=>{try{g(!0),await f("/admin/promo",e),u(!1),j()}catch(e){alert(e.message)}finally{g(!1)}},w=async e=>{try{g(!0),await y(`/admin/promo/${x.code}`,e),u(!1),h(null),j()}catch(e){alert(e.message)}finally{g(!1)}},_=async e=>{if(confirm(`Are you sure you want to disable promo code "${e}"?`))try{await v(`/admin/promo/${e}`),j()}catch(e){alert(e.message)}};return t?(0,r.jsx)(l.A,{children:(0,r.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,r.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"})})}):d?(0,r.jsx)(l.A,{children:(0,r.jsxs)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-6 text-center",children:[(0,r.jsx)("h2",{className:"text-lg font-medium text-red-800",children:"Error"}),(0,r.jsx)("p",{className:"mt-2 text-red-600",children:d})]})}):(0,r.jsxs)(l.A,{children:[(0,r.jsxs)("div",{className:"mb-6 flex justify-between items-center",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Promo Codes"}),(0,r.jsx)("p",{className:"mt-1 text-gray-600",children:"Manage discount codes for subscriptions"})]}),(0,r.jsxs)("button",{onClick:()=>{h(null),u(!0)},className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors flex items-center gap-2",children:[(0,r.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,r.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),"Create New"]})]}),(0,r.jsx)("div",{className:"bg-white rounded-lg shadow overflow-hidden",children:(0,r.jsxs)("table",{className:"min-w-full divide-y divide-gray-200",children:[(0,r.jsx)("thead",{className:"bg-gray-50",children:(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Code"}),(0,r.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Discount"}),(0,r.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Used / Max"}),(0,r.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Valid Until"}),(0,r.jsx)("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Status"}),(0,r.jsx)("th",{className:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),(0,r.jsx)("tbody",{className:"bg-white divide-y divide-gray-200",children:0===e.length?(0,r.jsx)("tr",{children:(0,r.jsx)("td",{colSpan:6,className:"px-6 py-12 text-center text-gray-500",children:"No promo codes found. Create one to get started."})}):e.map(e=>{var a;return(0,r.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,r.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,r.jsx)("span",{className:"font-mono font-medium text-gray-900",children:e.code})}),(0,r.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:(e=>{switch(e.discount_type){case"free":return"100% Free";case"percentage":return`${e.discount_value}% Off`;case"fixed_amount":return`${"USD"===e.currency?"$":"NT$"}${e.discount_value} Off`;default:return"-"}})(e)}),(0,r.jsxs)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:[e.redemption_count||0," / ",e.max_redemptions>0?e.max_redemptions:"∞"]}),(0,r.jsx)("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-600",children:(a=e.valid_until)?new Date(a).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"-"}),(0,r.jsx)("td",{className:"px-6 py-4 whitespace-nowrap",children:(0,r.jsx)("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${"active"===e.status?"bg-green-100 text-green-800":"bg-gray-100 text-gray-600"}`,children:e.status||"active"})}),(0,r.jsxs)("td",{className:"px-6 py-4 whitespace-nowrap text-right text-sm",children:[(0,r.jsx)("button",{onClick:()=>{h(e),u(!0)},className:"text-blue-600 hover:text-blue-800 mr-3",children:"Edit"}),"active"===e.status&&(0,r.jsx)("button",{onClick:()=>_(e.code),className:"text-red-600 hover:text-red-800",children:"Disable"})]})]},e.code)})})]})}),(0,r.jsx)(o,{isOpen:m,onClose:()=>{u(!1),h(null)},onSubmit:x?w:N,initialData:x,isLoading:p})]})}},71506:(e,a,t)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/promo",function(){return t(52655)}])},79966:(e,a,t)=>{"use strict";t.d(a,{A:()=>i});var r=t(14232),s=t(89099),l=t(89335),n=t(41957);let i=()=>{let e=(0,s.useRouter)(),{getAccessToken:a}=(0,l.A)(),t=(0,r.useCallback)(async(t,r={})=>{let s=()=>e.replace(`/login?redirect=${encodeURIComponent(e.asPath)}`),l=await a();if(!l)throw s(),Error("No authentication token available");try{return await (0,n.AT)(t,{...r,token:l,unwrap:!1})}catch(e){if(401===e.statusCode)throw s(),Error("Session expired. Please log in again.");if(403===e.statusCode)throw Error("Admin access required");throw e}},[a,e]),i=(0,r.useCallback)(e=>t(e),[t]),o=(0,r.useCallback)((e,a)=>t(e,{method:"POST",body:a}),[t]);return{get:i,post:o,put:(0,r.useCallback)((e,a)=>t(e,{method:"PUT",body:a}),[t]),del:(0,r.useCallback)(e=>t(e,{method:"DELETE"}),[t]),request:t}}}},e=>{e.O(0,[8230,636,6593,8792],()=>e(e.s=71506)),_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.