/
opt
/
canhelp
/
apps
/
web
/
.next
/
static
/
chunks
/
app
/
schedule
/
/opt/canhelp/apps/web/.next/static/chunks/app/schedule
mkdir
upload
Name
Size
Mode
Actions
page-cc1e3b236017366f.js
13367
0644
edit
dl
rm
Edit:
/opt/canhelp/apps/web/.next/static/chunks/app/schedule/page-cc1e3b236017366f.js
(13367B)
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7826],{1592:(e,t,r)=>{"use strict";r.d(t,{CI:()=>a,Hh:()=>n,Jv:()=>s,wV:()=>c,yK:()=>l});let l=(0,r(6504).M)({baseURL:"https://api.canhelp.gr"}),{signIn:s,signOut:a,signUp:n,useSession:c}=l},2861:(e,t,r)=>{Promise.resolve().then(r.bind(r,9807))},9807:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>h});var l=r(4568),s=r(7620),a=r(7541),n=r(1592),c=r(9906),i=r(2982);let d={available:"busy",busy:null},o={ru:["Пн","Вт","Ср","Чт","Пт","Сб","Вс"],en:["Mo","Tu","We","Th","Fr","Sa","Su"],el:["Δε","Τρ","Τε","Πε","Πα","Σά","Κυ"]},x={ru:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],en:["January","February","March","April","May","June","July","August","September","October","November","December"],el:["Ιανουάριος","Φεβρουάριος","Μάρτιος","Απρίλιος","Μάιος","Ιούνιος","Ιούλιος","Αύγουστος","Σεπτέμβριος","Οκτώβριος","Νοέμβριος","Δεκέμβριος"]};function u(e,t,r){return"".concat(e,"-").concat(String(t+1).padStart(2,"0"),"-").concat(String(r).padStart(2,"0"))}function h(){var e;let{data:t,isPending:r}=(0,n.wV)(),o=(0,a.useRouter)(),x=(0,a.useSearchParams)(),{locale:u,t:h}=(0,c.Y)(),g=new Date,[b,f]=(0,s.useState)(g.getFullYear()),[y,p]=(0,s.useState)(g.getMonth()),[v,j]=(0,s.useState)({}),[w,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(null),[D,k]=(0,s.useState)(!1),[E,M]=(0,s.useState)("available"),[_,F]=(0,s.useState)(null),[K,z]=(0,s.useState)(!1),[O,T]=(0,s.useState)(null),B=new Date().toISOString().slice(0,10);(0,s.useEffect)(()=>{var e,l;r||t||o.push("/login"),!r&&t&&(null==(e=t.user)?void 0:e.role)!=="specialist"&&(null==(l=t.user)?void 0:l.role)!=="admin"&&o.push("/profile")},[t,r]);let L=(0,s.useCallback)(()=>{(0,i.Em)("/google/calendar/status").then(F).catch(()=>F({connected:!1}))},[]);(0,s.useEffect)(()=>{if(!t)return;L();let e=x.get("gcal");"connected"===e?(T(h("schedule.gcalConnected")),setTimeout(()=>T(null),5e3),o.replace("/schedule")):"error"===e&&(T(h("schedule.gcalError")),setTimeout(()=>T(null),5e3),o.replace("/schedule"))},[t]);let A=(0,s.useCallback)((e,t)=>{let r="".concat(e,"-").concat(String(t+1).padStart(2,"0"));(0,i.iN)(r).then(e=>{j(t=>{let r={...t};return e.forEach(e=>{r[e.date]=e.status}),r})}).catch(()=>{})},[]);async function H(e){var t;if(e<B)return;if(D){if(!C)return void S(e);let t=C<e?C:e,r=C<e?e:C;S(null),N("range");try{await (0,i.D1)(t,r,E),j(e=>{let l={...e},s=new Date(t),a=new Date(r);for(;s<=a;){let e=s.toISOString().slice(0,10);e>=B&&(l[e]=E),s.setDate(s.getDate()+1)}return l})}catch(e){}return void N(null)}let r=null!=(t=v[e])?t:null,l=null===r?"available":d[r];N(e),j(t=>({...t,[e]:l}));try{await (0,i.OM)(e,l)}catch(t){j(t=>({...t,[e]:r}))}N(null)}if((0,s.useEffect)(()=>{if(!t)return;A(b,y);let e=new Date(b,y+1,1);A(e.getFullYear(),e.getMonth())},[t,b,y,A]),r)return(0,l.jsx)("div",{className:"text-center py-20 text-gray-500",children:h("common.loading")});let I=null==t||null==(e=t.user)?void 0:e.role;if(!t||"specialist"!==I&&"admin"!==I)return null;async function J(){window.location.href="".concat("https://api.canhelp.gr","/api/google/calendar/connect")}async function P(){if(confirm(h("schedule.gcalDisconnectConfirm"))){z(!0);try{await (0,i.Em)("/google/calendar/disconnect",{method:"DELETE"}),F({connected:!1})}catch(e){}z(!1)}}async function W(){z(!0);try{var e;let t=await (0,i.Em)("/google/calendar/import",{method:"POST"});T(h("schedule.gcalImportDone").replace("{n}",String(null!=(e=t.imported)?e:0))),setTimeout(()=>T(null),5e3),A(b,y)}catch(e){}z(!1)}return(0,l.jsxs)("div",{className:"max-w-3xl mx-auto px-4 py-10",children:[O&&(0,l.jsx)("div",{className:"fixed top-4 right-4 z-50 bg-white border border-gray-200 shadow-lg rounded-xl px-4 py-3 text-sm text-gray-800 max-w-xs",children:O}),(0,l.jsxs)("div",{className:"mb-8",children:[(0,l.jsx)("h1",{className:"text-2xl font-bold text-white",children:h("schedule.title")}),(0,l.jsx)("p",{className:"text-sm text-white/70 mt-1",children:h("schedule.subtitle")})]}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-4 mb-6",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm text-white/80",children:[(0,l.jsx)("span",{className:"w-6 h-6 rounded-lg bg-emerald-100 border-2 border-emerald-400 flex items-center justify-center text-xs",children:"✓"}),h("schedule.available")]}),(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm text-white/80",children:[(0,l.jsx)("span",{className:"w-6 h-6 rounded-lg bg-red-100 border-2 border-red-400 flex items-center justify-center text-xs",children:"✗"}),h("schedule.busy")]}),(0,l.jsxs)("div",{className:"flex items-center gap-2 text-sm text-white/80",children:[(0,l.jsx)("span",{className:"w-6 h-6 rounded-lg bg-white/20 border border-white/30"}),h("schedule.unset")]}),(0,l.jsx)("div",{className:"text-xs text-white/50 self-center",children:h("schedule.click_hint")})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 mb-6 p-3 bg-white rounded-xl border border-gray-200",children:[(0,l.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,l.jsx)("div",{onClick:()=>{k(e=>!e),S(null)},className:"w-10 h-6 rounded-full transition-colors relative cursor-pointer ".concat(D?"bg-green-500":"bg-gray-200"),children:(0,l.jsx)("span",{className:"absolute top-1 w-4 h-4 bg-white rounded-full shadow transition-transform ".concat(D?"translate-x-5":"translate-x-1")})}),(0,l.jsx)("span",{className:"text-sm font-medium text-gray-700",children:h("schedule.range_mode")})]}),D&&(0,l.jsxs)("div",{className:"flex items-center gap-2 ml-4",children:[(0,l.jsx)("button",{onClick:()=>M("available"),className:"px-3 py-1 rounded-lg text-sm font-medium border transition ".concat("available"===E?"bg-emerald-100 border-emerald-400 text-emerald-700":"bg-white border-gray-200 text-gray-500"),children:h("schedule.available")}),(0,l.jsx)("button",{onClick:()=>M("busy"),className:"px-3 py-1 rounded-lg text-sm font-medium border transition ".concat("busy"===E?"bg-red-100 border-red-400 text-red-700":"bg-white border-gray-200 text-gray-500"),children:h("schedule.busy")}),C&&(0,l.jsx)("span",{className:"text-xs text-green-600",children:h("schedule.range_from").replace("{date}",C)})]})]}),(0,l.jsx)(m,{year:b,month:y,avail:v,saving:w,rangeStart:C,today:B,onToggle:H,onPrev:function(){0===y?(f(e=>e-1),p(11)):p(e=>e-1)},onNext:function(){11===y?(f(e=>e+1),p(0)):p(e=>e+1)}}),(0,l.jsxs)("div",{className:"mt-6 bg-white rounded-2xl border border-gray-200 p-5 shadow-sm",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,l.jsxs)("svg",{width:"22",height:"22",viewBox:"0 0 48 48",fill:"none",children:[(0,l.jsx)("rect",{width:"48",height:"48",rx:"8",fill:"#fff"}),(0,l.jsx)("path",{d:"M34 14H14a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h20a2 2 0 0 0 2-2V16a2 2 0 0 0-2-2z",fill:"#4285F4"}),(0,l.jsx)("path",{d:"M28 20h-8v2h8v-2zm0 4h-8v2h8v-2zm-2 4h-6v2h6v-2z",fill:"#fff"}),(0,l.jsx)("circle",{cx:"18",cy:"18",r:"2",fill:"#DB4437"}),(0,l.jsx)("circle",{cx:"30",cy:"18",r:"2",fill:"#DB4437"}),(0,l.jsx)("rect",{x:"17",y:"12",width:"2",height:"6",rx:"1",fill:"#DB4437"}),(0,l.jsx)("rect",{x:"29",y:"12",width:"2",height:"6",rx:"1",fill:"#DB4437"})]}),(0,l.jsx)("h3",{className:"font-semibold text-gray-900 text-sm",children:h("schedule.googleCalendar")})]}),null===_?(0,l.jsx)("div",{className:"text-xs text-gray-400",children:h("common.loading")}):_.connected?(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[(0,l.jsx)("circle",{cx:"8",cy:"8",r:"8",fill:"#22c55e"}),(0,l.jsx)("path",{d:"M5 8l2 2 4-4",stroke:"#fff",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),(0,l.jsxs)("span",{className:"text-sm text-gray-700",children:[h("schedule.connectedAs")," ",(0,l.jsx)("span",{className:"font-medium",children:_.email})]})]}),(0,l.jsx)("p",{className:"text-xs text-gray-400",children:h("schedule.gcalAutoSyncNote")}),(0,l.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,l.jsx)("button",{onClick:W,disabled:K,className:"px-3 py-1.5 rounded-lg border border-green-200 bg-green-50 text-green-700 text-xs font-medium hover:bg-green-100 disabled:opacity-50 transition",children:K?h("common.loading"):h("schedule.importFromGoogle")}),(0,l.jsx)("button",{onClick:P,disabled:K,className:"px-3 py-1.5 rounded-lg border border-gray-200 bg-white text-gray-500 text-xs font-medium hover:bg-gray-50 disabled:opacity-50 transition",children:h("schedule.disconnectGoogle")})]})]}):(0,l.jsxs)("div",{className:"space-y-3",children:[(0,l.jsx)("p",{className:"text-xs text-gray-500",children:h("schedule.gcalConnectDesc")}),(0,l.jsxs)("button",{onClick:J,className:"flex items-center gap-2 px-4 py-2 rounded-xl border border-gray-200 bg-white hover:bg-gray-50 transition text-sm font-medium text-gray-700",children:[(0,l.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 48 48",fill:"none",children:[(0,l.jsx)("path",{d:"M44.5 20H24v8.5h11.8C34.7 33.9 30.1 37 24 37c-7.2 0-13-5.8-13-13s5.8-13 13-13c3.1 0 5.9 1.1 8.1 2.9l6.4-6.4C34.6 4.1 29.6 2 24 2 11.8 2 2 11.8 2 24s9.8 22 22 22c11 0 21-8 21-22 0-1.3-.2-2.7-.5-4z",fill:"#FFC107"}),(0,l.jsx)("path",{d:"M6.3 14.7l7 5.1C15 16.1 19.1 13 24 13c3.1 0 5.9 1.1 8.1 2.9l6.4-6.4C34.6 4.1 29.6 2 24 2 16.3 2 9.7 7.4 6.3 14.7z",fill:"#FF3D00"}),(0,l.jsx)("path",{d:"M24 46c5.5 0 10.5-1.9 14.4-5.1l-6.7-5.5C29.5 37 26.9 38 24 38c-6.1 0-11.2-4-13-9.5l-7 5.4C7.6 41.9 15.2 46 24 46z",fill:"#4CAF50"}),(0,l.jsx)("path",{d:"M44.5 20H24v8.5h11.8c-.9 2.8-2.8 5.1-5.3 6.6l6.7 5.5C41.5 37.3 45 31.1 45 24c0-1.3-.2-2.7-.5-4z",fill:"#1976D2"})]}),h("schedule.connectGoogle")]})]})]})]})}function m(e){var t,r;let{year:s,month:a,avail:n,saving:i,rangeStart:d,today:h,onToggle:m,onPrev:g,onNext:b}=e,{locale:f,t:y}=(0,c.Y)(),p=null!=(t=o[f])?t:o.ru,v=null!=(r=x[f])?r:x.ru,j=(new Date(s,a,1).getDay()+6)%7,w=new Date(s,a+1,0).getDate(),N=new Date(s,a,0).getDate(),C=[];for(let e=j-1;e>=0;e--)C.push({day:N-e,cur:!1,dateKey:""});for(let e=1;e<=w;e++)C.push({day:e,cur:!0,dateKey:u(s,a,e)});let S=C.length%7;if(0!==S)for(let e=1;e<=7-S;e++)C.push({day:e,cur:!1,dateKey:""});let D=u(s,a,1).slice(0,7),k=Object.entries(n).filter(e=>{let[t,r]=e;return t.startsWith(D)&&t>=h&&"available"===r}).length,E=Object.entries(n).filter(e=>{let[t,r]=e;return t.startsWith(D)&&t>=h&&"busy"===r}).length;return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-gray-200 overflow-hidden shadow-sm",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-gray-100",children:[(0,l.jsx)("button",{onClick:g,className:"w-8 h-8 rounded-lg hover:bg-gray-100 flex items-center justify-center text-gray-500 transition",children:"‹"}),(0,l.jsxs)("div",{className:"text-center",children:[(0,l.jsxs)("h2",{className:"font-semibold text-gray-900",children:[v[a]," ",s]}),(0,l.jsxs)("p",{className:"text-xs text-gray-400 mt-0.5",children:[(0,l.jsxs)("span",{className:"text-emerald-600 font-medium",children:[k," ",y("schedule.free")]})," \xb7 ",(0,l.jsxs)("span",{className:"text-red-500 font-medium",children:[E," ",y("schedule.busy_count")]})]})]}),(0,l.jsx)("button",{onClick:b,className:"w-8 h-8 rounded-lg hover:bg-gray-100 flex items-center justify-center text-gray-500 transition",children:"›"})]}),(0,l.jsx)("div",{className:"grid grid-cols-7 border-b border-gray-100",children:p.map(e=>(0,l.jsx)("div",{className:"py-2 text-center text-xs font-medium text-gray-400",children:e},e))}),(0,l.jsx)("div",{className:"grid grid-cols-7",children:C.map((e,t)=>{var r;if(!e.cur)return(0,l.jsx)("div",{className:"p-1 h-12 flex items-center justify-center text-sm text-gray-200",children:e.day},"empty-".concat(t));let s=null!=(r=n[e.dateKey])?r:null,a=e.dateKey<h,c=e.dateKey===h,o=i===e.dateKey,x=d===e.dateKey,u="h-12 flex flex-col items-center justify-center rounded-xl m-0.5 text-sm font-medium transition-all select-none ";return a?u+="text-gray-200 cursor-default ":"available"===s?u+="bg-emerald-100 border-2 border-emerald-400 text-emerald-700 cursor-pointer hover:bg-emerald-200 ":"busy"===s?u+="bg-red-100 border-2 border-red-400 text-red-700 cursor-pointer hover:bg-red-200 ":u+="bg-gray-50 border border-gray-200 text-gray-700 cursor-pointer hover:bg-green-50 hover:border-green-300 ",c&&(u+="ring-2 ring-blue-400 ring-offset-1 "),x&&(u+="!ring-2 !ring-green-500 !ring-offset-1 scale-105 "),o&&(u+="opacity-60 pointer-events-none "),(0,l.jsxs)("button",{className:u,onClick:()=>m(e.dateKey),disabled:a||o,title:"available"===s?y("schedule.available"):"busy"===s?y("schedule.busy"):y("schedule.click_to_set"),children:[(0,l.jsx)("span",{children:e.day}),!a&&"available"===s&&(0,l.jsx)("span",{className:"text-[9px] leading-none text-emerald-600",children:y("schedule.available").toLowerCase()}),!a&&"busy"===s&&(0,l.jsx)("span",{className:"text-[9px] leading-none text-red-500",children:y("schedule.busy").toLowerCase()}),o&&(0,l.jsx)("span",{className:"text-[8px] text-gray-400",children:"..."})]},e.dateKey)})})]})}}},e=>{e.O(0,[1516,9906,2982,587,18,7358],()=>e(e.s=2861)),_N_E=e.O()}]);
Save
cmd:
run