Files
nashel-frontend/.next/static/chunks/app/page-38044fb0ac08baf3.js
T

1 line
7.1 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{5792:(e,i,t)=>{Promise.resolve().then(t.t.bind(t,8173,23)),Promise.resolve().then(t.bind(t,401))},401:(e,i,t)=>{"use strict";t.d(i,{PerformerButton:()=>l});var o=t(5155),r=t(3312),a=t(8173),n=t.n(a),s=t(2928);function l(){var e,i;let{isAuth:t,user:a}=(0,s.B)();return(null==a?void 0:null===(e=a.roles)||void 0===e?void 0:e.includes("Master"))||(null==a?void 0:null===(i=a.roles)||void 0===i?void 0:i.includes("Company"))?(0,o.jsx)(r.$,{variant:"outline",size:"lg",className:"h-14 px-8 text-lg",asChild:!0,children:(0,o.jsx)(n(),{href:"/orders",children:"Подобрать заказы"})}):(0,o.jsx)(r.$,{variant:"outline",size:"lg",className:"h-14 px-8 text-lg",asChild:!0,children:(0,o.jsx)(n(),{href:"/dashboard/profile",children:"Стать исполнителем"})})}},3312:(e,i,t)=>{"use strict";t.d(i,{$:()=>c});var o=t(5155),r=t(2115),a=t(2317),n=t(1027),s=t(7549);let l=(0,n.F)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),c=r.forwardRef((e,i)=>{let{className:t,variant:r,size:n,asChild:c=!1,...d}=e,u=c?a.DX:"button";return(0,o.jsx)(u,{className:(0,s.cn)(l({variant:r,size:n,className:t})),ref:i,...d})});c.displayName="Button"},2928:(e,i,t)=>{"use strict";t.d(i,{B:()=>n});var o=t(9827),r=t(3030),a=t(3705);let n=(0,o.v)((e,i)=>({user:null,isAuth:!1,isLoading:!1,isInitialized:!1,checkAuth:async()=>{if(!(0,r.getCookie)("accessToken")){e({isInitialized:!0,isAuth:!1});return}e({isLoading:!0});try{await i().getProfile(),e({isAuth:!0,isInitialized:!0})}catch(i){console.error("Auth check failed",i),(0,r.deleteCookie)("accessToken"),(0,r.deleteCookie)("refreshToken"),e({user:null,isAuth:!1,isInitialized:!0})}finally{e({isLoading:!1})}},login:async(t,o)=>{e({isLoading:!0});try{let{accessToken:n,refreshToken:s}=(await a.F.post("/auth/login",{phone:t,password:o})).data;(0,r.setCookie)("accessToken",n),(0,r.setCookie)("refreshToken",s),e({isAuth:!0}),await i().getProfile()}finally{e({isLoading:!1})}},register:async i=>{e({isLoading:!0});try{let{confirmPassword:e,...t}=i;await a.F.post("/auth/register",t)}finally{e({isLoading:!1})}},logout:()=>{(0,r.deleteCookie)("accessToken"),(0,r.deleteCookie)("refreshToken"),e({user:null,isAuth:!1}),window.location.href="/auth/login"},getProfile:async()=>{try{let i=await a.F.get("/profile",{params:{_t:Date.now()}});e({user:i.data,isAuth:!0})}catch(e){console.error("Profile load failed",e)}},updateProfile:async t=>{e({isLoading:!0});try{await a.F.put("/profile",t),await i().getProfile()}finally{e({isLoading:!1})}},changePhone:async t=>{e({isLoading:!0});try{await a.F.post("/profile/change-phone",{newPhone:t}),await i().getProfile()}finally{e({isLoading:!1})}},becomePerformer:async()=>{e({isLoading:!0});try{await a.F.post("/profile/become-performer"),await i().getProfile()}finally{e({isLoading:!1})}},becomePerformerFull:async t=>{e({isLoading:!0});try{await a.F.post("/profile/become-performer",{description:t.description,competencies:t.competencies,location:t.location,currentLocation:null,isAlwaysReady:t.workSchedule.isAlwaysReady,workingDays:t.workSchedule.isAlwaysReady?null:JSON.stringify(t.workSchedule.schedulePerDay)}),await i().getProfile()}finally{e({isLoading:!1})}},updateCompetencies:async t=>{e({isLoading:!0});try{await a.F.put("/profile/competencies",{Competencies:t}),await i().getProfile()}finally{e({isLoading:!1})}},uploadAvatar:async t=>{e({isLoading:!0});try{let e=new FormData;e.append("file",t),await a.F.post("/profile/avatar",e,{headers:{"Content-Type":"multipart/form-data"}}),await i().getProfile()}finally{e({isLoading:!1})}},changePassword:async(t,o)=>{e({isLoading:!0});try{var r;let e=null===(r=i().user)||void 0===r?void 0:r.id;if(!e)throw Error("Пользователь не авторизован");await a.F.post("/profile/change-password",{accountId:e,oldPassword:t,newPassword:o})}finally{e({isLoading:!1})}},updateLocation:async(t,o)=>{e({isLoading:!0});try{var r;let e=null===(r=i().user)||void 0===r?void 0:r.id;if(!e)throw Error("Пользователь не авторизован");await a.F.put("/profile/location",{accountId:e,location:t,currentLocation:o}),await i().getProfile()}finally{e({isLoading:!1})}},updateSchedule:async(t,o)=>{e({isLoading:!0});try{var r;let e=null===(r=i().user)||void 0===r?void 0:r.id;if(!e)throw Error("Пользователь не авторизован");let n=t?"[]":JSON.stringify(o||{});await a.F.put("/profile/schedule",{accountId:e,isAlwaysReady:t,workingDaysJson:n}),await i().getProfile()}finally{e({isLoading:!1})}}}))},3705:(e,i,t)=>{"use strict";t.d(i,{F:()=>a});var o=t(2651),r=t(3030);let a=o.A.create({baseURL:"http://127.0.0.1:5000/api",headers:{"Content-Type":"application/json"}});a.interceptors.request.use(e=>{let i=(0,r.getCookie)("accessToken");return i&&e.headers&&(e.headers.Authorization="Bearer ".concat(i)),console.log("\uD83D\uDE80 Sending request to: ".concat(e.baseURL).concat(e.url)),e});let n=!1,s=[],l=function(e){let i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;s.forEach(t=>{e?t.reject(e):t.resolve(i)}),s=[]};a.interceptors.response.use(e=>e,async e=>{var i;let t=e.config;if((null===(i=e.response)||void 0===i?void 0:i.status)===401&&!t._retry){if(n)return new Promise((e,i)=>{s.push({resolve:e,reject:i})}).then(e=>(t.headers.Authorization="Bearer ".concat(e),a(t))).catch(e=>Promise.reject(e));t._retry=!0,n=!0;let e=(0,r.getCookie)("refreshToken");try{let{accessToken:i,refreshToken:n}=(await o.A.post("".concat("http://127.0.0.1:5000/api","/auth/refresh"),{refreshToken:e})).data;return(0,r.setCookie)("accessToken",i),(0,r.setCookie)("refreshToken",n),a.defaults.headers.common.Authorization="Bearer ".concat(i),l(null,i),a(t)}catch(e){return l(e,null),(0,r.deleteCookie)("accessToken"),(0,r.deleteCookie)("refreshToken"),window.location.href="/auth/login",Promise.reject(e)}finally{n=!1}}return Promise.reject(e)})},7549:(e,i,t)=>{"use strict";t.d(i,{cn:()=>a,n:()=>n});var o=t(3463),r=t(9795);function a(){for(var e=arguments.length,i=Array(e),t=0;t<e;t++)i[t]=arguments[t];return(0,r.QP)((0,o.$)(i))}function n(e){if(!e)return"—";let i=e.replace(/\D/g,"");if(11===i.length){let e="8"===i[0]?"8":"+7";return"".concat(e," (").concat(i.slice(1,4),") ").concat(i.slice(4,7),"-").concat(i.slice(7,9),"-").concat(i.slice(9,11))}return e}}},e=>{var i=i=>e(e.s=i);e.O(0,[92,173,441,517,358],()=>i(5792)),_N_E=e.O()}]);