10 lines
14 KiB
JavaScript
10 lines
14 KiB
JavaScript
import{p as y,R as z,P as V,i as p,x as L,er as D,c0 as U,Z as ee,bp as te,ew as se,j as C,c as a,en as E,u as G,z as ne,ex as ae,eD as oe,eE as ce,eF as B,eG as de,H as W,eH as J,eI as N,cj as O,ch as ue,eJ as me,eK as he,as as fe,eL as ge,ah as _e,eM as pe,eN as ke,J as Ce,b_ as ve,e as Z,bc as R,r as be,a7 as Se,es as ye,C as X,em as Te,bt as Y,cg as xe,bk as we,h as $e,ae as Ne,cU as Oe,cz as je,cl as F,ck as Me}from"./bundle.2fc363c8.js";import{P as De}from"./bundle.fbc7dfd7.js";import{T as Ee}from"./bundle.91b2f03f.js";import{C as Ve}from"./bundle.bc739625.js";function A(){return A=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var l=arguments[n];for(var r in l)Object.prototype.hasOwnProperty.call(l,r)&&(t[r]=l[r])}return t},A.apply(this,arguments)}function Pe(t,n){if(t==null)return{};var l=Be(t,n),r,i;if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);for(i=0;i<e.length;i++)r=e[i],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(l[r]=t[r])}return l}function Be(t,n){if(t==null)return{};var l={},r=Object.keys(t),i,e;for(e=0;e<r.length;e++)i=r[e],!(n.indexOf(i)>=0)&&(l[i]=t[i]);return l}var K=y.forwardRef(function(t,n){var l=t.color,r=l===void 0?"currentColor":l,i=t.size,e=i===void 0?24:i,s=Pe(t,["color","size"]);return z.createElement("svg",A({ref:n,xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},s),z.createElement("circle",{cx:"12",cy:"12",r:"10"}),z.createElement("line",{x1:"10",y1:"15",x2:"10",y2:"9"}),z.createElement("line",{x1:"14",y1:"15",x2:"14",y2:"9"}))});K.propTypes={color:V.string,size:V.oneOfType([V.string,V.number])};K.displayName="PauseCircle";const ie=K;function q(){return q=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var l=arguments[n];for(var r in l)Object.prototype.hasOwnProperty.call(l,r)&&(t[r]=l[r])}return t},q.apply(this,arguments)}function Ye(t,n){if(t==null)return{};var l=ze(t,n),r,i;if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);for(i=0;i<e.length;i++)r=e[i],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(l[r]=t[r])}return l}function ze(t,n){if(t==null)return{};var l={},r=Object.keys(t),i,e;for(e=0;e<r.length;e++)i=r[e],!(n.indexOf(i)>=0)&&(l[i]=t[i]);return l}var Q=y.forwardRef(function(t,n){var l=t.color,r=l===void 0?"currentColor":l,i=t.size,e=i===void 0?24:i,s=Ye(t,["color","size"]);return z.createElement("svg",q({ref:n,xmlns:"http://www.w3.org/2000/svg",width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},s),z.createElement("circle",{cx:"12",cy:"12",r:"10"}),z.createElement("polygon",{points:"10 8 16 12 10 16 10 8"}))});Q.propTypes={color:V.string,size:V.oneOfType([V.string,V.number])};Q.displayName="PlayCircle";const Ie=Q;/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/function j(t){if(t!==0)return p.unix(t).format("YYYY-MM-DD")}function T(t){if(t!==0)return p.unix(t).format("HH:mm:ss")}function He(t,n,l){const r=j(t),i=T(n);let e=p.unix(n).diff(p.unix(t),"seconds");if(!l&&e<0&&n){const s=p(`${r} ${i}`,"YYYY-MM-DD HH:mm:ss").unix();e=p.unix(s).diff(p.unix(t),"seconds")}if(e<0)return"00:00:00";if(n&&r!=="1970-01-01"){let s=Math.floor(e/3600).toString();e-=Number(s)*3600;let d=Math.floor(e/60).toString();e-=Number(d)*60;let h=e.toString();return Number(s)<10&&(s="0"+s.toString()),Number(d)<10&&(d="0"+d.toString()),Number(h)<10&&(h="0"+h.toString()),s+":"+d+":"+h}else return"00:00:00"}function Fe(){const t=L();return(n,l,r,i,e)=>{const s=D(n),d=s[e][H.Start],h=l&&t.show_task_end_date?j(l):j(d||p().unix()),o=p(`${h} ${r}`,"YYYY-MM-DD HH:mm:ss").unix();return s[e][i]=o,JSON.stringify(s)}}function Le(){const t=L();return(n,l,r,i,e)=>{const s=T(l||p().unix()),d=p(`${r} ${s}`,"YYYY-MM-DD HH:mm:ss").unix(),h=D(n);if(h[i][e]=d,t&&!t.show_task_end_date&&h[i][H.End]){const o=T(h[i][H.End]),f=p(`${r} ${o}`,"YYYY-MM-DD HH:mm:ss").unix();h[i][H.End]=f}return JSON.stringify(h)}}function Je(t,n,l,r){let i=p.unix(l);const e=n.split(":");e[0]&&(i=i.add(parseFloat(e[0]),"hour")),e[1]&&(i=i.add(parseFloat(e[1]),"minute")),e[2]&&(i=i.add(parseFloat(e[2]),"second"));const s=D(t);return s[r][1]=i.unix(),JSON.stringify(s)}function Re({start:t,task:n}){const[l,r]=y.useState(Math.floor(Date.now()/1e3)-t);y.useEffect(()=>{const o=setInterval(()=>{r(f=>f+1)},1e3);return()=>clearInterval(o)},[]),y.useEffect(()=>{r(Math.floor(Date.now()/1e3)-t)},[t]);const i=o=>{const f=w=>String(w).padStart(2,"0"),x=Math.floor(o/3600),M=Math.floor(o%3600/60),v=o%60;return`${f(x)}:${f(M)}:${f(v)}`},e=U(),s=ee(),d=te(),h=se();return C("span",{className:"flex items-center space-x-2",children:[a("span",{children:i(l)}),E(n)&&!n.invoice_id&&a(ie,{className:"cursor-pointer",color:"#808080",size:24,stroke:e,strokeWidth:"1",onClick:()=>(s("edit_task")||d(n))&&h(n),cursor:s("edit_task")||d(n)?"pointer":"not-allowed"})]})}var H=(t=>(t[t.Start=0]="Start",t[t.End=1]="End",t[t.Description=2]="Description",t[t.Billable=3]="Billable",t))(H||{});function Ke(t){const{task:n,handleChange:l}=t,[r]=G(),i=ne(),e=ae(),s=L(),d=Fe(),h=Le(),[o,f]=y.useState(),x=()=>{const c=D(n.time_log),u=c.at(-1);let g=p().unix();u&&u[1]!==0&&(g=u[1]+1),c.push([g,0,"",!0]),l("time_log",JSON.stringify(c))},M=c=>{const u=D(n.time_log);u.splice(c,1),l("time_log",JSON.stringify(u))},v=(c,u,g,S)=>{f(S),l("time_log",d(n.time_log,c,u,g,S))},w=(c,u,g,S)=>{f(g),l("time_log",h(n.time_log,c,u,g,S))},P=(c,u,g)=>{f(g),l("time_log",Je(n.time_log,c,u,g))},k=(c,u,g)=>{const S=D(n.time_log);S[u][g]=c,l("time_log",JSON.stringify(S))},b=(c,u,g)=>{const S=D(n.time_log);S[u][g]=c,l("time_log",JSON.stringify(S))},m=c=>{const u=c.split(":");return u.length===3&&u.every(g=>g.length===2)},I=c=>/^\d{4}-\d{2}-\d{2}$/.test(c),re=()=>{let c=4;return s!=null&&s.show_task_end_date&&(c+=1),s!=null&&s.settings.allow_billable_task_items&&(c+=1),c};return y.useEffect(()=>{if(typeof o=="number"){const c=D(n.time_log),u=c[o]&&c[o][0],g=c[o]&&c[o][1];u&&g&&u>g&&(c[o][1]=u,l("time_log",JSON.stringify(c))),f(void 0)}},[o]),C(oe,{children:[C(ce,{children:[a(B,{children:r("start_date")}),a(B,{children:r("start_time")}),(s==null?void 0:s.show_task_end_date)&&a(B,{children:r("end_date")}),a(B,{children:r("end_time")}),a(B,{children:r("duration")}),(s==null?void 0:s.settings.allow_billable_task_items)&&a(B,{children:r("billable")}),a(B,{})]}),C(de,{children:[n.time_log&&JSON.parse(n.time_log).map(([c,u,g,S],$)=>C(W,{children:[C(J,{children:[a(N,{children:a(O,{style:{color:i.$3,colorScheme:i.$0},type:"date",value:j(c),onValueChange:_=>w(c,I(_)?_:j(c)||"",$,0)},`${p().unix().toString()}StartDate`)}),a(N,{children:a(O,{style:{color:i.$3,colorScheme:i.$0},type:"time",step:"1",value:T(c),onValueChange:_=>v(c,m(_)?_:T(c)||"",0,$)},`${p().unix().toString()}StartTime`)}),(s==null?void 0:s.show_task_end_date)&&a(N,{children:a(O,{style:{color:i.$3,colorScheme:i.$0},type:"date",value:j(u),onValueChange:_=>w(u,_?I(_)?_:j(u)||"":j(u)||j(c)||"",$,1)},`${p().unix().toString()}EndDate`)}),a(N,{children:a(O,{style:{color:i.$3,colorScheme:i.$0},type:"time",step:"1",value:T(u),onValueChange:_=>v(u,_?m(_)?_:T(u)||"":T(u)||T(c)||"",1,$)},`${p().unix().toString()}EndTime`)}),a(N,{children:u!==0||n.created_at===0?a(O,{debounceTimeout:1e3,value:He(c,u,s==null?void 0:s.show_task_end_date),onValueChange:_=>P(_,c,$)}):a(Re,{start:c,task:n},`duration-clock-${$}`)}),(s==null?void 0:s.settings.allow_billable_task_items)&&a(N,{children:a(ue,{style:{color:i.$3,colorScheme:i.$0},checked:S||typeof S>"u",onValueChange:(_,le)=>b(le||!1,$,3)})}),a(N,{rowSpan:s!=null&&s.settings.show_task_item_description?2:1,children:a("button",{style:{color:i.$3},className:"ml-2 text-gray-600 hover:text-red-600",onClick:()=>M($),children:a(me,{size:18})})})]}),(s==null?void 0:s.settings.show_task_item_description)&&a(J,{children:a(N,{colSpan:re(),children:a(O,{element:"textarea",textareaRows:2,value:g,onValueChange:_=>k(_,$,2)})})})]})),a(J,{className:"bg-slate-100 hover:bg-slate-200",children:a(N,{colSpan:100,children:a("button",{onClick:()=>n.created_at?e(n):x(),className:"w-full py-2 inline-flex justify-center items-center space-x-2 disabled:cursor-not-allowed",disabled:E(n)&&n.created_at!==0,children:E(n)&&n.created_at!==0?a("span",{children:r("stop_task_to_add_task_entry")}):C(W,{children:[a(he,{size:18})," ",a("span",{children:r("add_item")})]})})})})]})]})}function We(t){var P;const[n]=G(),l=U(),{isAdmin:r,isOwner:i}=fe(),[e,s]=y.useState(!1),[d,h]=y.useState(!1),[o,f]=y.useState(),[x,M]=y.useState(),{data:v}=ge({enabled:e}),w=()=>{d||(R.processing(),M(void 0),h(!0),be("POST",Z("/api/v1/task_statuses"),o).then(k=>{R.success("created_task_status"),Se(["task_statuses"]),f(v),t.onChange(k.data.data),s(!1)}).catch(k=>{var b;((b=k.response)==null?void 0:b.status)===422&&(M(k.response.data),R.dismiss())}).finally(()=>h(!1)))};return y.useEffect(()=>{v&&f(v)},[v]),C(W,{children:[C(_e,{title:n("new_task_status"),visible:e,onClose:()=>{s(!1),f(v)},children:[a(O,{required:!0,label:n("name"),value:o==null?void 0:o.name,onValueChange:k=>f(b=>b&&{...b,name:k}),errorMessage:x==null?void 0:x.errors.name}),a(pe,{children:n("color")}),a(ke,{value:(o==null?void 0:o.color)||l,onValueChange:k=>f(b=>b&&{...b,color:k})}),a(Ce,{className:"self-end",behavior:"button",onClick:w,children:n("save")})]}),a(ve,{endpoint:Z("/api/v1/task_statuses?status=active"),onChange:k=>k.resource&&t.onChange(k.resource),inputOptions:{label:(P=t.inputLabel)==null?void 0:P.toString(),value:t.value||null},entryOptions:{id:"id",label:"name",value:"id"},action:{label:n("new_task_status"),onClick:()=>s(!0),visible:r||i},onDismiss:t.onClearButtonClick,readonly:t.readonly,errorMessage:t.errorMessage})]})}function Qe(t){var w,P,k,b;const[n]=G(),l=ne(),r=ee(),i=te(),{task:e,handleChange:s,errors:d,page:h}=t,o=L(),f=U(),x=ae(),M=se(),v=ye(e.time_log,{inSeconds:!0,calculateLastTimeLog:!1});return C("div",{className:"grid grid-cols-12 gap-4",children:[C(X,{className:"col-span-12 xl:col-span-6 h-max",children:[e&&h==="edit"&&C("div",{className:"flex items-center justify-between px-5",children:[a(Te,{entity:e}),C("div",{className:"flex items-center gap-3",children:[E(e)&&a("div",{className:"flex items-center",children:a(Ee,{task:e})}),!E(e)&&a("div",{className:"flex items-center",children:!E(e)&&v&&a("p",{children:new Date(Number(v)*1e3).toISOString().slice(11,19)})}),!E(e)&&!e.invoice_id&&a(Ie,{className:"mr-0 ml-auto",color:"#808080",size:60,stroke:f,strokeWidth:"1",onClick:()=>(r("edit_task")||i(e))&&x(e),cursor:r("edit_task")||i(e)?"pointer":"not-allowed"}),E(e)&&!e.invoice_id&&a(ie,{className:"mr-0 ml-auto cursor-pointer",color:"#808080",size:60,stroke:f,strokeWidth:"1",onClick:()=>(r("edit_task")||i(e))&&M(e),cursor:r("edit_task")||i(e)?"pointer":"not-allowed"})]})]}),a(Y,{leftSide:n("client"),children:C("div",{className:"flex flex-col space-y-2",children:[a(xe,{onChange:m=>{var I;s("client_id",m.id),e.id||s("rate",((I=m==null?void 0:m.settings)==null?void 0:I.default_task_rate)??0)},value:e.client_id,clearButton:!!e.client_id,onClearButtonClick:()=>s("client_id",""),readonly:!!e.project_id,errorMessage:d==null?void 0:d.errors.client_id}),e.client_id&&a(Ve,{clientId:e.client_id})]})}),a(Y,{leftSide:n("project"),children:C("div",{className:"flex items-center justify-center",children:[a("span",{className:"flex flex-1 item-center gap-2",style:{color:l.$3,colorScheme:l.$0},children:a(De,{onChange:m=>{s("project_id",m.id),s("client_id",m.client_id),s("rate",m.task_rate)},value:e.project_id,clientId:e.client_id,clearButton:!!e.project_id,onClearButtonClick:()=>{s("project_id",""),s("client_id","")},errorMessage:d==null?void 0:d.errors.project_id})}),(e==null?void 0:e.project_id)&&a("span",{className:"flex item-center gap-2 pl-2",style:{color:l.$3,colorScheme:l.$0},children:a(we,{to:$e("/projects/:id",{id:e.project_id}),children:a(Ne,{element:Oe,size:18})})})]})}),a(Y,{leftSide:n("user"),children:a(je,{value:e==null?void 0:e.assigned_user_id,onChange:m=>s("assigned_user_id",m.id),onClearButtonClick:()=>s("assigned_user_id",""),errorMessage:d==null?void 0:d.errors.assigned_user_id,readonly:!r("edit_task")})}),e&&((w=o==null?void 0:o.custom_fields)==null?void 0:w.task1)&&a(F,{field:"task1",defaultValue:e.custom_value1||"",value:o.custom_fields.task1,onValueChange:m=>s("custom_value1",m)}),e&&((P=o==null?void 0:o.custom_fields)==null?void 0:P.task2)&&a(F,{field:"task2",defaultValue:e.custom_value2||"",value:o.custom_fields.task2,onValueChange:m=>s("custom_value2",m)})]}),C(X,{className:"col-span-12 xl:col-span-6 h-max",children:[a(Y,{leftSide:n("task_number"),children:a(O,{value:e.number,onValueChange:m=>s("number",m),errorMessage:d==null?void 0:d.errors.number})}),a(Y,{leftSide:n("rate"),children:a(Me,{value:e.rate,onValueChange:m=>s("rate",parseFloat(m)),errorMessage:d==null?void 0:d.errors.rate})}),a(Y,{leftSide:n("status"),children:a(We,{value:e.status_id,onChange:m=>m&&s("status_id",m.id),onClearButtonClick:()=>s("status_id",""),readonly:t.taskModal,errorMessage:d==null?void 0:d.errors.status_id})}),e&&((k=o==null?void 0:o.custom_fields)==null?void 0:k.task3)&&a(F,{field:"task3",defaultValue:e.custom_value3||"",value:o.custom_fields.task3,onValueChange:m=>s("custom_value3",m)}),e&&((b=o==null?void 0:o.custom_fields)==null?void 0:b.task4)&&a(F,{field:"task4",defaultValue:e.custom_value4||"",value:o.custom_fields.task4,onValueChange:m=>s("custom_value4",m)}),a(Y,{leftSide:n("description"),children:a(O,{element:"textarea",value:e.description,onValueChange:m=>s("description",m),errorMessage:d==null?void 0:d.errors.description})})]})]})}export{H as L,We as T,Le as a,T as b,Qe as c,He as d,Ke as e,Je as h,j as p,Fe as u};
|