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,em as M,bZ as Z,Z as ee,bo as te,er as se,j as C,c as a,eh as E,u as G,z as ne,es as ae,ey as le,ez as ce,eA as B,eB as de,H as R,eC as J,eD as N,cc as O,ca as ue,eE as me,eF as he,aq as fe,eG as ge,af as _e,eH as pe,eI as ke,J as Ce,bX as be,e as X,ba as A,r as ve,bb as Se,en as ye,C as K,eg as Te,bs as Y,c9 as xe,bj as we,h as $e,ac as Ne,cN as Oe,cs as je,ce as F,cd as De}from"./bundle.dc1ed9be.js";import{P as Me}from"./bundle.713cddf4.js";import{T as Ee}from"./bundle.7c351c6f.js";import{C as Ve}from"./bundle.3c467504.js";function W(){return W=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(t[r]=o[r])}return t},W.apply(this,arguments)}function Pe(t,n){if(t==null)return{};var o=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)&&(o[r]=t[r])}return o}function Be(t,n){if(t==null)return{};var o={},r=Object.keys(t),i,e;for(e=0;e<r.length;e++)i=r[e],!(n.indexOf(i)>=0)&&(o[i]=t[i]);return o}var Q=y.forwardRef(function(t,n){var o=t.color,r=o===void 0?"currentColor":o,i=t.size,e=i===void 0?24:i,s=Pe(t,["color","size"]);return z.createElement("svg",W({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"}))});Q.propTypes={color:V.string,size:V.oneOfType([V.string,V.number])};Q.displayName="PauseCircle";const ie=Q;function q(){return q=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var o=arguments[n];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(t[r]=o[r])}return t},q.apply(this,arguments)}function Ye(t,n){if(t==null)return{};var o=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)&&(o[r]=t[r])}return o}function ze(t,n){if(t==null)return{};var o={},r=Object.keys(t),i,e;for(e=0;e<r.length;e++)i=r[e],!(n.indexOf(i)>=0)&&(o[i]=t[i]);return o}var U=y.forwardRef(function(t,n){var o=t.color,r=o===void 0?"currentColor":o,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"}))});U.propTypes={color:V.string,size:V.oneOfType([V.string,V.number])};U.displayName="PlayCircle";const He=U;/**
|
|
* 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 Ie(t,n,o){const r=j(t),i=T(n);let e=p.unix(n).diff(p.unix(t),"seconds");if(!o&&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,o,r,i,e)=>{const s=M(n),d=s[e][I.Start],h=o&&t.show_task_end_date?j(o):j(d||p().unix()),l=p(`${h} ${r}`,"YYYY-MM-DD HH:mm:ss").unix();return s[e][i]=l,JSON.stringify(s)}}function Le(){const t=L();return(n,o,r,i,e)=>{const s=T(o||p().unix()),d=p(`${r} ${s}`,"YYYY-MM-DD HH:mm:ss").unix(),h=M(n);if(h[i][e]=d,t&&!t.show_task_end_date&&h[i][I.End]){const l=T(h[i][I.End]),f=p(`${r} ${l}`,"YYYY-MM-DD HH:mm:ss").unix();h[i][I.End]=f}return JSON.stringify(h)}}function Je(t,n,o,r){let i=p.unix(o);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=M(t);return s[r][1]=i.unix(),JSON.stringify(s)}function Ae({start:t,task:n}){const[o,r]=y.useState(Math.floor(Date.now()/1e3)-t);y.useEffect(()=>{const l=setInterval(()=>{r(f=>f+1)},1e3);return()=>clearInterval(l)},[]),y.useEffect(()=>{r(Math.floor(Date.now()/1e3)-t)},[t]);const i=l=>{const f=w=>String(w).padStart(2,"0"),x=Math.floor(l/3600),D=Math.floor(l%3600/60),b=l%60;return`${f(x)}:${f(D)}:${f(b)}`},e=Z(),s=ee(),d=te(),h=se();return C("span",{className:"flex items-center space-x-2",children:[a("span",{children:i(o)}),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 I=(t=>(t[t.Start=0]="Start",t[t.End=1]="End",t[t.Description=2]="Description",t[t.Billable=3]="Billable",t))(I||{});function Qe(t){const{task:n,handleChange:o}=t,[r]=G(),i=ne(),e=ae(),s=L(),d=Fe(),h=Le(),[l,f]=y.useState(),x=()=>{const c=M(n.time_log),u=c.at(-1);let g=p().unix();u&&u[1]!==0&&(g=u[1]+1),c.push([g,0,"",!0]),o("time_log",JSON.stringify(c))},D=c=>{const u=M(n.time_log);u.splice(c,1),o("time_log",JSON.stringify(u))},b=(c,u,g,S)=>{f(S),o("time_log",d(n.time_log,c,u,g,S))},w=(c,u,g,S)=>{f(g),o("time_log",h(n.time_log,c,u,g,S))},P=(c,u,g)=>{f(g),o("time_log",Je(n.time_log,c,u,g))},k=(c,u,g)=>{const S=M(n.time_log);S[u][g]=c,o("time_log",JSON.stringify(S))},v=(c,u,g)=>{const S=M(n.time_log);S[u][g]=c,o("time_log",JSON.stringify(S))},m=c=>{const u=c.split(":");return u.length===3&&u.every(g=>g.length===2)},H=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 l=="number"){const c=M(n.time_log),u=c[l]&&c[l][0],g=c[l]&&c[l][1];u&&g&&u>g&&(c[l][1]=u,o("time_log",JSON.stringify(c))),f(void 0)}},[l]),C(le,{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(R,{children:[C(J,{children:[a(N,{children:a(O,{style:{color:i.$3,colorScheme:i.$0},type:"date",value:j(c),onValueChange:_=>w(c,H(_)?_: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:_=>b(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,_?H(_)?_: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:_=>b(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:Ie(c,u,s==null?void 0:s.show_task_end_date),onValueChange:_=>P(_,c,$)}):a(Ae,{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:(_,oe)=>v(oe||!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:()=>D($),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(R,{children:[a(he,{size:18})," ",a("span",{children:r("add_item")})]})})})})]})]})}function Re(t){var P;const[n]=G(),o=Z(),{isAdmin:r,isOwner:i}=fe(),[e,s]=y.useState(!1),[d,h]=y.useState(!1),[l,f]=y.useState(),[x,D]=y.useState(),{data:b}=ge({enabled:e}),w=()=>{d||(A.processing(),D(void 0),h(!0),ve("POST",X("/api/v1/task_statuses"),l).then(k=>{A.success("created_task_status"),Se(["task_statuses"]),f(b),t.onChange(k.data.data),s(!1)}).catch(k=>{var v;((v=k.response)==null?void 0:v.status)===422&&(D(k.response.data),A.dismiss())}).finally(()=>h(!1)))};return y.useEffect(()=>{b&&f(b)},[b]),C(R,{children:[C(_e,{title:n("new_task_status"),visible:e,onClose:()=>{s(!1),f(b)},children:[a(O,{required:!0,label:n("name"),value:l==null?void 0:l.name,onValueChange:k=>f(v=>v&&{...v,name:k}),errorMessage:x==null?void 0:x.errors.name}),a(pe,{children:n("color")}),a(ke,{value:(l==null?void 0:l.color)||o,onValueChange:k=>f(v=>v&&{...v,color:k})}),a(Ce,{className:"self-end",behavior:"button",onClick:w,children:n("save")})]}),a(be,{endpoint:X("/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 Ue(t){var w,P,k,v;const[n]=G(),o=ne(),r=ee(),i=te(),{task:e,handleChange:s,errors:d,page:h}=t,l=L(),f=Z(),x=ae(),D=se(),b=ye(e.time_log,{inSeconds:!0,calculateLastTimeLog:!1});return C("div",{className:"grid grid-cols-12 gap-4",children:[C(K,{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)&&b&&a("p",{children:new Date(Number(b)*1e3).toISOString().slice(11,19)})}),!E(e)&&!e.invoice_id&&a(He,{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))&&D(e),cursor:r("edit_task")||i(e)?"pointer":"not-allowed"})]})]}),!e.project_id&&a(Y,{leftSide:n("client"),children:C("div",{className:"flex flex-col space-y-2",children:[a(xe,{onChange:m=>{var H;s("client_id",m.id),e.id||s("rate",((H=m==null?void 0:m.settings)==null?void 0:H.default_task_rate)??0)},value:e.client_id,clearButton:!!e.client_id,onClearButtonClick:()=>s("client_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:o.$3,colorScheme:o.$0},children:a(Me,{onChange:m=>{s("project_id",m.id),s("client_id",""),s("rate",m.task_rate)},value:e.project_id,clearButton:!!e.project_id,onClearButtonClick:()=>s("project_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:o.$3,colorScheme:o.$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=l==null?void 0:l.custom_fields)==null?void 0:w.task1)&&a(F,{field:"task1",defaultValue:e.custom_value1||"",value:l.custom_fields.task1,onValueChange:m=>s("custom_value1",m)}),e&&((P=l==null?void 0:l.custom_fields)==null?void 0:P.task2)&&a(F,{field:"task2",defaultValue:e.custom_value2||"",value:l.custom_fields.task2,onValueChange:m=>s("custom_value2",m)})]}),C(K,{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(De,{value:e.rate,onValueChange:m=>s("rate",parseFloat(m)),errorMessage:d==null?void 0:d.errors.rate})}),a(Y,{leftSide:n("status"),children:a(Re,{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=l==null?void 0:l.custom_fields)==null?void 0:k.task3)&&a(F,{field:"task3",defaultValue:e.custom_value3||"",value:l.custom_fields.task3,onValueChange:m=>s("custom_value3",m)}),e&&((v=l==null?void 0:l.custom_fields)==null?void 0:v.task4)&&a(F,{field:"task4",defaultValue:e.custom_value4||"",value:l.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{I as L,Re as T,Le as a,T as b,Ue as c,Ie as d,Qe as e,Je as h,j as p,Fe as u};
|