Files
nashel-frontend/.next/static/chunks/app/dashboard/offers/create/page-d2c1f3388d421c8e.js
T

1 line
11 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[894],{1731:(e,s,a)=>{Promise.resolve().then(a.bind(a,8704))},8704:(e,s,a)=>{"use strict";a.r(s),a.d(s,{default:()=>V});var t=a(5155),r=a(2115),l=a(6046),n=a(2679),i=a(9606),d=a(534),c=a(3312),o=a(4870),m=a(3900),x=a(7549);let u=r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)("textarea",{className:(0,x.cn)("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",a),ref:s,...r})});u.displayName="Textarea";var p=a(3823),h=a(1719),j=a(1902),f=a(8867),y=a(1567);let g=p.bL;p.YJ;let b=p.WT,v=r.forwardRef((e,s)=>{let{className:a,children:r,...l}=e;return(0,t.jsxs)(p.l9,{ref:s,className:(0,y.cn)("flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",a),...l,children:[r,(0,t.jsx)(p.In,{asChild:!0,children:(0,t.jsx)(h.A,{className:"h-4 w-4 opacity-50"})})]})});v.displayName=p.l9.displayName;let N=r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)(p.PP,{ref:s,className:(0,y.cn)("flex cursor-default items-center justify-center py-1",a),...r,children:(0,t.jsx)(j.A,{className:"h-4 w-4"})})});N.displayName=p.PP.displayName;let w=r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)(p.wn,{ref:s,className:(0,y.cn)("flex cursor-default items-center justify-center py-1",a),...r,children:(0,t.jsx)(h.A,{className:"h-4 w-4"})})});w.displayName=p.wn.displayName;let C=r.forwardRef((e,s)=>{let{className:a,children:r,position:l="popper",...n}=e;return(0,t.jsx)(p.ZL,{children:(0,t.jsxs)(p.UC,{ref:s,className:(0,y.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===l&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",a),position:l,...n,children:[(0,t.jsx)(N,{}),(0,t.jsx)(p.LM,{className:(0,y.cn)("p-1","popper"===l&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:r}),(0,t.jsx)(w,{})]})})});C.displayName=p.UC.displayName,r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)(p.JU,{ref:s,className:(0,y.cn)("px-2 py-1.5 text-sm font-semibold",a),...r})}).displayName=p.JU.displayName;let k=r.forwardRef((e,s)=>{let{className:a,children:r,...l}=e;return(0,t.jsxs)(p.q7,{ref:s,className:(0,y.cn)("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a),...l,children:[(0,t.jsx)("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,t.jsx)(p.VF,{children:(0,t.jsx)(f.A,{className:"h-4 w-4"})})}),(0,t.jsx)(p.p4,{children:r})]})});k.displayName=p.q7.displayName,r.forwardRef((e,s)=>{let{className:a,...r}=e;return(0,t.jsx)(p.wv,{ref:s,className:(0,y.cn)("-mx-1 my-1 h-px bg-muted",a),...r})}).displayName=p.wv.displayName;var R=a(9749),I=a(814),z=a(4505),P=a(3473),A=a(5686),B=a(9384),J=a(2928);let M=d.Ikc({categoryId:d.YjP().min(1,"Выберите категорию"),title:d.YjP().min(5,"Название должно быть минимум из 5 символов").max(100),description:d.YjP().min(10,"Описание должно быть минимум из 10 символов").max(2e3),price:d.Ikc({amount:d.aig().min(1,"Сумма должна быть больше 0"),type:d.aig().int().min(0).max(2)}),attributes:d.YOg(d.Ikc({key:d.YjP().min(1,"Введите название характеристики"),value:d.YjP().min(1,"Введите значение")})).optional()});function V(){let e=(0,l.useRouter)(),{user:s,isAuth:a}=(0,J.B)(),[d,x]=(0,r.useState)([]),[p,h]=(0,r.useState)(!0),[j,f]=(0,r.useState)(!1),y=(0,i.mN)({resolver:(0,n.u)(M),defaultValues:{title:"",description:"",price:{amount:0,type:0},attributes:[{key:"",value:""}]}}),{fields:N,append:w,remove:V}=(0,i.jz)({name:"attributes",control:y.control});async function Y(s){f(!0);try{var a;let t=(null===(a=s.attributes)||void 0===a?void 0:a.reduce((e,s)=>(s.key.trim()&&s.value.trim()&&(e[s.key]=s.value),e),{}))||{};await (0,B.ts)({categoryId:s.categoryId,title:s.title,description:s.description,price:{amount:s.price.amount,type:s.price.type},attributes:t}),I.oR.success("Услуга успешно создана"),e.push("/dashboard/offers")}catch(e){I.oR.error("Не удалось создать услугу. Проверьте данные и попробуйте снова.")}finally{f(!1)}}return((0,r.useEffect)(()=>{var t;if(a){if(!(null==s?void 0:null===(t=s.roles)||void 0===t?void 0:t.some(e=>["Master","Company","Candidate","Admin"].includes(e)))){I.oR.error("Сначала станьте исполнителем, чтобы создавать услуги"),e.push("/dashboard/become-performer");return}(async()=>{try{let e=await (0,B.bW)();x(e||[])}catch(e){I.oR.error("Ошибка загрузки категорий")}finally{h(!1)}})()}},[a,s,e]),p)?(0,t.jsx)("div",{className:"flex justify-center items-center py-20",children:(0,t.jsx)(z.A,{className:"h-8 w-8 animate-spin text-primary"})}):(0,t.jsx)("div",{className:"max-w-2xl mx-auto py-8",children:(0,t.jsxs)(R.Zp,{children:[(0,t.jsxs)(R.aR,{children:[(0,t.jsx)(R.ZB,{className:"text-2xl",children:"Создайте новую услугу"}),(0,t.jsx)(R.BT,{children:"Заполните детали о вашей услуге, чтобы привлечь больше клиентов."})]}),(0,t.jsx)(R.Wu,{children:(0,t.jsx)(o.lV,{...y,children:(0,t.jsxs)("form",{onSubmit:y.handleSubmit(Y),className:"space-y-8",children:[(0,t.jsx)(o.zB,{control:y.control,name:"categoryId",render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{children:[(0,t.jsx)(o.lR,{children:"Категория"}),(0,t.jsxs)(g,{onValueChange:s.onChange,defaultValue:s.value,children:[(0,t.jsx)(o.MJ,{children:(0,t.jsx)(v,{children:(0,t.jsx)(b,{placeholder:"Выберите категорию услуги"})})}),(0,t.jsx)(C,{children:d.map(e=>(0,t.jsx)(k,{value:e.id,children:e.name},e.id))})]}),(0,t.jsx)(o.Rr,{children:"Выберите раздел, в котором клиенты смогут найти вашу услугу."}),(0,t.jsx)(o.C5,{})]})}}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(o.zB,{control:y.control,name:"title",render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{children:[(0,t.jsx)(o.lR,{children:"Название услуги"}),(0,t.jsx)(o.MJ,{children:(0,t.jsx)(m.p,{placeholder:"Например: Ремонт квартир под ключ",...s})}),(0,t.jsx)(o.C5,{})]})}}),(0,t.jsx)(o.zB,{control:y.control,name:"description",render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{children:[(0,t.jsx)(o.lR,{children:"Описание"}),(0,t.jsx)(o.MJ,{children:(0,t.jsx)(u,{placeholder:"Детально опишите, что включает ваша услуга...",className:"min-h-[120px]",...s})}),(0,t.jsx)(o.C5,{})]})}})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsx)(o.zB,{control:y.control,name:"price.amount",render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{children:[(0,t.jsx)(o.lR,{children:"Стоимость (₽)"}),(0,t.jsx)(o.MJ,{children:(0,t.jsx)(m.p,{type:"number",placeholder:"0",...s,onChange:e=>s.onChange(Number(e.target.value))})}),(0,t.jsx)(o.C5,{})]})}}),(0,t.jsx)(o.zB,{control:y.control,name:"price.type",render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{children:[(0,t.jsx)(o.lR,{children:"Тип цены"}),(0,t.jsxs)(g,{onValueChange:e=>s.onChange(parseInt(e)),defaultValue:s.value.toString(),children:[(0,t.jsx)(o.MJ,{children:(0,t.jsx)(v,{children:(0,t.jsx)(b,{placeholder:"Тип оплаты"})})}),(0,t.jsxs)(C,{children:[(0,t.jsx)(k,{value:"0",children:"Фиксированная"}),(0,t.jsx)(k,{value:"1",children:"Почасовая"}),(0,t.jsx)(k,{value:"2",children:"Договорная"})]})]}),(0,t.jsx)(o.C5,{})]})}})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-sm font-medium leading-none mb-1",children:"Дополнительные характеристики"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:'Добавьте важные детали ("Опыт", "Гарантия")'})]}),(0,t.jsxs)(c.$,{type:"button",variant:"outline",size:"sm",onClick:()=>w({key:"",value:""}),children:[(0,t.jsx)(P.A,{className:"mr-2 h-4 w-4"}),"Добавить"]})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[N.map((e,s)=>(0,t.jsxs)("div",{className:"flex gap-3 items-start",children:[(0,t.jsx)(o.zB,{control:y.control,name:"attributes.".concat(s,".key"),render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{className:"flex-1 space-y-0",children:[(0,t.jsx)(o.MJ,{children:(0,t.jsx)(m.p,{placeholder:"Например: Гарантия",...s})}),(0,t.jsx)(o.C5,{})]})}}),(0,t.jsx)(o.zB,{control:y.control,name:"attributes.".concat(s,".value"),render:e=>{let{field:s}=e;return(0,t.jsxs)(o.eI,{className:"flex-1 space-y-0",children:[(0,t.jsx)(o.MJ,{children:(0,t.jsx)(m.p,{placeholder:"Например: 1 год",...s})}),(0,t.jsx)(o.C5,{})]})}}),(0,t.jsx)(c.$,{type:"button",variant:"ghost",size:"icon",className:"text-destructive h-9 w-9 flex-shrink-0",onClick:()=>V(s),children:(0,t.jsx)(A.A,{className:"h-4 w-4"})})]},e.id)),0===N.length&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-4 bg-muted/50 rounded-md border border-dashed",children:"Нет добавленных характеристик"})]})]}),(0,t.jsxs)("div",{className:"flex justify-end pt-4",children:[(0,t.jsx)(c.$,{type:"button",variant:"outline",className:"mr-3",onClick:()=>e.push("/dashboard/offers"),disabled:j,children:"Отмена"}),(0,t.jsx)(c.$,{type:"submit",disabled:j,children:j?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(z.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Сохранение..."]}):"Создать услугу"})]})]})})})]})})}},1567:(e,s,a)=>{"use strict";a.d(s,{cn:()=>l});var t=a(3463),r=a(9795);function l(){for(var e=arguments.length,s=Array(e),a=0;a<e;a++)s[a]=arguments[a];return(0,r.QP)((0,t.$)(s))}},9384:(e,s,a)=>{"use strict";a.d(s,{aT:()=>l,bW:()=>r,ts:()=>n});var t=a(3705);let r=async()=>(await t.F.get("/catalog/categories")).data,l=async()=>(await t.F.get("/catalog/offers/my")).data,n=async e=>(await t.F.post("/catalog/offers",e)).data}},e=>{var s=s=>e(e.s=s);e.O(0,[92,273,814,465,393,975,70,441,517,358],()=>s(1731)),_N_E=e.O()}]);